Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
e13e31f7
Unverified
Commit
e13e31f7
authored
Dec 30, 2017
by
Mihai Moldovan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'uli42-pr/fix_abstract' into 3.6.x
Attributes GH PR #615:
https://github.com/ArcticaProject/nx-libs/pull/615
Fixes: ArcticaProject/nx-libs#612 Fixes: ArcticaProject/nx-libs#572
parents
2d44051a
367bec59
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
168 additions
and
102 deletions
+168
-102
Auth.cpp
nxcomp/src/Auth.cpp
+4
-10
ChannelEndPoint.cpp
nxcomp/src/ChannelEndPoint.cpp
+23
-11
Children.cpp
nxcomp/src/Children.cpp
+9
-10
EncodeBuffer.cpp
nxcomp/src/EncodeBuffer.cpp
+16
-1
Loop.cpp
nxcomp/src/Loop.cpp
+109
-57
Proxy.cpp
nxcomp/src/Proxy.cpp
+7
-13
No files found.
nxcomp/src/Auth.cpp
View file @
e13e31f7
...
@@ -212,16 +212,14 @@ int Auth::getCookie()
...
@@ -212,16 +212,14 @@ int Auth::getCookie()
if
(
environment
!=
NULL
&&
*
environment
!=
'\0'
)
if
(
environment
!=
NULL
&&
*
environment
!=
'\0'
)
{
{
s
trncpy
(
file_
,
environment
,
DEFAULT_STRING_LIMIT
-
1
);
s
nprintf
(
file_
,
DEFAULT_STRING_LIMIT
,
"%s"
,
environment
);
}
}
else
else
{
{
snprintf
(
file_
,
DEFAULT_STRING_LIMIT
-
1
,
"%s/.Xauthority"
,
snprintf
(
file_
,
DEFAULT_STRING_LIMIT
,
"%s/.Xauthority"
,
control
->
HomePath
);
control
->
HomePath
);
}
}
*
(
file_
+
DEFAULT_STRING_LIMIT
-
1
)
=
'\0'
;
#ifdef TEST
#ifdef TEST
*
logofs
<<
"Auth: Using X authorization file '"
<<
file_
*
logofs
<<
"Auth: Using X authorization file '"
<<
file_
<<
"'.
\n
"
<<
logofs_flush
;
<<
"'.
\n
"
<<
logofs_flush
;
...
@@ -242,18 +240,14 @@ int Auth::getCookie()
...
@@ -242,18 +240,14 @@ int Auth::getCookie()
#if defined(__CYGWIN32__)
#if defined(__CYGWIN32__)
snprintf
(
command
,
DEFAULT_STRING_LIMIT
-
1
,
snprintf
(
command
,
DEFAULT_STRING_LIMIT
,
"%s/bin/nxauth"
,
control
->
SystemPath
);
"%s/bin/nxauth"
,
control
->
SystemPath
);
*
(
command
+
DEFAULT_STRING_LIMIT
-
1
)
=
'\0'
;
#elif defined(__APPLE__)
#elif defined(__APPLE__)
snprintf
(
command
,
DEFAULT_STRING_LIMIT
-
1
,
snprintf
(
command
,
DEFAULT_STRING_LIMIT
,
"%s/nxauth"
,
control
->
SystemPath
);
"%s/nxauth"
,
control
->
SystemPath
);
*
(
command
+
DEFAULT_STRING_LIMIT
-
1
)
=
'\0'
;
#else
#else
strcpy
(
command
,
"xauth"
);
strcpy
(
command
,
"xauth"
);
...
...
nxcomp/src/ChannelEndPoint.cpp
View file @
e13e31f7
...
@@ -113,13 +113,19 @@ ChannelEndPoint::setSpec(const char *hostName, long port) {
...
@@ -113,13 +113,19 @@ ChannelEndPoint::setSpec(const char *hostName, long port) {
bool
bool
ChannelEndPoint
::
getSpec
(
char
**
socketUri
)
const
{
ChannelEndPoint
::
getSpec
(
char
**
socketUri
)
const
{
if
(
socketUri
)
*
socketUri
=
NULL
;
if
(
socketUri
)
{
*
socketUri
=
NULL
;
}
else
{
return
false
;
}
char
*
unixPath
=
NULL
;
char
*
unixPath
=
NULL
;
char
*
hostName
=
NULL
;
char
*
hostName
=
NULL
;
long
port
=
-
1
;
long
port
=
-
1
;
char
*
newSocketUri
=
NULL
;
int
length
=
-
1
;
int
length
=
-
1
;
if
(
getUnixPath
(
&
unixPath
))
if
(
getUnixPath
(
&
unixPath
))
...
@@ -133,17 +139,21 @@ ChannelEndPoint::getSpec(char **socketUri) const {
...
@@ -133,17 +139,21 @@ ChannelEndPoint::getSpec(char **socketUri) const {
if
(
length
>
0
)
if
(
length
>
0
)
{
{
newSocketUri
=
static_cast
<
char
*>
(
calloc
(
length
+
1
,
sizeof
(
char
)));
char
*
newSocketUri
=
static_cast
<
char
*>
(
calloc
(
length
+
1
,
sizeof
(
char
)));
if
(
newSocketUri
)
{
if
(
isUnixSocket
())
if
(
isUnixSocket
())
snprintf
(
newSocketUri
,
length
+
1
,
"unix:%s"
,
unixPath
);
snprintf
(
newSocketUri
,
length
+
1
,
"unix:%s"
,
unixPath
);
else
else
snprintf
(
newSocketUri
,
length
+
1
,
"tcp:%s:%ld"
,
hostName
,
port
);
snprintf
(
newSocketUri
,
length
+
1
,
"tcp:%s:%ld"
,
hostName
,
port
);
if
(
socketUri
)
*
socketUri
=
strdup
(
newSocketUri
);
*
socketUri
=
strdup
(
newSocketUri
);
}
SAFE_FREE
(
newSocketUri
);
SAFE_FREE
(
newSocketUri
);
}
}
SAFE_FREE
(
unixPath
);
SAFE_FREE
(
unixPath
);
SAFE_FREE
(
hostName
);
SAFE_FREE
(
hostName
);
...
@@ -170,8 +180,6 @@ ChannelEndPoint::setDefaultUnixPath(char *path) {
...
@@ -170,8 +180,6 @@ ChannelEndPoint::setDefaultUnixPath(char *path) {
if
(
path
&&
strlen
(
path
))
if
(
path
&&
strlen
(
path
))
defaultUnixPath_
=
strdup
(
path
);
defaultUnixPath_
=
strdup
(
path
);
else
defaultUnixPath_
=
NULL
;
isUnix_
=
getUnixPath
();
isUnix_
=
getUnixPath
();
}
}
...
@@ -199,7 +207,10 @@ ChannelEndPoint::getPort(long *port) const {
...
@@ -199,7 +207,10 @@ ChannelEndPoint::getPort(long *port) const {
bool
bool
ChannelEndPoint
::
getUnixPath
(
char
**
unixPath
)
const
{
ChannelEndPoint
::
getUnixPath
(
char
**
unixPath
)
const
{
if
(
unixPath
)
*
unixPath
=
NULL
;
if
(
unixPath
)
*
unixPath
=
NULL
;
else
return
false
;
long
p
;
long
p
;
char
*
path
=
NULL
;
char
*
path
=
NULL
;
...
@@ -219,7 +230,6 @@ ChannelEndPoint::getUnixPath(char **unixPath) const {
...
@@ -219,7 +230,6 @@ ChannelEndPoint::getUnixPath(char **unixPath) const {
return
false
;
return
false
;
}
}
if
(
unixPath
)
*
unixPath
=
strdup
(
path
);
*
unixPath
=
strdup
(
path
);
return
true
;
return
true
;
...
@@ -263,8 +273,10 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const {
...
@@ -263,8 +273,10 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const {
char
*
h
=
NULL
;
char
*
h
=
NULL
;
ssize_t
h_len
;
ssize_t
h_len
;
if
(
host
)
*
host
=
NULL
;
if
(
host
)
if
(
port
)
*
port
=
0
;
*
host
=
NULL
;
if
(
port
)
*
port
=
0
;
if
(
getPort
(
&
p
))
{
if
(
getPort
(
&
p
))
{
h_len
=
0
;
h_len
=
0
;
...
...
nxcomp/src/Children.cpp
View file @
e13e31f7
...
@@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message,
...
@@ -275,12 +275,14 @@ int NXTransDialog(const char *caption, const char *message,
#ifdef __APPLE__
#ifdef __APPLE__
// FIXME: missing length limitation!
strcat
(
newPath
,
"/Applications/NX Client for OSX.app/Contents/MacOS:"
);
strcat
(
newPath
,
"/Applications/NX Client for OSX.app/Contents/MacOS:"
);
#endif
#endif
#ifdef __CYGWIN32__
#ifdef __CYGWIN32__
// FIXME: missing length limitation!
strcat
(
newPath
,
".:"
);
strcat
(
newPath
,
".:"
);
#endif
#endif
...
@@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message,
...
@@ -289,9 +291,8 @@ int NXTransDialog(const char *caption, const char *message,
char
*
oldPath
=
getenv
(
"PATH"
);
char
*
oldPath
=
getenv
(
"PATH"
);
strncpy
(
newPath
+
newLength
,
oldPath
,
DEFAULT_STRING_LIMIT
-
newLength
-
1
);
// FIXME: check if strncat would be better here
snprintf
(
newPath
+
newLength
,
DEFAULT_STRING_LIMIT
-
newLength
,
"%s"
,
oldPath
);
newPath
[
DEFAULT_STRING_LIMIT
-
1
]
=
'\0'
;
#ifdef WARNING
#ifdef WARNING
*
logofs
<<
"NXTransDialog: WARNING! Trying with path '"
*
logofs
<<
"NXTransDialog: WARNING! Trying with path '"
...
@@ -427,17 +428,13 @@ int NXTransClient(const char* display)
...
@@ -427,17 +428,13 @@ int NXTransClient(const char* display)
#ifdef __sun
#ifdef __sun
snprintf
(
newDisplay
,
DISPLAY_LENGTH_LIMIT
-
1
,
"DISPLAY=%s"
,
display
);
snprintf
(
newDisplay
,
DISPLAY_LENGTH_LIMIT
,
"DISPLAY=%s"
,
display
);
newDisplay
[
DISPLAY_LENGTH_LIMIT
-
1
]
=
'\0'
;
putenv
(
newDisplay
);
putenv
(
newDisplay
);
#else
#else
strncpy
(
newDisplay
,
display
,
DISPLAY_LENGTH_LIMIT
-
1
);
snprintf
(
newDisplay
,
DISPLAY_LENGTH_LIMIT
,
"%s"
,
display
);
newDisplay
[
DISPLAY_LENGTH_LIMIT
-
1
]
=
'\0'
;
setenv
(
"DISPLAY"
,
newDisplay
,
1
);
setenv
(
"DISPLAY"
,
newDisplay
,
1
);
...
@@ -467,6 +464,7 @@ int NXTransClient(const char* display)
...
@@ -467,6 +464,7 @@ int NXTransClient(const char* display)
if
(
i
==
0
)
if
(
i
==
0
)
{
{
// FIXME: code dpulication: this whole block is duplicated in NXTransDialog
strcpy
(
command
,
"nxclient"
);
strcpy
(
command
,
"nxclient"
);
char
newPath
[
DEFAULT_STRING_LIMIT
];
char
newPath
[
DEFAULT_STRING_LIMIT
];
...
@@ -489,7 +487,8 @@ int NXTransClient(const char* display)
...
@@ -489,7 +487,8 @@ int NXTransClient(const char* display)
char
*
oldPath
=
getenv
(
"PATH"
);
char
*
oldPath
=
getenv
(
"PATH"
);
strncpy
(
newPath
+
newLength
,
oldPath
,
DEFAULT_STRING_LIMIT
-
newLength
-
1
);
// FIXME: check if strncat would be better here
snprintf
(
newPath
+
newLength
,
DEFAULT_STRING_LIMIT
-
newLength
,
"%s"
,
oldPath
);
newPath
[
DEFAULT_STRING_LIMIT
-
1
]
=
'\0'
;
newPath
[
DEFAULT_STRING_LIMIT
-
1
]
=
'\0'
;
...
...
nxcomp/src/EncodeBuffer.cpp
View file @
e13e31f7
...
@@ -70,6 +70,13 @@ EncodeBuffer::EncodeBuffer()
...
@@ -70,6 +70,13 @@ EncodeBuffer::EncodeBuffer()
initialSize_
=
ENCODE_BUFFER_DEFAULT_SIZE
;
initialSize_
=
ENCODE_BUFFER_DEFAULT_SIZE
;
thresholdSize_
=
ENCODE_BUFFER_DEFAULT_SIZE
<<
1
;
thresholdSize_
=
ENCODE_BUFFER_DEFAULT_SIZE
<<
1
;
maximumSize_
=
ENCODE_BUFFER_DEFAULT_SIZE
<<
4
;
maximumSize_
=
ENCODE_BUFFER_DEFAULT_SIZE
<<
4
;
#ifdef VALGRIND
memset
(
buffer_
,
'\0'
,
size_
);
#endif
}
}
EncodeBuffer
::~
EncodeBuffer
()
EncodeBuffer
::~
EncodeBuffer
()
...
@@ -101,7 +108,15 @@ void EncodeBuffer::fullReset()
...
@@ -101,7 +108,15 @@ void EncodeBuffer::fullReset()
size_
=
initialSize_
;
size_
=
initialSize_
;
buffer_
=
new
unsigned
char
[
size_
+
ENCODE_BUFFER_PREFIX_SIZE
+
buffer_
=
new
unsigned
char
[
size_
+
ENCODE_BUFFER_PREFIX_SIZE
+
ENCODE_BUFFER_POSTFIX_SIZE
]
+
ENCODE_BUFFER_PREFIX_SIZE
;
ENCODE_BUFFER_POSTFIX_SIZE
];
#ifdef VALGRIND
memset
(
buffer_
,
'\0'
,
size_
+
ENCODE_BUFFER_PREFIX_SIZE
+
ENCODE_BUFFER_POSTFIX_SIZE
);
#endif
buffer_
+=
ENCODE_BUFFER_PREFIX_SIZE
;
}
}
end_
=
buffer_
+
size_
;
end_
=
buffer_
+
size_
;
...
...
nxcomp/src/Loop.cpp
View file @
e13e31f7
...
@@ -55,6 +55,8 @@
...
@@ -55,6 +55,8 @@
#include "Misc.h"
#include "Misc.h"
#include <cstddef>
#ifdef __sun
#ifdef __sun
#include <strings.h>
#include <strings.h>
#endif
#endif
...
@@ -3141,6 +3143,9 @@ int InitBeforeNegotiation()
...
@@ -3141,6 +3143,9 @@ int InitBeforeNegotiation()
// Get ready to open the local display.
// Get ready to open the local display.
//
//
delete
xServerAddr
;
xServerAddr
=
NULL
;
SetupDisplaySocket
(
xServerAddrFamily
,
xServerAddr
,
xServerAddrLength
);
SetupDisplaySocket
(
xServerAddrFamily
,
xServerAddr
,
xServerAddrLength
);
}
}
...
@@ -3587,19 +3592,14 @@ int SetupAuthInstance()
...
@@ -3587,19 +3592,14 @@ int SetupAuthInstance()
launchdAddrUnix
.
sun_family
=
AF_UNIX
;
launchdAddrUnix
.
sun_family
=
AF_UNIX
;
#ifdef __linux__
// determine the maximum number of characters that fit into struct
const
int
launchdAddrNameLength
=
108
;
// sockaddr_un's sun_path member
#else
std
::
size_t
launchdAddrNameLength
=
/* POSIX/SUS does not specify a length.
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
* BSD derivatives generally support 104 bytes, other systems may be more constrained.
* If you happen to run into such systems, extend this section with the appropriate limit.
*/
const
int
launchdAddrNameLength
=
104
;
#endif
int
success
=
-
1
;
int
success
=
-
1
;
s
trncpy
(
launchdAddrUnix
.
sun_path
,
displayHost
,
launchdAddrNameLength
);
s
nprintf
(
launchdAddrUnix
.
sun_path
,
launchdAddrNameLength
,
"%s"
,
displayHost
);
*
(
launchdAddrUnix
.
sun_path
+
launchdAddrNameLength
-
1
)
=
'\0'
;
*
(
launchdAddrUnix
.
sun_path
+
launchdAddrNameLength
-
1
)
=
'\0'
;
...
@@ -3780,13 +3780,13 @@ void SetupUnixSocket()
...
@@ -3780,13 +3780,13 @@ void SetupUnixSocket()
// The following is a dumb copy-paste. The
// The following is a dumb copy-paste. The
// nxcompsh library should offer a better
// nxcompsh library should offer a better
// implementation.
// implementation.
// addr is assumed to have been freed outside
//
//
void
SetupDisplaySocket
(
int
&
addr_family
,
sockaddr
*&
addr
,
void
SetupDisplaySocket
(
int
&
addr_family
,
sockaddr
*&
addr
,
unsigned
int
&
addr_length
)
unsigned
int
&
addr_length
)
{
{
addr_family
=
AF_INET
;
addr_family
=
AF_INET
;
addr
=
NULL
;
addr_length
=
0
;
addr_length
=
0
;
char
*
display
;
char
*
display
;
...
@@ -3858,7 +3858,8 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3858,7 +3858,8 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
#ifdef __APPLE__
#ifdef __APPLE__
if
((
strncasecmp
(
display
,
"/tmp/launch"
,
11
)
==
0
)
||
(
strncasecmp
(
display
,
"/private/tmp/com.apple.launchd"
,
30
)
==
0
))
if
((
strncasecmp
(
display
,
"/tmp/launch"
,
11
)
==
0
)
||
(
strncasecmp
(
display
,
"/private/tmp/com.apple.launchd"
,
30
)
==
0
))
{
{
nxinfo
<<
"Loop: Using launchd service on socket '"
nxinfo
<<
"Loop: Using launchd service on socket '"
<<
display
<<
"'.
\n
"
<<
std
::
flush
;
<<
display
<<
"'.
\n
"
<<
std
::
flush
;
...
@@ -3877,6 +3878,8 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3877,6 +3878,8 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
cerr
<<
"Error"
<<
": Invalid display '"
<<
display
<<
"'.
\n
"
;
cerr
<<
"Error"
<<
": Invalid display '"
<<
display
<<
"'.
\n
"
;
delete
[]
display
;
HandleCleanup
();
HandleCleanup
();
}
}
...
@@ -3903,13 +3906,15 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3903,13 +3906,15 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
// UNIX domain port.
// UNIX domain port.
//
//
// determine the maximum number of characters that fit into struct
// sockaddr_un's sun_path member
std
::
size_t
maxlen_un
=
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
nxinfo
<<
"Loop: Using real X server on UNIX domain socket.
\n
"
nxinfo
<<
"Loop: Using real X server on UNIX domain socket.
\n
"
<<
std
::
flush
;
<<
std
::
flush
;
sockaddr_un
*
xServerAddrUNIX
=
new
sockaddr_un
;
addr_family
=
AF_UNIX
;
addr_family
=
AF_UNIX
;
xServerAddrUNIX
->
sun_family
=
AF_UNIX
;
//
//
// The scope of this function is to fill either the sockaddr_un
// The scope of this function is to fill either the sockaddr_un
...
@@ -3929,40 +3934,68 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3929,40 +3934,68 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
// fall back to Unix domain socket file.
// fall back to Unix domain socket file.
#ifdef __linux__
#ifdef __linux__
int
testSocketFD
;
int
testSocketFD
=
socket
(
addr_family
,
SOCK_STREAM
,
PF_UNSPEC
);
testSocketFD
=
socket
(
addr_family
,
SOCK_STREAM
,
PF_UNSPEC
);
int
len
=
sprintf
(
unixSocketName
+
1
,
"/tmp/.X11-unix/X%d"
,
xPort
);
// this name cannot be changed as it is defined this way by the
// local X server
int
len
=
snprintf
(
unixSocketName
+
1
,
DEFAULT_STRING_LENGTH
-
1
,
"/tmp/.X11-unix/X%d"
,
xPort
);
unixSocketName
[
0
]
=
'\0'
;
unixSocketName
[
0
]
=
'\0'
;
sockaddr_un
*
xServerAddrABSTRACT
=
new
sockaddr_un
;
sockaddr_un
*
xServerAddrABSTRACT
=
new
sockaddr_un
;
memset
(
xServerAddrABSTRACT
,
0
,
addr_length
);
memset
(
xServerAddrABSTRACT
,
0
,
sizeof
(
struct
sockaddr_un
)
);
xServerAddrABSTRACT
->
sun_family
=
AF_UNIX
;
xServerAddrABSTRACT
->
sun_family
=
AF_UNIX
;
memcpy
(
xServerAddrABSTRACT
->
sun_path
,
unixSocketName
,
len
+
1
);
addr_length
=
len
+
3
;
int
ret
=
connect
(
testSocketFD
,
(
struct
sockaddr
*
)
xServerAddrABSTRACT
,
addr_length
);
if
(
maxlen_un
<
(
unsigned
int
)
len
+
1
)
{
nxfatal
<<
"Loop: PANIC! Abstract socket name '"
<<
unixSocketName
+
1
<<
"' is too long!"
<<
std
::
flush
;
delete
[]
display
;
delete
xServerAddrABSTRACT
;
HandleCleanup
();
}
// copy including the leading '\0'
memcpy
(
xServerAddrABSTRACT
->
sun_path
,
unixSocketName
,
len
+
1
);
// man 7 unix:
// "an abstract socket address is distinguished (from a
// pathname socket) by the fact that sun_path[0] is a null byte
// ('\0'). The socket's address in this namespace is given by the
// additional bytes in sun_path that are covered by the specified
// length of the address structure."
addr_length
=
offsetof
(
struct
sockaddr_un
,
sun_path
)
+
len
+
1
;
int
ret
=
connect
(
testSocketFD
,
(
struct
sockaddr
*
)
xServerAddrABSTRACT
,
addr_length
);
close
(
testSocketFD
);
if
(
ret
==
0
)
{
if
(
ret
==
0
)
{
cerr
<<
"Info"
<<
": Using abstract X11 socket in kernel namespace "
cerr
<<
"Info"
<<
": Using abstract X11 socket in kernel namespace "
<<
"for accessing DISPLAY=:"
<<
xPort
<<
".
\n
"
;
<<
"for accessing DISPLAY=:"
<<
xPort
<<
".
\n
"
;
close
(
testSocketFD
);
addr
=
(
sockaddr
*
)
xServerAddrABSTRACT
;
addr
=
(
sockaddr
*
)
xServerAddrABSTRACT
;
delete
[]
display
;
return
;
return
;
}
else
{
}
cerr
<<
"Info"
<<
": Falling back to file system X11 socket "
cerr
<<
"Info"
<<
": Falling back to file system X11 socket "
<<
"for accessing DISPLAY=:"
<<
xPort
<<
".
\n
"
;
<<
"for accessing DISPLAY=:"
<<
xPort
<<
".
\n
"
;
#endif
delete
xServerAddrABSTRACT
;
#endif
struct
stat
statInfo
;
struct
stat
statInfo
;
char
unixSocketDir
[
DEFAULT_STRING_LENGTH
];
char
unixSocketDir
[
DEFAULT_STRING_LENGTH
];
snprintf
(
unixSocketDir
,
DEFAULT_STRING_LENGTH
-
1
,
"/tmp/.X11-unix"
);
snprintf
(
unixSocketDir
,
DEFAULT_STRING_LENGTH
,
"/tmp/.X11-unix"
);
#ifdef __APPLE__
#ifdef __APPLE__
...
@@ -3975,7 +4008,7 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -3975,7 +4008,7 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
*
slash
=
'\0'
;
*
slash
=
'\0'
;
}
}
snprintf
(
unixSocketDir
,
DEFAULT_STRING_LENGTH
-
1
,
"%s"
,
display
);
snprintf
(
unixSocketDir
,
DEFAULT_STRING_LENGTH
,
"%s"
,
display
);
}
}
#endif
#endif
...
@@ -4000,16 +4033,18 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -4000,16 +4033,18 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
cerr
<<
"Error"
<<
": Error "
<<
EGET
()
<<
" '"
<<
ESTR
()
cerr
<<
"Error"
<<
": Error "
<<
EGET
()
<<
" '"
<<
ESTR
()
<<
"' checking '"
<<
unixSocketDir
<<
"'.
\n
"
;
<<
"' checking '"
<<
unixSocketDir
<<
"'.
\n
"
;
delete
[]
display
;
HandleCleanup
();
HandleCleanup
();
}
}
sprintf
(
unixSocketName
,
"%s/X%d"
,
unixSocketDir
,
xPort
);
snprintf
(
unixSocketName
,
DEFAULT_STRING_LENGTH
,
"%s/X%d"
,
unixSocketDir
,
xPort
);
#ifdef __APPLE__
#ifdef __APPLE__
if
(
useLaunchdSocket
==
1
)
if
(
useLaunchdSocket
==
1
)
{
{
s
trncpy
(
unixSocketName
,
displayHost
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
unixSocketName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
displayHost
);
}
}
#endif
#endif
...
@@ -4017,15 +4052,23 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -4017,15 +4052,23 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
nxinfo
<<
"Loop: Assuming X socket name '"
<<
unixSocketName
nxinfo
<<
"Loop: Assuming X socket name '"
<<
unixSocketName
<<
"'.
\n
"
<<
std
::
flush
;
<<
"'.
\n
"
<<
std
::
flush
;
if
(
maxlen_un
<
strlen
(
unixSocketName
)
+
1
)
{
nxfatal
<<
"Loop: PANIC! Socket name '"
<<
unixSocketName
<<
"' is too long!"
<<
std
::
flush
;
delete
[]
display
;
HandleCleanup
();
}
sockaddr_un
*
xServerAddrUNIX
=
new
sockaddr_un
;
xServerAddrUNIX
->
sun_family
=
AF_UNIX
;
strcpy
(
xServerAddrUNIX
->
sun_path
,
unixSocketName
);
strcpy
(
xServerAddrUNIX
->
sun_path
,
unixSocketName
);
addr
=
(
sockaddr
*
)
xServerAddrUNIX
;
addr
=
(
sockaddr
*
)
xServerAddrUNIX
;
addr_length
=
sizeof
(
sockaddr_un
);
addr_length
=
sizeof
(
sockaddr_un
);
#ifdef __linux__
}
#endif
}
}
else
else
{
{
...
@@ -4048,6 +4091,7 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
...
@@ -4048,6 +4091,7 @@ void SetupDisplaySocket(int &addr_family, sockaddr *&addr,
cerr
<<
"Error"
<<
": Unknown display host '"
<<
display
cerr
<<
"Error"
<<
": Unknown display host '"
<<
display
<<
"'.
\n
"
;
<<
"'.
\n
"
;
delete
[]
display
;
HandleCleanup
();
HandleCleanup
();
}
}
...
@@ -6214,6 +6258,8 @@ int WaitForRemote(ChannelEndPoint &socketAddress)
...
@@ -6214,6 +6258,8 @@ int WaitForRemote(ChannelEndPoint &socketAddress)
pFD
=
ListenConnection
(
socketAddress
,
"NX"
);
pFD
=
ListenConnection
(
socketAddress
,
"NX"
);
SAFE_FREE
(
socketUri
);
socketAddress
.
getSpec
(
&
socketUri
);
socketAddress
.
getSpec
(
&
socketUri
);
nxinfo
<<
"Loop: Waiting for connection from "
nxinfo
<<
"Loop: Waiting for connection from "
<<
hostLabel
<<
" on socket '"
<<
socketUri
<<
hostLabel
<<
" on socket '"
<<
socketUri
...
@@ -6436,6 +6482,7 @@ int PrepareProxyConnectionTCP(char** hostName, long int* portNum, int* timeout,
...
@@ -6436,6 +6482,7 @@ int PrepareProxyConnectionTCP(char** hostName, long int* portNum, int* timeout,
cerr
<<
"Error"
<<
": Unknown remote host '"
cerr
<<
"Error"
<<
": Unknown remote host '"
<<
*
hostName
<<
"'.
\n
"
;
<<
*
hostName
<<
"'.
\n
"
;
SAFE_FREE
(
*
hostName
);
HandleCleanup
();
HandleCleanup
();
}
}
...
@@ -6522,12 +6569,18 @@ int PrepareProxyConnectionUnix(char** path, int* timeout, int* proxyFileDescript
...
@@ -6522,12 +6569,18 @@ int PrepareProxyConnectionUnix(char** path, int* timeout, int* proxyFileDescript
/* FIXME: Add socket file existence and permission checks */
/* FIXME: Add socket file existence and permission checks */
*
proxyFileDescriptor
=
-
1
;
*
proxyFileDescriptor
=
-
1
;
*
reason
=
-
1
;
*
reason
=
-
1
;
// determine the maximum number of characters that fit into struct
// sockaddr_un's sun_path member
const
std
::
size_t
sockpathlen
=
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
sockaddr_un
addr
;
sockaddr_un
addr
;
addr
.
sun_family
=
AF_UNIX
;
addr
.
sun_family
=
AF_UNIX
;
s
trncpy
(
addr
.
sun_path
,
*
path
,
108
-
1
);
s
nprintf
(
addr
.
sun_path
,
sockpathlen
,
"%s"
,
*
path
);
*
proxyFileDescriptor
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
PF_UNSPEC
);
*
proxyFileDescriptor
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
PF_UNSPEC
);
*
reason
=
EGET
();
*
reason
=
EGET
();
...
@@ -6608,6 +6661,9 @@ int ConnectToRemote(ChannelEndPoint &socketAddress)
...
@@ -6608,6 +6661,9 @@ int ConnectToRemote(ChannelEndPoint &socketAddress)
<<
" in process with pid '"
<<
getpid
()
<<
" in process with pid '"
<<
getpid
()
<<
"'.
\n
"
<<
std
::
flush
;
<<
"'.
\n
"
<<
std
::
flush
;
SAFE_FREE
(
hostName
);
SAFE_FREE
(
unixPath
);
if
(
socketAddress
.
getUnixPath
(
&
unixPath
))
if
(
socketAddress
.
getUnixPath
(
&
unixPath
))
result
=
PrepareProxyConnectionUnix
(
&
unixPath
,
&
connectTimeout
,
&
pFD
,
&
reason
);
result
=
PrepareProxyConnectionUnix
(
&
unixPath
,
&
connectTimeout
,
&
pFD
,
&
reason
);
else
if
(
socketAddress
.
getTCPHostAndPort
(
&
hostName
,
&
portNum
))
else
if
(
socketAddress
.
getTCPHostAndPort
(
&
hostName
,
&
portNum
))
...
@@ -7867,11 +7923,11 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -7867,11 +7923,11 @@ int ParseEnvironmentOptions(const char *env, int force)
if
(
strcasecmp
(
name
,
"options"
)
==
0
)
if
(
strcasecmp
(
name
,
"options"
)
==
0
)
{
{
s
trncpy
(
fileOptions
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
fileOptions
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"display"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"display"
)
==
0
)
{
{
s
trncpy
(
displayHost
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
displayHost
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"link"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"link"
)
==
0
)
{
{
...
@@ -7927,7 +7983,7 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -7927,7 +7983,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
}
else
else
{
{
s
trncpy
(
sessionType
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionType
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
}
}
}
}
...
@@ -7980,7 +8036,7 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -7980,7 +8036,7 @@ int ParseEnvironmentOptions(const char *env, int force)
return
-
1
;
return
-
1
;
}
}
s
trncpy
(
acceptHost
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
acceptHost
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"connect"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"connect"
)
==
0
)
{
{
...
@@ -8018,7 +8074,7 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -8018,7 +8074,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
}
else
if
(
strcasecmp
(
name
,
"session"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"session"
)
==
0
)
{
{
s
trncpy
(
sessionFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"errors"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"errors"
)
==
0
)
{
{
...
@@ -8029,27 +8085,27 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -8029,27 +8085,27 @@ int ParseEnvironmentOptions(const char *env, int force)
// the same name.
// the same name.
//
//
s
trncpy
(
errorsFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
errorsFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"root"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"root"
)
==
0
)
{
{
s
trncpy
(
rootDir
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
rootDir
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"id"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"id"
)
==
0
)
{
{
s
trncpy
(
sessionId
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionId
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"stats"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"stats"
)
==
0
)
{
{
control
->
EnableStatistics
=
1
;
control
->
EnableStatistics
=
1
;
s
trncpy
(
statsFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
statsFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"cookie"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"cookie"
)
==
0
)
{
{
LowercaseArg
(
"local"
,
name
,
value
);
LowercaseArg
(
"local"
,
name
,
value
);
s
trncpy
(
authCookie
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
authCookie
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"nodelay"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"nodelay"
)
==
0
)
{
{
...
@@ -8278,7 +8334,7 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -8278,7 +8334,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
}
else
if
(
strcasecmp
(
name
,
"font"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"font"
)
==
0
)
{
{
s
trncpy
(
fontPort
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
fontPort
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"slave"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"slave"
)
==
0
)
{
{
...
@@ -8383,7 +8439,7 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -8383,7 +8439,7 @@ int ParseEnvironmentOptions(const char *env, int force)
}
}
else
if
(
strcasecmp
(
name
,
"product"
)
==
0
)
else
if
(
strcasecmp
(
name
,
"product"
)
==
0
)
{
{
s
trncpy
(
productName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
productName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
else
if
(
strcasecmp
(
name
,
"rootless"
)
==
0
||
else
if
(
strcasecmp
(
name
,
"rootless"
)
==
0
||
strcasecmp
(
name
,
"geometry"
)
==
0
||
strcasecmp
(
name
,
"geometry"
)
==
0
||
...
@@ -8473,7 +8529,7 @@ int ParseEnvironmentOptions(const char *env, int force)
...
@@ -8473,7 +8529,7 @@ int ParseEnvironmentOptions(const char *env, int force)
if
(
*
optionsFileName
==
'\0'
)
if
(
*
optionsFileName
==
'\0'
)
{
{
s
trncpy
(
optionsFileName
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
optionsFileName
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
nxinfo
<<
"Loop: Assuming name of options file '"
nxinfo
<<
"Loop: Assuming name of options file '"
<<
optionsFileName
<<
"'.
\n
"
<<
optionsFileName
<<
"'.
\n
"
...
@@ -9193,7 +9249,7 @@ int ParseRemoteOptions(char *opts)
...
@@ -9193,7 +9249,7 @@ int ParseRemoteOptions(char *opts)
}
}
else
else
{
{
s
trncpy
(
sessionType
,
value
,
DEFAULT_STRING_LENGTH
-
1
);
s
nprintf
(
sessionType
,
DEFAULT_STRING_LENGTH
,
"%s"
,
value
);
}
}
}
}
...
@@ -12663,6 +12719,7 @@ int ParseHostOption(const char *opt, char *host, long &port)
...
@@ -12663,6 +12719,7 @@ int ParseHostOption(const char *opt, char *host, long &port)
char
newHost
[
DEFAULT_STRING_LENGTH
]
=
{
0
};
char
newHost
[
DEFAULT_STRING_LENGTH
]
=
{
0
};
// opt cannot be longer than DEFAULT_STRING_LENGTH, this is checked above
strncpy
(
newHost
,
opt
,
strlen
(
opt
)
-
strlen
(
separator
));
strncpy
(
newHost
,
opt
,
strlen
(
opt
)
-
strlen
(
separator
));
*
(
newHost
+
strlen
(
opt
)
-
strlen
(
separator
))
=
'\0'
;
*
(
newHost
+
strlen
(
opt
)
-
strlen
(
separator
))
=
'\0'
;
...
@@ -13435,10 +13492,8 @@ int ParseArg(const char *type, const char *name, const char *value)
...
@@ -13435,10 +13492,8 @@ int ParseArg(const char *type, const char *name, const char *value)
char
*
string
=
new
char
[
strlen
(
value
)];
char
*
string
=
new
char
[
strlen
(
value
)];
strncpy
(
string
,
value
,
strlen
(
value
)
-
1
);
// copy value but cut off the last character
snprintf
(
string
,
strlen
(
value
),
"%s"
,
value
);
*
(
string
+
(
strlen
(
value
)
-
1
))
=
'\0'
;
nxinfo
<<
"Loop: Parsing integer option '"
<<
name
nxinfo
<<
"Loop: Parsing integer option '"
<<
name
<<
"' from string '"
<<
string
<<
"' with base set to "
;
<<
"' from string '"
<<
string
<<
"' with base set to "
;
...
@@ -13456,18 +13511,15 @@ int ParseArg(const char *type, const char *name, const char *value)
...
@@ -13456,18 +13511,15 @@ int ParseArg(const char *type, const char *name, const char *value)
nxinfo_append
<<
".
\n
"
<<
std
::
flush
;
nxinfo_append
<<
".
\n
"
<<
std
::
flush
;
double
result
=
atof
(
string
)
*
base
;
double
result
=
atof
(
string
)
*
base
;
if
(
result
<
0
||
result
>
(((
unsigned
)
-
1
)
>>
1
))
{
delete
[]
string
;
delete
[]
string
;
if
(
result
<
0
||
result
>
(((
unsigned
)
-
1
)
>>
1
))
{
return
-
1
;
return
-
1
;
}
}
delete
[]
string
;
nxinfo
<<
"Loop: Integer option parsed to '"
nxinfo
<<
"Loop: Integer option parsed to '"
<<
(
int
)
result
<<
"'.
\n
"
<<
std
::
flush
;
<<
(
int
)
result
<<
"'.
\n
"
<<
std
::
flush
;
...
...
nxcomp/src/Proxy.cpp
View file @
e13e31f7
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <cstdio>
#include <cstdio>
#include <unistd.h>
#include <unistd.h>
#include <cstdlib>
#include <cstdlib>
#include <cstddef>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
@@ -6122,7 +6123,7 @@ int Proxy::handleNewSlaveConnection(int clientFd)
...
@@ -6122,7 +6123,7 @@ int Proxy::handleNewSlaveConnection(int clientFd)
int
Proxy
::
handleNewGenericConnectionFromProxy
(
int
channelId
,
T_channel_type
type
,
int
Proxy
::
handleNewGenericConnectionFromProxy
(
int
channelId
,
T_channel_type
type
,
ChannelEndPoint
&
endPoint
,
const
char
*
label
)
ChannelEndPoint
&
endPoint
,
const
char
*
label
)
{
{
char
*
unixPath
,
*
host
;
char
*
unixPath
=
NULL
,
*
host
=
NULL
;
long
port
;
long
port
;
if
(
endPoint
.
getUnixPath
(
&
unixPath
))
{
if
(
endPoint
.
getUnixPath
(
&
unixPath
))
{
...
@@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type
...
@@ -6294,19 +6295,12 @@ int Proxy::handleNewGenericConnectionFromProxyUnix(int channelId, T_channel_type
serverAddrUnix
.
sun_family
=
AF_UNIX
;
serverAddrUnix
.
sun_family
=
AF_UNIX
;
#ifdef __linux__
// determine the maximum number of characters that fit into struct
const
int
serverAddrNameLength
=
108
;
// sockaddr_un's sun_path member
#else
std
::
size_t
serverAddrNameLength
=
/* POSIX/SUS does not specify a length.
sizeof
(
struct
sockaddr_un
)
-
offsetof
(
struct
sockaddr_un
,
sun_path
);
* BSD derivatives generally support 104 bytes, other systems may be more constrained.
* If you happen to run into such systems, extend this section with the appropriate limit.
*/
const
int
serverAddrNameLength
=
104
;
#endif
strncpy
(
serverAddrUnix
.
sun_path
,
path
,
serverAddrNameLength
);
*
(
serverAddrUnix
.
sun_path
+
serverAddrNameLength
-
1
)
=
'\0'
;
snprintf
(
serverAddrUnix
.
sun_path
,
serverAddrNameLength
,
"%s"
,
path
)
;
#ifdef TEST
#ifdef TEST
*
logofs
<<
"Proxy: Connecting to "
<<
label
<<
" server "
*
logofs
<<
"Proxy: Connecting to "
<<
label
<<
" server "
...
...
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