// Create a new application group for embedding a child application. private unsafe void CreateApplicationGroup() { String displayName; Xauth *auth; Xauth *authReturn; XSecurityAuthorizationAttributes xsa; Xlib.XSecurityAuthorization xs; // Check that we can create application groups. if(!CanEmbed(dpy, true, out displayName)) { return; } try { // Lock down the display while we do this. IntPtr display = dpy.Lock(); // Create the application group identifier. if(Xlib.XagCreateEmbeddedApplicationGroup (display, XVisualID.Zero, Xlib.XDefaultColormapOfScreen(screen.screen), Xlib.XBlackPixelOfScreen(screen.screen), Xlib.XWhitePixelOfScreen(screen.screen), out group) == XStatus.Zero) { return; } // Generate an authentication token for the group. auth = Xlib.XSecurityAllocXauth(); if(auth == null) { return; } auth->name = Marshal.StringToHGlobalAnsi ("MIT-MAGIC-COOKIE-1"); auth->name_length = 18; xsa = new XSecurityAuthorizationAttributes(); xsa.timeout = 300; xsa.trust_level = 0; // XSecurityClientTrusted xsa.group = (XID)group; xsa.event_mask = 0; authReturn = Xlib.XSecurityGenerateAuthorization (display, auth, (uint)(XSecurityAttributeMask.XSecurityTimeout | XSecurityAttributeMask.XSecurityTrustLevel | XSecurityAttributeMask.XSecurityGroup), ref xsa, out xs); if(authReturn == null) { Xlib.XSecurityFreeXauth(auth); return; } // Write the credentials to a temporary X authority file. String authFile = Path.GetTempFileName(); FileStream stream = new FileStream (authFile, FileMode.Create, FileAccess.Write); WriteShort(stream, 65535); // family = FamilyWild WriteShort(stream, 0); // address_length WriteShort(stream, 0); // number_length WriteShort(stream, authReturn->name_length); WriteBytes(stream, authReturn->name, authReturn->name_length); WriteShort(stream, authReturn->data_length); WriteBytes(stream, authReturn->data, authReturn->data_length); stream.Close(); // Free the Xauth structures that we don't need any more. Xlib.XSecurityFreeXauth(auth); Xlib.XSecurityFreeXauth(authReturn); // Record the app group information. redirectDisplay = displayName; authorityFile = authFile; // Create a wrapper around the appgroup to get events. groupWrapper = new AppGroupWidget(dpy, screen, group, this); } catch(MissingMethodException) { return; } catch(DllNotFoundException) { return; } catch(EntryPointNotFoundException) { return; } finally { dpy.Unlock(); } }
extern public static Xauth *XSecurityGenerateAuthorization (IntPtr dpy, Xauth *auth_in, uint valuemask, ref XSecurityAuthorizationAttributes attributes, out XSecurityAuthorization auth_id_return);