/// <summary> /// Setup the connection manager according to the parameters. /// </summary> /// <param name="param">parameters</param> /// <exception cref="X11UtilException"></exception> /// <exception cref="X11SocketException"></exception> public void Setup(X11ForwardingParams param) { if (_setupDone) { return; } _param = param.Clone(); _spoofedAuthProtocolName = DEFAULT_AUTH_NAME; _spoofedAuthCookie = GenerateCookie(); if (param.UseCygwinUnixDomainSocket) { _protocolEventManager.Trace("[X11] Use Cygwin's domain socket"); _socketFactory = () => new X11CygwinDomainSocket(param.X11UnixFolder); } else { _protocolEventManager.Trace("[X11] Use TCP socket"); _socketFactory = () => new X11TcpSocket(); } XauthorityEntry xauthEntry; if (param.NeedAuth) { string xauthFile = FindXauthorityFile(param); if (xauthFile == null) { throw new X11UtilException(Strings.GetString("XauthorityFileNotFound")); } var parser = new XauthorityParser(); xauthEntry = parser.FindBest(xauthFile, param.Display); if (xauthEntry == null) { throw new X11UtilException(Strings.GetString("SuitableAuthorizationInformationNotFound")); } } else { xauthEntry = new XauthorityEntry(0, "", param.Display, "", new byte[0]); } var cookieInfo = GetUntrustedAccessCookie(_socketFactory, param.Display, xauthEntry); if (cookieInfo == null) { // no SECURITY extension _protocolEventManager.Trace("[X11] \"Trusted\" access will be used."); _xAuthProtocolName = xauthEntry.Name; _xAuthCookie = xauthEntry.Data; _authEntry = xauthEntry; _authId = null; _setupDone = true; return; } _protocolEventManager.Trace("[X11] \"Untrusted\" access will be used."); _xAuthProtocolName = DEFAULT_AUTH_NAME; _xAuthCookie = cookieInfo.Item2; _authEntry = xauthEntry; _authId = cookieInfo.Item1; _setupDone = true; // TODO: // the authorization cookie should be deleted from the X server when // the forwarding channel is closed. }