Currently there is no uniform way to obtain a X session cookie as root. gdm exports it if the caller is root, kdm on the other hand doesn't. I think the correct place to obtain the cookie should be console kit, as it already knows the available x sessions.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.