xserver: Branch 'master' - 290 commits

Eamon Walsh ewalsh at kemper.freedesktop.org
Thu Dec 13 21:41:10 PST 2007


 .gitignore                                |    2 
 GL/glx/glxext.c                           |    9 
 GL/glx/glxscreens.c                       |   19 
 XTrap/xtrapddmi.c                         |    6 
 XTrap/xtrapdi.c                           |    6 
 Xext/Makefile.am                          |   14 
 Xext/SecurityPolicy                       |   88 -
 Xext/appgroup.c                           |   10 
 Xext/bigreq.c                             |    8 
 Xext/cup.c                                |    9 
 Xext/dpms.c                               |   10 
 Xext/dpmsproc.h                           |    4 
 Xext/dpmsstubs.c                          |    4 
 Xext/mbuf.c                               |    2 
 Xext/mitmisc.c                            |    6 
 Xext/panoramiX.c                          |   41 
 Xext/panoramiXprocs.c                     |    8 
 Xext/saver.c                              |   66 -
 Xext/security.c                           | 1470 ++++++------------------------
 Xext/securitysrv.h                        |    6 
 Xext/shape.c                              |   26 
 Xext/shm.c                                |   32 
 Xext/sync.c                               |   16 
 Xext/xace.c                               |  124 +-
 Xext/xace.h                               |   29 
 Xext/xacestr.h                            |   87 +
 Xext/xcmisc.c                             |    8 
 Xext/xevie.c                              |   19 
 Xext/xf86bigfont.c                        |    4 
 Xext/xprint.c                             |  174 ---
 Xext/xres.c                               |   21 
 Xext/xselinux.c                           | 1434 +++++++++++++++++++++++++++++
 Xext/xselinux.h                           |  195 +++
 Xext/xtest.c                              |   33 
 Xext/xvdisp.c                             |   29 
 Xext/xvdix.h                              |    9 
 Xext/xvmain.c                             |   32 
 Xext/xvmc.c                               |   23 
 Xi/allowev.c                              |    8 
 Xi/chgdctl.c                              |    7 
 Xi/chgfctl.c                              |    8 
 Xi/chgkmap.c                              |    7 
 Xi/chgprop.c                              |    3 
 Xi/chgptr.c                               |    2 
 Xi/closedev.c                             |    9 
 Xi/devbell.c                              |    9 
 Xi/exevents.c                             |   41 
 Xi/extinit.c                              |   25 
 Xi/getbmap.c                              |    8 
 Xi/getdctl.c                              |    9 
 Xi/getfctl.c                              |    9 
 Xi/getfocus.c                             |    8 
 Xi/getkmap.c                              |    8 
 Xi/getmmap.c                              |    8 
 Xi/getprop.c                              |    3 
 Xi/getselev.c                             |    3 
 Xi/getvers.c                              |    1 
 Xi/grabdev.c                              |   15 
 Xi/grabdevb.c                             |   23 
 Xi/grabdevk.c                             |   23 
 Xi/gtmotion.c                             |    9 
 Xi/listdev.c                              |   10 
 Xi/opendev.c                              |    7 
 Xi/queryst.c                              |    9 
 Xi/selectev.c                             |    3 
 Xi/sendexev.c                             |    8 
 Xi/setbmap.c                              |    7 
 Xi/setdval.c                              |    8 
 Xi/setfocus.c                             |    7 
 Xi/setmmap.c                              |    7 
 Xi/setmode.c                              |    8 
 Xi/stubs.c                                |    2 
 Xi/ungrdev.c                              |    8 
 Xi/ungrdevb.c                             |   16 
 Xi/ungrdevk.c                             |   16 
 afb/afb.h                                 |   19 
 afb/afbfillarc.c                          |    3 
 afb/afbfillrct.c                          |    3 
 afb/afbfillsp.c                           |   15 
 afb/afbgc.c                               |    7 
 afb/afbimggblt.c                          |    4 
 afb/afbline.c                             |    6 
 afb/afbpixmap.c                           |    1 
 afb/afbply1rct.c                          |    4 
 afb/afbplygblt.c                          |    4 
 afb/afbpolypnt.c                          |    4 
 afb/afbscrinit.c                          |   42 
 afb/afbtegblt.c                           |    4 
 afb/afbwindow.c                           |    1 
 afb/afbzerarc.c                           |    4 
 cfb/cfb.h                                 |    9 
 cfb/cfballpriv.c                          |   30 
 cfb/cfbmap.h                              |    6 
 cfb/cfbpixmap.c                           |    1 
 cfb/cfbrrop.h                             |    3 
 cfb/cfbscrinit.c                          |   18 
 cfb/cfbunmap.h                            |    6 
 cfb/cfbwindow.c                           |    4 
 composite/compalloc.c                     |   10 
 composite/compext.c                       |   57 -
 composite/compinit.c                      |   30 
 composite/compint.h                       |   16 
 config/dbus.c                             |    2 
 configure.ac                              |   40 
 damageext/damageext.c                     |   10 
 damageext/damageextint.h                  |    2 
 dbe/dbe.c                                 |  224 ----
 dbe/dbestruct.h                           |   37 
 dbe/midbe.c                               |   49 -
 dbe/midbestr.h                            |   12 
 dix/Makefile.am                           |    6 
 dix/colormap.c                            |   39 
 dix/cursor.c                              |  107 +-
 dix/deprecated.c                          |  162 +++
 dix/devices.c                             |  193 ++-
 dix/dispatch.c                            |  738 ++++++---------
 dix/dixfonts.c                            |   26 
 dix/dixutils.c                            |  104 --
 dix/events.c                              |  194 ++-
 dix/extension.c                           |   70 -
 dix/gc.c                                  |  100 --
 dix/getevents.c                           |   12 
 dix/grabs.c                               |   11 
 dix/main.c                                |   66 -
 dix/pixmap.c                              |   27 
 dix/privates.c                            |  517 +++-------
 dix/property.c                            |  155 +--
 dix/protocol.txt                          | 1054 +++++++++++++++++++++
 dix/registry.c                            |  328 ++++++
 dix/resource.c                            |  165 ---
 dix/window.c                              |  247 ++---
 doc/Makefile.am                           |    2 
 doc/SecurityPolicy.man.pre                |  258 -----
 doc/Xserver.man.pre                       |   13 
 exa/exa.c                                 |   20 
 exa/exa_priv.h                            |   10 
 fb/fb.h                                   |   20 
 fb/fballpriv.c                            |   48 
 fb/fboverlay.c                            |   19 
 fb/fboverlay.h                            |    9 
 fb/fbpixmap.c                             |    1 
 fb/fbpseudocolor.c                        |   50 -
 fb/fbscreen.c                             |    6 
 fb/fbwindow.c                             |    4 
 fb/wfbrename.h                            |   22 
 hw/dmx/dmxcmap.c                          |   14 
 hw/dmx/dmxcmap.h                          |    9 
 hw/dmx/dmxcursor.c                        |    8 
 hw/dmx/dmxcursor.h                        |    7 
 hw/dmx/dmxdpms.c                          |    9 
 hw/dmx/dmxfont.c                          |    7 
 hw/dmx/dmxgc.c                            |    6 
 hw/dmx/dmxgc.h                            |    4 
 hw/dmx/dmxpict.c                          |    3 
 hw/dmx/dmxpict.h                          |   10 
 hw/dmx/dmxpixmap.c                        |    5 
 hw/dmx/dmxpixmap.h                        |    4 
 hw/dmx/dmxscrinit.c                       |   46 
 hw/dmx/dmxscrinit.h                       |    2 
 hw/dmx/dmxwindow.c                        |    3 
 hw/dmx/dmxwindow.h                        |    6 
 hw/dmx/input/dmxconsole.c                 |   13 
 hw/dmx/input/dmxeq.c                      |    4 
 hw/kdrive/ephyr/ephyr.c                   |    2 
 hw/kdrive/ephyr/ephyrdriext.c             |   43 
 hw/kdrive/savage/s3draw.c                 |   17 
 hw/kdrive/savage/s3draw.h                 |   18 
 hw/kdrive/src/kaa.c                       |   22 
 hw/kdrive/src/kaa.h                       |   13 
 hw/kdrive/src/kdrive.c                    |   15 
 hw/kdrive/src/kdrive.h                    |    8 
 hw/kdrive/src/kxv.c                       |   44 
 hw/kdrive/vxworks/vxkbd.c                 |    2 
 hw/xfree86/common/xf86.h                  |   10 
 hw/xfree86/common/xf86DGA.c               |   44 
 hw/xfree86/common/xf86DPMS.c              |   48 
 hw/xfree86/common/xf86Events.c            |    6 
 hw/xfree86/common/xf86Globals.c           |    8 
 hw/xfree86/common/xf86Init.c              |   26 
 hw/xfree86/common/xf86PM.c                |    2 
 hw/xfree86/common/xf86RandR.c             |   20 
 hw/xfree86/common/xf86VidMode.c           |   27 
 hw/xfree86/common/xf86Xinput.c            |    1 
 hw/xfree86/common/xf86cmap.c              |  122 +-
 hw/xfree86/common/xf86fbman.c             |  148 +--
 hw/xfree86/common/xf86sbusBus.c           |   13 
 hw/xfree86/common/xf86xv.c                |   45 
 hw/xfree86/common/xf86xvmc.c              |   20 
 hw/xfree86/common/xf86xvpriv.h            |    3 
 hw/xfree86/dixmods/extmod/modinit.h       |    5 
 hw/xfree86/dixmods/extmod/xf86dga2.c      |   30 
 hw/xfree86/dixmods/extmod/xf86misc.c      |   40 
 hw/xfree86/dixmods/extmod/xf86vmode.c     |   43 
 hw/xfree86/dixmods/extmod/xvmod.c         |    2 
 hw/xfree86/dixmods/extmod/xvmodproc.h     |    2 
 hw/xfree86/dri/dri.c                      |   52 -
 hw/xfree86/dri/dristruct.h                |   22 
 hw/xfree86/exa/examodule.c                |   18 
 hw/xfree86/loader/dixsym.c                |   64 -
 hw/xfree86/loader/misym.c                 |    4 
 hw/xfree86/loader/xf86sym.c               |    4 
 hw/xfree86/modes/xf86Cursors.c            |    5 
 hw/xfree86/modes/xf86RandR12.c            |   28 
 hw/xfree86/os-support/solaris/sun_mouse.c |   14 
 hw/xfree86/rac/xf86RAC.c                  |   68 -
 hw/xfree86/ramdac/xf86Cursor.c            |   75 -
 hw/xfree86/ramdac/xf86CursorPriv.h        |    2 
 hw/xfree86/ramdac/xf86HWCurs.c            |   20 
 hw/xfree86/shadowfb/shadow.c              |   20 
 hw/xfree86/xaa/xaaDashLine.c              |    3 
 hw/xfree86/xaa/xaaGC.c                    |    3 
 hw/xfree86/xaa/xaaGCmisc.c                |    3 
 hw/xfree86/xaa/xaaInit.c                  |   45 
 hw/xfree86/xaa/xaaLineMisc.c              |    3 
 hw/xfree86/xaa/xaaOverlayDF.c             |   15 
 hw/xfree86/xaa/xaaStateChange.c           |   15 
 hw/xfree86/xaa/xaaWrapper.c               |   31 
 hw/xfree86/xaa/xaalocal.h                 |   22 
 hw/xfree86/xaa/xaawrap.h                  |   14 
 hw/xfree86/xf4bpp/mfbfillarc.c            |    3 
 hw/xfree86/xf4bpp/mfbimggblt.c            |    3 
 hw/xfree86/xf4bpp/mfbzerarc.c             |    3 
 hw/xfree86/xf4bpp/ppcArea.c               |    2 
 hw/xfree86/xf4bpp/ppcGC.c                 |   10 
 hw/xfree86/xf4bpp/ppcPixFS.c              |   24 
 hw/xfree86/xf4bpp/ppcPixmap.c             |    1 
 hw/xfree86/xf4bpp/ppcPolyPnt.c            |    2 
 hw/xfree86/xf4bpp/ppcWinFS.c              |   24 
 hw/xfree86/xf4bpp/vgaGC.c                 |    2 
 hw/xfree86/xf8_32bpp/cfb8_32.h            |   14 
 hw/xfree86/xf8_32bpp/cfbscrinit.c         |   33 
 hw/xfree86/xf8_32bpp/xf86overlay.c        |   35 
 hw/xgl/egl/kinput.c                       |    2 
 hw/xgl/egl/xegl.c                         |   20 
 hw/xgl/egl/xegl.h                         |    6 
 hw/xgl/glx/xglx.c                         |   26 
 hw/xgl/xgl.h                              |   33 
 hw/xgl/xglinput.c                         |    2 
 hw/xgl/xglpixmap.c                        |    1 
 hw/xgl/xglscreen.c                        |    3 
 hw/xgl/xglxv.c                            |    8 
 hw/xnest/Cursor.c                         |    6 
 hw/xnest/GC.c                             |    2 
 hw/xnest/Init.c                           |    2 
 hw/xnest/Pixmap.c                         |    8 
 hw/xnest/Screen.c                         |   20 
 hw/xnest/Window.c                         |    2 
 hw/xnest/XNCursor.h                       |    9 
 hw/xnest/XNGC.h                           |    6 
 hw/xnest/XNPixmap.h                       |    6 
 hw/xnest/XNWindow.h                       |    6 
 hw/xprint/attributes.c                    |   27 
 hw/xprint/pcl/Pcl.h                       |    8 
 hw/xprint/pcl/PclArc.c                    |    2 
 hw/xprint/pcl/PclColor.c                  |   28 
 hw/xprint/pcl/PclGC.c                     |   15 
 hw/xprint/pcl/PclInit.c                   |   62 -
 hw/xprint/pcl/PclLine.c                   |    4 
 hw/xprint/pcl/PclPixel.c                  |    8 
 hw/xprint/pcl/PclPolygon.c                |    6 
 hw/xprint/pcl/PclPrint.c                  |   20 
 hw/xprint/pcl/PclText.c                   |    4 
 hw/xprint/pcl/PclWindow.c                 |    7 
 hw/xprint/pcl/Pclmap.h                    |   10 
 hw/xprint/ps/Ps.h                         |    8 
 hw/xprint/ps/PsGC.c                       |   14 
 hw/xprint/ps/PsInit.c                     |   48 
 hw/xprint/ps/PsPixmap.c                   |    3 
 hw/xprint/ps/PsPrint.c                    |   33 
 hw/xprint/ps/PsWindow.c                   |    7 
 hw/xprint/raster/Raster.c                 |   44 
 hw/xquartz/darwin.c                       |   11 
 hw/xquartz/darwin.h                       |    6 
 hw/xquartz/darwinEvents.c                 |    2 
 hw/xquartz/quartz.c                       |   12 
 hw/xquartz/quartzCommon.h                 |    5 
 hw/xquartz/quartzCursor.c                 |   26 
 hw/xquartz/xpr/dri.c                      |   47 
 hw/xquartz/xpr/dristruct.h                |   21 
 hw/xquartz/xpr/xprCursor.c                |   20 
 hw/xquartz/xpr/xprFrame.c                 |    2 
 hw/xwin/win.h                             |   40 
 hw/xwin/winallpriv.c                      |   18 
 hw/xwin/winclipboardwrappers.c            |    1 
 hw/xwin/wincursor.c                       |    3 
 hw/xwin/winfillsp.c                       |    9 
 hw/xwin/winglobals.c                      |   10 
 hw/xwin/winmultiwindowwndproc.c           |    2 
 hw/xwin/winpixmap.c                       |    7 
 hw/xwin/winscrinit.c                      |    3 
 hw/xwin/winsetsp.c                        |    9 
 hw/xwin/winwin32rootless.c                |    2 
 include/Makefile.am                       |    3 
 include/colormapst.h                      |    3 
 include/cursor.h                          |   26 
 include/cursorstr.h                       |    6 
 include/dix-config.h.in                   |   15 
 include/dix.h                             |   75 -
 include/dixaccess.h                       |   53 +
 include/dixfont.h                         |    6 
 include/dixgrabs.h                        |    1 
 include/dixstruct.h                       |    7 
 include/extension.h                       |    8 
 include/extinit.h                         |    5 
 include/extnsionst.h                      |    7 
 include/gc.h                              |    4 
 include/gcstruct.h                        |    3 
 include/input.h                           |   18 
 include/inputstr.h                        |    5 
 include/miscstruct.h                      |   13 
 include/os.h                              |    2 
 include/pixmapstr.h                       |   14 
 include/privates.h                        |  157 +++
 include/property.h                        |   12 
 include/propertyst.h                      |    2 
 include/registry.h                        |   64 +
 include/resource.h                        |   92 +
 include/screenint.h                       |   38 
 include/scrnintstr.h                      |   11 
 include/selection.h                       |    4 
 include/window.h                          |   16 
 include/windowstr.h                       |    3 
 include/xkbsrv.h                          |   50 -
 include/xorg-config.h.in                  |    3 
 include/xorg-server.h.in                  |    3 
 mfb/mfb.h                                 |   10 
 mfb/mfbbitblt.c                           |   18 
 mfb/mfbfillarc.c                          |    3 
 mfb/mfbfillrct.c                          |    3 
 mfb/mfbfillsp.c                           |    9 
 mfb/mfbgc.c                               |   10 
 mfb/mfbimggblt.c                          |    3 
 mfb/mfbline.c                             |    6 
 mfb/mfbpixmap.c                           |    1 
 mfb/mfbpolypnt.c                          |    3 
 mfb/mfbscrinit.c                          |   25 
 mfb/mfbwindow.c                           |    1 
 mfb/mfbzerarc.c                           |    3 
 mi/mi.h                                   |    3 
 mi/mibank.c                               |   18 
 mi/midispcur.c                            |   56 -
 mi/mieq.c                                 |    4 
 mi/miinitext.c                            |   18 
 mi/miline.h                               |    8 
 mi/mioverlay.c                            |   27 
 mi/mipointer.c                            |   15 
 mi/mipointer.h                            |    3 
 mi/miscrinit.c                            |   25 
 mi/misprite.c                             |   78 -
 miext/cw/cw.c                             |   53 -
 miext/cw/cw.h                             |   29 
 miext/damage/damage.c                     |   41 
 miext/damage/damagestr.h                  |   15 
 miext/rootless/accel/rlAccel.c            |   13 
 miext/rootless/rootlessCommon.c           |    8 
 miext/rootless/rootlessCommon.h           |   21 
 miext/rootless/rootlessGC.c               |   10 
 miext/rootless/rootlessScreen.c           |   36 
 miext/rootless/rootlessWindow.c           |   14 
 miext/shadow/shadow.c                     |   15 
 miext/shadow/shadow.h                     |    5 
 os/Makefile.am                            |    7 
 os/WaitFor.c                              |    4 
 os/access.c                               |   32 
 os/auth.c                                 |   11 
 os/connection.c                           |   20 
 os/osdep.h                                |    3 
 os/secauth.c                              |  202 ----
 os/utils.c                                |   12 
 randr/randr.c                             |   16 
 randr/randrstr.h                          |   10 
 randr/rrcrtc.c                            |    5 
 randr/rrmode.c                            |    3 
 randr/rroutput.c                          |    5 
 record/record.c                           |   15 
 render/animcur.c                          |   32 
 render/glyph.c                            |  323 ------
 render/glyphstr.h                         |   43 
 render/mirect.c                           |    2 
 render/picture.c                          |  149 ---
 render/picture.h                          |    4 
 render/picturestr.h                       |   44 
 render/render.c                           |  130 +-
 xfixes/cursor.c                           |   81 -
 xfixes/region.c                           |   34 
 xfixes/saveset.c                          |    2 
 xfixes/select.c                           |    9 
 xfixes/xfixes.c                           |    6 
 xfixes/xfixesint.h                        |    2 
 xkb/ddxDevBtn.c                           |    2 
 xkb/ddxFakeBtn.c                          |    2 
 xkb/ddxFakeMtn.c                          |    2 
 xkb/xkb.c                                 |  101 +-
 xkb/xkbAccessX.c                          |    2 
 xkb/xkbActions.c                          |   23 
 xkb/xkbEvents.c                           |    2 
 xkb/xkbLEDs.c                             |   10 
 xkb/xkbPrOtherEv.c                        |    2 
 xkb/xkbUtils.c                            |  147 +--
 399 files changed, 7817 insertions(+), 7453 deletions(-)

New commits:
commit 86b2e59bfb79bd042a13c35fbb4ccecec576f629
Merge: 1c1a4bc... cb0d7e2...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 14 00:32:24 2007 -0500

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	configure.ac
    
    This is the last pull before merging to master.

diff --cc configure.ac
index 8dae13f,090a0f5..49d57d7
--- a/configure.ac
+++ b/configure.ac
@@@ -468,21 -475,18 +468,19 @@@ AC_ARG_WITH(xkb-path,         AS_HELP_S
  AC_ARG_WITH(xkb-output,       AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${datadir}/X11/xkb/compiled)]),
  				[ XKBOUTPUT="$withval" ],
  				[ XKBOUTPUT="compiled" ])
 -AC_ARG_WITH(serverconfig-path, AS_HELP_STRING([--with-serverconfig-path=PATH], [Path to server config (default: ${libdir}/xserver)]),
 +AC_ARG_WITH(serverconfig-path, AS_HELP_STRING([--with-serverconfig-path=PATH],
 +				   [Directory where ancillary server config files are installed (default: ${libdir}/xorg)]),
  				[ SERVERCONFIG="$withval" ],
 -				[ SERVERCONFIG="${libdir}/xserver" ])
 +				[ SERVERCONFIG="${libdir}/xorg" ])
- APPLE_APPLICATIONS_DIR="/Applications/Utilities"
  AC_ARG_WITH(apple-applications-dir,AS_HELP_STRING([--with-apple-applications-dir=PATH], [Path to the Applications directory (default: /Applications/Utilities)]),
- 				[ APPLE_APPLICATIONS_DIR="${withval}" ].
+ 				[ APPLE_APPLICATIONS_DIR="${withval}" ],
  				[ APPLE_APPLICATIONS_DIR="/Applications/Utilities" ])
- 
+ AC_SUBST([APPLE_APPLICATIONS_DIR])
  AC_ARG_WITH(launchd,          AS_HELP_STRING([--with-launchd], [Build with support for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto])
- 
- AC_ARG_WITH(pci-txt-ids-dir, AS_HELP_STRING([--with-pci-txt-ids-dir=PATH],
- [Path to pci id directory (default: ${datadir}/X11/pci)]),
- 				[ PCI_TXT_IDS_DIR="$withval" ],
- 				[ PCI_TXT_IDS_DIR="${datadir}/X11/pci" ])
+ AC_ARG_WITH(launchagents-dir,AS_HELP_STRING([--with-launchagents-dir=PATH], [Path to launchd's LaunchAgents directory (default: /Library/LaunchAgents)]),
+ 				[ launchagentsdir="${withval}" ],
+ 				[ launchagentsdir="/Library/LaunchAgents" ])
+ AC_SUBST([launchagentsdir])
  AC_ARG_ENABLE(builddocs,      AS_HELP_STRING([--enable-builddocs], [Build docs (default: disabled)]),
                                  [BUILDDOCS=$enableval],
                                  [BUILDDOCS=no])
commit 1c1a4bc970be061484bb8dcccf945eb08144c656
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Dec 13 19:51:40 2007 -0500

    devPrivates rework: more cleanup from previous merge operation.

diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index e3d0cfb..b6be47f 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -44,6 +44,7 @@
 #include <X11/dri/xf86dri.h>
 #include <X11/dri/xf86dristr.h>
 #include "misc.h"
+#include "privates.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "colormapst.h"
@@ -118,14 +119,13 @@ static Bool findWindowPairFromLocal (WindowPtr a_local,
 
 static unsigned char DRIReqCode = 0;
 
-static int ephyrDRIGeneration=-1 ;
-static int ephyrDRIWindowIndex=-1 ;
-static int ephyrDRIScreenIndex=-1 ;
+static DevPrivateKey ephyrDRIWindowKey = &ephyrDRIWindowKey;
+static DevPrivateKey ephyrDRIScreenKey = &ephyrDRIScreenKey;
 
-#define GET_EPHYR_DRI_WINDOW_PRIV(win) \
-    ((EphyrDRIWindowPrivPtr)((win)->devPrivates[ephyrDRIWindowIndex].ptr))
-#define GET_EPHYR_DRI_SCREEN_PRIV(screen) \
-    ((EphyrDRIScreenPrivPtr)((screen)->devPrivates[ephyrDRIScreenIndex].ptr))
+#define GET_EPHYR_DRI_WINDOW_PRIV(win) ((EphyrDRIWindowPrivPtr) \
+    dixLookupPrivate(&(win)->devPrivates, ephyrDRIWindowKey))
+#define GET_EPHYR_DRI_SCREEN_PRIV(screen) ((EphyrDRIScreenPrivPtr) \
+    dixLookupPrivate(&(screen)->devPrivates, ephyrDRIScreenKey))
 
 
 Bool
@@ -164,28 +164,18 @@ ephyrDRIExtensionInit (ScreenPtr a_screen)
         EPHYR_LOG_ERROR ("failed to register DRI extension\n") ;
         goto out ;
     }
-    if (ephyrDRIGeneration != serverGeneration) {
-        ephyrDRIScreenIndex = AllocateScreenPrivateIndex () ;
-        if (ephyrDRIScreenIndex < 0) {
-            EPHYR_LOG_ERROR ("failed to allocate screen priv index\n") ;
-            goto out ;
-        }
-    }
     screen_priv = xcalloc (1, sizeof (EphyrDRIScreenPrivRec)) ;
     if (!screen_priv) {
         EPHYR_LOG_ERROR ("failed to allocate screen_priv\n") ;
         goto out ;
     }
-    a_screen->devPrivates[ephyrDRIScreenIndex].ptr = screen_priv;
+    dixSetPrivate(&a_screen->devPrivates, ephyrDRIScreenKey, screen_priv);
 
     if (!ephyrDRIScreenInit (a_screen)) {
         EPHYR_LOG_ERROR ("ephyrDRIScreenInit() failed\n") ;
         goto out ;
     }
     EphyrMirrorHostVisuals (a_screen) ;
-    if (ephyrDRIGeneration != serverGeneration) {
-        ephyrDRIGeneration = serverGeneration ;
-    }
     is_ok=TRUE ;
 out:
     EPHYR_LOG ("leave\n") ;
@@ -203,17 +193,6 @@ ephyrDRIScreenInit (ScreenPtr a_screen)
     screen_priv=GET_EPHYR_DRI_SCREEN_PRIV (a_screen) ;
     EPHYR_RETURN_VAL_IF_FAIL (screen_priv, FALSE) ;
 
-    if (ephyrDRIGeneration != serverGeneration) {
-        ephyrDRIWindowIndex = AllocateWindowPrivateIndex () ;
-        if (ephyrDRIWindowIndex < 0) {
-            EPHYR_LOG_ERROR ("failed to allocate window priv index\n") ;
-            goto out ;
-        }
-    }
-    if (!AllocateWindowPrivate (a_screen, ephyrDRIWindowIndex, 0)) {
-        EPHYR_LOG_ERROR ("failed to allocate window privates\n") ;
-        goto out ;
-    }
     screen_priv->CreateWindow = a_screen->CreateWindow ;
     screen_priv->DestroyWindow = a_screen->DestroyWindow ;
     screen_priv->MoveWindow = a_screen->MoveWindow ;
@@ -254,7 +233,7 @@ ephyrDRICreateWindow (WindowPtr a_win)
     screen->CreateWindow = ephyrDRICreateWindow ;
 
     if (is_ok) {
-        a_win->devPrivates[ephyrDRIWindowIndex].ptr = NULL ;
+	dixSetPrivate(&a_win->devPrivates, ephyrDRIWindowKey, NULL);
     }
     return is_ok ;
 }
@@ -285,7 +264,7 @@ ephyrDRIDestroyWindow (WindowPtr a_win)
         if (win_priv) {
             destroyHostPeerWindow (a_win) ;
             xfree (win_priv) ;
-            a_win->devPrivates[ephyrDRIWindowIndex].ptr = NULL ;
+	    dixSetPrivate(&a_win->devPrivates, ephyrDRIWindowKey, NULL);
             EPHYR_LOG ("destroyed the remote peer window\n") ;
         }
     }
@@ -1088,7 +1067,7 @@ ProcXF86DRICreateDrawable (ClientPtr client)
             EPHYR_LOG_ERROR ("failed to allocate window private\n") ;
             return BadAlloc ;
         }
-        window->devPrivates[ephyrDRIWindowIndex].ptr = win_priv ;
+	dixSetPrivate(&window->devPrivates, ephyrDRIWindowKey, win_priv);
         EPHYR_LOG ("paired window '%#x' with remote '%d'\n",
                    (unsigned int)window, remote_win) ;
     }
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 5376f19..50148c4 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -29,6 +29,7 @@
 #endif
 #include <mivalidate.h>
 #include <dixstruct.h>
+#include "privates.h"
 #ifdef RANDR
 #include <randrstr.h>
 #endif
@@ -66,8 +67,8 @@ KdDepths    kdDepths[] = {
 
 #define KD_DEFAULT_BUTTONS 5
 
-int                 kdScreenPrivateIndex;
-unsigned long       kdGeneration;
+DevPrivateKey       kdScreenPrivateKey = &kdScreenPrivateKey;
+unsigned long	    kdGeneration;
 
 Bool                kdVideoTest;
 unsigned long       kdVideoTestTime;
@@ -751,10 +752,8 @@ KdAllocatePrivates (ScreenPtr pScreen)
     KdPrivScreenPtr	pScreenPriv;
     
     if (kdGeneration != serverGeneration)
-    {
-	kdScreenPrivateIndex = AllocateScreenPrivateIndex();
-	kdGeneration         = serverGeneration;
-    }
+	kdGeneration = serverGeneration;
+
     pScreenPriv = (KdPrivScreenPtr) xalloc(sizeof (*pScreenPriv));
     if (!pScreenPriv)
 	return FALSE;
@@ -1401,8 +1400,8 @@ KdInitOutput (ScreenInfo    *pScreenInfo,
 }
 
 #ifdef DPMSExtension
-void
-DPMSSet(int level)
+int
+DPMSSet(ClientPtr client, int level)
 {
 }
 
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index b6ff4f8..0b8d1c4 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -106,9 +106,10 @@ static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr*, int);
 
 DevPrivateKey KdXVWindowKey = &KdXVWindowKey;
 DevPrivateKey KdXvScreenKey = &KdXvScreenKey;
+static unsigned long KdXVGeneration = 0;
 static unsigned long PortResource = 0;
 
-int (*XvGetScreenKeyProc)(void) = XvGetScreenKey;
+DevPrivateKey (*XvGetScreenKeyProc)(void) = XvGetScreenKey;
 unsigned long (*XvGetRTPortProc)(void) = XvGetRTPort;
 int (*XvScreenInitProc)(ScreenPtr) = XvScreenInit;
 
@@ -191,12 +192,15 @@ KdXVScreenInit(
 
 /*   fprintf(stderr,"KdXVScreenInit initializing %d adaptors\n",num); */
 
+  if (KdXVGeneration != serverGeneration)
+      KdXVGeneration = serverGeneration;
+
   if(!XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
 	return FALSE;  
 
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
-  KdXvScreenIndex = (*XvGetScreenKeyProc)();
+  KdXvScreenKey = (*XvGetScreenKeyProc)();
   PortResource = (*XvGetRTPortProc)();
 
   pxvs = GET_XV_SCREEN(pScreen);
@@ -1106,7 +1110,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
 	    pPriv->pDraw = NULL;
 
 	    if(!pPrev) 
-		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv->next);
+		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, WinPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
 	    tmp = WinPriv;
diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index ab4dc0d..d932bcd 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -88,7 +88,7 @@ FILE *debug_log_fp = NULL;
  * X server shared global variables
  */
 int                     darwinScreensFound = 0;
-int                     darwinScreenIndex = 0;
+DevPrivateKey           darwinScreenKey = &darwinScreenKey;
 io_connect_t            darwinParamConnect = 0;
 int                     darwinEventReadFD = -1;
 int                     darwinEventWriteFD = -1;
@@ -613,7 +613,6 @@ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo)
 void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv )
 {
     int i;
-    static unsigned long generation = 0;
 
     pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
     pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
@@ -625,12 +624,6 @@ void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv )
     for (i = 0; i < NUMFORMATS; i++)
         pScreenInfo->formats[i] = formats[i];
 
-    // Allocate private storage for each screen's Darwin specific info
-    if (generation != serverGeneration) {
-        darwinScreenIndex = AllocateScreenPrivateIndex();
-        generation = serverGeneration;
-    }
-
     // Discover screens and do mode specific initialization
     QuartzInitOutput(argc, argv);
 
commit c8feb73f5841e7812d8dfdb91f1064e2033d028c
Merge: 9a7ce57... a125ce4...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Dec 13 18:38:25 2007 -0500

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	Xext/EVI.c
    	Xext/bigreq.c
    	Xext/cup.c
    	Xext/dpms.c
    	Xext/fontcache.c
    	Xext/mitmisc.c
    	Xext/xcmisc.c
    	Xext/xf86bigfont.c
    	Xext/xtest.c
    	configure.ac
    	dbe/dbe.c
    	hw/darwin/darwin.h
    	hw/darwin/darwinEvents.c
    	hw/darwin/iokit/xfIOKit.h
    	hw/darwin/iokit/xfIOKitCursor.c
    	hw/darwin/quartz/fullscreen/fullscreen.c
    	hw/darwin/quartz/fullscreen/quartzCursor.c
    	hw/darwin/quartz/quartz.c
    	hw/darwin/quartz/quartzCommon.h
    	hw/darwin/quartz/quartzCursor.c
    	hw/darwin/quartz/xpr/dri.c
    	hw/darwin/quartz/xpr/dristruct.h
    	hw/darwin/quartz/xpr/xprCursor.c
    	hw/darwin/quartz/xpr/xprFrame.c
    	hw/xfree86/modes/xf86RandR12.c
    	include/cursor.h
    	miext/rootless/rootlessCommon.h
    	miext/rootless/rootlessScreen.c
    	miext/rootless/rootlessWindow.c
    	render/picturestr.h
    
    Trying to pick up the pieces from the darwin churn here...

diff --cc Xext/xvmain.c
index a2fc108,1b80bc8..9834fcf
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@@ -102,10 -102,10 +102,10 @@@ SOFTWARE
  #ifdef PANORAMIX
  #include "panoramiX.h"
  #include "panoramiXsrv.h"
- #include "xvdisp.h"
  #endif
+ #include "xvdisp.h"
  
 -int  XvScreenIndex = -1;
 +static DevPrivateKey XvScreenKey = &XvScreenKey;
  unsigned long XvExtensionGeneration = 0;
  unsigned long XvScreenGeneration = 0;
  unsigned long XvResourceGeneration = 0;
@@@ -311,21 -323,21 +311,21 @@@ XvCloseScreen
  
    xfree(pxvs);
  
 -  pScreen->devPrivates[XvScreenIndex].ptr = (pointer)NULL;
 +  dixSetPrivate(&pScreen->devPrivates, XvScreenKey, NULL);
  
    return (*pScreen->CloseScreen)(ii, pScreen);
- 
  }
  
  static void
  XvResetProc(ExtensionEntry* extEntry)
  {
+     XvResetProcVector();
  }
  
 -_X_EXPORT int
 -XvGetScreenIndex(void)
 +_X_EXPORT DevPrivateKey
 +XvGetScreenKey(void)
  {
 -  return XvScreenIndex;
 +    return XvScreenKey;
  }
  
  _X_EXPORT unsigned long
diff --cc cfb/cfbmap.h
index 2e709b1,d6d4475..16e4afc
--- a/cfb/cfbmap.h
+++ b/cfb/cfbmap.h
@@@ -266,7 -140,7 +140,7 @@@ cfb can not hack PSZ ye
  #define cfbFillSpanTileOddGeneral CFBNAME(FillSpanTileOddGeneral)
  #define cfbFinishScreenInit CFBNAME(FinishScreenInit)
  #define cfbGCFuncs CFBNAME(GCFuncs)
--#define cfbGCPrivateIndex CFBNAME(GCPrivateIndex)
++#define cfbGCPrivateKey CFBNAME(GCPrivateKey)
  #define cfbGetImage CFBNAME(GetImage)
  #define cfbGetScreenPixmap CFBNAME(GetScreenPixmap)
  #define cfbGetSpans CFBNAME(GetSpans)
@@@ -296,7 -170,7 +170,7 @@@
  #define cfbRestoreAreas CFBNAME(RestoreAreas)
  #define cfbSaveAreas CFBNAME(SaveAreas)
  #define cfbScreenInit CFBNAME(ScreenInit)
--#define cfbScreenPrivateIndex CFBNAME(ScreenPrivateIndex)
++#define cfbScreenPrivateKey CFBNAME(ScreenPrivateKey)
  #define cfbSegmentSD CFBNAME(SegmentSD)
  #define cfbSegmentSS CFBNAME(SegmentSS)
  #define cfbSetScanline CFBNAME(SetScanline)
@@@ -320,7 -194,7 +194,7 @@@
  #define cfbUnnaturalTileFS CFBNAME(UnnaturalTileFS)
  #define cfbValidateGC CFBNAME(ValidateGC)
  #define cfbVertS CFBNAME(VertS)
--#define cfbWindowPrivateIndex CFBNAME(WindowPrivateIndex)
++#define cfbWindowPrivateKey CFBNAME(WindowPrivateKey)
  #define cfbXRotatePixmap CFBNAME(XRotatePixmap)
  #define cfbYRotatePixmap CFBNAME(YRotatePixmap)
  #define cfbZeroPolyArcSS8Copy CFBNAME(ZeroPolyArcSSCopy)
diff --cc cfb/cfbunmap.h
index d15c23e,d15c23e..db98892
--- a/cfb/cfbunmap.h
+++ b/cfb/cfbunmap.h
@@@ -93,7 -93,7 +93,7 @@@
  #undef cfbFillSpanTileOddGeneral
  #undef cfbFinishScreenInit
  #undef cfbGCFuncs
--#undef cfbGCPrivateIndex
++#undef cfbGCPrivateKey
  #undef cfbGetImage
  #undef cfbGetScreenPixmap
  #undef cfbGetSpans
@@@ -123,7 -123,7 +123,7 @@@
  #undef cfbRestoreAreas
  #undef cfbSaveAreas
  #undef cfbScreenInit
--#undef cfbScreenPrivateIndex
++#undef cfbScreenPrivateKey
  #undef cfbSegmentSD
  #undef cfbSegmentSS
  #undef cfbSetScanline
@@@ -147,7 -147,7 +147,7 @@@
  #undef cfbUnnaturalTileFS
  #undef cfbValidateGC
  #undef cfbVertS
--#undef cfbWindowPrivateIndex
++#undef cfbWindowPrivateKey
  #undef cfbXRotatePixmap
  #undef cfbYRotatePixmap
  #undef cfbZeroPolyArcSS8Copy
diff --cc configure.ac
index 042cfdd,b56c115..8dae13f
--- a/configure.ac
+++ b/configure.ac
@@@ -453,14 -475,16 +468,17 @@@ AC_ARG_WITH(xkb-path,         AS_HELP_S
  AC_ARG_WITH(xkb-output,       AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${datadir}/X11/xkb/compiled)]),
  				[ XKBOUTPUT="$withval" ],
  				[ XKBOUTPUT="compiled" ])
 -AC_ARG_WITH(serverconfig-path, AS_HELP_STRING([--with-serverconfig-path=PATH], [Path to server config (default: ${libdir}/xserver)]),
 +AC_ARG_WITH(serverconfig-path, AS_HELP_STRING([--with-serverconfig-path=PATH],
 +				   [Directory where ancillary server config files are installed (default: ${libdir}/xorg)]),
  				[ SERVERCONFIG="$withval" ],
 -				[ SERVERCONFIG="${libdir}/xserver" ])
 +				[ SERVERCONFIG="${libdir}/xorg" ])
- APPLE_APPLICATIONS_DIR="${bindir}/Applications"
- AC_ARG_WITH(apple-applications-dir,AS_HELP_STRING([--with-apple-applications-dir=PATH], [Path to the Applications directory (default: ${bindir}/Applications)]),
-                                [ APPLE_APPLICATIONS_DIR="${withval}" ].
-                                [ APPLE_APPLICATIONS_DIR="${bindir}/Applications" ])
+ APPLE_APPLICATIONS_DIR="/Applications/Utilities"
+ AC_ARG_WITH(apple-applications-dir,AS_HELP_STRING([--with-apple-applications-dir=PATH], [Path to the Applications directory (default: /Applications/Utilities)]),
+ 				[ APPLE_APPLICATIONS_DIR="${withval}" ].
+ 				[ APPLE_APPLICATIONS_DIR="/Applications/Utilities" ])
+ 
+ AC_ARG_WITH(launchd,          AS_HELP_STRING([--with-launchd], [Build with support for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto])
+ 
  AC_ARG_WITH(pci-txt-ids-dir, AS_HELP_STRING([--with-pci-txt-ids-dir=PATH],
  [Path to pci id directory (default: ${datadir}/X11/pci)]),
  				[ PCI_TXT_IDS_DIR="$withval" ],
@@@ -1324,11 -1282,8 +1294,8 @@@ if test "x$XORG" = xyes -o "x$XGL" = xy
  	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
  	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
  	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
 -	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB"
 +	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB"
  
- dnl Check to see if dlopen is in default libraries (like Solaris, which
- dnl has it in libc), or if libdl is needed to get it.
- 
  	PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.8.0])
  	XORG_SYS_LIBS="$XORG_SYS_LIBS $PCIACCESS_LIBS $DLOPEN_LIBS $GLX_SYS_LIBS"
  	XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
diff --cc hw/xfree86/loader/xf86sym.c
index 67a2fe7,050b873..623e87a
--- a/hw/xfree86/loader/xf86sym.c
+++ b/hw/xfree86/loader/xf86sym.c
@@@ -1088,17 -905,9 +905,9 @@@ _X_HIDDEN void *xfree86LookupTab[] = 
  #endif
  #endif
  
-     /* Some variables. */
- 
-     SYMVAR(xf86stdin)
-     SYMVAR(xf86stdout)
-     SYMVAR(xf86stderr)
-     SYMVAR(xf86errno)
-     SYMVAR(xf86HUGE_VAL)
- 
      /* General variables (from xf86.h) */
 -    SYMVAR(xf86ScreenIndex)
 -    SYMVAR(xf86PixmapIndex)
 +    SYMVAR(xf86ScreenKey)
 +    SYMVAR(xf86PixmapKey)
      SYMVAR(xf86Screens)
      SYMVAR(byte_reversed)
      SYMVAR(xf86inSuspend)
diff --cc hw/xfree86/modes/xf86RandR12.c
index 18989bb,bb7f945..e2668fb
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@@ -59,11 -59,11 +59,11 @@@ static Bool xf86RandR12Init12 (ScreenPt
  static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen);
  #endif
  
 -static int	    xf86RandR12Index = -1;
 -static int	    xf86RandR12Generation;
 +static int xf86RandR12Generation;
- static DevPrivateKey xf86RandR12Key = &xf86RandR12Key;
++static DevPrivateKey xf86RandR12Key;
  
 -#define XF86RANDRINFO(p) \
 -	((XF86RandRInfoPtr)(p)->devPrivates[xf86RandR12Index].ptr)
 +#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \
 +    dixLookupPrivate(&(p)->devPrivates, xf86RandR12Key))
  
  static int
  xf86RandR12ModeRefresh (DisplayModePtr mode)
@@@ -340,10 -340,12 +340,12 @@@ xf86RandR12ScreenSetSize (ScreenPtr	pSc
      PixmapPtr		pScrnPix = (*pScreen->GetScreenPixmap)(pScreen);
      Bool		ret = FALSE;
  
-     if (randrp->virtualX == -1 || randrp->virtualY == -1)
-     {
- 	randrp->virtualX = pScrn->virtualX;
- 	randrp->virtualY = pScrn->virtualY;
 -    if (xf86RandR12Index != -1) {
++    if (xf86RandR12Key) {
+         if (randrp->virtualX == -1 || randrp->virtualY == -1)
+         {
+ 	    randrp->virtualX = pScrn->virtualX;
+ 	    randrp->virtualY = pScrn->virtualY;
+         }
      }
      if (pRoot && pScrn->vtSema)
  	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE);
@@@ -366,7 -368,7 +368,7 @@@ finish
      if (pRoot && pScrn->vtSema)
  	(*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
  #if RANDR_12_INTERFACE
-     if (WindowTable[pScreen->myNum] && ret)
 -    if ((xf86RandR12Index != -1) && WindowTable[pScreen->myNum] && ret)
++    if (xf86RandR12Key && WindowTable[pScreen->myNum] && ret)
  	RRScreenSizeNotify (pScreen);
  #endif
      return ret;
@@@ -466,6 -468,9 +468,9 @@@ xf86RandR12CreateScreenResources (Scree
  				  mmHeight);
      }
  
 -    if (xf86RandR12Index == -1)
++    if (xf86RandR12Key == NULL)
+ 	return TRUE;
+ 
      if (randrp->virtualX == -1 || randrp->virtualY == -1)
      {
  	randrp->virtualX = pScrn->virtualX;
@@@ -491,9 -496,12 +496,12 @@@ xf86RandR12Init (ScreenPtr pScreen
      if (!noPanoramiXExtension)
  	return TRUE;
  #endif
++
      if (xf86RandR12Generation != serverGeneration)
 -    {
 -	xf86RandR12Index = AllocateScreenPrivateIndex();
  	xf86RandR12Generation = serverGeneration;
 -    }
 +
++    xf86RandR12Key = &xf86RandR12Key;
+ 
      randrp = xalloc (sizeof (XF86RandRInfoRec));
      if (!randrp)
  	return FALSE;
@@@ -535,7 -543,13 +543,13 @@@ xf86RandR12SetRotations (ScreenPtr pScr
      ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
      int			c;
      xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+ #endif
  
 -    if (xf86RandR12Index == -1)
++    if (xf86RandR12Key == NULL)
+ 	return;
+ 
+     randrp = XF86RANDRINFO(pScreen);
+ #if RANDR_12_INTERFACE
      for (c = 0; c < config->num_crtc; c++) {
  	xf86CrtcPtr    crtc = config->crtc[c];
  
@@@ -1065,9 -1076,11 +1076,11 @@@ xf86RandR12CreateScreenResources12 (Scr
      ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
      xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
  
 -    if (xf86RandR12Index == -1)
++    if (xf86RandR12Key == NULL)
+ 	return TRUE;
+ 
      for (c = 0; c < config->num_crtc; c++)
- 	xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc);
-     
+         xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc);
      
      RRScreenSetSizeRange (pScreen, config->minWidth, config->minHeight,
  			  config->maxWidth, config->maxHeight);
@@@ -1084,11 -1097,11 +1097,11 @@@ xf86RandR12TellChanged (ScreenPtr pScre
  {
      ScrnInfoPtr		pScrn = xf86Screens[pScreen->myNum];
      xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
-     XF86RandRInfoPtr	randrp = XF86RANDRINFO(pScreen);
      int			c;
  
-     if (!randrp)
 -    if (xf86RandR12Index == -1)
++    if (xf86RandR12Key == NULL)
  	return;
+ 
      xf86RandR12SetInfo12 (pScreen);
      for (c = 0; c < config->num_crtc; c++)
  	xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc);
diff --cc hw/xquartz/darwin.c
index 0000000,299d983..ab4dc0d
mode 000000,100644..100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@@ -1,0 -1,1088 +1,1088 @@@
+ /**************************************************************
+  *
+  * Shared code for the Darwin X Server
+  * running with Quartz or IOKit display mode
+  *
+  * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
+  * Copyright (c) 2007 Apple Inc.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifdef HAVE_DIX_CONFIG_H
+ #include <dix-config.h>
+ #endif
+ 
+ #include <X11/X.h>
+ #include <X11/Xproto.h>
+ #include "os.h"
+ #include "servermd.h"
+ #include "inputstr.h"
+ #include "scrnintstr.h"
+ #include "mibstore.h"		// mi backing store implementation
+ #include "mipointer.h"		// mi software cursor
+ #include "micmap.h"		// mi colormap code
+ #include "fb.h"			// fb framebuffer code
+ #include "site.h"
+ #include "globals.h"
+ #include "dix.h"
+ 
+ #ifdef XINPUT
+ # include <X11/extensions/XI.h>
+ # include <X11/extensions/XIproto.h>
+ # include "exevents.h"
+ # include "extinit.h"
+ #endif
+ 
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <sys/syslimits.h>
+ #include <stdio.h>
+ #include <fcntl.h>
+ #include <unistd.h>
+ 
+ #define HAS_UTSNAME 1
+ #include <sys/utsname.h>
+ 
+ #define NO_CFPLUGIN
+ #include <IOKit/IOKitLib.h>
+ #include <IOKit/hidsystem/IOHIDLib.h>
+ #include <IOKit/hidsystem/ev_keymap.h>
+ 
+ #ifdef MITSHM
+ #define _XSHM_SERVER_
+ #include <X11/extensions/XShm.h>
+ #endif
+ 
+ #include "darwin.h"
+ #include "darwinEvents.h"
+ #include "darwinKeyboard.h"
+ #include "quartz.h"
+ #include "darwinClut8.h"
+ 
+ #ifdef ENABLE_DEBUG_LOG
+ FILE *debug_log_fp = NULL;
+ #endif
+ 
+ /*
+  * X server shared global variables
+  */
+ int                     darwinScreensFound = 0;
+ int                     darwinScreenIndex = 0;
+ io_connect_t            darwinParamConnect = 0;
+ int                     darwinEventReadFD = -1;
+ int                     darwinEventWriteFD = -1;
+ // int                     darwinMouseAccelChange = 1;
+ int                     darwinFakeButtons = 0;
+ 
+ // location of X11's (0,0) point in global screen coordinates
+ int                     darwinMainScreenX = 0;
+ int                     darwinMainScreenY = 0;
+ 
+ // parameters read from the command line or user preferences
+ unsigned int            darwinDesiredWidth = 0, darwinDesiredHeight = 0;
+ int                     darwinDesiredDepth = -1;
+ int                     darwinDesiredRefresh = -1;
+ char                    *darwinKeymapFile = "USA.keymapping";
+ int                     darwinSyncKeymap = FALSE;
+ 
+ // modifier masks for faking mouse buttons
+ int                     darwinFakeMouse2Mask = NX_ALTERNATEMASK;
+ int                     darwinFakeMouse3Mask = NX_COMMANDMASK;
+ 
+ // devices
+ DeviceIntPtr            darwinPointer = NULL;
+ DeviceIntPtr            darwinKeyboard = NULL;
+ 
+ // Common pixmap formats
+ static PixmapFormatRec formats[] = {
+         { 1,    1,      BITMAP_SCANLINE_PAD },
+         { 4,    8,      BITMAP_SCANLINE_PAD },
+         { 8,    8,      BITMAP_SCANLINE_PAD },
+         { 15,   16,     BITMAP_SCANLINE_PAD },
+         { 16,   16,     BITMAP_SCANLINE_PAD },
+         { 24,   32,     BITMAP_SCANLINE_PAD },
+         { 32,   32,     BITMAP_SCANLINE_PAD }
+ };
+ const int NUMFORMATS = sizeof(formats)/sizeof(formats[0]);
+ 
+ #ifndef OSNAME
+ #define OSNAME " Darwin"
+ #endif
+ #ifndef OSVENDOR
+ #define OSVENDOR ""
+ #endif
+ #ifndef PRE_RELEASE
+ #define PRE_RELEASE XORG_VERSION_SNAP
+ #endif
+ #ifndef BUILD_DATE
+ #define BUILD_DATE ""
+ #endif
+ #ifndef XORG_RELEASE
+ #define XORG_RELEASE "?"
+ #endif
+ 
+ void DDXRingBell(int volume, int pitch, int duration) {
+   // FIXME -- make some noise, yo
+ }
+ 
+ void
+ DarwinPrintBanner(void)
+ { 
+   // this should change depending on which specific server we are building
+   ErrorF("X11.app starting:\n");
+   ErrorF("Xquartz server based on X.org %s, built on %s\n", XORG_RELEASE, BUILD_DATE );
+ }
+ 
+ 
+ /*
+  * DarwinSaveScreen
+  *  X screensaver support. Not implemented.
+  */
+ static Bool DarwinSaveScreen(ScreenPtr pScreen, int on)
+ {
+     // FIXME
+     if (on == SCREEN_SAVER_FORCER) {
+     } else if (on == SCREEN_SAVER_ON) {
+     } else {
+     }
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * DarwinAddScreen
+  *  This is a callback from dix during AddScreen() from InitOutput().
+  *  Initialize the screen and communicate information about it back to dix.
+  */
+ static Bool DarwinAddScreen(
+     int         index,
+     ScreenPtr   pScreen,
+     int         argc,
+     char        **argv )
+ {
+     int         bitsPerRGB, i, dpi;
+     static int  foundIndex = 0;
+     Bool        ret;
+     VisualPtr   visual;
+     ColormapPtr pmap;
+     DarwinFramebufferPtr dfb;
+ 
+     // reset index of found screens for each server generation
+     if (index == 0) foundIndex = 0;
+ 
+     // allocate space for private per screen storage
+     dfb = xalloc(sizeof(DarwinFramebufferRec));
+ 
+     // SCREEN_PRIV(pScreen) = dfb;
 -    pScreen->devPrivates[darwinScreenIndex].ptr = dfb;
++    dixSetPrivate(&pScreen->devPrivates, darwinScreenKey, dfb);
+ 
+     // setup hardware/mode specific details
+     ret = QuartzAddScreen(foundIndex, pScreen);
+     foundIndex++;
+     if (! ret)
+         return FALSE;
+ 
+     bitsPerRGB = dfb->bitsPerComponent;
+ 
+     // reset the visual list
+     miClearVisualTypes();
+ 
+     // setup a single visual appropriate for our pixel type
+     if (dfb->colorType == TrueColor) {
+         if (!miSetVisualTypes( dfb->colorBitsPerPixel, TrueColorMask,
+                                bitsPerRGB, TrueColor )) {
+             return FALSE;
+         }
+     } else if (dfb->colorType == PseudoColor) {
+         if (!miSetVisualTypes( dfb->colorBitsPerPixel, PseudoColorMask,
+                                bitsPerRGB, PseudoColor )) {
+             return FALSE;
+         }
+     } else if (dfb->colorType == StaticColor) {
+         if (!miSetVisualTypes( dfb->colorBitsPerPixel, StaticColorMask,
+                                bitsPerRGB, StaticColor )) {
+             return FALSE;
+         }
+     } else {
+         return FALSE;
+     }
+ 
+     miSetPixmapDepths();
+ 
+     // machine independent screen init
+     // setup _Screen structure in pScreen
+     if (monitorResolution)
+         dpi = monitorResolution;
+     else
+         dpi = 75;
+ 
+     // initialize fb
+     if (! fbScreenInit(pScreen,
+                 dfb->framebuffer,                 // pointer to screen bitmap
+                 dfb->width, dfb->height,          // screen size in pixels
+                 dpi, dpi,                         // dots per inch
+                 dfb->pitch/(dfb->bitsPerPixel/8), // pixel width of framebuffer
+                 dfb->bitsPerPixel))               // bits per pixel for screen
+     {
+         return FALSE;
+     }
+ 
+     // set the RGB order correctly for TrueColor
+     if (dfb->bitsPerPixel > 8) {
+         for (i = 0, visual = pScreen->visuals;  // someday we may have more than 1
+             i < pScreen->numVisuals; i++, visual++) {
+             if (visual->class == TrueColor) {
+                 visual->offsetRed = bitsPerRGB * 2;
+                 visual->offsetGreen = bitsPerRGB;
+                 visual->offsetBlue = 0;
+                 visual->redMask = ((1<<bitsPerRGB)-1) << visual->offsetRed;
+                 visual->greenMask = ((1<<bitsPerRGB)-1) << visual->offsetGreen;
+                 visual->blueMask = ((1<<bitsPerRGB)-1) << visual->offsetBlue;
+             }
+         }
+     }
+ 
+ #ifdef RENDER
+     if (! fbPictureInit(pScreen, 0, 0)) {
+         return FALSE;
+     }
+ #endif
+ 
+ #ifdef MITSHM
+     ShmRegisterFbFuncs(pScreen);
+ #endif
+ 
+     // this must be initialized (why doesn't X have a default?)
+     pScreen->SaveScreen = DarwinSaveScreen;
+ 
+     // finish mode dependent screen setup including cursor support
+     if (!QuartzSetupScreen(index, pScreen)) {
+         return FALSE;
+     }
+ 
+     // create and install the default colormap and
+     // set pScreen->blackPixel / pScreen->white
+     if (!miCreateDefColormap( pScreen )) {
+         return FALSE;
+     }
+ 
+     /* Set the colormap to the statically defined one if we're in 8 bit
+      * mode and we're using a fixed color map.  Essentially this translates
+      * to Darwin/x86 in 8-bit mode.
+      */
+     if( (dfb->colorBitsPerPixel == 8) &&
+                 (dfb->colorType == StaticColor) )
+     {
+         pmap = miInstalledMaps[pScreen->myNum];
+         visual = pmap->pVisual;
+         for( i = 0; i < visual->ColormapEntries; i++ ) {
+             pmap->red[i].co.local.red   = darwinClut8[i].red;
+             pmap->red[i].co.local.green = darwinClut8[i].green;
+             pmap->red[i].co.local.blue  = darwinClut8[i].blue;
+         }
+     }
+ 
+     dixScreenOrigins[index].x = dfb->x;
+     dixScreenOrigins[index].y = dfb->y;
+ 
+     /*    ErrorF("Screen %d added: %dx%d @ (%d,%d)\n",
+ 	  index, dfb->width, dfb->height, dfb->x, dfb->y); */
+ 
+     return TRUE;
+ }
+ 
+ /*
+  =============================================================================
+ 
+  mouse and keyboard callbacks
+ 
+  =============================================================================
+ */
+ 
+ #if 0
+ /*
+  * DarwinChangePointerControl
+  *  Set mouse acceleration and thresholding
+  *  FIXME: We currently ignore the threshold in ctrl->threshold.
+  */
+ static void DarwinChangePointerControl(
+     DeviceIntPtr    device,
+     PtrCtrl         *ctrl )
+ {
+     kern_return_t   kr;
+     double          acceleration;
+ 
+     if (!darwinMouseAccelChange)
+         return;
+ 
+     acceleration = ctrl->num / ctrl->den;
+     kr = IOHIDSetMouseAcceleration( darwinParamConnect, acceleration );
+     if (kr != KERN_SUCCESS)
+         ErrorF( "Could not set mouse acceleration with kernel return = 0x%x.\n", kr );
+ }
+ #endif
+ 
+ /*
+  * DarwinMouseProc
+  *  Handle the initialization, etc. of a mouse
+  */
+ static int DarwinMouseProc(
+     DeviceIntPtr    pPointer,
+     int             what )
+ {
+     CARD8 map[6];
+ 
+     switch (what) {
+ 
+         case DEVICE_INIT:
+             pPointer->public.on = FALSE;
+ 
+             // Set button map.
+             map[1] = 1;
+             map[2] = 2;
+             map[3] = 3;
+             map[4] = 4;
+             map[5] = 5;
+             InitPointerDeviceStruct( (DevicePtr)pPointer, map, 5,
+ 				     GetMotionHistory,
+ 				     (PtrCtrlProcPtr)NoopDDA,
+ 				     GetMotionHistorySize(), 2);
+ 
+ #ifdef XINPUT
+             InitValuatorAxisStruct( pPointer,
+                                     0,     // X axis
+                                     0,     // min value
+                                     16000, // max value (fixme screen size?)
+                                     1,     // resolution (fixme ?)
+                                     1,     // min resolution
+                                     1 );   // max resolution
+             InitValuatorAxisStruct( pPointer,
+                                     1,     // X axis
+                                     0,     // min value
+                                     16000, // max value (fixme screen size?)
+                                     1,     // resolution (fixme ?)
+                                     1,     // min resolution
+                                     1 );   // max resolution
+ #endif
+             break;
+ 
+         case DEVICE_ON:
+             pPointer->public.on = TRUE;
+             AddEnabledDevice( darwinEventReadFD );
+             return Success;
+ 
+         case DEVICE_CLOSE:
+         case DEVICE_OFF:
+             pPointer->public.on = FALSE;
+             RemoveEnabledDevice( darwinEventReadFD );
+             return Success;
+     }
+ 
+     return Success;
+ }
+ 
+ 
+ /*
+  * DarwinKeybdProc
+  *  Callback from X
+  */
+ static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff )
+ {
+     switch ( onoff ) {
+         case DEVICE_INIT:
+             DarwinKeyboardInit( pDev );
+             break;
+         case DEVICE_ON:
+             pDev->public.on = TRUE;
+             AddEnabledDevice( darwinEventReadFD );
+             break;
+         case DEVICE_OFF:
+             pDev->public.on = FALSE;
+             RemoveEnabledDevice( darwinEventReadFD );
+             break;
+         case DEVICE_CLOSE:
+             break;
+     }
+ 
+     return Success;
+ }
+ 
+ /*
+ ===========================================================================
+ 
+  Utility routines
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * DarwinFindLibraryFile
+  *  Search for a file in the standard Library paths, which are (in order):
+  *
+  *      ~/Library/              user specific
+  *      /Library/               host specific
+  *      /Network/Library/       LAN specific
+  *      /System/Library/        OS specific
+  *
+  *  A sub-path can be specified to search in below the various Library
+  *  directories. Returns a new character string (owned by the caller)
+  *  containing the full path to the first file found.
+  */
+ static char * DarwinFindLibraryFile(
+     const char *file,
+     const char *pathext )
+ {
+     // Library search paths
+     char *pathList[] = {
+         "",
+         "/Network",
+         "/System",
+         NULL
+     };
+     char *home;
+     char *fullPath;
+     int i = 0;
+ 
+     // Return the file name as is if it is already a fully qualified path.
+     if (!access(file, F_OK)) {
+         fullPath = xalloc(strlen(file)+1);
+         strcpy(fullPath, file);
+         return fullPath;
+     }
+ 
+     fullPath = xalloc(PATH_MAX);
+ 
+     home = getenv("HOME");
+     if (home) {
+         snprintf(fullPath, PATH_MAX, "%s/Library/%s/%s", home, pathext, file);
+         if (!access(fullPath, F_OK))
+             return fullPath;
+     }
+ 
+     while (pathList[i]) {
+         snprintf(fullPath, PATH_MAX, "%s/Library/%s/%s", pathList[i++],
+                  pathext, file);
+         if (!access(fullPath, F_OK))
+             return fullPath;
+     }
+ 
+     xfree(fullPath);
+     return NULL;
+ }
+ 
+ 
+ /*
+  * DarwinParseModifierList
+  *  Parse a list of modifier names and return a corresponding modifier mask
+  */
+ int DarwinParseModifierList(
+     const char *constmodifiers) // string containing list of modifier names
+ {
+     int result = 0;
+ 
+     if (constmodifiers) {
+         char *modifiers = strdup(constmodifiers);
+         char *modifier;
+         int nxkey;
+         char *p = modifiers;
+ 
+         while (p) {
+             modifier = strsep(&p, " ,+&|/"); // allow lots of separators
+             nxkey = DarwinModifierStringToNXKey(modifier);
+             if (nxkey != -1)
+                 result |= DarwinModifierNXKeyToNXMask(nxkey);
+             else
+                 ErrorF("fakebuttons: Unknown modifier \"%s\"\n", modifier);
+         }
+         free(modifiers);
+     }
+     return result;
+ }
+ 
+ /*
+ ===========================================================================
+ 
+  Functions needed to link against device independent X
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * InitInput
+  *  Register the keyboard and mouse devices
+  */
+ void InitInput( int argc, char **argv )
+ {
+     darwinPointer = AddInputDevice(DarwinMouseProc, TRUE);
+     RegisterPointerDevice( darwinPointer );
+ 
+     darwinKeyboard = AddInputDevice(DarwinKeybdProc, TRUE);
+     RegisterKeyboardDevice( darwinKeyboard );
+ 
+     DarwinEQInit( (DevicePtr)darwinKeyboard, (DevicePtr)darwinPointer );
+ 
+     QuartzInitInput(argc, argv);
+ }
+ 
+ 
+ /*
+  * DarwinAdjustScreenOrigins
+  *  Shift all screens so the X11 (0, 0) coordinate is at the top
+  *  left of the global screen coordinates.
+  *
+  *  Screens can be arranged so the top left isn't on any screen, so
+  *  instead use the top left of the leftmost screen as (0,0). This
+  *  may mean some screen space is in -y, but it's better that (0,0)
+  *  be onscreen, or else default xterms disappear. It's better that
+  *  -y be used than -x, because when popup menus are forced
+  *  "onscreen" by dumb window managers like twm, they'll shift the
+  *  menus down instead of left, which still looks funny but is an
+  *  easier target to hit.
+  */
+ void
+ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo)
+ {
+     int i, left, top;
+ 
+     left = dixScreenOrigins[0].x;
+     top  = dixScreenOrigins[0].y;
+ 
+     /* Find leftmost screen. If there's a tie, take the topmost of the two. */
+     for (i = 1; i < pScreenInfo->numScreens; i++) {
+         if (dixScreenOrigins[i].x < left  ||
+             (dixScreenOrigins[i].x == left &&
+              dixScreenOrigins[i].y < top))
+         {
+             left = dixScreenOrigins[i].x;
+             top = dixScreenOrigins[i].y;
+         }
+     }
+ 
+     darwinMainScreenX = left;
+     darwinMainScreenY = top;
+ 
+     /* Shift all screens so that there is a screen whose top left
+        is at X11 (0,0) and at global screen coordinate
+        (darwinMainScreenX, darwinMainScreenY). */
+ 
+     if (darwinMainScreenX != 0 || darwinMainScreenY != 0) {
+         for (i = 0; i < pScreenInfo->numScreens; i++) {
+             dixScreenOrigins[i].x -= darwinMainScreenX;
+             dixScreenOrigins[i].y -= darwinMainScreenY;
+     /*            ErrorF("Screen %d placed at X11 coordinate (%d,%d).\n",
+ 		  i, dixScreenOrigins[i].x, dixScreenOrigins[i].y); */
+         }
+     }
+ }
+ 
+ 
+ /*
+  * InitOutput
+  *  Initialize screenInfo for all actually accessible framebuffers.
+  *
+  *  The display mode dependent code gets called three times. The mode
+  *  specific InitOutput routines are expected to discover the number
+  *  of potentially useful screens and cache routes to them internally.
+  *  Inside DarwinAddScreen are two other mode specific calls.
+  *  A mode specific AddScreen routine is called for each screen to
+  *  actually initialize the screen with the ScreenPtr structure.
+  *  After other screen setup has been done, a mode specific
+  *  SetupScreen function can be called to finalize screen setup.
+  */
+ void InitOutput( ScreenInfo *pScreenInfo, int argc, char **argv )
+ {
+     int i;
+     static unsigned long generation = 0;
+ 
+     pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+     pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+     pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+     pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+ 
+     // List how we want common pixmap formats to be padded
+     pScreenInfo->numPixmapFormats = NUMFORMATS;
+     for (i = 0; i < NUMFORMATS; i++)
+         pScreenInfo->formats[i] = formats[i];
+ 
+     // Allocate private storage for each screen's Darwin specific info
+     if (generation != serverGeneration) {
+         darwinScreenIndex = AllocateScreenPrivateIndex();
+         generation = serverGeneration;
+     }
+ 
+     // Discover screens and do mode specific initialization
+     QuartzInitOutput(argc, argv);
+ 
+     // Add screens
+     for (i = 0; i < darwinScreensFound; i++) {
+         AddScreen( DarwinAddScreen, argc, argv );
+     }
+ 
+     DarwinAdjustScreenOrigins(pScreenInfo);
+ }
+ 
+ 
+ /*
+  * OsVendorFataError
+  */
+ void OsVendorFatalError( void )
+ {
+     ErrorF( "   OsVendorFatalError\n" );
+ }
+ 
+ 
+ /*
+  * OsVendorInit
+  *  Initialization of Darwin OS support.
+  */
+ void OsVendorInit(void)
+ {
+     if (serverGeneration == 1) {
+         DarwinPrintBanner();
+ #ifdef ENABLE_DEBUG_LOG
+ 	{
+ 	  char *home_dir=NULL, *log_file_path=NULL;
+ 	  home_dir = getenv("HOME");
+ 	  if (home_dir) asprintf(&log_file_path, "%s/%s", home_dir, DEBUG_LOG_NAME);
+ 	  if (log_file_path) {
+ 	    if (!access(log_file_path, F_OK)) {
+ 	      debug_log_fp = fopen(log_file_path, "a");
+ 	      if (debug_log_fp) ErrorF("Debug logging enabled to %s\n", log_file_path);
+ 	    }
+ 	    free(log_file_path);
+ 	  }
+ 	}
+ #endif
+     }
+     //    DEBUG_LOG("Xquartz started at %s\n", ctime(time(NULL)));
+ 
+     // Find the full path to the keymapping file.
+     if ( darwinKeymapFile ) {
+         char *tempStr = DarwinFindLibraryFile(darwinKeymapFile, "Keyboards");
+         if ( !tempStr ) {
+             ErrorF("Could not find keymapping file %s.\n", darwinKeymapFile);
+         } else {
+             ErrorF("Using keymapping provided in %s.\n", tempStr);
+         }
+         darwinKeymapFile = tempStr;
+     }
+ }
+ 
+ 
+ /*
+  * ddxInitGlobals
+  *  Called by InitGlobals() from os/util.c.
+  */
+ void ddxInitGlobals(void)
+ {
+ }
+ 
+ 
+ /*
+  * ddxProcessArgument
+  *  Process device-dependent command line args. Returns 0 if argument is
+  *  not device dependent, otherwise Count of number of elements of argv
+  *  that are part of a device dependent commandline option.
+  */
+ int ddxProcessArgument( int argc, char *argv[], int i )
+ {
+     if( !strcmp( argv[i], "-launchd" ) ) {
+         ErrorF( "Launchd command line argument noticed.\n" );
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-fullscreen" ) ) {
+         ErrorF( "Running full screen in parallel with Mac OS X Quartz window server.\n" );
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-rootless" ) ) {
+         ErrorF( "Running rootless inside Mac OS X window server.\n" );
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-quartz" ) ) {
+         ErrorF( "Running in parallel with Mac OS X Quartz window server.\n" );
+         return 1;
+     }
+ 
+     // The Mac OS X front end uses this argument, which we just ignore here.
+     if ( !strcmp( argv[i], "-nostartx" ) ) {
+         return 1;
+     }
+ 
+     // This command line arg is passed when launched from the Aqua GUI.
+     if ( !strncmp( argv[i], "-psn_", 5 ) ) {
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-fakebuttons" ) ) {
+         darwinFakeButtons = TRUE;
+         ErrorF( "Faking a three button mouse\n" );
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-nofakebuttons" ) ) {
+         darwinFakeButtons = FALSE;
+         ErrorF( "Not faking a three button mouse\n" );
+         return 1;
+     }
+ 
+     if (!strcmp( argv[i], "-fakemouse2" ) ) {
+         if ( i == argc-1 ) {
+             FatalError( "-fakemouse2 must be followed by a modifer list\n" );
+         }
+         if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], ""))
+             darwinFakeMouse2Mask = 0;
+         else
+             darwinFakeMouse2Mask = DarwinParseModifierList(argv[i+1]);
+         ErrorF("Modifier mask to fake mouse button 2 = 0x%x\n",
+                darwinFakeMouse2Mask);
+         return 2;
+     }
+ 
+     if (!strcmp( argv[i], "-fakemouse3" ) ) {
+         if ( i == argc-1 ) {
+             FatalError( "-fakemouse3 must be followed by a modifer list\n" );
+         }
+         if (!strcasecmp(argv[i+1], "none") || !strcmp(argv[i+1], ""))
+             darwinFakeMouse3Mask = 0;
+         else
+             darwinFakeMouse3Mask = DarwinParseModifierList(argv[i+1]);
+         ErrorF("Modifier mask to fake mouse button 3 = 0x%x\n",
+                darwinFakeMouse3Mask);
+         return 2;
+     }
+ 
+     if ( !strcmp( argv[i], "-keymap" ) ) {
+         if ( i == argc-1 ) {
+             FatalError( "-keymap must be followed by a filename\n" );
+         }
+         darwinKeymapFile = argv[i+1];
+         return 2;
+     }
+ 
+     if ( !strcmp( argv[i], "-nokeymap" ) ) {
+         darwinKeymapFile = NULL;
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "+synckeymap" ) ) {
+         darwinSyncKeymap = TRUE;
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-synckeymap" ) ) {
+         darwinSyncKeymap = FALSE;
+         return 1;
+     }
+ 
+     if ( !strcmp( argv[i], "-size" ) ) {
+         if ( i >= argc-2 ) {
+             FatalError( "-size must be followed by two numbers\n" );
+         }
+ #ifdef OLD_POWERBOOK_G3
+         ErrorF( "Ignoring unsupported -size option on old PowerBook G3\n" );
+ #else
+         darwinDesiredWidth = atoi( argv[i+1] );
+         darwinDesiredHeight = atoi( argv[i+2] );
+         ErrorF( "Attempting to use width x height = %i x %i\n",
+                 darwinDesiredWidth, darwinDesiredHeight );
+ #endif
+         return 3;
+     }
+ 
+     if ( !strcmp( argv[i], "-depth" ) ) {
+         int     bitDepth;
+ 
+         if ( i == argc-1 ) {
+             FatalError( "-depth must be followed by a number\n" );
+         }
+ #ifdef OLD_POWERBOOK_G3
+         ErrorF( "Ignoring unsupported -depth option on old PowerBook G3\n");
+ #else
+         bitDepth = atoi( argv[i+1] );
+         if (bitDepth == 8)
+             darwinDesiredDepth = 0;
+         else if (bitDepth == 15)
+             darwinDesiredDepth = 1;
+         else if (bitDepth == 24)
+             darwinDesiredDepth = 2;
+         else
+             FatalError( "Unsupported pixel depth. Use 8, 15, or 24 bits\n" );
+         ErrorF( "Attempting to use pixel depth of %i\n", bitDepth );
+ #endif
+         return 2;
+     }
+ 
+     if ( !strcmp( argv[i], "-refresh" ) ) {
+         if ( i == argc-1 ) {
+             FatalError( "-refresh must be followed by a number\n" );
+         }
+ #ifdef OLD_POWERBOOK_G3
+         ErrorF( "Ignoring unsupported -refresh option on old PowerBook G3\n");
+ #else
+         darwinDesiredRefresh = atoi( argv[i+1] );
+         ErrorF( "Attempting to use refresh rate of %i\n", darwinDesiredRefresh );
+ #endif
+         return 2;
+     }
+ 
+     if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
+         DarwinPrintBanner();
+         exit(0);
+     }
+ 
+     // XDarwinStartup uses this argument to indicate the IOKit X server
+     // should be started. Ignore it here.
+     if ( !strcmp( argv[i], "-iokit" ) ) {
+         return 1;
+     }
+ 
+     return 0;
+ }
+ 
+ 
+ /*
+  * ddxUseMsg --
+  *  Print out correct use of device dependent commandline options.
+  *  Maybe the user now knows what really to do ...
+  */
+ void ddxUseMsg( void )
+ {
+     ErrorF("\n");
+     ErrorF("\n");
+     ErrorF("Device Dependent Usage:\n");
+     ErrorF("\n");
+     ErrorF("-fakebuttons : fake a three button mouse with Command and Option keys.\n");
+     ErrorF("-nofakebuttons : don't fake a three button mouse.\n");
+     ErrorF("-fakemouse2 <modifiers> : fake middle mouse button with modifier keys.\n");
+     ErrorF("-fakemouse3 <modifiers> : fake right mouse button with modifier keys.\n");
+     ErrorF("  ex: -fakemouse2 \"option,shift\" = option-shift-click is middle button.\n");
+     ErrorF("-keymap <file> : read the keymapping from a file instead of the kernel.\n");
+     ErrorF("-version : show the server version.\n");
+     ErrorF("\n");
+     ErrorF("Quartz modes (Experimental / In Development):\n");
+     ErrorF("-fullscreen : run full screen in parallel with Mac OS X window server.\n");
+     ErrorF("-rootless : run rootless inside Mac OS X window server.\n");
+     ErrorF("\n");
+     ErrorF("Options ignored in rootless mode:\n");
+     ErrorF("-size <height> <width> : use a screen resolution of <height> x <width>.\n");
+     ErrorF("-depth <8,15,24> : use this bit depth.\n");
+     ErrorF("-refresh <rate> : use a monitor refresh rate of <rate> Hz.\n");
+     ErrorF("\n");
+ }
+ 
+ 
+ /*
+  * ddxGiveUp --
+  *      Device dependent cleanup. Called by dix before normal server death.
+  */
+ void ddxGiveUp( void )
+ {
+     ErrorF( "Quitting XQuartz...\n" );
+ 
+     QuartzGiveUp();
+ }
+ 
+ 
+ /*
+  * AbortDDX --
+  *      DDX - specific abort routine.  Called by AbortServer(). The attempt is
+  *      made to restore all original setting of the displays. Also all devices
+  *      are closed.
+  */
+ void AbortDDX( void )
+ {
+     ErrorF( "   AbortDDX\n" );
+     /*
+      * This is needed for a abnormal server exit, since the normal exit stuff
+      * MUST also be performed (i.e. the vt must be left in a defined state)
+      */
+     ddxGiveUp();
+ }
+ 
+ 
+ /*
+  * DPMS extension stubs
+  */
+ Bool DPMSSupported(void)
+ {
+     return FALSE;
+ }
+ 
+ void DPMSSet(int level)
+ {
+ }
+ 
+ int DPMSGet(int *level)
+ {
+     return -1;
+ }
+ 
+ #include "mivalidate.h" // for union _Validate used by windowstr.h
+ #include "windowstr.h"  // for struct _Window
+ #include "scrnintstr.h" // for struct _Screen
+ 
+ // This is copied from Xserver/hw/xfree86/common/xf86Helper.c.
+ // Quartz mode uses this when switching in and out of Quartz.
+ // Quartz or IOKit can use this when waking from sleep.
+ // Copyright (c) 1997-1998 by The XFree86 Project, Inc.
+ 
+ /*
+  * xf86SetRootClip --
+  *	Enable or disable rendering to the screen by
+  *	setting the root clip list and revalidating
+  *	all of the windows
+  */
+ 
+ void
+ xf86SetRootClip (ScreenPtr pScreen, BOOL enable)
+ {
+     WindowPtr	pWin = WindowTable[pScreen->myNum];
+     WindowPtr	pChild;
+     Bool	WasViewable = (Bool)(pWin->viewable);
+     Bool	anyMarked = TRUE;
+     RegionPtr	pOldClip = NULL, bsExposed;
+ #ifdef DO_SAVE_UNDERS
+     Bool	dosave = FALSE;
+ #endif
+     WindowPtr   pLayerWin;
+     BoxRec	box;
+ 
+     if (WasViewable)
+     {
+ 	for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib)
+ 	{
+ 	    (void) (*pScreen->MarkOverlappedWindows)(pChild,
+ 						     pChild,
+ 						     &pLayerWin);
+ 	}
+ 	(*pScreen->MarkWindow) (pWin);
+ 	anyMarked = TRUE;
+ 	if (pWin->valdata)
+ 	{
+ 	    if (HasBorder (pWin))
+ 	    {
+ 		RegionPtr	borderVisible;
+ 
+ 		borderVisible = REGION_CREATE(pScreen, NullBox, 1);
+ 		REGION_SUBTRACT(pScreen, borderVisible,
+ 				&pWin->borderClip, &pWin->winSize);
+ 		pWin->valdata->before.borderVisible = borderVisible;
+ 	    }
+ 	    pWin->valdata->before.resized = TRUE;
+ 	}
+     }
+ 
+     /*
+      * Use REGION_BREAK to avoid optimizations in ValidateTree
+      * that assume the root borderClip can't change well, normally
+      * it doesn't...)
+      */
+     if (enable)
+     {
+ 	box.x1 = 0;
+ 	box.y1 = 0;
+ 	box.x2 = pScreen->width;
+ 	box.y2 = pScreen->height;
+ 	REGION_RESET(pScreen, &pWin->borderClip, &box);
+ 	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+     }
+     else
+     {
+ 	REGION_EMPTY(pScreen, &pWin->borderClip);
+ 	REGION_BREAK (pWin->drawable.pScreen, &pWin->clipList);
+     }
+ 
+     ResizeChildrenWinSize (pWin, 0, 0, 0, 0);
+ 
+     if (WasViewable)
+     {
+ 	if (pWin->backStorage)
+ 	{
+ 	    pOldClip = REGION_CREATE(pScreen, NullBox, 1);
+ 	    REGION_COPY(pScreen, pOldClip, &pWin->clipList);
+ 	}
+ 
+ 	if (pWin->firstChild)
+ 	{
+ 	    anyMarked |= (*pScreen->MarkOverlappedWindows)(pWin->firstChild,
+ 							   pWin->firstChild,
+ 							   (WindowPtr *)NULL);
+ 	}
+ 	else
+ 	{
+ 	    (*pScreen->MarkWindow) (pWin);
+ 	    anyMarked = TRUE;
+ 	}
+ 
+ #ifdef DO_SAVE_UNDERS
+ 	if (DO_SAVE_UNDERS(pWin))
+ 	{
+ 	    dosave = (*pScreen->ChangeSaveUnder)(pLayerWin, pLayerWin);
+ 	}
+ #endif /* DO_SAVE_UNDERS */
+ 
+ 	if (anyMarked)
+ 	    (*pScreen->ValidateTree)(pWin, NullWindow, VTOther);
+     }
+ 
+     if (pWin->backStorage &&
+ 	((pWin->backingStore == Always) || WasViewable))
+     {
+ 	if (!WasViewable)
+ 	    pOldClip = &pWin->clipList; /* a convenient empty region */
+ 	bsExposed = (*pScreen->TranslateBackingStore)
+ 			     (pWin, 0, 0, pOldClip,
+ 			      pWin->drawable.x, pWin->drawable.y);
+ 	if (WasViewable)
+ 	    REGION_DESTROY(pScreen, pOldClip);
+ 	if (bsExposed)
+ 	{
+ 	    RegionPtr	valExposed = NullRegion;
+ 
+ 	    if (pWin->valdata)
+ 		valExposed = &pWin->valdata->after.exposed;
+ 	    (*pScreen->WindowExposures) (pWin, valExposed, bsExposed);
+ 	    if (valExposed)
+ 		REGION_EMPTY(pScreen, valExposed);
+ 	    REGION_DESTROY(pScreen, bsExposed);
+ 	}
+     }
+     if (WasViewable)
+     {
+ 	if (anyMarked)
+ 	    (*pScreen->HandleExposures)(pWin);
+ #ifdef DO_SAVE_UNDERS
+ 	if (dosave)
+ 	    (*pScreen->PostChangeSaveUnder)(pLayerWin, pLayerWin);
+ #endif /* DO_SAVE_UNDERS */
+ 	if (anyMarked && pScreen->PostValidateTree)
+ 	    (*pScreen->PostValidateTree)(pWin, NullWindow, VTOther);
+     }
+     if (pWin->realized)
+ 	WindowsRestructured ();
+     FlushAllOutput ();
+ }
diff --cc hw/xquartz/darwin.h
index 0000000,f835ae0..c569d66
mode 000000,100644..100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@@ -1,0 -1,128 +1,128 @@@
+ /*
+  * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifndef _DARWIN_H
+ #define _DARWIN_H
+ 
+ #include <IOKit/IOTypes.h>
+ #include "inputstr.h"
+ #include "scrnintstr.h"
+ #include <X11/extensions/XKB.h>
+ #include <assert.h>
+ 
+ typedef struct {
+     void                *framebuffer;
+     int                 x;
+     int                 y;
+     int                 width;
+     int                 height;
+     int                 pitch;
+     int                 colorType;
+     int                 bitsPerPixel;
+     int                 colorBitsPerPixel;
+     int                 bitsPerComponent;
+ } DarwinFramebufferRec, *DarwinFramebufferPtr;
+ 
+ // From darwin.c
+ void DarwinPrintBanner(void);
+ int DarwinParseModifierList(const char *constmodifiers);
+ void DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo);
+ void xf86SetRootClip (ScreenPtr pScreen, BOOL enable);
+ 
 -#define SCREEN_PRIV(pScreen) \
 -    ((DarwinFramebufferPtr)pScreen->devPrivates[darwinScreenIndex].ptr)
++#define SCREEN_PRIV(pScreen) ((DarwinFramebufferPtr) \
++    dixLookupPrivate(&pScreen->devPrivates, darwinScreenKey))
+ 
+ /*
+  * Global variables from darwin.c
+  */
 -extern int              darwinScreenIndex; // index into pScreen.devPrivates
++extern DevPrivateKey    darwinScreenKey; // index into pScreen.devPrivates
+ extern int              darwinScreensFound;
+ extern io_connect_t     darwinParamConnect;
+ extern int              darwinEventReadFD;
+ extern int              darwinEventWriteFD;
+ extern DeviceIntPtr     darwinPointer;
+ extern DeviceIntPtr     darwinKeyboard;
+ 
+ // User preferences
+ extern int              darwinMouseAccelChange;
+ extern int              darwinFakeButtons;
+ extern int              darwinFakeMouse2Mask;
+ extern int              darwinFakeMouse3Mask;
+ extern char            *darwinKeymapFile;
+ extern int              darwinSyncKeymap;
+ extern unsigned int     darwinDesiredWidth, darwinDesiredHeight;
+ extern int              darwinDesiredDepth;
+ extern int              darwinDesiredRefresh;
+ 
+ // location of X11's (0,0) point in global screen coordinates
+ extern int              darwinMainScreenX;
+ extern int              darwinMainScreenY;
+ 
+ 
+ /*
+  * Special ddx events understood by the X server
+  */
+ enum {
+     kXDarwinUpdateModifiers   // update all modifier keys
+             = LASTEvent+1,    // (from X.h list of event names)
+     kXDarwinUpdateButtons,    // update state of mouse buttons 2 and up
+     kXDarwinScrollWheel,      // scroll wheel event
+     /*
+      * Quartz-specific events -- not used in IOKit mode
+      */
+     kXDarwinActivate,         // restore X drawing and cursor
+     kXDarwinDeactivate,       // clip X drawing and switch to Aqua cursor
+     kXDarwinSetRootClip,      // enable or disable drawing to the X screen
+     kXDarwinQuit,             // kill the X server and release the display
+     kXDarwinReadPasteboard,   // copy Mac OS X pasteboard into X cut buffer
+     kXDarwinWritePasteboard,  // copy X cut buffer onto Mac OS X pasteboard
+     kXDarwinBringAllToFront,  // bring all X windows to front
+     kXDarwinToggleFullscreen, // Enable/Disable fullscreen mode
+     kXDarwinSetRootless,      // Set rootless mode
+     /*
+      * AppleWM events
+      */
+     kXDarwinControllerNotify, // send an AppleWMControllerNotify event
+     kXDarwinPasteboardNotify, // notify the WM to copy or paste
+     /*
+      * Xplugin notification events
+      */
+     kXDarwinDisplayChanged,   // display configuration has changed
+     kXDarwinWindowState,      // window visibility state has changed
+     kXDarwinWindowMoved       // window has moved on screen
+ };
+ 
+ #define ENABLE_DEBUG_LOG 1
+ 
+ #ifdef ENABLE_DEBUG_LOG
+ extern FILE *debug_log_fp;
+ #define DEBUG_LOG_NAME "x11-debug.txt"
+ #define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%d: " msg, __FUNCTION__, __LINE__, ##args )
+ #else
+ #define DEBUG_LOG(msg, args...) 
+ #endif
+ 
+ #endif  /* _DARWIN_H */
diff --cc hw/xquartz/darwinEvents.c
index 0000000,1d09e09..1760792
mode 000000,100644..100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@@ -1,0 -1,462 +1,462 @@@
+ /*
+ Darwin event queue and event handling
+ 
+ Copyright 2007 Apple Inc.
+ Copyright 2004 Kaleb S. KEITHLEY. All Rights Reserved.
+ Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
+ 
+ This file is based on mieq.c by Keith Packard,
+ which contains the following copyright:
+ Copyright 1990, 1998  The Open Group
+ 
+ Permission to use, copy, modify, distribute, and sell this software and its
+ documentation for any purpose is hereby granted without fee, provided that
+ the above copyright notice appear in all copies and that both that
+ copyright notice and this permission notice appear in supporting
+ documentation.
+ 
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+ OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ 
+ Except as contained in this notice, the name of The Open Group shall not be
+ used in advertising or otherwise to promote the sale, use or other dealings
+ in this Software without prior written authorization from The Open Group.
+  */
+ 
+ #define NEED_EVENTS
+ #include   <X11/X.h>
+ #include   <X11/Xmd.h>
+ #include   <X11/Xproto.h>
+ #include   "misc.h"
+ #include   "windowstr.h"
+ #include   "pixmapstr.h"
+ #include   "inputstr.h"
+ #include   "mi.h"
+ #include   "scrnintstr.h"
+ #include   "mipointer.h"
+ 
+ #include "darwin.h"
+ #include "quartz.h"
+ #include "darwinKeyboard.h"
+ 
+ #include <sys/types.h>
+ #include <sys/uio.h>
+ #include <unistd.h>
+ #include <IOKit/hidsystem/IOLLEvent.h>
+ 
+ /* Fake button press/release for scroll wheel move. */
+ #define SCROLLWHEELUPFAKE   4
+ #define SCROLLWHEELDOWNFAKE 5
+ 
+ #define QUEUE_SIZE 256
+ 
+ typedef struct _Event {
+     xEvent      event;
+     ScreenPtr   pScreen;
+ } EventRec, *EventPtr;
+ 
+ int input_check_zero, input_check_flag;
+ 
+ static int old_flags = 0;  // last known modifier state
+ 
+ typedef struct _EventQueue {
+     HWEventQueueType    head, tail; /* long for SetInputCheck */
+     CARD32      lastEventTime;      /* to avoid time running backwards */
+     Bool        lastMotion;
+     EventRec    events[QUEUE_SIZE]; /* static allocation for signals */
+     DevicePtr   pKbd, pPtr;         /* device pointer, to get funcs */
+     ScreenPtr   pEnqueueScreen;     /* screen events are being delivered to */
+     ScreenPtr   pDequeueScreen;     /* screen events are being dispatched to */
+ } EventQueueRec, *EventQueuePtr;
+ 
+ static EventQueueRec darwinEventQueue;
+ xEvent *darwinEvents;
+ 
+ /*
+  * DarwinPressModifierMask
+  *  Press or release the given modifier key, specified by its mask.
+  */
+ static void DarwinPressModifierMask(
+     int pressed,				    
+     int mask)       // one of NX_*MASK constants
+ {
+     int key = DarwinModifierNXMaskToNXKey(mask);
+ 
+     if (key != -1) {
+         int keycode = DarwinModifierNXKeyToNXKeycode(key, 0);
+         if (keycode != 0)
+ 	  DarwinSendKeyboardEvents(pressed, keycode);
+     }
+ }
+ 
+ #ifdef NX_DEVICELCTLKEYMASK
+ #define CONTROL_MASK(flags) (flags & (NX_DEVICELCTLKEYMASK|NX_DEVICERCTLKEYMASK))
+ #else
+ #define CONTROL_MASK(flags) (NX_CONTROLMASK)
+ #endif /* NX_DEVICELCTLKEYMASK */
+ 
+ #ifdef NX_DEVICELSHIFTKEYMASK
+ #define SHIFT_MASK(flags) (flags & (NX_DEVICELSHIFTKEYMASK|NX_DEVICERSHIFTKEYMASK))
+ #else
+ #define SHIFT_MASK(flags) (NX_SHIFTMASK)
+ #endif /* NX_DEVICELSHIFTKEYMASK */
+ 
+ #ifdef NX_DEVICELCMDKEYMASK
+ #define COMMAND_MASK(flags) (flags & (NX_DEVICELCMDKEYMASK|NX_DEVICERCMDKEYMASK))
+ #else
+ #define COMMAND_MASK(flags) (NX_COMMANDMASK)
+ #endif /* NX_DEVICELCMDKEYMASK */
+ 
+ #ifdef NX_DEVICELALTKEYMASK
+ #define ALTERNATE_MASK(flags) (flags & (NX_DEVICELALTKEYMASK|NX_DEVICERALTKEYMASK))
+ #else
+ #define ALTERNATE_MASK(flags) (NX_ALTERNATEMASK)
+ #endif /* NX_DEVICELALTKEYMASK */
+ 
+ /*
+  * DarwinUpdateModifiers
+  *  Send events to update the modifier state.
+  */
+ static void DarwinUpdateModifiers(
+     int pressed,        // KeyPress or KeyRelease
+     int flags )         // modifier flags that have changed
+ {
+     if (flags & NX_ALPHASHIFTMASK) {
+         DarwinPressModifierMask(pressed, NX_ALPHASHIFTMASK);
+     }
+     if (flags & NX_COMMANDMASK) {
+         DarwinPressModifierMask(pressed, COMMAND_MASK(flags));
+     }
+     if (flags & NX_CONTROLMASK) {
+         DarwinPressModifierMask(pressed, CONTROL_MASK(flags));
+     }
+     if (flags & NX_ALTERNATEMASK) {
+         DarwinPressModifierMask(pressed, ALTERNATE_MASK(flags));
+     }
+     if (flags & NX_SHIFTMASK) {
+         DarwinPressModifierMask(pressed, SHIFT_MASK(flags));
+     }
+     if (flags & NX_SECONDARYFNMASK) {
+         DarwinPressModifierMask(pressed, NX_SECONDARYFNMASK);
+     }
+ }
+ 
+ /*
+  * DarwinReleaseModifiers
+  * This hacky function releases all modifier keys.  It should be called when X11.app
+  * is deactivated (kXDarwinDeactivate) to prevent modifiers from getting stuck if they
+  * are held down during a "context" switch -- otherwise, we would miss the KeyUp.
+  */
+ static void DarwinReleaseModifiers(void) {
+ 	DarwinUpdateModifiers(KeyRelease, COMMAND_MASK(-1) | CONTROL_MASK(-1) | ALTERNATE_MASK(-1) | SHIFT_MASK(-1));
+ }
+ 
+ /*
+  * DarwinSimulateMouseClick
+  *  Send a mouse click to X when multiple mouse buttons are simulated
+  *  with modifier-clicks, such as command-click for button 2. The dix
+  *  layer is told that the previously pressed modifier key(s) are
+  *  released, the simulated click event is sent. After the mouse button
+  *  is released, the modifier keys are reverted to their actual state,
+  *  which may or may not be pressed at that point. This is usually
+  *  closest to what the user wants. Ie. the user typically wants to
+  *  simulate a button 2 press instead of Command-button 2.
+  */
+ static void DarwinSimulateMouseClick(
+     int pointer_x,
+     int pointer_y,
+     int whichButton,    // mouse button to be pressed
+     int modifierMask)   // modifiers used for the fake click
+ {
+     // first fool X into forgetting about the keys
+ 	// for some reason, it's not enough to tell X we released the Command key -- 
+ 	// it has to be the *left* Command key.
+ 	if (modifierMask & NX_COMMANDMASK) modifierMask |=NX_DEVICELCMDKEYMASK ;
+     DarwinUpdateModifiers(KeyRelease, modifierMask);
+ 
+     // push the mouse button
+     DarwinSendPointerEvents(ButtonPress, whichButton, pointer_x, pointer_y);
+     DarwinSendPointerEvents(ButtonRelease, whichButton, pointer_x, pointer_y);
+ 
+     // restore old modifiers
+     DarwinUpdateModifiers(KeyPress, modifierMask);
+ }
+ 
+ 
+ Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) { 
+     darwinEvents = (xEvent *)malloc(sizeof(xEvent) * GetMaximumEventsNum());
+     mieqInit();
+     darwinEventQueue.head = darwinEventQueue.tail = 0;
+     darwinEventQueue.lastEventTime = GetTimeInMillis ();
+     darwinEventQueue.pKbd = pKbd;
+     darwinEventQueue.pPtr = pPtr;
+     darwinEventQueue.pEnqueueScreen = screenInfo.screens[0];
+     darwinEventQueue.pDequeueScreen = darwinEventQueue.pEnqueueScreen;
+     SetInputCheck(&input_check_zero, &input_check_flag);
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * DarwinEQEnqueue
+  *  Must be thread safe with ProcessInputEvents.
+  *    DarwinEQEnqueue    - called from event gathering thread
+  *    ProcessInputEvents - called from X server thread
+  *  DarwinEQEnqueue should never be called from more than one thread.
+  * 
+  * This should be deprecated in favor of miEQEnqueue -- BB
+  */
+ void DarwinEQEnqueue(const xEvent *e) {
+     HWEventQueueType oldtail, newtail;
+     char byte = 0;
+ 
+     oldtail = darwinEventQueue.tail;
+ 
+     // mieqEnqueue() collapses successive motion events into one event.
+     // This is difficult to do in a thread-safe way and rarely useful.
+ 
+     newtail = oldtail + 1;
+     if (newtail == QUEUE_SIZE) newtail = 0;
+     /* Toss events which come in late */
+     if (newtail == darwinEventQueue.head) return;
+ 
+     darwinEventQueue.events[oldtail].event = *e;
+ 
+     /*
+      * Make sure that event times don't go backwards - this
+      * is "unnecessary", but very useful
+      */
+     if (e->u.keyButtonPointer.time < darwinEventQueue.lastEventTime &&
+         darwinEventQueue.lastEventTime - e->u.keyButtonPointer.time < 10000)
+     {
+         darwinEventQueue.events[oldtail].event.u.keyButtonPointer.time =
+         darwinEventQueue.lastEventTime;
+     }
+     darwinEventQueue.events[oldtail].pScreen = darwinEventQueue.pEnqueueScreen;
+ 
+     // Update the tail after the event is prepared
+     darwinEventQueue.tail = newtail;
+ 
+     // Signal there is an event ready to handle
+     DarwinPokeEQ();
+ }
+ 
+ 
+ /*
+  * DarwinEQPointerPost
+  *  Post a pointer event. Used by the mipointer.c routines.
+  */
+ void DarwinEQPointerPost(xEvent *e) {
+     (*darwinEventQueue.pPtr->processInputProc)
+             (e, (DeviceIntPtr)darwinEventQueue.pPtr, 1);
+ }
+ 
+ 
+ void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX) {
+     darwinEventQueue.pEnqueueScreen = pScreen;
+     if (fromDIX)
+         darwinEventQueue.pDequeueScreen = pScreen;
+ }
+ 
+ 
+ /*
+  * ProcessInputEvents
+  *  Read and process events from the event queue until it is empty.
+  */
+ void ProcessInputEvents(void) {
+     EventRec *e;
+     int     x, y;
+     xEvent  xe;
+     static int  old_flags = 0;  // last known modifier state
+     // button number and modifier mask of currently pressed fake button
+     input_check_flag=0;
+ 
+     //    ErrorF("calling mieqProcessInputEvents\n");
+     mieqProcessInputEvents();
+ 
+     // Empty the signaling pipe
+     x = sizeof(xe);
+     while (x == sizeof(xe)) 
+         x = read(darwinEventReadFD, &xe, sizeof(xe));
+ 
+     while (darwinEventQueue.head != darwinEventQueue.tail)
+     {
+         if (screenIsSaved == SCREEN_SAVER_ON)
 -            SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
++            dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+ 
+         e = &darwinEventQueue.events[darwinEventQueue.head];
+         xe = e->event;
+ 
+         // Shift from global screen coordinates to coordinates relative to
+         // the origin of the current screen.
+         xe.u.keyButtonPointer.rootX -= darwinMainScreenX +
+                 dixScreenOrigins[miPointerCurrentScreen()->myNum].x;
+         xe.u.keyButtonPointer.rootY -= darwinMainScreenY +
+                 dixScreenOrigins[miPointerCurrentScreen()->myNum].y;
+ 	
+ 	/*	ErrorF("old rootX = (%d,%d) darwinMainScreen = (%d,%d) dixScreenOrigins[%d]=(%d,%d)\n",
+ 	       xe.u.keyButtonPointer.rootX, xe.u.keyButtonPointer.rootY,
+ 	       darwinMainScreenX, darwinMainScreenY,
+ 	       miPointerCurrentScreen()->myNum,
+ 	       dixScreenOrigins[miPointerCurrentScreen()->myNum].x,
+ 	       dixScreenOrigins[miPointerCurrentScreen()->myNum].y); */
+ 
+ 	//Assumption - screen switching can only occur on motion events
+ 
+         if (e->pScreen != darwinEventQueue.pDequeueScreen)
+         {
+             darwinEventQueue.pDequeueScreen = e->pScreen;
+             x = xe.u.keyButtonPointer.rootX;
+             y = xe.u.keyButtonPointer.rootY;
+             if (darwinEventQueue.head == QUEUE_SIZE - 1)
+                 darwinEventQueue.head = 0;
+             else
+                 ++darwinEventQueue.head;
+             NewCurrentScreen (darwinEventQueue.pDequeueScreen, x, y);
+         }
+         else
+         {
+             if (darwinEventQueue.head == QUEUE_SIZE - 1)
+                 darwinEventQueue.head = 0;
+             else
+                 ++darwinEventQueue.head;
+             switch (xe.u.u.type) {
+             case KeyPress:
+             case KeyRelease:
+ 	      ErrorF("Unexpected Keyboard event in DarwinProcessInputEvents\n");
+ 	      break;
+ 
+             case ButtonPress:
+ 	      ErrorF("Unexpected ButtonPress event in DarwinProcessInputEvents\n");
+                 break;
+ 
+             case ButtonRelease:
+ 	      ErrorF("Unexpected ButtonRelease event in DarwinProcessInputEvents\n");
+                 break;
+ 
+             case MotionNotify:
+ 	      ErrorF("Unexpected ButtonRelease event in DarwinProcessInputEvents\n");
+                 break;
+ 
+             case kXDarwinUpdateModifiers:
+ 	      ErrorF("Unexpected ButtonRelease event in DarwinProcessInputEvents\n");
+ 	      break;
+ 
+             case kXDarwinUpdateButtons:
+ 	      ErrorF("Unexpected XDarwinScrollWheel event in DarwinProcessInputEvents\n");
+ 	      break;
+ 
+             case kXDarwinScrollWheel: 
+ 	      ErrorF("Unexpected XDarwinScrollWheel event in DarwinProcessInputEvents\n");
+ 	      break;
+ 
+ 			case kXDarwinDeactivate:
+ 				DarwinReleaseModifiers();
+ 				// fall through
+             default:
+                 // Check for mode specific event
+                 QuartzProcessEvent(&xe);
+             }
+         }
+     }
+ 
+     //    miPointerUpdate();
+ }
+ 
+ /* Sends a null byte down darwinEventWriteFD, which will cause the
+    Dispatch() event loop to check out event queue */
+ void DarwinPokeEQ(void) {
+   char nullbyte=0;
+   input_check_flag++;
+   //  <daniels> bushing: oh, i ... er ... christ.
+   write(darwinEventWriteFD, &nullbyte, 1);
+ }
+ 
+ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y) {
+   static int darwinFakeMouseButtonDown = 0;
+   static int darwinFakeMouseButtonMask = 0;
+   int i, num_events;
+   int valuators[2] = {pointer_x, pointer_y};
+   if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
+     // Mimic multi-button mouse with modifier-clicks
+     // If both sets of modifiers are pressed,
+     // button 2 is clicked.
+     if ((old_flags & darwinFakeMouse2Mask) == darwinFakeMouse2Mask) {
+       DarwinSimulateMouseClick(pointer_x, pointer_y, 2, darwinFakeMouse2Mask);
+       darwinFakeMouseButtonDown = 2;
+       darwinFakeMouseButtonMask = darwinFakeMouse2Mask;
+     } else if ((old_flags & darwinFakeMouse3Mask) == darwinFakeMouse3Mask) {
+       DarwinSimulateMouseClick(pointer_x, pointer_y, 3, darwinFakeMouse3Mask);
+       darwinFakeMouseButtonDown = 3;
+       darwinFakeMouseButtonMask = darwinFakeMouse3Mask;
+     }
+   }
+   if (ev_type == ButtonRelease && darwinFakeButtons && darwinFakeMouseButtonDown) {
+     // If last mousedown was a fake click, don't check for
+     // mouse modifiers here. The user may have released the
+     // modifiers before the mouse button.
+     ev_button = darwinFakeMouseButtonDown;
+     darwinFakeMouseButtonDown = 0;
+     // Bring modifiers back up to date
+     DarwinUpdateModifiers(KeyPress, darwinFakeMouseButtonMask & old_flags);
+     darwinFakeMouseButtonMask = 0;
+   } 
+ 
+   num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
+ 				POINTER_ABSOLUTE, 0, 2, valuators);
+       
+   for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+   DarwinPokeEQ();
+ }
+ 
+ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
+   int i, num_events;
+   if (old_flags == 0 && darwinSyncKeymap && darwinKeymapFile == NULL) {
+     /* See if keymap has changed. */
+ 
+     static unsigned int last_seed;
+     unsigned int this_seed;
+ 
+     this_seed = QuartzSystemKeymapSeed();
+     if (this_seed != last_seed) {
+       last_seed = this_seed;
+       DarwinKeyboardReload(darwinKeyboard);
+     }
+   }
+ 
+   num_events = GetKeyboardEvents(darwinEvents, darwinKeyboard, ev_type, keycode + MIN_KEYCODE);
+   for(i=0; i<num_events; i++) mieqEnqueue(darwinKeyboard,&darwinEvents[i]);
+   DarwinPokeEQ();
+ }
+ 
+ /* Send the appropriate number of button 4 / 5 clicks to emulate scroll wheel */
+ void DarwinSendScrollEvents(float count, int pointer_x, int pointer_y) {
+   int i;
+   int ev_button = count > 0.0f ? 4 : 5;
+   int valuators[2] = {pointer_x, pointer_y};
+ 
+   for (count = fabs(count); count > 0.0; count = count - 1.0f) {
+     int num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonPress, ev_button, 
+ 				      POINTER_ABSOLUTE, 0, 2, valuators);
+     for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
+     num_events = GetPointerEvents(darwinEvents, darwinPointer, ButtonRelease, ev_button, 
+ 				      POINTER_ABSOLUTE, 0, 2, valuators);
+     for(i=0; i<num_events; i++) mieqEnqueue(darwinPointer,&darwinEvents[i]);
+   }
+   DarwinPokeEQ();
+ }
+ 
+ /* Send the appropriate KeyPress/KeyRelease events to GetKeyboardEvents to
+    reflect changing modifier flags (alt, control, meta, etc) */
+ void DarwinUpdateModKeys(int flags) {
+   DarwinUpdateModifiers(KeyRelease, old_flags & ~flags);
+   DarwinUpdateModifiers(KeyPress, ~old_flags & flags);
+   old_flags = flags;
+ }
diff --cc hw/xquartz/quartz.c
index 0000000,7be91ec..2063300
mode 000000,100644..100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@@ -1,0 -1,539 +1,531 @@@
+ /*
+  *
+  * Quartz-specific support for the Darwin X Server
+  *
+  * Copyright (c) 2001-2004 Greg Parker and Torrey T. Lyons.
+  *                 All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifdef HAVE_DIX_CONFIG_H
+ #include <dix-config.h>
+ #endif
+ 
+ #include "quartzCommon.h"
+ #include "quartz.h"
+ #include "darwin.h"
+ #include "darwinEvents.h"
+ #include "quartzAudio.h"
+ #include "pseudoramiX.h"
+ #define _APPLEWM_SERVER_
+ #include "X11/extensions/applewm.h"
+ #include "applewmExt.h"
+ 
+ #include "X11Application.h"
+ 
+ // X headers
+ #include "scrnintstr.h"
+ #include "windowstr.h"
+ #include "colormapst.h"
+ #include "globals.h"
+ #include "rootlessWindow.h"
+ 
+ // System headers
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ #include <IOKit/pwr_mgt/IOPMLib.h>
+ 
+ #define FAKE_RANDR 1
+ 
+ // Shared global variables for Quartz modes
+ int                     quartzEventWriteFD = -1;
+ int                     quartzStartClients = 1;
+ int                     quartzRootless = -1;
+ int                     quartzUseSysBeep = 0;
+ int                     quartzUseAGL = 1;
+ int                     quartzEnableKeyEquivalents = 1;
+ int                     quartzServerVisible = TRUE;
+ int                     quartzServerQuitting = FALSE;
 -int                     quartzScreenIndex = 0;
++DevPrivateKey           quartzScreenKey = &quartzScreenKey;
+ int                     aquaMenuBarHeight = 0;
+ int                     noPseudoramiXExtension = FALSE;
+ QuartzModeProcsPtr      quartzProcs = NULL;
+ const char             *quartzOpenGLBundle = NULL;
+ 
+ #if defined(RANDR) && !defined(FAKE_RANDR)
+ Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
+   return FALSE;
+ }
+ 
+ Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
+ 			       Rotation            randr,
+ 			       int                 rate,
+ 			       RRScreenSizePtr     pSize) {
+   return FALSE;
+ }
+ 
+ Bool QuartzRandRInit (ScreenPtr pScreen) {
+   rrScrPrivPtr    pScrPriv;
+     
+   if (!RRScreenInit (pScreen)) return FALSE;
+ 
+   pScrPriv = rrGetScrPriv(pScreen);
+   pScrPriv->rrGetInfo = QuartzRandRGetInfo;
+   pScrPriv->rrSetConfig = QuartzRandRSetConfig;
+   return TRUE;
+ }
+ #endif
+ 
+ /*
+ ===========================================================================
+ 
+  Screen functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzAddScreen
+  *  Do mode dependent initialization of each screen for Quartz.
+  */
+ Bool QuartzAddScreen(
+     int index,
+     ScreenPtr pScreen)
+ {
+     // allocate space for private per screen Quartz specific storage
+     QuartzScreenPtr displayInfo = xcalloc(sizeof(QuartzScreenRec), 1);
+ 
+     // QUARTZ_PRIV(pScreen) = displayInfo;
 -    pScreen->devPrivates[quartzScreenIndex].ptr = displayInfo;
++    dixSetPrivate(&pScreen->devPrivates, quartzScreenKey, displayInfo);
+ 
+     // do Quartz mode specific initialization
+     return quartzProcs->AddScreen(index, pScreen);
+ }
+ 
+ 
+ /*
+  * QuartzSetupScreen
+  *  Finalize mode specific setup of each screen.
+  */
+ Bool QuartzSetupScreen(
+     int index,
+     ScreenPtr pScreen)
+ {
+     // do Quartz mode specific setup
+     if (! quartzProcs->SetupScreen(index, pScreen))
+         return FALSE;
+ 
+     // setup cursor support
+     if (! quartzProcs->InitCursor(pScreen))
+         return FALSE;
+ 
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * QuartzInitOutput
+  *  Quartz display initialization.
+  */
+ void QuartzInitOutput(
+     int argc,
+     char **argv )
+ {
 -    static unsigned long generation = 0;
 -
 -    // Allocate private storage for each screen's Quartz specific info
 -    if (generation != serverGeneration) {
 -        quartzScreenIndex = AllocateScreenPrivateIndex();
 -        generation = serverGeneration;
 -    }
 -
+     if (serverGeneration == 0) {
+         QuartzAudioInit();
+     }
+ 
+     if (!RegisterBlockAndWakeupHandlers(QuartzBlockHandler,
+                                         QuartzWakeupHandler,
+                                         NULL))
+     {
+         FatalError("Could not register block and wakeup handlers.");
+     }
+ 
+     // Do display mode specific initialization
+     quartzProcs->DisplayInit();
+ 
+     // Init PseudoramiX implementation of Xinerama.
+     // This should be in InitExtensions, but that causes link errors
+     // for servers that don't link in pseudoramiX.c.
+     if (!noPseudoramiXExtension) {
+         PseudoramiXExtensionInit(argc, argv);
+     }
+ }
+ 
+ 
+ /*
+  * QuartzInitInput
+  *  Inform the main thread the X server is ready to handle events.
+  */
+ void QuartzInitInput(
+     int argc,
+     char **argv )
+ {
+     X11ApplicationSetCanQuit(1);
+     X11ApplicationServerReady();
+     // Do final display mode specific initialization before handling events
+     if (quartzProcs->InitInput)
+         quartzProcs->InitInput(argc, argv);
+ }
+ 
+ 
+ #ifdef FAKE_RANDR
+ extern char	*ConnectionInfo;
+ 
+ static int padlength[4] = {0, 3, 2, 1};
+ 
+ static void
+ RREditConnectionInfo (ScreenPtr pScreen)
+ {
+     xConnSetup	    *connSetup;
+     char	    *vendor;
+     xPixmapFormat   *formats;
+     xWindowRoot	    *root;
+     xDepth	    *depth;
+     xVisualType	    *visual;
+     int		    screen = 0;
+     int		    d;
+ 
+     connSetup = (xConnSetup *) ConnectionInfo;
+     vendor = (char *) connSetup + sizeof (xConnSetup);
+     formats = (xPixmapFormat *) ((char *) vendor +
+ 				 connSetup->nbytesVendor +
+ 				 padlength[connSetup->nbytesVendor & 3]);
+     root = (xWindowRoot *) ((char *) formats +
+ 			    sizeof (xPixmapFormat) * screenInfo.numPixmapFormats);
+     while (screen != pScreen->myNum)
+     {
+ 	depth = (xDepth *) ((char *) root + 
+ 			    sizeof (xWindowRoot));
+ 	for (d = 0; d < root->nDepths; d++)
+ 	{
+ 	    visual = (xVisualType *) ((char *) depth +
+ 				      sizeof (xDepth));
+ 	    depth = (xDepth *) ((char *) visual +
+ 				depth->nVisuals * sizeof (xVisualType));
+ 	}
+ 	root = (xWindowRoot *) ((char *) depth);
+ 	screen++;
+     }
+     root->pixWidth = pScreen->width;
+     root->pixHeight = pScreen->height;
+     root->mmWidth = pScreen->mmWidth;
+     root->mmHeight = pScreen->mmHeight;
+ }
+ #endif
+ 
+ /*
+  * QuartzUpdateScreens
+  *  Adjust for screen arrangement changes.
+  */
+ static void QuartzUpdateScreens(void)
+ {
+     ScreenPtr pScreen;
+     WindowPtr pRoot;
+     int x, y, width, height, sx, sy;
+     xEvent e;
+ 
+     DEBUG_LOG("QuartzUpdateScreens()\n");
+     if (noPseudoramiXExtension || screenInfo.numScreens != 1)
+     {
+         /* FIXME: if not using Xinerama, we have multiple screens, and
+            to do this properly may need to add or remove screens. Which
+            isn't possible. So don't do anything. Another reason why
+            we default to running with Xinerama. */
+ 
+         return;
+     }
+ 
+     pScreen = screenInfo.screens[0];
+ 
+     PseudoramiXResetScreens();
+     quartzProcs->AddPseudoramiXScreens(&x, &y, &width, &height);
+ 
+     dixScreenOrigins[pScreen->myNum].x = x;
+     dixScreenOrigins[pScreen->myNum].y = y;
+     pScreen->mmWidth = pScreen->mmWidth * ((double) width / pScreen->width);
+     pScreen->mmHeight = pScreen->mmHeight * ((double) height / pScreen->height);
+     pScreen->width = width;
+     pScreen->height = height;
+     
+ #ifndef FAKE_RANDR
+     if(!QuartzRandRInit(pScreen))
+       FatalError("Failed to init RandR extension.\n");
+ #endif
+ 
+     DarwinAdjustScreenOrigins(&screenInfo);
+     quartzProcs->UpdateScreen(pScreen);
+ 
+     sx = dixScreenOrigins[pScreen->myNum].x + darwinMainScreenX;
+     sy = dixScreenOrigins[pScreen->myNum].y + darwinMainScreenY;
+ 
+     /* Adjust the root window. */
+     pRoot = WindowTable[pScreen->myNum];
+     AppleWMSetScreenOrigin(pRoot);
+     pScreen->ResizeWindow(pRoot, x - sx, y - sy, width, height, NULL);
+     miPaintWindow(pRoot, &pRoot->borderClip,  PW_BACKGROUND);
+ //    QuartzIgnoreNextWarpCursor();
+     DefineInitialRootWindow(pRoot);
+ 
+     /* Send an event for the root reconfigure */
+     e.u.u.type = ConfigureNotify;
+     e.u.configureNotify.window = pRoot->drawable.id;
+     e.u.configureNotify.aboveSibling = None;
+     e.u.configureNotify.x = x - sx;
+     e.u.configureNotify.y = y - sy;
+     e.u.configureNotify.width = width;
+     e.u.configureNotify.height = height;
+     e.u.configureNotify.borderWidth = wBorderWidth(pRoot);
+     e.u.configureNotify.override = pRoot->overrideRedirect;
+     DeliverEvents(pRoot, &e, 1, NullWindow);
+ 
+ #ifdef FAKE_RANDR
+     RREditConnectionInfo(pScreen);
+ #endif
+ }
+ 
+ 
+ /*
+  * QuartzShow
+  *  Show the X server on screen. Does nothing if already shown.
+  *  Calls mode specific screen resume to restore the X clip regions
+  *  (if needed) and the X server cursor state.
+  */
+ static void QuartzShow(
+     int x,      // cursor location
+     int y )
+ {
+     int i;
+ 
+     if (!quartzServerVisible) {
+         quartzServerVisible = TRUE;
+         for (i = 0; i < screenInfo.numScreens; i++) {
+             if (screenInfo.screens[i]) {
+                 quartzProcs->ResumeScreen(screenInfo.screens[i], x, y);
+             }
+         }
+     }
+ }
+ 
+ 
+ /*
+  * QuartzHide
+  *  Remove the X server display from the screen. Does nothing if already
+  *  hidden. Calls mode specific screen suspend to set X clip regions to
+  *  prevent drawing (if needed) and restore the Aqua cursor.
+  */
+ static void QuartzHide(void)
+ {
+     int i;
+ 
+     if (quartzServerVisible) {
+         for (i = 0; i < screenInfo.numScreens; i++) {
+             if (screenInfo.screens[i]) {
+                 quartzProcs->SuspendScreen(screenInfo.screens[i]);
+             }
+         }
+     }
+     quartzServerVisible = FALSE;
+ }
+ 
+ 
+ /*
+  * QuartzSetRootClip
+  *  Enable or disable rendering to the X screen.
+  */
+ static void QuartzSetRootClip(
+     BOOL enable)
+ {
+     int i;
+ 
+     if (!quartzServerVisible)
+         return;
+ 
+     for (i = 0; i < screenInfo.numScreens; i++) {
+         if (screenInfo.screens[i]) {
+             xf86SetRootClip(screenInfo.screens[i], enable);
+         }
+     }
+ }
+ 
+ 
+ /*
+  * QuartzMessageServerThread
+  *  Send the X server thread a message by placing it on the event queue.
+  */
+ void
+ QuartzMessageServerThread(
+     int type,
+     int argc, ...)
+ {
+     xEvent xe;
+     INT32 *argv;
+     int i, max_args;
+     va_list args;
+ 
+     memset(&xe, 0, sizeof(xe));
+     xe.u.u.type = type;
+     xe.u.clientMessage.u.l.type = type;
+ 
+     argv = &xe.u.clientMessage.u.l.longs0;
+     max_args = 4;
+ 
+     if (argc > 0 && argc <= max_args) {
+         va_start (args, argc);
+         for (i = 0; i < argc; i++)
+             argv[i] = (int) va_arg (args, int);
+         va_end (args);
+     }
+ 
+     DarwinEQEnqueue(&xe);
+ }
+ 
+ 
+ /*
+  * QuartzProcessEvent
+  *  Process Quartz specific events.
+  */
+ void QuartzProcessEvent(
+     xEvent *xe)
+ {
+     switch (xe->u.u.type) {
+         case kXDarwinControllerNotify:
+ 	  DEBUG_LOG("kXDarwinControllerNotify\n");
+             AppleWMSendEvent(AppleWMControllerNotify,
+                              AppleWMControllerNotifyMask,
+                              xe->u.clientMessage.u.l.longs0,
+                              xe->u.clientMessage.u.l.longs1);
+             break;
+ 
+         case kXDarwinPasteboardNotify:
+ 	  DEBUG_LOG("kXDarwinPasteboardNotify\n");
+             AppleWMSendEvent(AppleWMPasteboardNotify,
+                              AppleWMPasteboardNotifyMask,
+                              xe->u.clientMessage.u.l.longs0,
+                              xe->u.clientMessage.u.l.longs1);
+             break;
+ 
+         case kXDarwinActivate:
+ 	  DEBUG_LOG("kXDarwinActivate\n");
+             QuartzShow(xe->u.keyButtonPointer.rootX,
+                        xe->u.keyButtonPointer.rootY);
+             AppleWMSendEvent(AppleWMActivationNotify,
+                              AppleWMActivationNotifyMask,
+                              AppleWMIsActive, 0);
+             break;
+ 
+         case kXDarwinDeactivate:
+   	  DEBUG_LOG("kXDarwinDeactivate\n");
+             AppleWMSendEvent(AppleWMActivationNotify,
+                              AppleWMActivationNotifyMask,
+                              AppleWMIsInactive, 0);
+             QuartzHide();
+             break;
+ 
+         case kXDarwinDisplayChanged:
+ 	    DEBUG_LOG("kXDarwinDisplayChanged\n");
+             QuartzUpdateScreens();
+             break;
+ 
+         case kXDarwinWindowState:
+ 	  DEBUG_LOG("kXDarwinWindowState\n");
+             RootlessNativeWindowStateChanged(xe->u.clientMessage.u.l.longs0,
+ 		  			     xe->u.clientMessage.u.l.longs1);
+ 	    break;
+ 	  
+         case kXDarwinWindowMoved:
+ 	  DEBUG_LOG("kXDarwinWindowMoved\n");
+ 	  RootlessNativeWindowMoved ((WindowPtr)xe->u.clientMessage.u.l.longs0);
+ 	    break;
+ 
+         case kXDarwinToggleFullscreen:
+ 	  DEBUG_LOG("kXDarwinToggleFullscreen\n");
+ #ifdef DARWIN_DDX_MISSING
+             if (quartzEnableRootless) QuartzSetFullscreen(!quartzHasRoot);
+             else if (quartzHasRoot) QuartzHide();
+             else QuartzShow();
+ #else
+     //	    ErrorF("kXDarwinToggleFullscreen not implemented\n");
+ #endif
+             break;
+ 
+         case kXDarwinSetRootless:
+ #ifdef DARWIN_DDX_MISSING
+             QuartzSetRootless(xe->u.clientMessage.u.l.longs0);
+             if (!quartzEnableRootless && !quartzHasRoot) QuartzHide();
+ #else
+     //	    ErrorF("kXDarwinSetRootless not implemented\n");
+ #endif
+             break;
+ 
+         case kXDarwinSetRootClip:
+             QuartzSetRootClip((BOOL)xe->u.clientMessage.u.l.longs0);
+             break;
+ 
+         case kXDarwinQuit:
+             GiveUp(0);
+             break;
+ 
+         case kXDarwinReadPasteboard:
+             QuartzReadPasteboard();
+             break;
+ 
+         case kXDarwinWritePasteboard:
+             QuartzWritePasteboard();
+             break;
+ 
+         case kXDarwinBringAllToFront:
+   	  DEBUG_LOG("kXDarwinBringAllToFront\n");
+ 	    RootlessOrderAllWindows();
+             break;
+ 
+         default:
+             ErrorF("Unknown application defined event type %d.\n", xe->u.u.type);
+     }
+ }
+ 
+ 
+ /*
+  * QuartzGiveUp
+  *  Cleanup before X server shutdown
+  *  Release the screen and restore the Aqua cursor.
+  */
+ void QuartzGiveUp(void)
+ {
+ #if 0
+ // Trying to switch cursors when quitting causes deadlock
+     int i;
+ 
+     for (i = 0; i < screenInfo.numScreens; i++) {
+         if (screenInfo.screens[i]) {
+             QuartzSuspendXCursor(screenInfo.screens[i]);
+         }
+     }
+ #endif
+ 
+     if (!quartzRootless)
+         quartzProcs->ReleaseScreens();
+ }
diff --cc hw/xquartz/quartzCommon.h
index 0000000,f0d5a7a..50b50f6
mode 000000,100644..100644
--- a/hw/xquartz/quartzCommon.h
+++ b/hw/xquartz/quartzCommon.h
@@@ -1,0 -1,107 +1,108 @@@
+ /*
+  * quartzCommon.h
+  *
+  * Common definitions used internally by all Quartz modes
+  *
+  * This file should be included before any X11 or IOKit headers
+  * so that it can avoid symbol conflicts.
+  *
+  * Copyright (c) 2001-2004 Torrey T. Lyons and Greg Parker.
+  *                 All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifndef _QUARTZCOMMON_H
+ #define _QUARTZCOMMON_H
+ 
+ // QuickDraw in ApplicationServices has the following conflicts with
+ // the basic X server headers. Use QD_<name> to use the QuickDraw
+ // definition of any of these symbols, or the normal name for the
+ // X11 definition.
+ #define Cursor       QD_Cursor
+ #define WindowPtr    QD_WindowPtr
+ #define Picture      QD_Picture
+ #include <ApplicationServices/ApplicationServices.h>
+ #undef Cursor
+ #undef WindowPtr
+ #undef Picture
+ #include <X11/Xdefs.h>
++#include "privates.h"
+ 
+ // Quartz specific per screen storage structure
+ typedef struct {
+     // List of CoreGraphics displays that this X11 screen covers.
+     // This is more than one CG display for video mirroring and
+     // rootless PseudoramiX mode.
+     // No CG display will be covered by more than one X11 screen.
+     int displayCount;
+     CGDirectDisplayID *displayIDs;
+ } QuartzScreenRec, *QuartzScreenPtr;
+ 
+ #define QUARTZ_PRIV(pScreen) \
 -    ((QuartzScreenPtr)pScreen->devPrivates[quartzScreenIndex].ptr)
++    ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
+ 
+ // Data stored at startup for Cocoa front end
+ extern int              quartzEventWriteFD;
+ extern int              quartzStartClients;
+ 
+ // User preferences used by Quartz modes
+ extern int              quartzRootless;
+ extern int              quartzUseSysBeep;
+ extern int              quartzUseAGL;
+ extern int              quartzEnableKeyEquivalents;
+ 
+ // Other shared data
+ extern int              quartzServerVisible;
+ extern int              quartzServerQuitting;
 -extern int              quartzScreenIndex;
++extern DevPrivateKey    quartzScreenKey;
+ extern int              aquaMenuBarHeight;
+ 
+ // Name of GLX bundle for native OpenGL
+ extern const char      *quartzOpenGLBundle;
+ 
+ void QuartzReadPreferences(void);
+ void QuartzMessageMainThread(unsigned msg, void *data, unsigned length);
+ void QuartzMessageServerThread(int type, int argc, ...);
+ void QuartzSetWindowMenu(int nitems, const char **items,
+                          const char *shortcuts);
+ void QuartzFSCapture(void);
+ void QuartzFSRelease(void);
+ int  QuartzFSUseQDCursor(int depth);
+ void QuartzBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask);
+ void QuartzWakeupHandler(pointer blockData, int result, pointer pReadmask);
+ 
+ // Messages that can be sent to the main thread.
+ enum {
+     kQuartzServerHidden,
+     kQuartzServerStarted,
+     kQuartzServerDied,
+     kQuartzCursorUpdate,
+     kQuartzPostEvent,
+     kQuartzSetWindowMenu,
+     kQuartzSetWindowMenuCheck,
+     kQuartzSetFrontProcess,
+     kQuartzSetCanQuit
+ };
+ 
+ #endif  /* _QUARTZCOMMON_H */
diff --cc hw/xquartz/quartzCursor.c
index 0000000,6e86acb..f82ccd3
mode 000000,100644..100644
--- a/hw/xquartz/quartzCursor.c
+++ b/hw/xquartz/quartzCursor.c
@@@ -1,0 -1,654 +1,646 @@@
+ /**************************************************************
+  *
+  * Support for using the Quartz Window Manager cursor
+  *
+  * Copyright (c) 2001-2003 Torrey T. Lyons and Greg Parker.
+  *                 All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifdef HAVE_DIX_CONFIG_H
+ #include <dix-config.h>
+ #endif
+ 
+ #include "quartzCommon.h"
+ #include "quartzCursor.h"
+ #include "darwin.h"
+ 
+ #include <pthread.h>
+ 
+ #include "mi.h"
+ #include "scrnintstr.h"
+ #include "cursorstr.h"
+ #include "mipointrst.h"
+ #include "globals.h"
+ 
+ // Size of the QuickDraw cursor
+ #define CURSORWIDTH 16
+ #define CURSORHEIGHT 16
+ 
+ typedef struct {
+     int                     qdCursorMode;
+     int                     qdCursorVisible;
+     int                     useQDCursor;
+     QueryBestSizeProcPtr    QueryBestSize;
+     miPointerSpriteFuncPtr  spriteFuncs;
+ } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
+ 
 -static int darwinCursorScreenIndex = -1;
 -static unsigned long darwinCursorGeneration = 0;
++static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKey;
+ static CursorPtr quartzLatentCursor = NULL;
+ static QD_Cursor gQDArrow; // QuickDraw arrow cursor
+ 
+ // Cursor for the main thread to set (NULL = arrow cursor).
+ static CCrsrHandle currentCursor = NULL;
+ static pthread_mutex_t cursorMutex;
+ static pthread_cond_t cursorCondition;
+ 
 -#define CURSOR_PRIV(pScreen) \
 -    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
++#define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
++    dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
+ 
+ #define HIDE_QD_CURSOR(pScreen, visible)                                \
+     if (visible) {                                                      \
+         int ix;                                                         \
+         for (ix = 0; ix < QUARTZ_PRIV(pScreen)->displayCount; ix++) {   \
+             CGDisplayHideCursor(QUARTZ_PRIV(pScreen)->displayIDs[ix]);  \
+         }                                                               \
+         visible = FALSE;                                                \
+     } ((void)0)
+ 
+ #define SHOW_QD_CURSOR(pScreen, visible)                                \
+     {                                                                   \
+         int ix;                                                         \
+         for (ix = 0; ix < QUARTZ_PRIV(pScreen)->displayCount; ix++) {   \
+             CGDisplayShowCursor(QUARTZ_PRIV(pScreen)->displayIDs[ix]);  \
+         }                                                               \
+         visible = TRUE;                                                 \
+     } ((void)0)
+ 
+ #define CHANGE_QD_CURSOR(cursorH)                                       \
+     if (!quartzServerQuitting) {                                        \
+         /* Acquire lock and tell the main thread to change cursor */    \
+         pthread_mutex_lock(&cursorMutex);                               \
+         currentCursor = (CCrsrHandle) (cursorH);                        \
+         QuartzMessageMainThread(kQuartzCursorUpdate, NULL, 0);          \
+                                                                         \
+         /* Wait for the main thread to change the cursor */             \
+         pthread_cond_wait(&cursorCondition, &cursorMutex);              \
+         pthread_mutex_unlock(&cursorMutex);                             \
+     } ((void)0)
+ 
+ 
+ /*
+  * MakeQDCursor helpers: CTAB_ENTER, interleave
+  */
+ 
+ // Add a color entry to a ctab
+ #define CTAB_ENTER(ctab, index, r, g, b)                                \
+     ctab->ctTable[index].value = index;                                 \
+     ctab->ctTable[index].rgb.red = r;                                   \
+     ctab->ctTable[index].rgb.green = g;                                 \
+     ctab->ctTable[index].rgb.blue = b
+ 
+ // Make an unsigned short by interleaving the bits of bytes c1 and c2.
+ // High bit of c1 is first; low bit of c2 is last.
+ // Interleave is a built-in INTERCAL operator.
+ static unsigned short
+ interleave(
+     unsigned char c1,
+     unsigned char c2 )
+ {
+     return
+         ((c1 & 0x80) << 8) | ((c2 & 0x80) << 7) |
+         ((c1 & 0x40) << 7) | ((c2 & 0x40) << 6) |
+         ((c1 & 0x20) << 6) | ((c2 & 0x20) << 5) |
+         ((c1 & 0x10) << 5) | ((c2 & 0x10) << 4) |
+         ((c1 & 0x08) << 4) | ((c2 & 0x08) << 3) |
+         ((c1 & 0x04) << 3) | ((c2 & 0x04) << 2) |
+         ((c1 & 0x02) << 2) | ((c2 & 0x02) << 1) |
+         ((c1 & 0x01) << 1) | ((c2 & 0x01) << 0) ;
+ }
+ 
+ /*
+  * MakeQDCursor
+  * Make a QuickDraw color cursor from the given X11 cursor.
+  * Warning: This code is nasty. Color cursors were meant to be read
+  * from resources; constructing the structures programmatically is messy.
+  */
+ /*
+     QuickDraw cursor representation:
+     Our color cursor is a 2 bit per pixel pixmap.
+     Each pixel's bits are (source<<1 | mask) from the original X cursor pixel.
+     The cursor's color table maps the colors like this:
+     (2-bit value | X result    | colortable | Mac result)
+              00  | transparent | white      | transparent (white outside mask)
+              01  | back color  | back color | back color
+              10  | undefined   | black      | invert background (just for fun)
+              11  | fore color  | fore color | fore color
+ */
+ static CCrsrHandle
+ MakeQDCursor(
+     CursorPtr pCursor )
+ {
+     CCrsrHandle result;
+     CCrsrPtr curs;
+     int i, w, h;
+     unsigned short rowMask;
+     PixMap *pix;
+     ColorTable *ctab;
+     unsigned short *image;
+ 
+     result = (CCrsrHandle) NewHandleClear(sizeof(CCrsr));
+     if (!result) return NULL;
+     HLock((Handle)result);
+     curs = *result;
+ 
+     // Initialize CCrsr
+     curs->crsrType = 0x8001;     // 0x8000 = b&w, 0x8001 = color
+     curs->crsrMap = (PixMapHandle) NewHandleClear(sizeof(PixMap));
+     if (!curs->crsrMap) goto pixAllocFailed;
+     HLock((Handle)curs->crsrMap);
+     pix = *curs->crsrMap;
+     curs->crsrData = NULL;       // raw cursor image data (set below)
+     curs->crsrXData = NULL;      // QD's processed data
+     curs->crsrXValid = 0;        // zero means QD must re-process cursor data
+     curs->crsrXHandle = NULL;    // reserved
+     memset(curs->crsr1Data, 0, CURSORWIDTH*CURSORHEIGHT/8); // b&w data
+     memset(curs->crsrMask,  0, CURSORWIDTH*CURSORHEIGHT/8); // b&w & color mask
+     curs->crsrHotSpot.h = min(CURSORWIDTH,  pCursor->bits->xhot); // hot spot
+     curs->crsrHotSpot.v = min(CURSORHEIGHT, pCursor->bits->yhot); // hot spot
+     curs->crsrXTable = 0;        // reserved
+     curs->crsrID = GetCTSeed();  // unique ID from Color Manager
+ 
+     // Set the b&w data and mask
+     w = min(pCursor->bits->width,  CURSORWIDTH);
+     h = min(pCursor->bits->height, CURSORHEIGHT);
+     rowMask = ~((1 << (CURSORWIDTH - w)) - 1);
+     for (i = 0; i < h; i++) {
+         curs->crsr1Data[i] = rowMask &
+         ((pCursor->bits->source[i*4]<<8) | pCursor->bits->source[i*4+1]);
+         curs->crsrMask[i] = rowMask &
+         ((pCursor->bits->mask[i*4]<<8)   | pCursor->bits->mask[i*4+1]);
+     }
+ 
+     // Set the color data and mask
+     // crsrMap: defines bit depth and size and colortable only
+     pix->rowBytes = (CURSORWIDTH * 2 / 8) | 0x8000; // last bit on means PixMap
+     SetRect(&pix->bounds, 0, 0, CURSORWIDTH, CURSORHEIGHT); // see TN 1020
+     pix->pixelSize = 2;
+     pix->cmpCount = 1;
+     pix->cmpSize = 2;
+     // pix->pmTable set below
+ 
+     // crsrData is the pixel data. crsrMap's baseAddr is not used.
+     curs->crsrData = NewHandleClear(CURSORWIDTH*CURSORHEIGHT * 2 / 8);
+     if (!curs->crsrData) goto imageAllocFailed;
+     HLock((Handle)curs->crsrData);
+     image = (unsigned short *) *curs->crsrData;
+     // Pixel data is just 1-bit data and mask interleaved (see above)
+     for (i = 0; i < h; i++) {
+         unsigned char s, m;
+         s = pCursor->bits->source[i*4] & (rowMask >> 8);
+         m = pCursor->bits->mask[i*4] & (rowMask >> 8);
+         image[2*i] = interleave(s, m);
+         s = pCursor->bits->source[i*4+1] & (rowMask & 0x00ff);
+         m = pCursor->bits->mask[i*4+1] & (rowMask & 0x00ff);
+         image[2*i+1] = interleave(s, m);
+     }
+ 
+     // Build the color table (entries described above)
+     // NewPixMap allocates a color table handle.
+     pix->pmTable = (CTabHandle) NewHandleClear(sizeof(ColorTable) + 3
+                     * sizeof(ColorSpec));
+     if (!pix->pmTable) goto ctabAllocFailed;
+     HLock((Handle)pix->pmTable);
+     ctab = *pix->pmTable;
+     ctab->ctSeed = GetCTSeed();
+     ctab->ctFlags = 0;
+     ctab->ctSize = 3; // color count - 1
+     CTAB_ENTER(ctab, 0, 0xffff, 0xffff, 0xffff);
+     CTAB_ENTER(ctab, 1, pCursor->backRed, pCursor->backGreen,
+                pCursor->backBlue);
+     CTAB_ENTER(ctab, 2, 0x0000, 0x0000, 0x0000);
+     CTAB_ENTER(ctab, 3, pCursor->foreRed, pCursor->foreGreen,
+                pCursor->foreBlue);
+ 
+     HUnlock((Handle)pix->pmTable); // ctab
+     HUnlock((Handle)curs->crsrData); // image data
+     HUnlock((Handle)curs->crsrMap); // pix
+     HUnlock((Handle)result); // cursor
+ 
+     return result;
+ 
+     // "What we have here is a failure to allocate"
+ ctabAllocFailed:
+     HUnlock((Handle)curs->crsrData);
+     DisposeHandle((Handle)curs->crsrData);
+ imageAllocFailed:
+     HUnlock((Handle)curs->crsrMap);
+     DisposeHandle((Handle)curs->crsrMap);
+ pixAllocFailed:
+     HUnlock((Handle)result);
+     DisposeHandle((Handle)result);
+     return NULL;
+ }
+ 
+ 
+ /*
+  * FreeQDCursor
+  * Destroy a QuickDraw color cursor created with MakeQDCursor().
+  * The cursor must not currently be on screen.
+  */
+ static void FreeQDCursor(CCrsrHandle cursHandle)
+ {
+     CCrsrPtr curs;
+     PixMap *pix;
+ 
+     HLock((Handle)cursHandle);
+     curs = *cursHandle;
+     HLock((Handle)curs->crsrMap);
+     pix = *curs->crsrMap;
+     DisposeHandle((Handle)pix->pmTable);
+     HUnlock((Handle)curs->crsrMap);
+     DisposeHandle((Handle)curs->crsrMap);
+     DisposeHandle((Handle)curs->crsrData);
+     HUnlock((Handle)cursHandle);
+     DisposeHandle((Handle)cursHandle);
+ }
+ 
+ 
+ /*
+ ===========================================================================
+ 
+  Pointer sprite functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzRealizeCursor
+  * Convert the X cursor representation to QuickDraw format if possible.
+  */
+ Bool
+ QuartzRealizeCursor(
+     ScreenPtr pScreen,
+     CursorPtr pCursor )
+ {
+     CCrsrHandle qdCursor;
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     if(!pCursor || !pCursor->bits)
+         return FALSE;
+ 
+     // if the cursor is too big we use a software cursor
+     if ((pCursor->bits->height > CURSORHEIGHT) ||
+         (pCursor->bits->width > CURSORWIDTH) || !ScreenPriv->useQDCursor)
+     {
+         if (quartzRootless) {
+             // rootless can't use a software cursor
+             return TRUE;
+         } else {
+             return (*ScreenPriv->spriteFuncs->RealizeCursor)
+                         (pScreen, pCursor);
+         }
+     }
+ 
+     // make new cursor image
+     qdCursor = MakeQDCursor(pCursor);
+     if (!qdCursor) return FALSE;
+ 
+     // save the result
 -    pCursor->devPriv[pScreen->myNum] = (pointer) qdCursor;
++    dixSetPrivate(&pCursor->devPrivates, pScreen, qdCursor);
+ 
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * QuartzUnrealizeCursor
+  * Free the storage space associated with a realized cursor.
+  */
+ Bool
+ QuartzUnrealizeCursor(
+     ScreenPtr pScreen,
+     CursorPtr pCursor )
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     if ((pCursor->bits->height > CURSORHEIGHT) ||
+         (pCursor->bits->width > CURSORWIDTH) || !ScreenPriv->useQDCursor)
+     {
+         if (quartzRootless) {
+             return TRUE;
+         } else {
+             return (*ScreenPriv->spriteFuncs->UnrealizeCursor)
+                         (pScreen, pCursor);
+         }
+     } else {
 -        CCrsrHandle oldCursor = (CCrsrHandle) pCursor->devPriv[pScreen->myNum];
 -
++        CCrsrHandle oldCursor = dixLookupPrivate(&pCursor->devPrivates,
++						 pScreen);
+         if (currentCursor != oldCursor) {
+             // This should only fail when quitting, in which case we just leak.
+             FreeQDCursor(oldCursor);
+         }
 -        pCursor->devPriv[pScreen->myNum] = NULL;
++	dixSetPrivate(&pCursor->devPrivates, pScreen, NULL);
+         return TRUE;
+     }
+ }
+ 
+ 
+ /*
+  * QuartzSetCursor
+  * Set the cursor sprite and position.
+  * Use QuickDraw cursor if possible.
+  */
+ static void
+ QuartzSetCursor(
+     ScreenPtr       pScreen,
+     CursorPtr       pCursor,
+     int             x,
+     int             y)
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     quartzLatentCursor = pCursor;
+ 
+     // Don't touch Mac OS cursor if X is hidden!
+     if (!quartzServerVisible)
+         return;
+ 
+     if (!pCursor) {
+         // Remove the cursor completely.
+         HIDE_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
+         if (! ScreenPriv->qdCursorMode)
+             (*ScreenPriv->spriteFuncs->SetCursor)(pScreen, 0, x, y);
+     }
+     else if ((pCursor->bits->height <= CURSORHEIGHT) &&
+              (pCursor->bits->width <= CURSORWIDTH) && ScreenPriv->useQDCursor)
+     {
+         // Cursor is small enough to use QuickDraw directly.
+         if (! ScreenPriv->qdCursorMode)    // remove the X cursor
+             (*ScreenPriv->spriteFuncs->SetCursor)(pScreen, 0, x, y);
+         ScreenPriv->qdCursorMode = TRUE;
+ 
 -        CHANGE_QD_CURSOR(pCursor->devPriv[pScreen->myNum]);
++        CHANGE_QD_CURSOR(dixLookupPrivate(&pCursor->devPrivates, pScreen));
+         SHOW_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
+     }
+     else if (quartzRootless) {
+         // Rootless can't use a software cursor, so we just use Mac OS arrow.
+         CHANGE_QD_CURSOR(NULL);
+         SHOW_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
+     }
+     else {
+         // Cursor is too big for QuickDraw. Use X software cursor.
+         HIDE_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
+         ScreenPriv->qdCursorMode = FALSE;
+         (*ScreenPriv->spriteFuncs->SetCursor)(pScreen, pCursor, x, y);
+     }
+ }
+ 
+ 
+ /*
+  * QuartzReallySetCursor
+  * Set the QuickDraw cursor. Called from the main thread since changing the
+  * cursor with QuickDraw is not thread safe on dual processor machines.
+  */
+ void
+ QuartzReallySetCursor()
+ {
+     pthread_mutex_lock(&cursorMutex);
+ 
+     if (currentCursor) {
+         SetCCursor(currentCursor);
+     } else {
+         SetCursor(&gQDArrow);
+     }
+ 
+     pthread_cond_signal(&cursorCondition);
+     pthread_mutex_unlock(&cursorMutex);
+ }
+ 
+ 
+ /*
+  * QuartzMoveCursor
+  * Move the cursor. This is a noop for QuickDraw.
+  */
+ static void
+ QuartzMoveCursor(
+     ScreenPtr   pScreen,
+     int         x,
+     int         y)
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     // only the X cursor needs to be explicitly moved
+     if (!ScreenPriv->qdCursorMode)
+         (*ScreenPriv->spriteFuncs->MoveCursor)(pScreen, x, y);
+ }
+ 
+ 
+ static miPointerSpriteFuncRec quartzSpriteFuncsRec = {
+     QuartzRealizeCursor,
+     QuartzUnrealizeCursor,
+     QuartzSetCursor,
+     QuartzMoveCursor
+ };
+ 
+ 
+ /*
+ ===========================================================================
+ 
+  Pointer screen functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzCursorOffScreen
+  */
+ static Bool QuartzCursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
+ {
+     return FALSE;
+ }
+ 
+ 
+ /*
+  * QuartzCrossScreen
+  */
+ static void QuartzCrossScreen(ScreenPtr pScreen, Bool entering)
+ {
+     return;
+ }
+ 
+ 
+ /*
+  * QuartzWarpCursor
+  *  Change the cursor position without generating an event or motion history.
+  *  The input coordinates (x,y) are in pScreen-local X11 coordinates.
+  *
+  */
+ static void
+ QuartzWarpCursor(
+     ScreenPtr               pScreen,
+     int                     x,
+     int                     y)
+ {
+     static int              neverMoved = TRUE;
+ 
+     if (neverMoved) {
+         // Don't move the cursor the first time. This is the jump-to-center
+         // initialization, and it's annoying because we may still be in MacOS.
+         neverMoved = FALSE;
+         return;
+     }
+ 
+     if (quartzServerVisible) {
+         CGDisplayErr        cgErr;
+         CGPoint             cgPoint;
+         // Only need to do this for one display. Any display will do.
+         CGDirectDisplayID   cgID = QUARTZ_PRIV(pScreen)->displayIDs[0];
+         CGRect              cgRect = CGDisplayBounds(cgID);
+ 
+         // Convert (x,y) to CoreGraphics screen-local CG coordinates.
+         // This is necessary because the X11 screen and CG screen may not
+         // coincide. (e.g. X11 screen may be moved to dodge the menu bar)
+ 
+         // Make point in X11 global coordinates
+         cgPoint = CGPointMake(x + dixScreenOrigins[pScreen->myNum].x,
+                               y + dixScreenOrigins[pScreen->myNum].y);
+         // Shift to CoreGraphics global screen coordinates
+         cgPoint.x += darwinMainScreenX;
+         cgPoint.y += darwinMainScreenY;
+         // Shift to CoreGraphics screen-local coordinates
+         cgPoint.x -= cgRect.origin.x;
+         cgPoint.y -= cgRect.origin.y;
+ 
+         cgErr = CGDisplayMoveCursorToPoint(cgID, cgPoint);
+         if (cgErr != CGDisplayNoErr) {
+             ErrorF("Could not set cursor position with error code 0x%x.\n",
+                     cgErr);
+         }
+     }
+ 
+     miPointerWarpCursor(pScreen, x, y);
+     miPointerUpdate();
+ }
+ 
+ 
+ static miPointerScreenFuncRec quartzScreenFuncsRec = {
+     QuartzCursorOffScreen,
+     QuartzCrossScreen,
+     QuartzWarpCursor,
+     DarwinEQPointerPost,
+     DarwinEQSwitchScreen
+ };
+ 
+ 
+ /*
+ ===========================================================================
+ 
+  Other screen functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzCursorQueryBestSize
+  * Handle queries for best cursor size
+  */
+ static void
+ QuartzCursorQueryBestSize(
+    int              class,
+    unsigned short   *width,
+    unsigned short   *height,
+    ScreenPtr        pScreen)
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     if (class == CursorShape) {
+         *width = CURSORWIDTH;
+         *height = CURSORHEIGHT;
+     } else {
+         (*ScreenPriv->QueryBestSize)(class, width, height, pScreen);
+     }
+ }
+ 
+ 
+ /*
+  * QuartzInitCursor
+  * Initialize cursor support
+  */
+ Bool
+ QuartzInitCursor(
+     ScreenPtr   pScreen )
+ {
+     QuartzCursorScreenPtr   ScreenPriv;
+     miPointerScreenPtr      PointPriv;
+     DarwinFramebufferPtr    dfb = SCREEN_PRIV(pScreen);
+ 
+     // initialize software cursor handling (always needed as backup)
+     if (!miDCInitialize(pScreen, &quartzScreenFuncsRec)) {
+         return FALSE;
+     }
+ 
 -    // allocate private storage for this screen's QuickDraw cursor info
 -    if (darwinCursorGeneration != serverGeneration) {
 -        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
 -            return FALSE;
 -        darwinCursorGeneration = serverGeneration;
 -    }
 -
+     ScreenPriv = xcalloc( 1, sizeof(QuartzCursorScreenRec) );
+     if (!ScreenPriv) return FALSE;
+ 
+     CURSOR_PRIV(pScreen) = ScreenPriv;
+ 
+     // override some screen procedures
+     ScreenPriv->QueryBestSize = pScreen->QueryBestSize;
+     pScreen->QueryBestSize = QuartzCursorQueryBestSize;
+ 
+     // initialize QuickDraw cursor handling
+     GetQDGlobalsArrow(&gQDArrow);
+     PointPriv = (miPointerScreenPtr)
 -                    pScreen->devPrivates[miPointerScreenIndex].ptr;
++	dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
+ 
+     ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
+     PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
+ 
+     if (!quartzRootless)
+         ScreenPriv->useQDCursor = QuartzFSUseQDCursor(dfb->colorBitsPerPixel);
+     else
+         ScreenPriv->useQDCursor = TRUE;
+     ScreenPriv->qdCursorMode = TRUE;
+     ScreenPriv->qdCursorVisible = TRUE;
+ 
+     // initialize cursor mutex lock
+     pthread_mutex_init(&cursorMutex, NULL);
+ 
+     // initialize condition for waiting
+     pthread_cond_init(&cursorCondition, NULL);
+ 
+     return TRUE;
+ }
+ 
+ 
+ // X server is hiding. Restore the Aqua cursor.
+ void QuartzSuspendXCursor(
+     ScreenPtr pScreen )
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     CHANGE_QD_CURSOR(NULL);
+     SHOW_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
+ }
+ 
+ 
+ // X server is showing. Restore the X cursor.
+ void QuartzResumeXCursor(
+     ScreenPtr pScreen,
+     int x,
+     int y )
+ {
+     QuartzSetCursor(pScreen, quartzLatentCursor, x, y);
+ }
diff --cc hw/xquartz/xpr/dri.c
index 0000000,e5591ab..3aacb19
mode 000000,100644..100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@@ -1,0 -1,760 +1,737 @@@
+ /**************************************************************************
+ 
+ Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ Copyright 2000 VA Linux Systems, Inc.
+ Copyright (c) 2002 Apple Computer, Inc.
+ All Rights Reserved.
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sub license, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ 
+ The above copyright notice and this permission notice (including the
+ next paragraph) shall be included in all copies or substantial portions
+ of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ 
+ **************************************************************************/
+ 
+ /*
+  * Authors:
+  *   Jens Owen <jens at valinux.com>
+  *   Rickard E. (Rik) Faith <faith at valinux.com>
+  *
+  */
+ 
+ #ifdef HAVE_DIX_CONFIG_H
+ #include <dix-config.h>
+ #endif
+ 
+ #ifdef XFree86LOADER
+ #include "xf86.h"
+ #include "xf86_ansic.h"
+ #else
+ #include <sys/time.h>
+ #include <unistd.h>
+ #endif
+ 
+ #define NEED_REPLIES
+ #define NEED_EVENTS
+ #include <X11/X.h>
+ #include <X11/Xproto.h>
+ #include "misc.h"
+ #include "dixstruct.h"
+ #include "extnsionst.h"
+ #include "colormapst.h"
+ #include "cursorstr.h"
+ #include "scrnintstr.h"
+ #include "windowstr.h"
+ #include "servermd.h"
+ #define _APPLEDRI_SERVER_
+ #include "appledristr.h"
+ #include "swaprep.h"
+ #include "dri.h"
+ #include "dristruct.h"
+ #include "mi.h"
+ #include "mipointer.h"
+ #include "rootless.h"
+ #include "x-hash.h"
+ #include "x-hook.h"
+ 
+ #include <AvailabilityMacros.h>
+ 
 -static int DRIScreenPrivIndex = -1;
 -static int DRIWindowPrivIndex = -1;
 -static int DRIPixmapPrivIndex = -1;
++static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKey;
++static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKey;
++static DevPrivateKey DRIPixmapPrivKey = &DRIPixmapPrivKey;
+ 
+ static RESTYPE DRIDrawablePrivResType;
+ 
+ static x_hash_table *surface_hash;      /* maps surface ids -> drawablePrivs */
+ 
+ /* FIXME: don't hardcode this? */
+ #define CG_INFO_FILE "/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/Info-macos.plist"
+ 
+ /* Corresponds to SU Jaguar Green */
+ #define CG_REQUIRED_MAJOR 1
+ #define CG_REQUIRED_MINOR 157
+ #define CG_REQUIRED_MICRO 11
+ 
+ /* Returns version as major.minor.micro in 10.10.10 fixed form */
+ static unsigned int
+ get_cg_version (void)
+ {
+     static unsigned int version;
+ 
+     FILE *fh;
+     char *ptr;
+ 
+     if (version != 0)
+         return version;
+ 
+     /* I tried CFBundleGetVersion, but it returns zero, so.. */
+ 
+     fh = fopen (CG_INFO_FILE, "r");
+     if (fh != NULL)
+     {
+         char buf[256];
+ 
+         while (fgets (buf, sizeof (buf), fh) != NULL)
+         {
+             unsigned char c;
+ 
+             if (!strstr (buf, "<key>CFBundleShortVersionString</key>")
+                 || fgets (buf, sizeof (buf), fh) == NULL)
+             {
+                 continue;
+             }
+ 
+             ptr = strstr (buf, "<string>");
+             if (ptr == NULL)
+                 continue;
+ 
+             ptr += strlen ("<string>");
+ 
+             /* Now PTR points to "MAJOR.MINOR.MICRO". */
+ 
+             version = 0;
+ 
+         again:
+             switch ((c = *ptr++))
+             {
+             case '.':
+                 version = version * 1024;
+                 goto again;
+ 
+             case '0': case '1': case '2': case '3': case '4':
+             case '5': case '6': case '7': case '8': case '9':
+                 version = ((version & ~0x3ff)
+                           + (version & 0x3ff) * 10 + (c - '0'));
+                 goto again;
+             }
+             break;
+         }
+ 
+         fclose (fh);
+     }
+ 
+     return version;
+ }
+ 
+ static Bool
+ test_cg_version (unsigned int major, unsigned int minor, unsigned int micro)
+ {
+     unsigned int cg_ver = get_cg_version ();
+ 
+     unsigned int cg_major = (cg_ver >> 20) & 0x3ff;
+     unsigned int cg_minor = (cg_ver >> 10) & 0x3ff;
+     unsigned int cg_micro =  cg_ver        & 0x3ff;
+ 
+     if (cg_major > major)
+         return TRUE;
+     else if (cg_major < major)
+         return FALSE;
+ 
+     /* cg_major == major */
+ 
+     if (cg_minor > minor)
+         return TRUE;
+     else if (cg_minor < minor)
+         return FALSE;
+ 
+     /* cg_minor == minor */
+ 
+     if (cg_micro < micro)
+         return FALSE;
+ 
+     return TRUE;
+ }
+ 
+ Bool
+ DRIScreenInit(ScreenPtr pScreen)
+ {
+     DRIScreenPrivPtr    pDRIPriv;
+     int                 i;
+ 
+     pDRIPriv = (DRIScreenPrivPtr) xcalloc(1, sizeof(DRIScreenPrivRec));
+     if (!pDRIPriv) {
 -        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
++	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
+         return FALSE;
+     }
+ 
 -    pScreen->devPrivates[DRIScreenPrivIndex].ptr = (pointer) pDRIPriv;
++    dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, pDRIPriv);
+     pDRIPriv->directRenderingSupport = TRUE;
+     pDRIPriv->nrWindows = 0;
+ 
+     /* Need recent cg for window access update */
+     if (!test_cg_version (CG_REQUIRED_MAJOR,
+                           CG_REQUIRED_MINOR,
+                           CG_REQUIRED_MICRO))
+     {
+         ErrorF ("[DRI] disabled direct rendering; requires CoreGraphics %d.%d.%d\n",
+                 CG_REQUIRED_MAJOR, CG_REQUIRED_MINOR, CG_REQUIRED_MICRO);
+ 
+         pDRIPriv->directRenderingSupport = FALSE;
+ 
+         /* Note we don't nuke the dri private, since we need it for
+            managing indirect surfaces. */
+     }
+ 
+     /* Initialize drawable tables */
+     for (i = 0; i < DRI_MAX_DRAWABLES; i++) {
+         pDRIPriv->DRIDrawables[i] = NULL;
+     }
+ 
+     return TRUE;
+ }
+ 
+ Bool
+ DRIFinishScreenInit(ScreenPtr pScreen)
+ {
+     DRIScreenPrivPtr  pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+ 
 -    /* Allocate zero sized private area for each window. Should a window
 -     * become a DRI window, we'll hang a DRIWindowPrivateRec off of this
 -     * private index.
 -     */
 -    if (!AllocateWindowPrivate(pScreen, DRIWindowPrivIndex, 0))
 -        return FALSE;
 -
+     /* Wrap DRI support */
+     pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
+     pScreen->ValidateTree = DRIValidateTree;
+ 
+     pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
+     pScreen->PostValidateTree = DRIPostValidateTree;
+ 
+     pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
+     pScreen->WindowExposures = DRIWindowExposures;
+ 
+     pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
+     pScreen->CopyWindow = DRICopyWindow;
+ 
+     pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
+     pScreen->ClipNotify = DRIClipNotify;
+ 
+     //    ErrorF("[DRI] screen %d installation complete\n", pScreen->myNum);
+ 
+     return TRUE;
+ }
+ 
+ void
+ DRICloseScreen(ScreenPtr pScreen)
+ {
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+ 
+     if (pDRIPriv && pDRIPriv->directRenderingSupport) {
+         xfree(pDRIPriv);
 -        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
++	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
+     }
+ }
+ 
+ Bool
+ DRIExtensionInit(void)
+ {
 -    static unsigned long DRIGeneration = 0;
 -
 -    if (DRIGeneration != serverGeneration) {
 -        if ((DRIScreenPrivIndex = AllocateScreenPrivateIndex()) < 0)
 -            return FALSE;
 -        DRIGeneration = serverGeneration;
 -    }
 -
 -    /*
 -     * Allocate a window private index with a zero sized private area for
 -     * each window, then should a window become a DRI window, we'll hang
 -     * a DRIWindowPrivateRec off of this private index. Do same for pixmaps.
 -     */
 -    if ((DRIWindowPrivIndex = AllocateWindowPrivateIndex()) < 0)
 -        return FALSE;
 -    if ((DRIPixmapPrivIndex = AllocatePixmapPrivateIndex()) < 0)
 -        return FALSE;
 -
+     DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete);
+ 
+     return TRUE;
+ }
+ 
+ void
+ DRIReset(void)
+ {
+     /*
+      * This stub routine is called when the X Server recycles, resources
+      * allocated by DRIExtensionInit need to be managed here.
+      *
+      * Currently this routine is a stub because all the interesting resources
+      * are managed via the screen init process.
+      */
+ }
+ 
+ Bool
+ DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool* isCapable)
+ {
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+ 
+     if (pDRIPriv)
+         *isCapable = pDRIPriv->directRenderingSupport;
+     else
+         *isCapable = FALSE;
+ 
+     return TRUE;
+ }
+ 
+ Bool
+ DRIAuthConnection(ScreenPtr pScreen, unsigned int magic)
+ {
+ #if 0
+     /* FIXME: something? */
+ 
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+ 
+     if (drmAuthMagic(pDRIPriv->drmFD, magic)) return FALSE;
+ #endif
+     return TRUE;
+ }
+ 
+ static void
+ DRIUpdateSurface(DRIDrawablePrivPtr pDRIDrawablePriv, DrawablePtr pDraw)
+ {
+     xp_window_changes wc;
+     unsigned int flags = 0;
+ 
+     if (pDRIDrawablePriv->sid == 0)
+         return;
+ 
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+     wc.depth = (pDraw->bitsPerPixel == 32 ? XP_DEPTH_ARGB8888
+                 : pDraw->bitsPerPixel == 16 ? XP_DEPTH_RGB555 : XP_DEPTH_NIL);
+     if (wc.depth != XP_DEPTH_NIL)
+         flags |= XP_DEPTH;
+ #endif
+ 
+     if (pDraw->type == DRAWABLE_WINDOW) {
+         WindowPtr pWin = (WindowPtr) pDraw;
+         WindowPtr pTopWin = TopLevelParent(pWin);
+ 
+         wc.x = pWin->drawable.x - (pTopWin->drawable.x - pTopWin->borderWidth);
+         wc.y = pWin->drawable.y - (pTopWin->drawable.y - pTopWin->borderWidth);
+         wc.width = pWin->drawable.width + 2 * pWin->borderWidth;
+         wc.height = pWin->drawable.height + 2 * pWin->borderWidth;
+         wc.bit_gravity = XP_GRAVITY_NONE;
+ 
+         wc.shape_nrects = REGION_NUM_RECTS(&pWin->clipList);
+         wc.shape_rects = REGION_RECTS(&pWin->clipList);
+         wc.shape_tx = - (pTopWin->drawable.x - pTopWin->borderWidth);
+         wc.shape_ty = - (pTopWin->drawable.y - pTopWin->borderWidth);
+ 
+         flags |= XP_BOUNDS | XP_SHAPE;
+ 
+     } else if (pDraw->type == DRAWABLE_PIXMAP) {
+         wc.x = 0;
+         wc.y = 0;
+         wc.width = pDraw->width;
+         wc.height = pDraw->height;
+         wc.bit_gravity = XP_GRAVITY_NONE;
+         flags |= XP_BOUNDS;
+     }
+ 
+     xp_configure_surface(pDRIDrawablePriv->sid, flags, &wc);
+ }
+ 
+ Bool
+ DRICreateSurface(ScreenPtr pScreen, Drawable id,
+                  DrawablePtr pDrawable, xp_client_id client_id,
+                  xp_surface_id *surface_id, unsigned int ret_key[2],
+                  void (*notify) (void *arg, void *data), void *notify_data)
+ {
+     DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+     DRIDrawablePrivPtr  pDRIDrawablePriv;
+     xp_window_id        wid = 0;
+ 
+     if (pDrawable->type == DRAWABLE_WINDOW) {
+         WindowPtr pWin = (WindowPtr)pDrawable;
+ 
+         pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+         if (pDRIDrawablePriv == NULL) {
+             xp_error err;
+             xp_window_changes wc;
+ 
+             /* allocate a DRI Window Private record */
+             if (!(pDRIDrawablePriv = xalloc(sizeof(DRIDrawablePrivRec)))) {
+                 return FALSE;
+             }
+ 
+             pDRIDrawablePriv->pDraw = pDrawable;
+             pDRIDrawablePriv->pScreen = pScreen;
+             pDRIDrawablePriv->refCount = 0;
+             pDRIDrawablePriv->drawableIndex = -1;
+             pDRIDrawablePriv->notifiers = NULL;
+ 
+             /* find the physical window */
+             wid = (xp_window_id) RootlessFrameForWindow(pWin, TRUE);
+             if (wid == 0) {
+                 xfree(pDRIDrawablePriv);
+                 return FALSE;
+             }
+ 
+             /* allocate the physical surface */
+             err = xp_create_surface(wid, &pDRIDrawablePriv->sid);
+             if (err != Success) {
+                 xfree(pDRIDrawablePriv);
+                 return FALSE;
+             }
+ 
+             /* Make it visible */
+             wc.stack_mode = XP_MAPPED_ABOVE;
+             wc.sibling = 0;
+             err = xp_configure_surface(pDRIDrawablePriv->sid, XP_STACKING, &wc);
+             if (err != Success)
+             {
+                 xp_destroy_surface(pDRIDrawablePriv->sid);
+                 xfree(pDRIDrawablePriv);
+                 return FALSE;
+             }
+ 
+             /* save private off of preallocated index */
 -            pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv;
++	    dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey,
++			  pDRIDrawablePriv);
+         }
+     }
+ 
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+     else if (pDrawable->type == DRAWABLE_PIXMAP) {
+         PixmapPtr pPix = (PixmapPtr)pDrawable;
+ 
+         pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
+         if (pDRIDrawablePriv == NULL) {
+             xp_error err;
+ 
+             /* allocate a DRI Window Private record */
+             if (!(pDRIDrawablePriv = xcalloc(1, sizeof(DRIDrawablePrivRec)))) {
+                 return FALSE;
+             }
+ 
+             pDRIDrawablePriv->pDraw = pDrawable;
+             pDRIDrawablePriv->pScreen = pScreen;
+             pDRIDrawablePriv->refCount = 0;
+             pDRIDrawablePriv->drawableIndex = -1;
+             pDRIDrawablePriv->notifiers = NULL;
+ 
+             /* Passing a null window id to Xplugin in 10.3+ asks for
+                an accelerated offscreen surface. */
+ 
+             err = xp_create_surface(0, &pDRIDrawablePriv->sid);
+             if (err != Success) {
+                 xfree(pDRIDrawablePriv);
+                 return FALSE;
+             }
+ 
+             /* save private off of preallocated index */
 -            pPix->devPrivates[DRIPixmapPrivIndex].ptr = (pointer)pDRIDrawablePriv;
++	    dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey,
++			  pDRIDrawablePriv);
+         }
+     }
+ #endif
+ 
+     else { /* for GLX 1.3, a PBuffer */
+         /* NOT_DONE */
+         return FALSE;
+     }
+ 
+     /* Finish initialization of new surfaces */
+     if (pDRIDrawablePriv->refCount == 0) {
+         unsigned int key[2] = {0};
+         xp_error err;
+ 
+         /* try to give the client access to the surface */
+         if (client_id != 0 && wid != 0)
+         {
+             err = xp_export_surface(wid, pDRIDrawablePriv->sid,
+                                     client_id, key);
+             if (err != Success) {
+                 xp_destroy_surface(pDRIDrawablePriv->sid);
+                 xfree(pDRIDrawablePriv);
+                 return FALSE;
+             }
+         }
+ 
+         pDRIDrawablePriv->key[0] = key[0];
+         pDRIDrawablePriv->key[1] = key[1];
+ 
+         ++pDRIPriv->nrWindows;
+ 
+         /* and stash it by surface id */
+         if (surface_hash == NULL)
+             surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
+         x_hash_table_insert(surface_hash,
+                             (void *) pDRIDrawablePriv->sid, pDRIDrawablePriv);
+ 
+         /* track this in case this window is destroyed */
+         AddResource(id, DRIDrawablePrivResType, (pointer)pDrawable);
+ 
+         /* Initialize shape */
+         DRIUpdateSurface(pDRIDrawablePriv, pDrawable);
+     }
+ 
+     pDRIDrawablePriv->refCount++;
+ 
+     *surface_id = pDRIDrawablePriv->sid;
+ 
+     if (ret_key != NULL) {
+         ret_key[0] = pDRIDrawablePriv->key[0];
+         ret_key[1] = pDRIDrawablePriv->key[1];
+     }
+ 
+     if (notify != NULL) {
+         pDRIDrawablePriv->notifiers = x_hook_add(pDRIDrawablePriv->notifiers,
+                                                  notify, notify_data);
+     }
+ 
+     return TRUE;
+ }
+ 
+ Bool
+ DRIDestroySurface(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable,
+                   void (*notify) (void *, void *), void *notify_data)
+ {
+     DRIDrawablePrivPtr  pDRIDrawablePriv;
+ 
+     if (pDrawable->type == DRAWABLE_WINDOW) {
+         pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW((WindowPtr)pDrawable);
+     } else if (pDrawable->type == DRAWABLE_PIXMAP) {
+         pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP((PixmapPtr)pDrawable);
+     } else {
+         return FALSE;
+     }
+ 
+     if (pDRIDrawablePriv != NULL) {
+         if (notify != NULL) {
+             pDRIDrawablePriv->notifiers = x_hook_remove(pDRIDrawablePriv->notifiers,
+                                                         notify, notify_data);
+         }
+         if (--pDRIDrawablePriv->refCount <= 0) {
+             /* This calls back to DRIDrawablePrivDelete
+                which frees the private area */
+             FreeResourceByType(id, DRIDrawablePrivResType, FALSE);
+         }
+     }
+ 
+     return TRUE;
+ }
+ 
+ Bool
+ DRIDrawablePrivDelete(pointer pResource, XID id)
+ {
+     DrawablePtr         pDrawable = (DrawablePtr)pResource;
+     DRIScreenPrivPtr    pDRIPriv = DRI_SCREEN_PRIV(pDrawable->pScreen);
+     DRIDrawablePrivPtr  pDRIDrawablePriv = NULL;
+     WindowPtr           pWin = NULL;
+     PixmapPtr           pPix = NULL;
+ 
+     if (pDrawable->type == DRAWABLE_WINDOW) {
+         pWin = (WindowPtr)pDrawable;
+         pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+     } else if (pDrawable->type == DRAWABLE_PIXMAP) {
+         pPix = (PixmapPtr)pDrawable;
+         pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix);
+     }
+ 
+     if (pDRIDrawablePriv == NULL)
+         return FALSE;
+ 
+     if (pDRIDrawablePriv->drawableIndex != -1) {
+         /* release drawable table entry */
+         pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL;
+     }
+ 
+     if (pDRIDrawablePriv->sid != 0) {
+         xp_destroy_surface(pDRIDrawablePriv->sid);
+         x_hash_table_remove(surface_hash, (void *) pDRIDrawablePriv->sid);
+     }
+ 
+     if (pDRIDrawablePriv->notifiers != NULL)
+         x_hook_free(pDRIDrawablePriv->notifiers);
+ 
+     xfree(pDRIDrawablePriv);
+ 
+     if (pDrawable->type == DRAWABLE_WINDOW) {
 -        pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
++	dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL);
+     } else if (pDrawable->type == DRAWABLE_PIXMAP) {
 -        pPix->devPrivates[DRIPixmapPrivIndex].ptr = NULL;
++	dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL);
+     }
+ 
+     --pDRIPriv->nrWindows;
+ 
+     return TRUE;
+ }
+ 
+ void
+ DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
+ {
+     ScreenPtr pScreen = pWin->drawable.pScreen;
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+     DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+ 
+     if (pDRIDrawablePriv) {
+         /* FIXME: something? */
+     }
+ 
+     pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
+ 
+     (*pScreen->WindowExposures)(pWin, prgn, bsreg);
+ 
+     pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
+     pScreen->WindowExposures = DRIWindowExposures;
+ }
+ 
+ void
+ DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
+ {
+     ScreenPtr pScreen = pWin->drawable.pScreen;
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+     DRIDrawablePrivPtr pDRIDrawablePriv;
+ 
+     if (pDRIPriv->nrWindows > 0) {
+        pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
+        if (pDRIDrawablePriv != NULL) {
+             DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable);
+        }
+     }
+ 
+     /* unwrap */
+     pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow;
+ 
+     /* call lower layers */
+     (*pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc);
+ 
+     /* rewrap */
+     pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
+     pScreen->CopyWindow = DRICopyWindow;
+ }
+ 
+ int
+ DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
+ {
+     ScreenPtr pScreen = pParent->drawable.pScreen;
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+     int returnValue;
+ 
+     /* unwrap */
+     pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
+ 
+     /* call lower layers */
+     returnValue = (*pScreen->ValidateTree)(pParent, pChild, kind);
+ 
+     /* rewrap */
+     pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
+     pScreen->ValidateTree = DRIValidateTree;
+ 
+     return returnValue;
+ }
+ 
+ void
+ DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
+ {
+     ScreenPtr pScreen;
+     DRIScreenPrivPtr pDRIPriv;
+ 
+     if (pParent) {
+         pScreen = pParent->drawable.pScreen;
+     } else {
+         pScreen = pChild->drawable.pScreen;
+     }
+     pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+ 
+     if (pDRIPriv->wrap.PostValidateTree) {
+         /* unwrap */
+         pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
+ 
+         /* call lower layers */
+         (*pScreen->PostValidateTree)(pParent, pChild, kind);
+ 
+         /* rewrap */
+         pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
+         pScreen->PostValidateTree = DRIPostValidateTree;
+     }
+ }
+ 
+ void
+ DRIClipNotify(WindowPtr pWin, int dx, int dy)
+ {
+     ScreenPtr pScreen = pWin->drawable.pScreen;
+     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
+     DRIDrawablePrivPtr  pDRIDrawablePriv;
+ 
+     if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
+         DRIUpdateSurface(pDRIDrawablePriv, &pWin->drawable);
+     }
+ 
+     if (pDRIPriv->wrap.ClipNotify) {
+         pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify;
+ 
+         (*pScreen->ClipNotify)(pWin, dx, dy);
+ 
+         pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
+         pScreen->ClipNotify = DRIClipNotify;
+     }
+ }
+ 
+ /* This lets us get at the unwrapped functions so that they can correctly
+  * call the lower level functions, and choose whether they will be
+  * called at every level of recursion (eg in validatetree).
+  */
+ DRIWrappedFuncsRec *
+ DRIGetWrappedFuncs(ScreenPtr pScreen)
+ {
+     return &(DRI_SCREEN_PRIV(pScreen)->wrap);
+ }
+ 
+ void
+ DRIQueryVersion(int *majorVersion,
+                 int *minorVersion,
+                 int *patchVersion)
+ {
+     *majorVersion = APPLE_DRI_MAJOR_VERSION;
+     *minorVersion = APPLE_DRI_MINOR_VERSION;
+     *patchVersion = APPLE_DRI_PATCH_VERSION;
+ }
+ 
+ void
+ DRISurfaceNotify(xp_surface_id id, int kind)
+ {
+     DRIDrawablePrivPtr pDRIDrawablePriv = NULL;
+     DRISurfaceNotifyArg arg;
+ 
+     arg.id = id;
+     arg.kind = kind;
+ 
+     if (surface_hash != NULL)
+     {
+         pDRIDrawablePriv = x_hash_table_lookup(surface_hash,
+                                                (void *) id, NULL);
+     }
+ 
+     if (pDRIDrawablePriv == NULL)
+         return;
+ 
+     if (kind == AppleDRISurfaceNotifyDestroyed)
+     {
+         pDRIDrawablePriv->sid = 0;
+         x_hash_table_remove(surface_hash, (void *) id);
+     }
+ 
+     x_hook_run(pDRIDrawablePriv->notifiers, &arg);
+ 
+     if (kind == AppleDRISurfaceNotifyDestroyed)
+     {
+         /* Kill off the handle. */
+ 
+         FreeResourceByType(pDRIDrawablePriv->pDraw->id,
+                            DRIDrawablePrivResType, FALSE);
+     }
+ }
diff --cc hw/xquartz/xpr/dristruct.h
index 0000000,9a3d01c..19d78a9
mode 000000,100644..100644
--- a/hw/xquartz/xpr/dristruct.h
+++ b/hw/xquartz/xpr/dristruct.h
@@@ -1,0 -1,81 +1,76 @@@
+ /**************************************************************************
+ 
+ Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ Copyright (c) 2002 Apple Computer, Inc.
+ All Rights Reserved.
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a
+ copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sub license, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+ 
+ The above copyright notice and this permission notice (including the
+ next paragraph) shall be included in all copies or substantial portions
+ of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ 
+ **************************************************************************/
+ 
+ /*
+  * Authors:
+  *   Jens Owen <jens at precisioninsight.com>
+  *
+  */
+ 
+ #ifndef DRI_STRUCT_H
+ #define DRI_STRUCT_H
+ 
+ #include "dri.h"
+ #include "x-list.h"
+ 
+ #define DRI_MAX_DRAWABLES 256
+ 
 -#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) \
 -    ((DRIWindowPrivIndex < 0) ? \
 -     NULL : \
 -     ((DRIDrawablePrivPtr)((pWin)->devPrivates[DRIWindowPrivIndex].ptr)))
++#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) ((DRIDrawablePrivPtr) \
++    dixLookupPrivate(&(pWin)->devPrivates, DRIWindowPrivKey))
+ 
 -#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) \
 -    ((DRIPixmapPrivIndex < 0) ? \
 -     NULL : \
 -     ((DRIDrawablePrivPtr)((pPix)->devPrivates[DRIPixmapPrivIndex].ptr)))
++#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) ((DRIDrawablePrivPtr) \
++    dixLookupPrivate(&(pPix)->devPrivates, DRIPixmapPrivKey))
+ 
+ typedef struct _DRIDrawablePrivRec
+ {
+     xp_surface_id   sid;
+     int             drawableIndex;
+     DrawablePtr     pDraw;
+     ScreenPtr       pScreen;
+     int             refCount;
+     unsigned int    key[2];
+     x_list          *notifiers;     /* list of (FUN . DATA) */
+ } DRIDrawablePrivRec, *DRIDrawablePrivPtr;
+ 
 -#define DRI_SCREEN_PRIV(pScreen) \
 -    ((DRIScreenPrivIndex < 0) ? \
 -     NULL : \
 -     ((DRIScreenPrivPtr)((pScreen)->devPrivates[DRIScreenPrivIndex].ptr)))
++#define DRI_SCREEN_PRIV(pScreen) ((DRIScreenPrivPtr) \
++    dixLookupPrivate(&(pScreen)->devPrivates, DRIScreenPrivKey))
+ 
+ #define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \
 -    (screenInfo.screens[screenIndex]->devPrivates[DRIScreenPrivIndex].ptr))
++    dixLookupPrivate(&screenInfo.screens[screenIndex]->devPrivates, \
++		     DRIScreenPrivKey))
+ 
+ 
+ typedef struct _DRIScreenPrivRec
+ {
+     Bool                directRenderingSupport;
+     int                 nrWindows;
+     DRIWrappedFuncsRec  wrap;
+     DrawablePtr         DRIDrawables[DRI_MAX_DRAWABLES];
+ } DRIScreenPrivRec, *DRIScreenPrivPtr;
+ 
+ #endif /* DRI_STRUCT_H */
diff --cc hw/xquartz/xpr/xprCursor.c
index 0000000,dc7a73e..e084ef9
mode 000000,100644..100644
--- a/hw/xquartz/xpr/xprCursor.c
+++ b/hw/xquartz/xpr/xprCursor.c
@@@ -1,0 -1,432 +1,422 @@@
+ /**************************************************************
+  *
+  * Xplugin cursor support
+  *
+  * Copyright (c) 2001 Torrey T. Lyons and Greg Parker.
+  * Copyright (c) 2002 Apple Computer, Inc.
+  *                 All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifdef HAVE_DIX_CONFIG_H
+ #include <dix-config.h>
+ #endif
+ 
+ #include "quartzCommon.h"
+ #include "xpr.h"
+ #include "darwin.h"
+ #include "darwinEvents.h"
+ #include "Xplugin.h"
+ 
+ #include "mi.h"
+ #include "scrnintstr.h"
+ #include "cursorstr.h"
+ #include "mipointrst.h"
+ #include "windowstr.h"
+ #include "globals.h"
+ #include "servermd.h"
+ #include "dixevents.h"
+ 
+ typedef struct {
+     int                     cursorVisible;
+     QueryBestSizeProcPtr    QueryBestSize;
+     miPointerSpriteFuncPtr  spriteFuncs;
+ } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
+ 
 -static int darwinCursorScreenIndex = -1;
 -static unsigned long darwinCursorGeneration = 0;
++static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKey;
+ 
 -#define CURSOR_PRIV(pScreen) \
 -    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
++#define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
++    dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
+ 
+ 
+ static Bool
+ load_cursor(CursorPtr src, int screen)
+ {
+     uint32_t *data;
+     uint32_t rowbytes;
+     int width, height;
+     int hot_x, hot_y;
+ 
+     uint32_t fg_color, bg_color;
+     uint8_t *srow, *sptr;
+     uint8_t *mrow, *mptr;
+     uint32_t *drow, *dptr;
+     unsigned xcount, ycount;
+ 
+     xp_error err;
+ 
+     width = src->bits->width;
+     height = src->bits->height;
+     hot_x = src->bits->xhot;
+     hot_y = src->bits->yhot;
+ 
+ #ifdef ARGB_CURSOR
+     if (src->bits->argb != NULL)
+     {
+ #if BITMAP_BIT_ORDER == MSBFirst
+         rowbytes = src->bits->width * sizeof (CARD32);
+         data = (uint32_t *) src->bits->argb;
+ #else
+         const uint32_t *be_data=(uint32_t *) src->bits->argb;
+         unsigned i;
+         rowbytes = src->bits->width * sizeof (CARD32);
+         data=alloca (rowbytes * src->bits->height);
+         for(i=0;i<(src->bits->width*src->bits->height);i++)
+             data[i]=ntohl(be_data[i]);
+ #endif
+     }
+     else
+ #endif
+     {
+         fg_color = 0xFF00 | (src->foreRed >> 8);
+         fg_color <<= 16;
+         fg_color |= src->foreGreen & 0xFF00;
+         fg_color |= src->foreBlue >> 8;
+ 
+         bg_color = 0xFF00 | (src->backRed >> 8);
+         bg_color <<= 16;
+         bg_color |= src->backGreen & 0xFF00;
+         bg_color |= src->backBlue >> 8;
+ 
+         fg_color = htonl(fg_color);
+         bg_color = htonl(bg_color);
+ 
+         /* round up to 8 pixel boundary so we can convert whole bytes */
+         rowbytes = ((src->bits->width * 4) + 31) & ~31;
+         data = alloca(rowbytes * src->bits->height);
+ 
+         if (!src->bits->emptyMask)
+         {
+             ycount = src->bits->height;
+             srow = src->bits->source; mrow = src->bits->mask;
+             drow = data;
+ 
+             while (ycount-- > 0)
+             {
+                 xcount = (src->bits->width + 7) / 8;
+                 sptr = srow; mptr = mrow;
+                 dptr = drow;
+ 
+                 while (xcount-- > 0)
+                 {
+                     uint8_t s, m;
+                     int i;
+ 
+                     s = *sptr++; m = *mptr++;
+                     for (i = 0; i < 8; i++)
+                     {
+ #if BITMAP_BIT_ORDER == MSBFirst
+                         if (m & 128)
+                             *dptr++ = (s & 128) ? fg_color : bg_color;
+                         else
+                             *dptr++ = 0;
+                         s <<= 1; m <<= 1;
+ #else
+                         if (m & 1)
+                             *dptr++ = (s & 1) ? fg_color : bg_color;
+                         else
+                             *dptr++ = 0;
+                         s >>= 1; m >>= 1;
+ #endif
+                     }
+                 }
+ 
+                 srow += BitmapBytePad(src->bits->width);
+                 mrow += BitmapBytePad(src->bits->width);
+                 drow = (uint32_t *) ((char *) drow + rowbytes);
+             }
+         }
+         else
+         {
+             memset(data, 0, src->bits->height * rowbytes);
+         }
+     }
+ 
+     err = xp_set_cursor(width, height, hot_x, hot_y, data, rowbytes);
+     return err == Success;
+ }
+ 
+ 
+ /*
+ ===========================================================================
+ 
+  Pointer sprite functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzRealizeCursor
+  *  Convert the X cursor representation to native format if possible.
+  */
+ static Bool
+ QuartzRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
+ {
+     if(pCursor == NULL || pCursor->bits == NULL)
+         return FALSE;
+ 
+     /* FIXME: cache ARGB8888 representation? */
+ 
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * QuartzUnrealizeCursor
+  *  Free the storage space associated with a realized cursor.
+  */
+ static Bool
+ QuartzUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
+ {
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * QuartzSetCursor
+  *  Set the cursor sprite and position.
+  */
+ static void
+ QuartzSetCursor(ScreenPtr pScreen, CursorPtr pCursor, int x, int y)
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     if (!quartzServerVisible)
+         return;
+ 
+     if (pCursor == NULL)
+     {
+         if (ScreenPriv->cursorVisible)
+         {
+             xp_hide_cursor();
+             ScreenPriv->cursorVisible = FALSE;
+         }
+     }
+     else
+     {
+         load_cursor(pCursor, pScreen->myNum);
+ 
+         if (!ScreenPriv->cursorVisible)
+         {
+             xp_show_cursor();
+             ScreenPriv->cursorVisible = TRUE;
+         }
+     }
+ }
+ 
+ 
+ /*
+  * QuartzMoveCursor
+  *  Move the cursor. This is a noop for us.
+  */
+ static void
+ QuartzMoveCursor(ScreenPtr pScreen, int x, int y)
+ {
+ }
+ 
+ 
+ static miPointerSpriteFuncRec quartzSpriteFuncsRec = {
+     QuartzRealizeCursor,
+     QuartzUnrealizeCursor,
+     QuartzSetCursor,
+     QuartzMoveCursor
+ };
+ 
+ 
+ /*
+ ===========================================================================
+ 
+  Pointer screen functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzCursorOffScreen
+  */
+ static Bool
+ QuartzCursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
+ {
+     return FALSE;
+ }
+ 
+ 
+ /*
+  * QuartzCrossScreen
+  */
+ static void
+ QuartzCrossScreen(ScreenPtr pScreen, Bool entering)
+ {
+     return;
+ }
+ 
+ 
+ /*
+  * QuartzWarpCursor
+  *  Change the cursor position without generating an event or motion history.
+  *  The input coordinates (x,y) are in pScreen-local X11 coordinates.
+  *
+  */
+ static void
+ QuartzWarpCursor(ScreenPtr pScreen, int x, int y)
+ {
+     static Bool neverMoved = TRUE;
+ 
+     if (neverMoved)
+     {
+         /* Don't move the cursor the first time. This is the
+            jump-to-center initialization, and it's annoying. */
+         neverMoved = FALSE;
+         return;
+     }
+ 
+     if (quartzServerVisible)
+     {
+         int sx, sy;
+ 
+         sx = dixScreenOrigins[pScreen->myNum].x + darwinMainScreenX;
+         sy = dixScreenOrigins[pScreen->myNum].y + darwinMainScreenY;
+ 
+         CGWarpMouseCursorPosition(CGPointMake(sx + x, sy + y));
+     }
+ 
+     miPointerWarpCursor(pScreen, x, y);
+     miPointerUpdate();
+ }
+ 
+ 
+ static miPointerScreenFuncRec quartzScreenFuncsRec = {
+     QuartzCursorOffScreen,
+     QuartzCrossScreen,
+     QuartzWarpCursor,
+     DarwinEQPointerPost,
+     DarwinEQSwitchScreen
+ };
+ 
+ 
+ /*
+ ===========================================================================
+ 
+  Other screen functions
+ 
+ ===========================================================================
+ */
+ 
+ /*
+  * QuartzCursorQueryBestSize
+  *  Handle queries for best cursor size
+  */
+ static void
+ QuartzCursorQueryBestSize(int class, unsigned short *width,
+                           unsigned short *height, ScreenPtr pScreen)
+ {
+     QuartzCursorScreenPtr ScreenPriv = CURSOR_PRIV(pScreen);
+ 
+     if (class == CursorShape)
+     {
+         /* FIXME: query window server? */
+         *width = 32;
+         *height = 32;
+     }
+     else
+     {
+         (*ScreenPriv->QueryBestSize)(class, width, height, pScreen);
+     }
+ }
+ 
+ /*
+  * QuartzInitCursor
+  *  Initialize cursor support
+  */
+ Bool
+ QuartzInitCursor(ScreenPtr pScreen)
+ {
+     QuartzCursorScreenPtr ScreenPriv;
+     miPointerScreenPtr PointPriv;
+ 
+     /* initialize software cursor handling (always needed as backup) */
+     if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
+         return FALSE;
+ 
 -    /* allocate private storage for this screen's QuickDraw cursor info */
 -    if (darwinCursorGeneration != serverGeneration)
 -    {
 -        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
 -            return FALSE;
 -
 -        darwinCursorGeneration = serverGeneration;
 -    }
 -
+     ScreenPriv = xcalloc(1, sizeof(QuartzCursorScreenRec));
+     if (ScreenPriv == NULL)
+         return FALSE;
+ 
+     /* CURSOR_PRIV(pScreen) = ScreenPriv; */
 -    pScreen->devPrivates[darwinCursorScreenIndex].ptr = ScreenPriv;
++    dixSetPrivate(&pScreen->devPrivates, darwinCursorScreenKey, ScreenPriv);
+ 
+     /* override some screen procedures */
+     ScreenPriv->QueryBestSize = pScreen->QueryBestSize;
+     pScreen->QueryBestSize = QuartzCursorQueryBestSize;
+ 
 -    PointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr;
++    PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
+ 
+     ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
+     PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
+ 
+     ScreenPriv->cursorVisible = TRUE;
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * QuartzSuspendXCursor
+  *  X server is hiding. Restore the Aqua cursor.
+  */
+ void
+ QuartzSuspendXCursor(ScreenPtr pScreen)
+ {
+ }
+ 
+ 
+ /*
+  * QuartzResumeXCursor
+  *  X server is showing. Restore the X cursor.
+  */
+ void
+ QuartzResumeXCursor(ScreenPtr pScreen, int x, int y)
+ {
+     WindowPtr pWin;
+     CursorPtr pCursor;
+ 
+     pWin = GetSpriteWindow();
+     if (pWin->drawable.pScreen != pScreen)
+         return;
+ 
+     pCursor = GetSpriteCursor();
+     if (pCursor == NULL)
+         return;
+ 
+     QuartzSetCursor(pScreen, pCursor, x, y);
+ }
diff --cc hw/xquartz/xpr/xprFrame.c
index 0000000,2d97f27..b9a33de
mode 000000,100644..100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@@ -1,0 -1,528 +1,528 @@@
+ /*
+  * Xplugin rootless implementation frame functions
+  *
+  * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+  * Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
+  *
+  * Permission is hereby granted, free of charge, to any person obtaining a
+  * copy of this software and associated documentation files (the "Software"),
+  * to deal in the Software without restriction, including without limitation
+  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+  * and/or sell copies of the Software, and to permit persons to whom the
+  * Software is furnished to do so, subject to the following conditions:
+  *
+  * The above copyright notice and this permission notice shall be included in
+  * all copies or substantial portions of the Software.
+  *
+  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+  * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+  * DEALINGS IN THE SOFTWARE.
+  *
+  * Except as contained in this notice, the name(s) of the above copyright
+  * holders shall not be used in advertising or otherwise to promote the sale,
+  * use or other dealings in this Software without prior written authorization.
+  */
+ 
+ #ifdef HAVE_DIX_CONFIG_H
+ #include <dix-config.h>
+ #endif
+ 
+ #include "xpr.h"
+ #include "rootlessCommon.h"
+ #include "Xplugin.h"
+ #include "x-hash.h"
+ #include "x-list.h"
+ #include "applewmExt.h"
+ 
+ #include "propertyst.h"
+ #include "dix.h"
+ #include <X11/Xatom.h>
+ #include "windowstr.h"
+ 
+ #include <pthread.h>
+ 
+ #define DEFINE_ATOM_HELPER(func,atom_name)                      \
+ static Atom func (void) {                                       \
+     static int generation;                                      \
+     static Atom atom;                                           \
+     if (generation != serverGeneration) {                       \
+         generation = serverGeneration;                          \
+         atom = MakeAtom (atom_name, strlen (atom_name), TRUE);  \
+     }                                                           \
+     return atom;                                                \
+ }
+ 
+ DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
+ 
+ /* Maps xp_window_id -> RootlessWindowRec */
+ static x_hash_table *window_hash;
+ static pthread_mutex_t window_hash_mutex;
+ 
+ static Bool no_configure_window;
+ 
+ 
+ static inline xp_error
+ xprConfigureWindow(xp_window_id id, unsigned int mask,
+                    const xp_window_changes *values)
+ {
+   //  ErrorF("xprConfigureWindow()\n");
+     if (!no_configure_window)
+         return xp_configure_window(id, mask, values);
+     else
+         return XP_Success;
+ }
+ 
+ 
+ static void
+ xprSetNativeProperty(RootlessWindowPtr pFrame)
+ {
+     xp_error err;
+     unsigned int native_id;
+     long data;
+ 
+     err = xp_get_native_window((xp_window_id) pFrame->wid, &native_id);
+     if (err == Success)
+     {
+         /* FIXME: move this to AppleWM extension */
+ 
+         data = native_id;
+         ChangeWindowProperty(pFrame->win, xa_native_window_id(),
+                              XA_INTEGER, 32, PropModeReplace, 1, &data, TRUE);
+     }
+ }
+ 
+ 
+ /*
+  * Create and display a new frame.
+  */
+ Bool
+ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
+                int newX, int newY, RegionPtr pShape)
+ {
+     WindowPtr pWin = pFrame->win;
+     xp_window_changes wc;
+     unsigned int mask = 0;
+     xp_error err;
+ 
+     wc.x = newX;
+     wc.y = newY;
+     wc.width = pFrame->width;
+     wc.height = pFrame->height;
+     wc.bit_gravity = XP_GRAVITY_NONE;
+     mask |= XP_BOUNDS;
+ 
+     if (pWin->drawable.depth == 8)
+     {
+         wc.depth = XP_DEPTH_INDEX8;
+ #if 0
+         wc.colormap = xprColormapCallback;
+         wc.colormap_data = pScreen;
+         mask |= XP_COLORMAP;
+ #endif
+     }
+     else if (pWin->drawable.depth == 15)
+         wc.depth = XP_DEPTH_RGB555;
+     else if (pWin->drawable.depth == 24)
+         wc.depth = XP_DEPTH_ARGB8888;
+     else
+         wc.depth = XP_DEPTH_NIL;
+     mask |= XP_DEPTH;
+ 
+     if (pShape != NULL)
+     {
+         wc.shape_nrects = REGION_NUM_RECTS(pShape);
+         wc.shape_rects = REGION_RECTS(pShape);
+         wc.shape_tx = wc.shape_ty = 0;
+         mask |= XP_SHAPE;
+     }
+ 
+     err = xp_create_window(mask, &wc, (xp_window_id *) &pFrame->wid);
+ 
+     if (err != Success)
+     {
+         return FALSE;
+     }
+ 
+     if (window_hash == NULL)
+     {
+         window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
+         pthread_mutex_init(&window_hash_mutex, NULL);
+     }
+ 
+     pthread_mutex_lock(&window_hash_mutex);
+     x_hash_table_insert(window_hash, pFrame->wid, pFrame);
+     pthread_mutex_unlock(&window_hash_mutex);
+ 
+     xprSetNativeProperty(pFrame);
+ 
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * Destroy a frame.
+  */
+ void
+ xprDestroyFrame(RootlessFrameID wid)
+ {
+     pthread_mutex_lock(&window_hash_mutex);
+     x_hash_table_remove(window_hash, wid);
+     pthread_mutex_unlock(&window_hash_mutex);
+ 
+     xp_destroy_window((xp_window_id) wid);
+ }
+ 
+ 
+ /*
+  * Move a frame on screen.
+  */
+ void
+ xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
+ {
+     xp_window_changes wc;
+ 
+     wc.x = newX;
+     wc.y = newY;
+     //    ErrorF("xprMoveFrame(%d, %p, %d, %d)\n", wid, pScreen, newX, newY);
+     xprConfigureWindow((xp_window_id) wid, XP_ORIGIN, &wc);
+ }
+ 
+ 
+ /*
+  * Resize and move a frame.
+  */
+ void
+ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
+                int newX, int newY, unsigned int newW, unsigned int newH,
+                unsigned int gravity)
+ {
+     xp_window_changes wc;
+ 
+     wc.x = newX;
+     wc.y = newY;
+     wc.width = newW;
+     wc.height = newH;
+     wc.bit_gravity = gravity;
+ 
+     /* It's unlikely that being async will save us anything here.
+        But it can't hurt. */
+ 
+     xprConfigureWindow((xp_window_id) wid, XP_BOUNDS, &wc);
+ }
+ 
+ 
+ /*
+  * Change frame stacking.
+  */
+ void
+ xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid)
+ {
+     xp_window_changes wc;
+ 
+     /* Stack frame below nextWid it if it exists, or raise
+        frame above everything otherwise. */
+ 
+     if (nextWid == NULL)
+     {
+         wc.stack_mode = XP_MAPPED_ABOVE;
+         wc.sibling = 0;
+     }
+     else
+     {
+         wc.stack_mode = XP_MAPPED_BELOW;
+         wc.sibling = (xp_window_id) nextWid;
+     }
+ 
+     xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
+ }
+ 
+ 
+ /*
+  * Change the frame's shape.
+  */
+ void
+ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
+ {
+     xp_window_changes wc;
+ 
+     if (pShape != NULL)
+     {
+         wc.shape_nrects = REGION_NUM_RECTS(pShape);
+         wc.shape_rects = REGION_RECTS(pShape);
+     }
+     else
+     {
+         wc.shape_nrects = -1;
+         wc.shape_rects = NULL;
+     }
+ 
+     wc.shape_tx = wc.shape_ty = 0;
+ 
+     xprConfigureWindow((xp_window_id) wid, XP_SHAPE, &wc);
+ }
+ 
+ 
+ /*
+  * Unmap a frame.
+  */
+ void
+ xprUnmapFrame(RootlessFrameID wid)
+ {
+     xp_window_changes wc;
+ 
+     wc.stack_mode = XP_UNMAPPED;
+     wc.sibling = 0;
+ 
+     xprConfigureWindow((xp_window_id) wid, XP_STACKING, &wc);
+ }
+ 
+ 
+ /*
+  * Start drawing to a frame.
+  *  Prepare for direct access to its backing buffer.
+  */
+ void
+ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
+ {
+     void *data[2];
+     unsigned int rowbytes[2];
+     xp_error err;
+ 
+     err = xp_lock_window((xp_window_id) wid, NULL, NULL, data, rowbytes, NULL);
+     if (err != Success)
+         FatalError("Could not lock window %i for drawing.", (int) wid);
+ 
+     *pixelData = data[0];
+     *bytesPerRow = rowbytes[0];
+ }
+ 
+ 
+ /*
+  * Stop drawing to a frame.
+  */
+ void
+ xprStopDrawing(RootlessFrameID wid, Bool flush)
+ {
+     xp_unlock_window((xp_window_id) wid, flush);
+ }
+ 
+ 
+ /*
+  * Flush drawing updates to the screen.
+  */
+ void
+ xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
+ {
+     xp_flush_window((xp_window_id) wid);
+ }
+ 
+ 
+ /*
+  * Mark damaged rectangles as requiring redisplay to screen.
+  */
+ void
+ xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
+                int shift_x, int shift_y)
+ {
+     xp_mark_window((xp_window_id) wid, nrects, rects, shift_x, shift_y);
+ }
+ 
+ 
+ /*
+  * Called after the window associated with a frame has been switched
+  * to a new top-level parent.
+  */
+ void
+ xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
+ {
 -    DeleteProperty(oldWin, xa_native_window_id());
++    DeleteProperty(serverClient, oldWin, xa_native_window_id());
+ 
+     xprSetNativeProperty(pFrame);
+ }
+ 
+ 
+ /*
+  * Called to check if the frame should be reordered when it is restacked.
+  */
+ Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
+ {
+     WindowPtr pWin = pFrame->win;
+ 
+     return AppleWMDoReorderWindow(pWin);
+ }
+ 
+ 
+ /*
+  * Copy area in frame to another part of frame.
+  *  Used to accelerate scrolling.
+  */
+ void
+ xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
+               int dx, int dy)
+ {
+     xp_copy_window((xp_window_id) wid, (xp_window_id) wid,
+                    dstNrects, dstRects, dx, dy);
+ }
+ 
+ 
+ static RootlessFrameProcsRec xprRootlessProcs = {
+     xprCreateFrame,
+     xprDestroyFrame,
+     xprMoveFrame,
+     xprResizeFrame,
+     xprRestackFrame,
+     xprReshapeFrame,
+     xprUnmapFrame,
+     xprStartDrawing,
+     xprStopDrawing,
+     xprUpdateRegion,
+     xprDamageRects,
+     xprSwitchWindow,
+     xprDoReorderWindow,
+     xp_copy_bytes,
+     xp_fill_bytes,
+     xp_composite_pixels,
+     xprCopyWindow
+ };
+ 
+ 
+ /*
+  * Initialize XPR implementation
+  */
+ Bool
+ xprInit(ScreenPtr pScreen)
+ {
+     RootlessInit(pScreen, &xprRootlessProcs);
+ 
+     rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
+     rootless_FillBytes_threshold = xp_fill_bytes_threshold;
+     rootless_CompositePixels_threshold = xp_composite_area_threshold;
+     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
+ 
+     no_configure_window = FALSE;
+ 
+     return TRUE;
+ }
+ 
+ 
+ /*
+  * Given the id of a physical window, try to find the top-level (or root)
+  * X window that it represents.
+  */
+ WindowPtr
+ xprGetXWindow(xp_window_id wid)
+ {
+     RootlessWindowRec *winRec;
+ 
+     if (window_hash == NULL)
+         return NULL;
+ 
+     winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
+ 
+     return winRec != NULL ? winRec->win : NULL;
+ }
+ 
+ /*
+  * Given the id of a physical window, try to find the top-level (or root)
+  * X window that it represents.
+  */
+ WindowPtr
+ xprGetXWindowFromAppKit(int windowNumber)
+ {
+     RootlessWindowRec *winRec;
+     Bool ret;
+     xp_window_id wid;
+ 
+     if (window_hash == NULL)
+         return FALSE;
+ 
+     /* need to lock, since this function can be called by any thread */
+ 
+     pthread_mutex_lock(&window_hash_mutex);
+ 
+     if (xp_lookup_native_window(windowNumber, &wid))
+         ret = xprGetXWindow(wid) != NULL;
+     else
+         ret = FALSE;
+ 
+     pthread_mutex_unlock(&window_hash_mutex);
+ 
+     if (!ret) return NULL;
+     winRec = x_hash_table_lookup(window_hash, (void *) wid, NULL);
+ 
+     return winRec != NULL ? winRec->win : NULL;
+ }
+ 
+ 
+ /*
+  * The windowNumber is an AppKit window number. Returns TRUE if xpr is
+  * displaying a window with that number.
+  */
+ Bool
+ xprIsX11Window(void *nsWindow, int windowNumber)
+ {
+     Bool ret;
+     xp_window_id wid;
+ 
+     if (window_hash == NULL)
+         return FALSE;
+ 
+     /* need to lock, since this function can be called by any thread */
+ 
+     pthread_mutex_lock(&window_hash_mutex);
+ 
+     if (xp_lookup_native_window(windowNumber, &wid))
+         ret = xprGetXWindow(wid) != NULL;
+     else
+         ret = FALSE;
+ 
+     pthread_mutex_unlock(&window_hash_mutex);
+ 
+     return ret;
+ }
+ 
+ 
+ /*
+  * xprHideWindows
+  *  Hide or unhide all top level windows. This is called for application hide/
+  *  unhide events if the window manager is not Apple-WM aware. Xplugin windows
+  *  do not hide or unhide themselves.
+  */
+ void
+ xprHideWindows(Bool hide)
+ {
+     int screen;
+     WindowPtr pRoot, pWin;
+ 
+     for (screen = 0; screen < screenInfo.numScreens; screen++) {
+         pRoot = WindowTable[screenInfo.screens[screen]->myNum];
+         RootlessFrameID prevWid = NULL;
+ 
+         for (pWin = pRoot->firstChild; pWin; pWin = pWin->nextSib) {
+             RootlessWindowRec *winRec = WINREC(pWin);
+ 
+             if (winRec != NULL) {
+                 if (hide) {
+                     xprUnmapFrame(winRec->wid);
+                 } else {
+                     BoxRec box;
+ 
+                     xprRestackFrame(winRec->wid, prevWid);
+                     prevWid = winRec->wid;
+ 
+                     box.x1 = 0;
+                     box.y1 = 0;
+                     box.x2 = winRec->width;
+                     box.y2 = winRec->height;
+ 
+                     xprDamageRects(winRec->wid, 1, &box, 0, 0);
+                     RootlessQueueRedisplay(screenInfo.screens[screen]);
+                 }
+             }
+         }
+     }
+ }
diff --cc miext/rootless/rootlessCommon.c
index 9cbb7fa,562f655..97c92d3
--- a/miext/rootless/rootlessCommon.c
+++ b/miext/rootless/rootlessCommon.c
@@@ -136,8 -172,24 +172,24 @@@ void RootlessStartDrawing(WindowPtr pWi
          winRec->is_drawing = TRUE;
      }
  
-     winRec->oldPixmap = pScreen->GetWindowPixmap(pWindow);
-     pScreen->SetWindowPixmap(pWindow, winRec->pixmap);
+     PixmapPtr curPixmap = pScreen->GetWindowPixmap(pWindow);
+     if (curPixmap == winRec->pixmap)
+     {
+         RL_DEBUG_MSG("Window %p already has winRec->pixmap %p; not pushing\n", pWindow, winRec->pixmap);
+     }
+     else
+     {
 -        PixmapPtr oldPixmap = pWindow->devPrivates[rootlessWindowOldPixmapPrivateIndex].ptr;
++        PixmapPtr oldPixmap = dixLookupPrivate(&pWindow->devPrivates, rootlessWindowOldPixmapPrivateKey);
+         if (oldPixmap != NULL)
+         {
+             if (oldPixmap == curPixmap)
+                 RL_DEBUG_MSG("Window %p's curPixmap %p is the same as its oldPixmap; strange\n", pWindow, curPixmap);
+             else
+                 RL_DEBUG_MSG("Window %p's existing oldPixmap %p being lost!\n", pWindow, oldPixmap);
+         }
 -        pWindow->devPrivates[rootlessWindowOldPixmapPrivateIndex].ptr = curPixmap;
++	dixSetPrivate(&pWindow->devPrivates, rootlessWindowOldPixmapPrivateKey, curPixmap);
+         pScreen->SetWindowPixmap(pWindow, winRec->pixmap);
+     }
  }
  
  
@@@ -146,6 -198,29 +198,29 @@@
   *  Stop drawing to a window's backing buffer. If flush is true,
   *  damaged regions are flushed to the screen.
   */
+ static int RestorePreDrawingPixmapVisitor(WindowPtr pWindow, pointer data)
+ {
+     RootlessWindowRec *winRec = (RootlessWindowRec*)data;
+     ScreenPtr pScreen = pWindow->drawable.pScreen;
+     PixmapPtr exPixmap = pScreen->GetWindowPixmap(pWindow);
 -    PixmapPtr oldPixmap = pWindow->devPrivates[rootlessWindowOldPixmapPrivateIndex].ptr;
++    PixmapPtr oldPixmap = dixLookupPrivate(&pWindow->devPrivates, rootlessWindowOldPixmapPrivateKey);
+     if (oldPixmap == NULL)
+     {
+         if (exPixmap == winRec->pixmap)
+             RL_DEBUG_MSG("Window %p appears to be in drawing mode (ex-pixmap %p equals winRec->pixmap, which is being freed) but has no oldPixmap!\n", pWindow, exPixmap);
+     }
+     else
+     {
+         if (exPixmap != winRec->pixmap)
+             RL_DEBUG_MSG("Window %p appears to be in drawing mode (oldPixmap %p) but ex-pixmap %p not winRec->pixmap %p!\n", pWindow, oldPixmap, exPixmap, winRec->pixmap);
+         if (oldPixmap == winRec->pixmap)
+             RL_DEBUG_MSG("Window %p's oldPixmap %p is winRec->pixmap, which has just been freed!\n", pWindow, oldPixmap);
+         pScreen->SetWindowPixmap(pWindow, oldPixmap);
 -        pWindow->devPrivates[rootlessWindowOldPixmapPrivateIndex].ptr = NULL;
++        dixSetPrivate(&pWindow->devPrivates, rootlessWindowOldPixmapPrivateKey, NULL);
+     }
+     return WT_WALKCHILDREN;
+ }
+ 
  void RootlessStopDrawing(WindowPtr pWindow, Bool flush)
  {
      ScreenPtr pScreen = pWindow->drawable.pScreen;
diff --cc miext/rootless/rootlessCommon.h
index 537ffda,fd8725a..9e4a14a
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@@ -52,9 -57,10 +57,10 @@@
  
  
  // Global variables
 -extern int rootlessGCPrivateIndex;
 -extern int rootlessScreenPrivateIndex;
 -extern int rootlessWindowPrivateIndex;
 -extern int rootlessWindowOldPixmapPrivateIndex;
 +extern DevPrivateKey rootlessGCPrivateKey;
 +extern DevPrivateKey rootlessScreenPrivateKey;
 +extern DevPrivateKey rootlessWindowPrivateKey;
++extern DevPrivateKey rootlessWindowOldPixmapPrivateKey;
  
  
  // RootlessGCRec: private per-gc data
diff --cc miext/rootless/rootlessScreen.c
index 18673a8,19dba6e..5031858
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@@ -61,9 -62,10 +62,10 @@@ extern int RootlessMiValidateTree(Windo
  extern Bool RootlessCreateGC(GCPtr pGC);
  
  // Initialize globals
 -int rootlessGCPrivateIndex = -1;
 -int rootlessScreenPrivateIndex = -1;
 -int rootlessWindowPrivateIndex = -1;
 -int rootlessWindowOldPixmapPrivateIndex = -1;
 +DevPrivateKey rootlessGCPrivateKey = &rootlessGCPrivateKey;
 +DevPrivateKey rootlessScreenPrivateKey = &rootlessScreenPrivateKey;
 +DevPrivateKey rootlessWindowPrivateKey = &rootlessWindowPrivateKey;
++DevPrivateKey rootlessWindowOldPixmapPrivateKey = &rootlessWindowOldPixmapPrivateKey;
  
  
  /*
@@@ -633,9 -718,12 +699,11 @@@ Bool RootlessInit(ScreenPtr pScreen, Ro
      if (!RootlessAllocatePrivates(pScreen))
          return FALSE;
  
 -    s = (RootlessScreenRec*)
 -        pScreen->devPrivates[rootlessScreenPrivateIndex].ptr;
 +    s = SCREENREC(pScreen);
  
      s->imp = procs;
+     s->colormap = NULL;
+     s->redisplay_expired = FALSE;
  
      RootlessWrap(pScreen);
  
diff --cc miext/rootless/rootlessWindow.c
index 16cbb18,bb5ba48..b953398
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@@ -197,7 -197,8 +197,8 @@@ RootlessCreateWindow(WindowPtr pWin
      Bool result;
      RegionRec saveRoot;
  
 -    WINREC(pWin) = NULL;
 -    pWin->devPrivates[rootlessWindowOldPixmapPrivateIndex].ptr = NULL;
 +    SETWINREC(pWin, NULL);
++    dixSetPrivate(&pWin->devPrivates, rootlessWindowOldPixmapPrivateKey, NULL);
  
      SCREEN_UNWRAP(pWin->drawable.pScreen, CreateWindow);
  
diff --cc os/Makefile.am
index a119824,16070f5..ce60585
--- a/os/Makefile.am
+++ b/os/Makefile.am
@@@ -36,15 -41,8 +36,8 @@@ if NEED_STRLCA
  libos_la_SOURCES += $(STRLCAT_SRCS)
  endif
  
- libcwrapper_la_SOURCES = \
- 	$(top_srcdir)/hw/xfree86/os-support/shared/libc_wrapper.c
- libcwrapper_la_CFLAGS = \
- 	-DSELF_CONTAINED_WRAPPER \
- 	-I$(top_srcdir)/hw/xfree86/os-support \
- 	$(AM_CFLAGS)
- 
  EXTRA_DIST = $(SECURERPC_SRCS) $(INTERNALMALLOC_SRCS) \
 -     $(XCSECURITY_SRCS) $(XDMCP_SRCS) $(STRLCAT_SRCS)
 +     $(XDMCP_SRCS) $(STRLCAT_SRCS)
  
  if XSERVER_DTRACE
  # Generate dtrace object code for probes in libos & libdix
diff --cc render/picture.h
index e8a098c,e8a098c..045b299
--- a/render/picture.h
+++ b/render/picture.h
@@@ -163,8 -163,8 +163,8 @@@ extern int  PictureCmapPolicy
  
  int	PictureParseCmapPolicy (const char *name);
  
--extern int	RenderErrBase;
--extern int	RenderClientPrivateIndex;
++extern int RenderErrBase;
++extern DevPrivateKey RenderClientPrivateKey;
  
  /* Fixed point updates from Carl Worth, USC, Information Sciences Institute */
  
diff --cc render/picturestr.h
index 4dfa944,ba165a4..acd15c7
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@@ -484,13 -501,10 +484,7 @@@ PictureFinishInit (void)
  void
  SetPictureToDefaults (PicturePtr pPicture);
  
- #if 0
- Bool
- miPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats);
- #endif
- 
- 
  PicturePtr
 -AllocatePicture (ScreenPtr  pScreen);
 -
 -PicturePtr
  CreatePicture (Picture		pid,
  	       DrawablePtr	pDrawable,
  	       PictFormatPtr	pFormat,
diff --cc render/render.c
index db9168b,b432406..f03f54a
--- a/render/render.c
+++ b/render/render.c
@@@ -213,11 -212,8 +213,8 @@@ int	(*SProcRenderVector[RenderNumberReq
  static void
  RenderResetProc (ExtensionEntry *extEntry);
      
- #if 0
- static CARD8	RenderReqCode;
- #endif
  int	RenderErrBase;
 -int	RenderClientPrivateIndex;
 +DevPrivateKey RenderClientPrivateKey;
  
  typedef struct _RenderClient {
      int	    major_version;
diff --cc xkb/xkbActions.c
index 380a232,6edac29..2aacc8c
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@@ -1020,10 -1041,12 +1032,13 @@@ _XkbFilterDeviceBtn(	XkbSrvInfoPtr	xkbi
  DeviceIntPtr	dev;
  int		button;
  
+     if (dev == inputInfo.keyboard)
+         return 0;
+ 
      if (filter->keycode==0) {		/* initial press */
 -	dev= _XkbLookupButtonDevice(pAction->devbtn.device,NULL);
 -	if ((!dev)||(!dev->public.on)||(&dev->public==LookupPointerDevice()))
 +	_XkbLookupButtonDevice(&dev, pAction->devbtn.device, serverClient,
 +			       DixUnknownAccess, &button);
 +	if (!dev || !dev->public.on || dev == inputInfo.pointer)
  	    return 1;
  
  	button= pAction->devbtn.button;
commit 9a7ce573636e349ee2967991c7cc1407e80ae524
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Dec 12 20:44:59 2007 -0500

    xselinux: Add new protocol for setting device create context.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 8f52c1e..bbae483 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1052,6 +1052,18 @@ ProcSELinuxGetSelectionManager(ClientPtr client)
 }
 
 static int
+ProcSELinuxSetDeviceCreateContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxGetDeviceCreateContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
 ProcSELinuxSetDeviceContext(ClientPtr client)
 {
     char *ctx;
@@ -1134,6 +1146,10 @@ ProcSELinuxDispatch(ClientPtr client)
 	return ProcSELinuxSetSelectionManager(client);
     case X_SELinuxGetSelectionManager:
     	return ProcSELinuxGetSelectionManager(client);
+    case X_SELinuxSetDeviceCreateContext:
+    	return ProcSELinuxSetDeviceCreateContext(client);
+    case X_SELinuxGetDeviceCreateContext:
+    	return ProcSELinuxGetDeviceCreateContext(client);
     case X_SELinuxSetDeviceContext:
     	return ProcSELinuxSetDeviceContext(client);
     case X_SELinuxGetDeviceContext:
@@ -1185,6 +1201,18 @@ SProcSELinuxGetSelectionManager(ClientPtr client)
 }
 
 static int
+SProcSELinuxSetDeviceCreateContext(ClientPtr client)
+{
+    return ProcSELinuxSetDeviceCreateContext(client);
+}
+
+static int
+SProcSELinuxGetDeviceCreateContext(ClientPtr client)
+{
+    return ProcSELinuxGetDeviceCreateContext(client);
+}
+
+static int
 SProcSELinuxSetDeviceContext(ClientPtr client)
 {
     return ProcSELinuxSetDeviceContext(client);
@@ -1247,6 +1275,10 @@ SProcSELinuxDispatch(ClientPtr client)
 	return SProcSELinuxSetSelectionManager(client);
     case X_SELinuxGetSelectionManager:
     	return SProcSELinuxGetSelectionManager(client);
+    case X_SELinuxSetDeviceCreateContext:
+    	return SProcSELinuxSetDeviceCreateContext(client);
+    case X_SELinuxGetDeviceCreateContext:
+    	return SProcSELinuxGetDeviceCreateContext(client);
     case X_SELinuxSetDeviceContext:
     	return SProcSELinuxSetDeviceContext(client);
     case X_SELinuxGetDeviceContext:
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index ea8d9e4..ebcc4aa 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -33,14 +33,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define X_SELinuxQueryVersion			0
 #define X_SELinuxSetSelectionManager		1
 #define X_SELinuxGetSelectionManager		2
-#define X_SELinuxSetDeviceContext		3
-#define X_SELinuxGetDeviceContext		4
-#define X_SELinuxSetPropertyCreateContext	5
-#define X_SELinuxGetPropertyCreateContext	6
-#define X_SELinuxGetPropertyContext		7
-#define X_SELinuxSetWindowCreateContext		8
-#define X_SELinuxGetWindowCreateContext		9
-#define X_SELinuxGetWindowContext		10
+#define X_SELinuxSetDeviceCreateContext		3
+#define X_SELinuxGetDeviceCreateContext		4
+#define X_SELinuxSetDeviceContext		5
+#define X_SELinuxGetDeviceContext		6
+#define X_SELinuxSetPropertyCreateContext	7
+#define X_SELinuxGetPropertyCreateContext	8
+#define X_SELinuxGetPropertyContext		9
+#define X_SELinuxSetWindowCreateContext		10
+#define X_SELinuxGetWindowCreateContext		11
+#define X_SELinuxGetWindowContext		12
 
 typedef struct {
     CARD8   reqType;
commit 8503072e1c2b89dca786d4afb72aa60a170d2fbd
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 26 16:52:41 2007 -0500

    registry: add missing include statement.

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 919bcda..577e17c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -148,6 +148,7 @@ int ProcInitialConnection();
 #endif
 
 #ifdef XSERVER_DTRACE
+#include "registry.h"
 #include "Xserver-dtrace.h"
 #endif
 
commit 996b621bec1bbc4fb21970c75eaec62053bc6ccb
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 26 15:59:44 2007 -0500

    registry: swap out the DTRACE XErrorDB stuff for the new registry call.

diff --git a/configure.ac b/configure.ac
index d78bc1c..042cfdd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,13 +90,6 @@ if test "x$WDTRACE" != "xno" ; then
 fi
 AM_CONDITIONAL(XSERVER_DTRACE, [test "x$WDTRACE" != "xno"])
 
-# DTrace support uses XErrorDB to get request names
-AC_ARG_WITH(xerrordb,
-            AS_HELP_STRING([--with-xerrordb=PATH], [Path to XErrorDB file (default: ${datadir}/X11/XErrorDB)]),
-	    [ XERRORDB_PATH="$withval" ],
-	    [ XERRORDB_PATH="${datadir}/X11/XErrorDB" ])
-AC_DEFINE_DIR(XERRORDB_PATH, XERRORDB_PATH, [Path to XErrorDB file])
-
 AC_HEADER_DIRENT
 AC_HEADER_STDC
 AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h])
diff --git a/dix/dispatch.c b/dix/dispatch.c
index dcd4b53..919bcda 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -148,14 +148,7 @@ int ProcInitialConnection();
 #endif
 
 #ifdef XSERVER_DTRACE
-#include <sys/types.h>
-typedef const char *string;
 #include "Xserver-dtrace.h"
-
-char *RequestNames[256];
-static void LoadRequestNames(void);
-static void FreeRequestNames(void);
-#define GetRequestName(i) (RequestNames[i])
 #endif
 
 #define mskcnt ((MAXCLIENTS + 31) / 32)
@@ -383,10 +376,6 @@ Dispatch(void)
     if (!clientReady)
 	return;
 
-#ifdef XSERVER_DTRACE
-    LoadRequestNames();
-#endif
-
     while (!dispatchException)
     {
         if (*icheck[0] != *icheck[1])
@@ -464,7 +453,7 @@ Dispatch(void)
 		client->requestLogIndex++;
 #endif
 #ifdef XSERVER_DTRACE
-		XSERVER_REQUEST_START(GetRequestName(MAJOROP), MAJOROP,
+		XSERVER_REQUEST_START(LookupMajorName(MAJOROP), MAJOROP,
 			      ((xReq *)client->requestBuffer)->length,
 			      client->index, client->requestBuffer);
 #endif
@@ -476,7 +465,7 @@ Dispatch(void)
 		    XaceHookAuditEnd(client, result);
 		}
 #ifdef XSERVER_DTRACE
-		XSERVER_REQUEST_DONE(GetRequestName(MAJOROP), MAJOROP,
+		XSERVER_REQUEST_DONE(LookupMajorName(MAJOROP), MAJOROP,
 			      client->sequence, client->index, result);
 #endif
 
@@ -510,9 +499,6 @@ Dispatch(void)
     KillAllClients();
     xfree(clientReady);
     dispatchException &= ~DE_RESET;
-#ifdef XSERVER_DTRACE
-    FreeRequestNames();
-#endif
 }
 
 #undef MAJOROP
@@ -4045,60 +4031,3 @@ MarkClientException(ClientPtr client)
 {
     client->noClientException = -1;
 }
-
-#ifdef XSERVER_DTRACE
-#include <ctype.h>
-
-/* Load table of request names for dtrace probes */
-static void LoadRequestNames(void)
-{
-    int i;
-    FILE *xedb;
-    extern void LoadExtensionNames(char **RequestNames);
-
-    bzero(RequestNames, 256 * sizeof(char *));
-
-    xedb = fopen(XERRORDB_PATH, "r");
-    if (xedb != NULL) {
-	char buf[256];
-	while (fgets(buf, sizeof(buf), xedb)) {
-	    if ((strncmp("XRequest.", buf, 9) == 0) && (isdigit(buf[9]))) {
-		char *name;
-		i = strtol(buf + 9, &name, 10);
-		if (RequestNames[i] == 0) {
-		    char *end = strchr(name, '\n');
-		    if (end) { *end = '\0'; }
-		    RequestNames[i] = strdup(name + 1);
-		}
-	    }
-	}
-	fclose(xedb);
-    }
-
-    LoadExtensionNames(RequestNames);
-
-    for (i = 0; i < 256; i++) {
-	if (RequestNames[i] == 0) {
-#define RN_SIZE 12 /* "Request#' + up to 3 digits + \0 */
-	    RequestNames[i] = xalloc(RN_SIZE);
-	    if (RequestNames[i]) {
-		snprintf(RequestNames[i], RN_SIZE, "Request#%d", i);
-	    }
-	}
-	/* fprintf(stderr, "%d: %s\n", i, RequestNames[i]); */
-    }
-}
-
-static void FreeRequestNames(void)
-{
-    int i;
-
-    for (i = 0; i < 256; i++) {
-	if (RequestNames[i] != 0) {
-	    free(RequestNames[i]);
-	    RequestNames[i] = 0;
-	}
-    }
-}
-
-#endif
diff --git a/dix/extension.c b/dix/extension.c
index 42fdc12..9740c1b 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -354,17 +354,3 @@ ProcListExtensions(ClientPtr client)
     }
     return(client->noClientException);
 }
-
-#ifdef XSERVER_DTRACE
-void LoadExtensionNames(char **RequestNames) {
-    int i;
-
-    for (i=0; i<NumExtensions; i++) {
-	int r = extensions[i]->base;
-
-	if (RequestNames[r] == NULL) {
-	    RequestNames[r] = strdup(extensions[i]->name);
-	}
-    }
-}
-#endif
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index c442962..2af994f 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -500,9 +500,6 @@
 /* Define to 1 if the DTrace Xserver provider probes should be built in */
 #undef XSERVER_DTRACE
 
-/* Path to XErrorDB file */
-#undef XERRORDB_PATH
-
 /* Define to 16-bit byteswap macro */
 #undef bswap_16
 
commit 54cb729ecc2d366c1af836cb3d2ffc8e864e9b79
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 26 15:59:01 2007 -0500

    registry: Add a call for DTRACE compatibility.

diff --git a/dix/registry.c b/dix/registry.c
index 02b42d4..10fa21f 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -218,6 +218,25 @@ LookupRequestName(int major, int minor)
 }
 
 const char *
+LookupMajorName(int major)
+{
+    if (major < 128) {
+	const char *retval;
+
+	if (major >= nmajor)
+	    return XREGISTRY_UNKNOWN;
+	if (0 >= nminor[major])
+	    return XREGISTRY_UNKNOWN;
+
+	retval = requests[major][0];
+	return retval ? retval + sizeof(CORE) : XREGISTRY_UNKNOWN;
+    } else {
+	ExtensionEntry *extEntry = GetExtensionEntry(major);
+	return extEntry ? extEntry->name : XREGISTRY_UNKNOWN;
+    }
+}
+
+const char *
 LookupEventName(int event)
 {
     event &= 127;
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 79cc6e7..49c7d27 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -289,6 +289,11 @@ _X_HIDDEN void *dixLookupTab[] = {
     /* registry.c */
 #ifdef XREGISTRY
     SYMFUNC(RegisterResourceName)
+    SYMFUNC(LookupMajorName)
+    SYMFUNC(LookupRequestName)
+    SYMFUNC(LookupEventName)
+    SYMFUNC(LookupErrorName)
+    SYMFUNC(LookupResourceName)
 #endif
     /* swaprep.c */
     SYMFUNC(CopySwap32Write)
diff --git a/include/registry.h b/include/registry.h
index 90c3de3..edd6ef9 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -29,6 +29,7 @@ void RegisterExtensionNames(ExtensionEntry *ext);
 /*
  * Lookup functions.  The returned string must not be modified or freed.
  */
+const char *LookupMajorName(int major);
 const char *LookupRequestName(int major, int minor);
 const char *LookupEventName(int event);
 const char *LookupErrorName(int error);
@@ -51,6 +52,7 @@ void dixResetRegistry(void);
 #define RegisterResourceName(a, b) { ; }
 #define RegisterExtensionNames(a) { ; }
 
+#define LookupMajorName(a) XREGISTRY_UNKNOWN
 #define LookupRequestName(a, b) XREGISTRY_UNKNOWN
 #define LookupEventName(a) XREGISTRY_UNKNOWN
 #define LookupErrorName(a) XREGISTRY_UNKNOWN
commit decd5a7c605e42c99b6a4523c8e1833b859d9b24
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 26 15:26:49 2007 -0500

    registry: Rebase registry to use the server config file of protocol names.

diff --git a/dix/extension.c b/dix/extension.c
index 0e97976..42fdc12 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -60,6 +60,7 @@ SOFTWARE.
 #include "scrnintstr.h"
 #include "dispatch.h"
 #include "privates.h"
+#include "registry.h"
 #include "xace.h"
 
 #define EXTENSION_BASE  128
@@ -143,6 +144,7 @@ AddExtension(char *name, int NumEvents, int NumErrors,
         ext->errorLast = 0;
     }
 
+    RegisterExtensionNames(ext);
     return(ext);
 }
 
diff --git a/dix/registry.c b/dix/registry.c
index 1cf7fa5..02b42d4 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -23,17 +23,30 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #ifdef XREGISTRY
 
+#include <stdlib.h>
+#include <string.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include "resource.h"
 #include "registry.h"
 
 #define BASE_SIZE 16
-#define CORE "X11:"
+#define CORE "X11"
+#define FILENAME SERVER_MISC_CONFIG_PATH "/protocol.txt"
 
-static const char ***requests, **events, **errors, **resources;
+#define PROT_COMMENT '#'
+#define PROT_REQUEST 'R'
+#define PROT_EVENT 'V'
+#define PROT_ERROR 'E'
+
+static FILE *fh;
+
+static char ***requests, **events, **errors, **resources;
 static unsigned nmajor, *nminor, nevent, nerror, nresource;
 
+/*
+ * File parsing routines
+ */
 static int double_size(void *p, unsigned n, unsigned size)
 {
     char **ptr = (char **)p;
@@ -57,58 +70,131 @@ static int double_size(void *p, unsigned n, unsigned size)
     return TRUE;
 }       
 
-/*
- * Registration functions
- */
-
-void
-RegisterRequestName(unsigned major, unsigned minor, const char *name)
+static void
+RegisterRequestName(unsigned major, unsigned minor, char *name)
 {
     while (major >= nmajor) {
-	if (!double_size(&requests, nmajor, sizeof(const char **)))
+	if (!double_size(&requests, nmajor, sizeof(char **)))
 	    return;
 	if (!double_size(&nminor, nmajor, sizeof(unsigned)))
 	    return;
 	nmajor = nmajor ? nmajor * 2 : BASE_SIZE;
     }
     while (minor >= nminor[major]) {
-	if (!double_size(requests+major, nminor[major], sizeof(const char *)))
+	if (!double_size(requests+major, nminor[major], sizeof(char *)))
 	    return;
 	nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE;
     }
 
+    free(requests[major][minor]);
     requests[major][minor] = name;
 }
 
-void
-RegisterEventName(unsigned event, const char *name) {
+static void
+RegisterEventName(unsigned event, char *name) {
     while (event >= nevent) {
-	if (!double_size(&events, nevent, sizeof(const char *)))
+	if (!double_size(&events, nevent, sizeof(char *)))
 	    return;
 	nevent = nevent ? nevent * 2 : BASE_SIZE;
     }
 
+    free(events[event]);
     events[event] = name;
 }
 
-void
-RegisterErrorName(unsigned error, const char *name) {
+static void
+RegisterErrorName(unsigned error, char *name) {
     while (error >= nerror) {
-	if (!double_size(&errors, nerror, sizeof(const char *)))
+	if (!double_size(&errors, nerror, sizeof(char *)))
 	    return;
 	nerror = nerror ? nerror * 2 : BASE_SIZE;
     }
 
+    free(errors[error]);
     errors[error] = name;
 }
 
 void
-RegisterResourceName(RESTYPE resource, const char *name)
+RegisterExtensionNames(ExtensionEntry *extEntry)
+{
+    char buf[256], *lineobj, *ptr;
+    unsigned offset;
+
+    if (fh == NULL)
+	return;
+
+    rewind(fh);
+
+    while (fgets(buf, sizeof(buf), fh)) {
+	ptr = strchr(buf, '\n');
+	if (ptr)
+	    *ptr = 0;
+
+	switch (buf[0]) {
+	case PROT_REQUEST:
+	case PROT_EVENT:
+	case PROT_ERROR:
+	    break;
+	case PROT_COMMENT:
+	case '\0':
+	    continue;
+	default:
+	    continue;
+	}
+
+	ptr = strchr(buf, ' ');
+	if (!ptr || ptr != buf + 4) {
+	    LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
+	    continue;
+	}
+	lineobj = strdup(ptr + 1);
+	if (!lineobj)
+	    continue;
+
+	ptr = strchr(buf, ':');
+	if (!ptr) {
+	    LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
+	    continue;
+	}
+	*ptr = 0;
+
+	if (strcmp(buf + 5, extEntry->name))
+	    continue;
+
+	offset = strtol(buf + 1, &ptr, 10);
+	if (offset == 0 && ptr == buf + 1) {
+	    LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
+	    continue;
+	}
+
+	switch(buf[0]) {
+	case PROT_REQUEST:
+	    if (extEntry->base)
+		RegisterRequestName(extEntry->base, offset, lineobj);
+	    else
+		RegisterRequestName(offset, 0, lineobj);
+	    break;
+	case PROT_EVENT:
+	    RegisterEventName(extEntry->eventBase + offset, lineobj);
+	    break;
+	case PROT_ERROR:
+	    RegisterErrorName(extEntry->errorBase + offset, lineobj);
+	    break;
+	}
+    }
+}
+
+/*
+ * Registration functions
+ */
+
+void
+RegisterResourceName(RESTYPE resource, char *name)
 {
     resource &= TypeMask;
 
     while (resource >= nresource) {
-	if (!double_size(&resources, nresource, sizeof(const char *)))
+	if (!double_size(&resources, nresource, sizeof(char *)))
 	    return;
 	nresource = nresource ? nresource * 2 : BASE_SIZE;
     }
@@ -166,13 +252,25 @@ LookupResourceName(RESTYPE resource)
 void
 dixResetRegistry(void)
 {
+    ExtensionEntry extEntry;
+
     /* Free all memory */
-    while (nmajor)
-	xfree(requests[--nmajor]);
+    while (nmajor--) {
+	while (nminor[nmajor])
+	    free(requests[nmajor][--nminor[nmajor]]);
+	xfree(requests[nmajor]);
+    }
     xfree(requests);
     xfree(nminor);
+
+    while (nevent--)
+	free(events[nevent]);
     xfree(events);
+
+    while (nerror--)
+	free(errors[nerror]);
     xfree(errors);
+
     xfree(resources);
 
     requests = NULL;
@@ -183,6 +281,13 @@ dixResetRegistry(void)
 
     nmajor = nevent = nerror = nresource = 0;
 
+    /* Open the protocol file */
+    if (fh)
+	fclose(fh);
+    fh = fopen(FILENAME, "r");
+    if (!fh)
+	LogMessage(X_WARNING, "Failed to open protocol names file " FILENAME);
+
     /* Add built-in resources */
     RegisterResourceName(RT_NONE, "NONE");
     RegisterResourceName(RT_WINDOW, "WINDOW");
@@ -196,181 +301,9 @@ dixResetRegistry(void)
     RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
 
     /* Add the core protocol */
-    RegisterRequestName(X_CreateWindow, 0, CORE "CreateWindow");
-    RegisterRequestName(X_ChangeWindowAttributes, 0, CORE "ChangeWindowAttributes");
-    RegisterRequestName(X_GetWindowAttributes, 0, CORE "GetWindowAttributes");
-    RegisterRequestName(X_DestroyWindow, 0, CORE "DestroyWindow");
-    RegisterRequestName(X_DestroySubwindows, 0, CORE "DestroySubwindows");
-    RegisterRequestName(X_ChangeSaveSet, 0, CORE "ChangeSaveSet");
-    RegisterRequestName(X_ReparentWindow, 0, CORE "ReparentWindow");
-    RegisterRequestName(X_MapWindow, 0, CORE "MapWindow");
-    RegisterRequestName(X_MapSubwindows, 0, CORE "MapSubwindows");
-    RegisterRequestName(X_UnmapWindow, 0, CORE "UnmapWindow");
-    RegisterRequestName(X_UnmapSubwindows, 0, CORE "UnmapSubwindows");
-    RegisterRequestName(X_ConfigureWindow, 0, CORE "ConfigureWindow");
-    RegisterRequestName(X_CirculateWindow, 0, CORE "CirculateWindow");
-    RegisterRequestName(X_GetGeometry, 0, CORE "GetGeometry");
-    RegisterRequestName(X_QueryTree, 0, CORE "QueryTree");
-    RegisterRequestName(X_InternAtom, 0, CORE "InternAtom");
-    RegisterRequestName(X_GetAtomName, 0, CORE "GetAtomName");
-    RegisterRequestName(X_ChangeProperty, 0, CORE "ChangeProperty");
-    RegisterRequestName(X_DeleteProperty, 0, CORE "DeleteProperty");
-    RegisterRequestName(X_GetProperty, 0, CORE "GetProperty");
-    RegisterRequestName(X_ListProperties, 0, CORE "ListProperties");
-    RegisterRequestName(X_SetSelectionOwner, 0, CORE "SetSelectionOwner");
-    RegisterRequestName(X_GetSelectionOwner, 0, CORE "GetSelectionOwner");
-    RegisterRequestName(X_ConvertSelection, 0, CORE "ConvertSelection");
-    RegisterRequestName(X_SendEvent, 0, CORE "SendEvent");
-    RegisterRequestName(X_GrabPointer, 0, CORE "GrabPointer");
-    RegisterRequestName(X_UngrabPointer, 0, CORE "UngrabPointer");
-    RegisterRequestName(X_GrabButton, 0, CORE "GrabButton");
-    RegisterRequestName(X_UngrabButton, 0, CORE "UngrabButton");
-    RegisterRequestName(X_ChangeActivePointerGrab, 0, CORE "ChangeActivePointerGrab");
-    RegisterRequestName(X_GrabKeyboard, 0, CORE "GrabKeyboard");
-    RegisterRequestName(X_UngrabKeyboard, 0, CORE "UngrabKeyboard");
-    RegisterRequestName(X_GrabKey, 0, CORE "GrabKey");
-    RegisterRequestName(X_UngrabKey, 0, CORE "UngrabKey");
-    RegisterRequestName(X_AllowEvents, 0, CORE "AllowEvents");
-    RegisterRequestName(X_GrabServer, 0, CORE "GrabServer");
-    RegisterRequestName(X_UngrabServer, 0, CORE "UngrabServer");
-    RegisterRequestName(X_QueryPointer, 0, CORE "QueryPointer");
-    RegisterRequestName(X_GetMotionEvents, 0, CORE "GetMotionEvents");
-    RegisterRequestName(X_TranslateCoords, 0, CORE "TranslateCoords");
-    RegisterRequestName(X_WarpPointer, 0, CORE "WarpPointer");
-    RegisterRequestName(X_SetInputFocus, 0, CORE "SetInputFocus");
-    RegisterRequestName(X_GetInputFocus, 0, CORE "GetInputFocus");
-    RegisterRequestName(X_QueryKeymap, 0, CORE "QueryKeymap");
-    RegisterRequestName(X_OpenFont, 0, CORE "OpenFont");
-    RegisterRequestName(X_CloseFont, 0, CORE "CloseFont");
-    RegisterRequestName(X_QueryFont, 0, CORE "QueryFont");
-    RegisterRequestName(X_QueryTextExtents, 0, CORE "QueryTextExtents");
-    RegisterRequestName(X_ListFonts, 0, CORE "ListFonts");
-    RegisterRequestName(X_ListFontsWithInfo, 0, CORE "ListFontsWithInfo");
-    RegisterRequestName(X_SetFontPath, 0, CORE "SetFontPath");
-    RegisterRequestName(X_GetFontPath, 0, CORE "GetFontPath");
-    RegisterRequestName(X_CreatePixmap, 0, CORE "CreatePixmap");
-    RegisterRequestName(X_FreePixmap, 0, CORE "FreePixmap");
-    RegisterRequestName(X_CreateGC, 0, CORE "CreateGC");
-    RegisterRequestName(X_ChangeGC, 0, CORE "ChangeGC");
-    RegisterRequestName(X_CopyGC, 0, CORE "CopyGC");
-    RegisterRequestName(X_SetDashes, 0, CORE "SetDashes");
-    RegisterRequestName(X_SetClipRectangles, 0, CORE "SetClipRectangles");
-    RegisterRequestName(X_FreeGC, 0, CORE "FreeGC");
-    RegisterRequestName(X_ClearArea, 0, CORE "ClearArea");
-    RegisterRequestName(X_CopyArea, 0, CORE "CopyArea");
-    RegisterRequestName(X_CopyPlane, 0, CORE "CopyPlane");
-    RegisterRequestName(X_PolyPoint, 0, CORE "PolyPoint");
-    RegisterRequestName(X_PolyLine, 0, CORE "PolyLine");
-    RegisterRequestName(X_PolySegment, 0, CORE "PolySegment");
-    RegisterRequestName(X_PolyRectangle, 0, CORE "PolyRectangle");
-    RegisterRequestName(X_PolyArc, 0, CORE "PolyArc");
-    RegisterRequestName(X_FillPoly, 0, CORE "FillPoly");
-    RegisterRequestName(X_PolyFillRectangle, 0, CORE "PolyFillRectangle");
-    RegisterRequestName(X_PolyFillArc, 0, CORE "PolyFillArc");
-    RegisterRequestName(X_PutImage, 0, CORE "PutImage");
-    RegisterRequestName(X_GetImage, 0, CORE "GetImage");
-    RegisterRequestName(X_PolyText8, 0, CORE "PolyText8");
-    RegisterRequestName(X_PolyText16, 0, CORE "PolyText16");
-    RegisterRequestName(X_ImageText8, 0, CORE "ImageText8");
-    RegisterRequestName(X_ImageText16, 0, CORE "ImageText16");
-    RegisterRequestName(X_CreateColormap, 0, CORE "CreateColormap");
-    RegisterRequestName(X_FreeColormap, 0, CORE "FreeColormap");
-    RegisterRequestName(X_CopyColormapAndFree, 0, CORE "CopyColormapAndFree");
-    RegisterRequestName(X_InstallColormap, 0, CORE "InstallColormap");
-    RegisterRequestName(X_UninstallColormap, 0, CORE "UninstallColormap");
-    RegisterRequestName(X_ListInstalledColormaps, 0, CORE "ListInstalledColormaps");
-    RegisterRequestName(X_AllocColor, 0, CORE "AllocColor");
-    RegisterRequestName(X_AllocNamedColor, 0, CORE "AllocNamedColor");
-    RegisterRequestName(X_AllocColorCells, 0, CORE "AllocColorCells");
-    RegisterRequestName(X_AllocColorPlanes, 0, CORE "AllocColorPlanes");
-    RegisterRequestName(X_FreeColors, 0, CORE "FreeColors");
-    RegisterRequestName(X_StoreColors, 0, CORE "StoreColors");
-    RegisterRequestName(X_StoreNamedColor, 0, CORE "StoreNamedColor");
-    RegisterRequestName(X_QueryColors, 0, CORE "QueryColors");
-    RegisterRequestName(X_LookupColor, 0, CORE "LookupColor");
-    RegisterRequestName(X_CreateCursor, 0, CORE "CreateCursor");
-    RegisterRequestName(X_CreateGlyphCursor, 0, CORE "CreateGlyphCursor");
-    RegisterRequestName(X_FreeCursor, 0, CORE "FreeCursor");
-    RegisterRequestName(X_RecolorCursor, 0, CORE "RecolorCursor");
-    RegisterRequestName(X_QueryBestSize, 0, CORE "QueryBestSize");
-    RegisterRequestName(X_QueryExtension, 0, CORE "QueryExtension");
-    RegisterRequestName(X_ListExtensions, 0, CORE "ListExtensions");
-    RegisterRequestName(X_ChangeKeyboardMapping, 0, CORE "ChangeKeyboardMapping");
-    RegisterRequestName(X_GetKeyboardMapping, 0, CORE "GetKeyboardMapping");
-    RegisterRequestName(X_ChangeKeyboardControl, 0, CORE "ChangeKeyboardControl");
-    RegisterRequestName(X_GetKeyboardControl, 0, CORE "GetKeyboardControl");
-    RegisterRequestName(X_Bell, 0, CORE "Bell");
-    RegisterRequestName(X_ChangePointerControl, 0, CORE "ChangePointerControl");
-    RegisterRequestName(X_GetPointerControl, 0, CORE "GetPointerControl");
-    RegisterRequestName(X_SetScreenSaver, 0, CORE "SetScreenSaver");
-    RegisterRequestName(X_GetScreenSaver, 0, CORE "GetScreenSaver");
-    RegisterRequestName(X_ChangeHosts, 0, CORE "ChangeHosts");
-    RegisterRequestName(X_ListHosts, 0, CORE "ListHosts");
-    RegisterRequestName(X_SetAccessControl, 0, CORE "SetAccessControl");
-    RegisterRequestName(X_SetCloseDownMode, 0, CORE "SetCloseDownMode");
-    RegisterRequestName(X_KillClient, 0, CORE "KillClient");
-    RegisterRequestName(X_RotateProperties, 0, CORE "RotateProperties");
-    RegisterRequestName(X_ForceScreenSaver, 0, CORE "ForceScreenSaver");
-    RegisterRequestName(X_SetPointerMapping, 0, CORE "SetPointerMapping");
-    RegisterRequestName(X_GetPointerMapping, 0, CORE "GetPointerMapping");
-    RegisterRequestName(X_SetModifierMapping, 0, CORE "SetModifierMapping");
-    RegisterRequestName(X_GetModifierMapping, 0, CORE "GetModifierMapping");
-    RegisterRequestName(X_NoOperation, 0, CORE "NoOperation");
-
-    RegisterErrorName(Success, CORE "Success");
-    RegisterErrorName(BadRequest, CORE "BadRequest");
-    RegisterErrorName(BadValue, CORE "BadValue");
-    RegisterErrorName(BadWindow, CORE "BadWindow");
-    RegisterErrorName(BadPixmap, CORE "BadPixmap");
-    RegisterErrorName(BadAtom, CORE "BadAtom");
-    RegisterErrorName(BadCursor, CORE "BadCursor");
-    RegisterErrorName(BadFont, CORE "BadFont");
-    RegisterErrorName(BadMatch, CORE "BadMatch");
-    RegisterErrorName(BadDrawable, CORE "BadDrawable");
-    RegisterErrorName(BadAccess, CORE "BadAccess");
-    RegisterErrorName(BadAlloc, CORE "BadAlloc");
-    RegisterErrorName(BadColor, CORE "BadColor");
-    RegisterErrorName(BadGC, CORE "BadGC");
-    RegisterErrorName(BadIDChoice, CORE "BadIDChoice");
-    RegisterErrorName(BadName, CORE "BadName");
-    RegisterErrorName(BadLength, CORE "BadLength");
-    RegisterErrorName(BadImplementation, CORE "BadImplementation");
-
-    RegisterEventName(X_Error, CORE "Error");
-    RegisterEventName(X_Reply, CORE "Reply");
-    RegisterEventName(KeyPress, CORE "KeyPress");
-    RegisterEventName(KeyRelease, CORE "KeyRelease");
-    RegisterEventName(ButtonPress, CORE "ButtonPress");
-    RegisterEventName(ButtonRelease, CORE "ButtonRelease");
-    RegisterEventName(MotionNotify, CORE "MotionNotify");
-    RegisterEventName(EnterNotify, CORE "EnterNotify");
-    RegisterEventName(LeaveNotify, CORE "LeaveNotify");
-    RegisterEventName(FocusIn, CORE "FocusIn");
-    RegisterEventName(FocusOut, CORE "FocusOut");
-    RegisterEventName(KeymapNotify, CORE "KeymapNotify");
-    RegisterEventName(Expose, CORE "Expose");
-    RegisterEventName(GraphicsExpose, CORE "GraphicsExpose");
-    RegisterEventName(NoExpose, CORE "NoExpose");
-    RegisterEventName(VisibilityNotify, CORE "VisibilityNotify");
-    RegisterEventName(CreateNotify, CORE "CreateNotify");
-    RegisterEventName(DestroyNotify, CORE "DestroyNotify");
-    RegisterEventName(UnmapNotify, CORE "UnmapNotify");
-    RegisterEventName(MapNotify, CORE "MapNotify");
-    RegisterEventName(MapRequest, CORE "MapRequest");
-    RegisterEventName(ReparentNotify, CORE "ReparentNotify");
-    RegisterEventName(ConfigureNotify, CORE "ConfigureNotify");
-    RegisterEventName(ConfigureRequest, CORE "ConfigureRequest");
-    RegisterEventName(GravityNotify, CORE "GravityNotify");
-    RegisterEventName(ResizeRequest, CORE "ResizeRequest");
-    RegisterEventName(CirculateNotify, CORE "CirculateNotify");
-    RegisterEventName(CirculateRequest, CORE "CirculateRequest");
-    RegisterEventName(PropertyNotify, CORE "PropertyNotify");
-    RegisterEventName(SelectionClear, CORE "SelectionClear");
-    RegisterEventName(SelectionRequest, CORE "SelectionRequest");
-    RegisterEventName(SelectionNotify, CORE "SelectionNotify");
-    RegisterEventName(ColormapNotify, CORE "ColormapNotify");
-    RegisterEventName(ClientMessage, CORE "ClientMessage");
-    RegisterEventName(MappingNotify, CORE "MappingNotify");
+    memset(&extEntry, 0, sizeof(extEntry));
+    extEntry.name = CORE;
+    RegisterExtensionNames(&extEntry);
 }
 
 #endif /* XREGISTRY */
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 1a259f5..79cc6e7 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -288,9 +288,6 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMVAR(ResourceStateCallback)
     /* registry.c */
 #ifdef XREGISTRY
-    SYMFUNC(RegisterRequestName)
-    SYMFUNC(RegisterEventName)
-    SYMFUNC(RegisterErrorName)
     SYMFUNC(RegisterResourceName)
 #endif
     /* swaprep.c */
diff --git a/include/registry.h b/include/registry.h
index d57f32d..90c3de3 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -15,6 +15,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifdef XREGISTRY
 
 #include "resource.h"
+#include "extnsionst.h"
 
 /* Internal string registry - for auditing, debugging, security, etc. */
 
@@ -22,13 +23,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * Registration functions.  The name string is not copied, so it must
  * not be a stack variable.
  */
-void RegisterRequestName(unsigned major, unsigned minor, const char *name);
-void RegisterEventName(unsigned event, const char *name);
-void RegisterErrorName(unsigned error, const char *name);
-void RegisterResourceName(RESTYPE type, const char *name);
+void RegisterResourceName(RESTYPE type, char *name);
+void RegisterExtensionNames(ExtensionEntry *ext);
 
 /*
- * Lookup functions.  The returned string must not be modified.
+ * Lookup functions.  The returned string must not be modified or freed.
  */
 const char *LookupRequestName(int major, int minor);
 const char *LookupEventName(int event);
@@ -49,10 +48,8 @@ void dixResetRegistry(void);
 
 /* Define calls away when the registry is not being built. */
 
-#define RegisterRequestName(a, b, c) { ; }
-#define RegisterEventName(a, b) { ; }
-#define RegisterErrorName(a, b) { ; }
 #define RegisterResourceName(a, b) { ; }
+#define RegisterExtensionNames(a) { ; }
 
 #define LookupRequestName(a, b) XREGISTRY_UNKNOWN
 #define LookupEventName(a) XREGISTRY_UNKNOWN
commit 9b0e72c8d960d056276f5fa93f3cc2872825711e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 26 15:26:04 2007 -0500

    registry: Add a great big list of protocol names, like the XErrorDB that
    ships with Xlib.  This is considered temporary, until server-side XCB can
    solve the problem programmatically.

diff --git a/dix/Makefile.am b/dix/Makefile.am
index 65c387c..2cf9014 100644
--- a/dix/Makefile.am
+++ b/dix/Makefile.am
@@ -42,6 +42,10 @@ INCLUDES = -I$(top_srcdir)/Xprint
 
 EXTRA_DIST = buildatoms BuiltInAtoms CHANGES Xserver.d Xserver-dtrace.h.in
 
+# Install list of protocol names
+miscconfigdir = $(SERVER_MISC_CONFIG_PATH)
+dist_miscconfig_DATA = protocol.txt
+
 if XSERVER_DTRACE
 # Generate dtrace header file for C sources to include
 BUILT_SOURCES = Xserver-dtrace.h
diff --git a/dix/protocol.txt b/dix/protocol.txt
new file mode 100644
index 0000000..f4cdf7b
--- /dev/null
+++ b/dix/protocol.txt
@@ -0,0 +1,1054 @@
+# Registry of protocol names used by X Server
+# This will eventually be replaced by server-side XCB
+#
+# Format is Xnnn <extension-name>:<object-name>
+# R=Request, V=Event, E=Error
+#
+# This is a security-sensitive file, please set permissions as appropriate.
+#
+R001 Adobe-DPS-Extension:Init
+R002 Adobe-DPS-Extension:CreateContext
+R003 Adobe-DPS-Extension:CreateSpace
+R004 Adobe-DPS-Extension:GiveInput
+R005 Adobe-DPS-Extension:GetStatus
+R006 Adobe-DPS-Extension:DestroySpace
+R007 Adobe-DPS-Extension:Reset
+R008 Adobe-DPS-Extension:NotifyContext
+R009 Adobe-DPS-Extension:CreateContextFromID
+R010 Adobe-DPS-Extension:XIDFromContext
+R011 Adobe-DPS-Extension:ContextFromXID
+R012 Adobe-DPS-Extension:SetStatusMask
+R013 Adobe-DPS-Extension:CreateSecureContext
+R014 Adobe-DPS-Extension:NotifyWhenReady
+R000 Apple-DRI:QueryVersion
+R001 Apple-DRI:QueryDirectRenderingCapable
+R002 Apple-DRI:CreateSurface
+R003 Apple-DRI:DestroySurface
+R004 Apple-DRI:AuthConnection
+V000 Apple-DRI:ObsoleteEvent1
+V001 Apple-DRI:ObsoleteEvent2
+V002 Apple-DRI:ObsoleteEvent3
+V003 Apple-DRI:SurfaceNotify
+E000 Apple-DRI:ClientNotLocal
+E001 Apple-DRI:OperationNotSupported
+R000 Apple-WM:QueryVersion
+R001 Apple-WM:FrameGetRect
+R002 Apple-WM:FrameHitTest
+R003 Apple-WM:FrameDraw
+R004 Apple-WM:DisableUpdate
+R005 Apple-WM:ReenableUpdate
+R006 Apple-WM:SelectInput
+R007 Apple-WM:SetWindowMenuCheck
+R008 Apple-WM:SetFrontProcess
+R009 Apple-WM:SetWindowLevel
+R010 Apple-WM:SetCanQuit
+R011 Apple-WM:SetWindowMenu
+V000 Apple-WM:ControllerNotify
+V001 Apple-WM:ActivationNotify
+V002 Apple-WM:PasteboardNotify
+E000 Apple-WM:ClientNotLocal
+E001 Apple-WM:OperationNotSupported
+R000 BIG-REQUESTS:Enable
+R000 Composite:CompositeQueryVersion
+R001 Composite:CompositeRedirectWindow
+R002 Composite:CompositeRedirectSubwindows
+R003 Composite:CompositeUnredirectWindow
+R004 Composite:CompositeUnredirectSubwindows
+R005 Composite:CompositeCreateRegionFromBorderClip
+R006 Composite:CompositeNameWindowPixmap
+R007 Composite:CompositeGetOverlayWindow
+R008 Composite:CompositeReleaseOverlayWindow
+R000 DAMAGE:QueryVersion
+R001 DAMAGE:Create
+R002 DAMAGE:Destroy
+R003 DAMAGE:Subtract
+R004 DAMAGE:Add
+V000 DAMAGE:Notify
+E000 DAMAGE:BadDamage
+R000 DEC-XTRAP:Reset
+R001 DEC-XTRAP:GetAvailable
+R002 DEC-XTRAP:Config
+R003 DEC-XTRAP:StartTrap
+R004 DEC-XTRAP:StopTrap
+R005 DEC-XTRAP:GetCurrent
+R006 DEC-XTRAP:GetStatistics
+R007 DEC-XTRAP:SimulateXEvent
+R008 DEC-XTRAP:GetVersion
+R009 DEC-XTRAP:GetLastInpTime
+V000 DEC-XTRAP:Event
+E002 DEC-XTRAP:BadIO
+E004 DEC-XTRAP:BadStatistics
+E005 DEC-XTRAP:BadDevices
+E007 DEC-XTRAP:BadScreen
+E008 DEC-XTRAP:BadSwapReq
+R000 DMX:DMXQueryVersion
+R001 DMX:DMXGetScreenCount
+R002 DMX:DMXGetScreenInfoDEPRECATED
+R003 DMX:DMXGetWindowAttributes
+R004 DMX:DMXGetInputCount
+R005 DMX:DMXGetInputAttributes
+R006 DMX:DMXForceWindowCreationDEPRECATED
+R007 DMX:DMXReconfigureScreenDEPRECATED
+R008 DMX:DMXSync
+R009 DMX:DMXForceWindowCreation
+R010 DMX:DMXGetScreenAttributes
+R011 DMX:DMXChangeScreensAttributes
+R012 DMX:DMXAddScreen
+R013 DMX:DMXRemoveScreen
+R014 DMX:DMXGetDesktopAttributes
+R015 DMX:DMXChangeDesktopAttributes
+R016 DMX:DMXAddInput
+R017 DMX:DMXRemoveInput
+R000 DOUBLE-BUFFER:GetVersion
+R001 DOUBLE-BUFFER:AllocateBackBufferName
+R002 DOUBLE-BUFFER:DeallocateBackBufferName
+R003 DOUBLE-BUFFER:SwapBuffers
+R004 DOUBLE-BUFFER:BeginIdiom
+R005 DOUBLE-BUFFER:EndIdiom
+R006 DOUBLE-BUFFER:GetVisualInfo
+R007 DOUBLE-BUFFER:GetBackBufferAttributes
+E000 DOUBLE-BUFFER:BadBuffer
+R000 DPMS:GetVersion
+R001 DPMS:Capable
+R002 DPMS:GetTimeouts
+R003 DPMS:SetTimeouts
+R004 DPMS:Enable
+R005 DPMS:Disable
+R006 DPMS:ForceLevel
+R007 DPMS:Info
+R000 Extended-Visual-Information:QueryVersion
+R001 Extended-Visual-Information:GetVisualInfo
+R000 FontCache:QueryVersion
+R001 FontCache:GetCacheSettings
+R002 FontCache:ChangeCacheSettings
+R003 FontCache:GetCacheStatistics
+E000 FontCache:BadProtocol
+E001 FontCache:CannotAllocMemory
+R001 GLX:
+R002 GLX:Large
+R003 GLX:CreateContext
+R004 GLX:DestroyContext
+R005 GLX:MakeCurrent
+R006 GLX:IsDirect
+R007 GLX:QueryVersion
+R008 GLX:WaitGL
+R009 GLX:WaitX
+R010 GLX:CopyContext
+R011 GLX:SwapBuffers
+R012 GLX:UseXFont
+R013 GLX:CreateGLXPixmap
+R014 GLX:GetVisualConfigs
+R015 GLX:DestroyGLXPixmap
+R016 GLX:VendorPrivate
+R017 GLX:VendorPrivateWithReply
+R018 GLX:QueryExtensionsString
+R019 GLX:QueryServerString
+R020 GLX:ClientInfo
+R101 GLX:NewList
+R102 GLX:EndList
+R103 GLX:DeleteLists
+R104 GLX:GenLists
+R105 GLX:FeedbackBuffer
+R106 GLX:SelectBuffer
+R107 GLX:Mode
+R108 GLX:Finish
+R109 GLX:PixelStoref
+R110 GLX:PixelStorei
+R111 GLX:ReadPixels
+R112 GLX:GetBooleanv
+R113 GLX:GetClipPlane
+R114 GLX:GetDoublev
+R115 GLX:GetError
+R116 GLX:GetFloatv
+R117 GLX:GetIntegerv
+R118 GLX:GetLightfv
+R119 GLX:GetLightiv
+R120 GLX:GetMapdv
+R121 GLX:GetMapfv
+R122 GLX:GetMapiv
+R123 GLX:GetMaterialfv
+R124 GLX:GetMaterialiv
+R125 GLX:GetPixelfv
+R126 GLX:GetPixelMapuiv
+R127 GLX:GetPixelMapusv
+R128 GLX:GetPolygonStipple
+R129 GLX:GetString
+R130 GLX:GetTexEnvfv
+R131 GLX:GetTexEnviv
+R132 GLX:GetTexGendv
+R133 GLX:GetTexGenfv
+R134 GLX:GetTexGeniv
+R135 GLX:GetTexImage
+R136 GLX:GetTexParameterfv
+R137 GLX:GetTexParameteriv
+R138 GLX:GetTexLevelParameterfv
+R139 GLX:GetTexLevelParameteriv
+R140 GLX:IsEnabled
+R141 GLX:IsList
+R142 GLX:Flush
+E000 GLX:BadContext
+E001 GLX:BadContextState
+E002 GLX:BadDrawable
+E003 GLX:BadPixmap
+E004 GLX:BadContextTag
+E005 GLX:BadCurrentWindow
+E006 GLX:BadRenderRequest
+E007 GLX:BadLargeRequest
+E008 GLX:UnsupportedPrivateRequest
+R000 LBX:QueryVersion
+R001 LBX:StartProxy
+R002 LBX:StopProxy
+R003 LBX:Switch
+R004 LBX:NewClient
+R005 LBX:CloseClient
+R006 LBX:ModifySequence
+R007 LBX:AllowMotion
+R008 LBX:IncrementPixel
+R009 LBX:Delta
+R010 LBX:GetModifierMapping
+R011 LBX:QueryTag
+R012 LBX:InvalidateTag
+R013 LBX:PolyPoint
+R014 LBX:PolyLine
+R015 LBX:PolySegment
+R016 LBX:PolyRectangle
+R017 LBX:PolyArc
+R018 LBX:FillPoly
+R019 LBX:PolyFillRectangle
+R020 LBX:PolyFillArc
+R021 LBX:GetKeyboardMapping
+R022 LBX:QueryFont
+R023 LBX:ChangeProperty
+R024 LBX:GetProperty
+R025 LBX:TagData
+R026 LBX:CopyArea
+R027 LBX:CopyPlane
+R028 LBX:PolyText8
+R029 LBX:PolyText16
+R030 LBX:ImageText8
+R031 LBX:ImageText16
+R032 LBX:QueryExtension
+R033 LBX:PutImage
+R034 LBX:GetImage
+R035 LBX:BeginLargeRequest
+R036 LBX:LargeRequestData
+R037 LBX:EndLargeRequest
+R038 LBX:InternAtoms
+R039 LBX:GetWinAttrAndGeom
+R040 LBX:GrabCmap
+R041 LBX:ReleaseCmap
+R042 LBX:AllocColor
+R043 LBX:Sync
+E000 LBX:BadLbxClient
+R000 MIT-SCREEN-SAVER:QueryVersion
+R001 MIT-SCREEN-SAVER:QueryInfo
+R002 MIT-SCREEN-SAVER:SelectInput
+R003 MIT-SCREEN-SAVER:SetAttributes
+R004 MIT-SCREEN-SAVER:UnsetAttributes
+R005 MIT-SCREEN-SAVER:Suspend
+V000 MIT-SCREEN-SAVER:Notify
+R000 MIT-SHM:QueryVersion
+R001 MIT-SHM:Attach
+R002 MIT-SHM:Detach
+R003 MIT-SHM:PutImage
+R004 MIT-SHM:GetImage
+R005 MIT-SHM:CreatePixmap
+V000 MIT-SHM:Completion
+E000 MIT-SHM:BadShmSeg
+R000 MIT-SUNDRY-NONSTANDARD:SetBugMode
+R001 MIT-SUNDRY-NONSTANDARD:GetBugMode
+R000 Multi-Buffering:GetBufferVersion
+R001 Multi-Buffering:CreateImageBuffers
+R002 Multi-Buffering:DestroyImageBuffers
+R003 Multi-Buffering:DisplayImageBuffers
+R004 Multi-Buffering:SetMBufferAttributes
+R005 Multi-Buffering:GetMBufferAttributes
+R006 Multi-Buffering:SetBufferAttributes
+R007 Multi-Buffering:GetBufferAttributes
+R008 Multi-Buffering:GetBufferInfo
+R009 Multi-Buffering:CreateStereoWindow
+R010 Multi-Buffering:ClearImageBufferArea
+V000 Multi-Buffering:ClobberNotify
+V001 Multi-Buffering:UpdateNotify
+E000 Multi-Buffering:BadBuffer
+R000 RANDR:QueryVersion
+R001 RANDR:OldGetScreenInfo
+R002 RANDR:SetScreenConfig
+R003 RANDR:OldScreenChangeSelectInput
+R004 RANDR:SelectInput
+R005 RANDR:GetScreenInfo
+R006 RANDR:GetScreenSizeRange
+R007 RANDR:SetScreenSize
+R008 RANDR:GetScreenResources
+R009 RANDR:GetOutputInfo
+R010 RANDR:ListOutputProperties
+R011 RANDR:QueryOutputProperty
+R012 RANDR:ConfigureOutputProperty
+R013 RANDR:ChangeOutputProperty
+R014 RANDR:DeleteOutputProperty
+R015 RANDR:GetOutputProperty
+R016 RANDR:CreateMode
+R017 RANDR:DestroyMode
+R018 RANDR:AddOutputMode
+R019 RANDR:DeleteOutputMode
+R020 RANDR:GetCrtcInfo
+R021 RANDR:SetCrtcConfig
+R022 RANDR:GetCrtcGammaSize
+R023 RANDR:GetCrtcGamma
+R024 RANDR:SetCrtcGamma
+V000 RANDR:ScreenChangeNotify
+V001 RANDR:Notify
+E000 RANDR:BadRROutput
+E001 RANDR:BadRRCrtc
+E002 RANDR:BadRRMode
+R000 RECORD:QueryVersion
+R001 RECORD:CreateContext
+R002 RECORD:RegisterClients
+R003 RECORD:UnregisterClients
+R004 RECORD:GetContext
+R005 RECORD:EnableContext
+R006 RECORD:DisableContext
+R007 RECORD:FreeContext
+E000 RECORD:BadContext
+R000 RENDER:QueryVersion
+R001 RENDER:QueryPictFormats
+R002 RENDER:QueryPictIndexValues
+R003 RENDER:QueryDithers
+R004 RENDER:CreatePicture
+R005 RENDER:ChangePicture
+R006 RENDER:SetPictureClipRectangles
+R007 RENDER:FreePicture
+R008 RENDER:Composite
+R009 RENDER:Scale
+R010 RENDER:Trapezoids
+R011 RENDER:Triangles
+R012 RENDER:TriStrip
+R013 RENDER:TriFan
+R014 RENDER:ColorTrapezoids
+R015 RENDER:ColorTriangles
+R016 RENDER:Transform
+R017 RENDER:CreateGlyphSet
+R018 RENDER:ReferenceGlyphSet
+R019 RENDER:FreeGlyphSet
+R020 RENDER:AddGlyphs
+R021 RENDER:AddGlyphsFromPicture
+R022 RENDER:FreeGlyphs
+R023 RENDER:CompositeGlyphs8
+R024 RENDER:CompositeGlyphs16
+R025 RENDER:CompositeGlyphs32
+R026 RENDER:FillRectangles
+R027 RENDER:CreateCursor
+R028 RENDER:SetPictureTransform
+R029 RENDER:QueryFilters
+R030 RENDER:SetPictureFilter
+R031 RENDER:CreateAnimCursor
+R032 RENDER:AddTraps
+R033 RENDER:CreateSolidFill
+R034 RENDER:CreateLinearGradient
+R035 RENDER:CreateRadialGradient
+R036 RENDER:CreateConicalGradient
+E000 RENDER:BadPictFormat
+E001 RENDER:BadPicture
+E002 RENDER:BadPictOp
+E003 RENDER:BadGlyphSet
+E004 RENDER:BadGlyph
+R000 SECURITY:QueryVersion
+R001 SECURITY:GenerateAuthorization
+R002 SECURITY:RevokeAuthorization
+V000 SECURITY:AuthorizationRevoked
+E000 SECURITY:BadAuthorization
+E001 SECURITY:BadAuthorizationProtocol
+R000 SELinux:SELinuxQueryVersion
+R001 SELinux:SELinuxSetSelectionManager
+R002 SELinux:SELinuxGetSelectionManager
+R003 SELinux:SELinuxSetDeviceContext
+R004 SELinux:SELinuxGetDeviceContext
+R005 SELinux:SELinuxSetPropertyCreateContext
+R006 SELinux:SELinuxGetPropertyCreateContext
+R007 SELinux:SELinuxGetPropertyContext
+R008 SELinux:SELinuxSetWindowCreateContext
+R009 SELinux:SELinuxGetWindowCreateContext
+R010 SELinux:SELinuxGetWindowContext
+R000 SHAPE:QueryVersion
+R001 SHAPE:Rectangles
+R002 SHAPE:Mask
+R003 SHAPE:Combine
+R004 SHAPE:Offset
+R005 SHAPE:QueryExtents
+R006 SHAPE:SelectInput
+R007 SHAPE:InputSelected
+R008 SHAPE:GetRectangles
+V000 SHAPE:Notify
+R000 SYNC:Initialize
+R001 SYNC:ListSystemCounters
+R002 SYNC:CreateCounter
+R003 SYNC:SetCounter
+R004 SYNC:ChangeCounter
+R005 SYNC:QueryCounter
+R006 SYNC:DestroyCounter
+R007 SYNC:Await
+R008 SYNC:CreateAlarm
+R009 SYNC:ChangeAlarm
+R010 SYNC:QueryAlarm
+R011 SYNC:DestroyAlarm
+R012 SYNC:SetPriority
+R013 SYNC:GetPriority
+V000 SYNC:CounterNotify
+V001 SYNC:AlarmNotify
+E000 SYNC:BadCounter
+E001 SYNC:BadAlarm
+R000 TOG-CUP:QueryVersion
+R001 TOG-CUP:GetReservedColormapEntries
+R002 TOG-CUP:StoreColors
+R000 Windows-WM:QueryVersion
+R001 Windows-WM:FrameGetRect
+R002 Windows-WM:FrameDraw
+R003 Windows-WM:FrameSetTitle
+R004 Windows-WM:DisableUpdate
+R005 Windows-WM:ReenableUpdate
+R006 Windows-WM:SelectInput
+R007 Windows-WM:SetFrontProcess
+V000 Windows-WM:ControllerNotify
+V001 Windows-WM:ActivationNotify
+E000 Windows-WM:ClientNotLocal
+E001 Windows-WM:OperationNotSupported
+R000 X-Resource:QueryVersion
+R001 X-Resource:QueryClients
+R002 X-Resource:QueryClientResources
+R003 X-Resource:QueryClientPixmapBytes
+R001 X11:CreateWindow
+R002 X11:ChangeWindowAttributes
+R003 X11:GetWindowAttributes
+R004 X11:DestroyWindow
+R005 X11:DestroySubwindows
+R006 X11:ChangeSaveSet
+R007 X11:ReparentWindow
+R008 X11:MapWindow
+R009 X11:MapSubwindows
+R010 X11:UnmapWindow
+R011 X11:UnmapSubwindows
+R012 X11:ConfigureWindow
+R013 X11:CirculateWindow
+R014 X11:GetGeometry
+R015 X11:QueryTree
+R016 X11:InternAtom
+R017 X11:GetAtomName
+R018 X11:ChangeProperty
+R019 X11:DeleteProperty
+R020 X11:GetProperty
+R021 X11:ListProperties
+R022 X11:SetSelectionOwner
+R023 X11:GetSelectionOwner
+R024 X11:ConvertSelection
+R025 X11:SendEvent
+R026 X11:GrabPointer
+R027 X11:UngrabPointer
+R028 X11:GrabButton
+R029 X11:UngrabButton
+R030 X11:ChangeActivePointerGrab
+R031 X11:GrabKeyboard
+R032 X11:UngrabKeyboard
+R033 X11:GrabKey
+R034 X11:UngrabKey
+R035 X11:AllowEvents
+R036 X11:GrabServer
+R037 X11:UngrabServer
+R038 X11:QueryPointer
+R039 X11:GetMotionEvents
+R040 X11:TranslateCoords
+R041 X11:WarpPointer
+R042 X11:SetInputFocus
+R043 X11:GetInputFocus
+R044 X11:QueryKeymap
+R045 X11:OpenFont
+R046 X11:CloseFont
+R047 X11:QueryFont
+R048 X11:QueryTextExtents
+R049 X11:ListFonts
+R050 X11:ListFontsWithInfo
+R051 X11:SetFontPath
+R052 X11:GetFontPath
+R053 X11:CreatePixmap
+R054 X11:FreePixmap
+R055 X11:CreateGC
+R056 X11:ChangeGC
+R057 X11:CopyGC
+R058 X11:SetDashes
+R059 X11:SetClipRectangles
+R060 X11:FreeGC
+R061 X11:ClearArea
+R062 X11:CopyArea
+R063 X11:CopyPlane
+R064 X11:PolyPoint
+R065 X11:PolyLine
+R066 X11:PolySegment
+R067 X11:PolyRectangle
+R068 X11:PolyArc
+R069 X11:FillPoly
+R070 X11:PolyFillRectangle
+R071 X11:PolyFillArc
+R072 X11:PutImage
+R073 X11:GetImage
+R074 X11:PolyText8
+R075 X11:PolyText16
+R076 X11:ImageText8
+R077 X11:ImageText16
+R078 X11:CreateColormap
+R079 X11:FreeColormap
+R080 X11:CopyColormapAndFree
+R081 X11:InstallColormap
+R082 X11:UninstallColormap
+R083 X11:ListInstalledColormaps
+R084 X11:AllocColor
+R085 X11:AllocNamedColor
+R086 X11:AllocColorCells
+R087 X11:AllocColorPlanes
+R088 X11:FreeColors
+R089 X11:StoreColors
+R090 X11:StoreNamedColor
+R091 X11:QueryColors
+R092 X11:LookupColor
+R093 X11:CreateCursor
+R094 X11:CreateGlyphCursor
+R095 X11:FreeCursor
+R096 X11:RecolorCursor
+R097 X11:QueryBestSize
+R098 X11:QueryExtension
+R099 X11:ListExtensions
+R100 X11:ChangeKeyboardMapping
+R101 X11:GetKeyboardMapping
+R102 X11:ChangeKeyboardControl
+R103 X11:GetKeyboardControl
+R104 X11:Bell
+R105 X11:ChangePointerControl
+R106 X11:GetPointerControl
+R107 X11:SetScreenSaver
+R108 X11:GetScreenSaver
+R109 X11:ChangeHosts
+R110 X11:ListHosts
+R111 X11:SetAccessControl
+R112 X11:SetCloseDownMode
+R113 X11:KillClient
+R114 X11:RotateProperties
+R115 X11:ForceScreenSaver
+R116 X11:SetPointerMapping
+R117 X11:GetPointerMapping
+R118 X11:SetModifierMapping
+R119 X11:GetModifierMapping
+R127 X11:NoOperation
+V000 X11:X_Error
+V001 X11:X_Reply
+V002 X11:KeyPress
+V003 X11:KeyRelease
+V004 X11:ButtonPress
+V005 X11:ButtonRelease
+V006 X11:MotionNotify
+V007 X11:EnterNotify
+V008 X11:LeaveNotify
+V009 X11:FocusIn
+V010 X11:FocusOut
+V011 X11:KeymapNotify
+V012 X11:Expose
+V013 X11:GraphicsExpose
+V014 X11:NoExpose
+V015 X11:VisibilityNotify
+V016 X11:CreateNotify
+V017 X11:DestroyNotify
+V018 X11:UnmapNotify
+V019 X11:MapNotify
+V020 X11:MapRequest
+V021 X11:ReparentNotify
+V022 X11:ConfigureNotify
+V023 X11:ConfigureRequest
+V024 X11:GravityNotify
+V025 X11:ResizeRequest
+V026 X11:CirculateNotify
+V027 X11:CirculateRequest
+V028 X11:PropertyNotify
+V029 X11:SelectionClear
+V030 X11:SelectionRequest
+V031 X11:SelectionNotify
+V032 X11:ColormapNotify
+V033 X11:ClientMessage
+V034 X11:MappingNotify
+E000 X11:Success
+E001 X11:BadRequest
+E002 X11:BadValue
+E003 X11:BadWindow
+E004 X11:BadPixmap
+E005 X11:BadAtom
+E006 X11:BadCursor
+E007 X11:BadFont
+E008 X11:BadMatch
+E009 X11:BadDrawable
+E010 X11:BadAccess
+E011 X11:BadAlloc
+E012 X11:BadColor
+E013 X11:BadGC
+E014 X11:BadIDChoice
+E015 X11:BadName
+E016 X11:BadLength
+E017 X11:BadImplementation
+R001 X3D-PEX:GetExtensionInfo
+R002 X3D-PEX:GetEnumeratedTypeInfo
+R003 X3D-PEX:GetImpDepConstants
+R004 X3D-PEX:CreateLookupTable
+R005 X3D-PEX:CopyLookupTable
+R006 X3D-PEX:FreeLookupTable
+R007 X3D-PEX:GetTableInfo
+R008 X3D-PEX:GetPredefinedEntries
+R009 X3D-PEX:GetDefinedIndices
+R010 X3D-PEX:GetTableEntry
+R011 X3D-PEX:GetTableEntries
+R012 X3D-PEX:SetTableEntries
+R013 X3D-PEX:DeleteTableEntries
+R014 X3D-PEX:CreatePipelineContext
+R015 X3D-PEX:CopyPipelineContext
+R016 X3D-PEX:FreePipelineContext
+R017 X3D-PEX:GetPipelineContext
+R018 X3D-PEX:ChangePipelineContext
+R019 X3D-PEX:CreateRenderer
+R020 X3D-PEX:FreeRenderer
+R021 X3D-PEX:ChangeRenderer
+R022 X3D-PEX:GetRendererAttributes
+R023 X3D-PEX:GetRendererDynamics
+R024 X3D-PEX:BeginRendering
+R025 X3D-PEX:EndRendering
+R026 X3D-PEX:BeginStructure
+R027 X3D-PEX:EndStructure
+R028 X3D-PEX:OutputCommands
+R029 X3D-PEX:Network
+R030 X3D-PEX:CreateStructure
+R031 X3D-PEX:CopyStructure
+R032 X3D-PEX:DestroyStructures
+R033 X3D-PEX:GetStructureInfo
+R034 X3D-PEX:GetElementInfo
+R035 X3D-PEX:GetStructuresInNetwork
+R036 X3D-PEX:GetAncestors
+R037 X3D-PEX:GetDescendants
+R038 X3D-PEX:FetchElements
+R039 X3D-PEX:SetEditingMode
+R040 X3D-PEX:SetElementPointer
+R041 X3D-PEX:SetElementPointerAtLabel
+R042 X3D-PEX:ElementSearch
+R043 X3D-PEX:StoreElements
+R044 X3D-PEX:DeleteElements
+R045 X3D-PEX:DeleteElementsToLabel
+R046 X3D-PEX:DeleteBetweenLabels
+R047 X3D-PEX:CopyElements
+R048 X3D-PEX:ChangeStructureRefs
+R049 X3D-PEX:CreateNameSet
+R050 X3D-PEX:CopyNameSet
+R051 X3D-PEX:FreeNameSet
+R052 X3D-PEX:GetNameSet
+R053 X3D-PEX:ChangeNameSet
+R054 X3D-PEX:CreateSearchContext
+R055 X3D-PEX:CopySearchContext
+R056 X3D-PEX:FreeSearchContext
+R057 X3D-PEX:GetSearchContext
+R058 X3D-PEX:ChangeSearchContext
+R059 X3D-PEX:SearchNetwork
+R060 X3D-PEX:CreatePhigsWks
+R061 X3D-PEX:FreePhigsWks
+R062 X3D-PEX:GetWksInfo
+R063 X3D-PEX:GetDynamics
+R064 X3D-PEX:GetViewRep
+R065 X3D-PEX:RedrawAllStructures
+R066 X3D-PEX:UpdateWorkstation
+R067 X3D-PEX:RedrawClipRegion
+R068 X3D-PEX:ExecuteDeferredActions
+R069 X3D-PEX:SetViewPriority
+R070 X3D-PEX:SetDisplayUpdateMode
+R071 X3D-PEX:MapDCtoWC
+R072 X3D-PEX:MapWCtoDC
+R073 X3D-PEX:SetViewRep
+R074 X3D-PEX:SetWksWindow
+R075 X3D-PEX:SetWksViewport
+R076 X3D-PEX:SetHlhsrMode
+R077 X3D-PEX:SetWksBufferMode
+R078 X3D-PEX:PostStructure
+R079 X3D-PEX:UnpostStructure
+R080 X3D-PEX:UnpostAllStructures
+R081 X3D-PEX:GetWksPostings
+R082 X3D-PEX:GetPickDevice
+R083 X3D-PEX:ChangePickDevice
+R084 X3D-PEX:CreatePickMeasure
+R085 X3D-PEX:FreePickMeasure
+R086 X3D-PEX:GetPickMeasure
+R087 X3D-PEX:UpdatePickMeasure
+R088 X3D-PEX:OpenFont
+R089 X3D-PEX:CloseFont
+R090 X3D-PEX:QueryFont
+R091 X3D-PEX:ListFonts
+R092 X3D-PEX:ListFontsWithInfo
+R093 X3D-PEX:QueryTextExtents
+R094 X3D-PEX:MatchRenderingTargets
+R095 X3D-PEX:Escape
+R096 X3D-PEX:EscapeWithReply
+R097 X3D-PEX:Elements
+R098 X3D-PEX:AccumulateState
+R099 X3D-PEX:BeginPickOne
+R100 X3D-PEX:EndPickOne
+R101 X3D-PEX:PickOne
+R102 X3D-PEX:BeginPickAll
+R103 X3D-PEX:EndPickAll
+R104 X3D-PEX:PickAll
+E000 X3D-PEX:ColorTypeError
+E001 X3D-PEX:erStateError
+E002 X3D-PEX:FloatingPointFormatError
+E003 X3D-PEX:LabelError
+E004 X3D-PEX:LookupTableError
+E005 X3D-PEX:NameSetError
+E006 X3D-PEX:PathError
+E007 X3D-PEX:FontError
+E008 X3D-PEX:PhigsWksError
+E009 X3D-PEX:PickMeasureError
+E010 X3D-PEX:PipelineContextError
+E011 X3D-PEX:erError
+E012 X3D-PEX:SearchContextError
+E013 X3D-PEX:StructureError
+E014 X3D-PEX:OutputCommandError
+R000 XC-APPGROUP:QueryVersion
+R001 XC-APPGROUP:Create
+R002 XC-APPGROUP:Destroy
+R003 XC-APPGROUP:GetAttr
+R004 XC-APPGROUP:Query
+R005 XC-APPGROUP:CreateAssoc
+R006 XC-APPGROUP:DestroyAssoc
+E000 XC-APPGROUP:BadAppGroup
+R000 XC-MISC:GetVersion
+R001 XC-MISC:GetXIDRange
+R002 XC-MISC:GetXIDList
+R000 XEVIE:QueryVersion
+R001 XEVIE:Start
+R002 XEVIE:End
+R003 XEVIE:Send
+R004 XEVIE:SelectInput
+R000 XFIXES:QueryVersion
+R001 XFIXES:ChangeSaveSet
+R002 XFIXES:SelectSelectionInput
+R003 XFIXES:SelectCursorInput
+R004 XFIXES:GetCursorImage
+R005 XFIXES:CreateRegion
+R006 XFIXES:CreateRegionFromBitmap
+R007 XFIXES:CreateRegionFromWindow
+R008 XFIXES:CreateRegionFromGC
+R009 XFIXES:CreateRegionFromPicture
+R010 XFIXES:DestroyRegion
+R011 XFIXES:SetRegion
+R012 XFIXES:CopyRegion
+R013 XFIXES:UnionRegion
+R014 XFIXES:IntersectRegion
+R015 XFIXES:SubtractRegion
+R016 XFIXES:InvertRegion
+R017 XFIXES:TranslateRegion
+R018 XFIXES:RegionExtents
+R019 XFIXES:FetchRegion
+R020 XFIXES:SetGCClipRegion
+R021 XFIXES:SetWindowShapeRegion
+R022 XFIXES:SetPictureClipRegion
+R023 XFIXES:SetCursorName
+R024 XFIXES:GetCursorName
+R025 XFIXES:GetCursorImageAndName
+R026 XFIXES:ChangeCursor
+R027 XFIXES:ChangeCursorByName
+R028 XFIXES:ExpandRegion
+R029 XFIXES:HideCursor
+R030 XFIXES:ShowCursor
+V000 XFIXES:SelectionNotify
+V001 XFIXES:CursorNotify
+E000 XFIXES:BadRegion
+R000 XFree86-Bigfont:QueryVersion
+R001 XFree86-Bigfont:QueryFont
+R000 XFree86-DGA:QueryVersion
+R001 XFree86-DGA:GetVideoLL
+R002 XFree86-DGA:DirectVideo
+R003 XFree86-DGA:GetViewPortSize
+R004 XFree86-DGA:SetViewPort
+R005 XFree86-DGA:GetVidPage
+R006 XFree86-DGA:SetVidPage
+R007 XFree86-DGA:InstallColormap
+R008 XFree86-DGA:QueryDirectVideo
+R009 XFree86-DGA:ViewPortChanged
+R010 XFree86-DGA:Obsolete1
+R011 XFree86-DGA:Obsolete2
+R012 XFree86-DGA:QueryModes
+R013 XFree86-DGA:SetMode
+R014 XFree86-DGA:SetViewport
+R015 XFree86-DGA:InstallColormap
+R016 XFree86-DGA:SelectInput
+R017 XFree86-DGA:FillRectangle
+R018 XFree86-DGA:CopyArea
+R019 XFree86-DGA:CopyTransparentArea
+R020 XFree86-DGA:GetViewportStatus
+R021 XFree86-DGA:Sync
+R022 XFree86-DGA:OpenFramebuffer
+R023 XFree86-DGA:CloseFramebuffer
+R024 XFree86-DGA:SetClientVersion
+R025 XFree86-DGA:ChangePixmapMode
+R026 XFree86-DGA:CreateColormap
+E000 XFree86-DGA:ClientNotLocal
+E001 XFree86-DGA:NoDirectVideoMode
+E002 XFree86-DGA:ScreenNotActive
+E003 XFree86-DGA:DirectNotActivated
+E004 XFree86-DGA:OperationNotSupported
+R000 XFree86-DRI:QueryVersion
+R001 XFree86-DRI:QueryDirectRenderingCapable
+R002 XFree86-DRI:OpenConnection
+R003 XFree86-DRI:CloseConnection
+R004 XFree86-DRI:GetClientDriverName
+R005 XFree86-DRI:CreateContext
+R006 XFree86-DRI:DestroyContext
+R007 XFree86-DRI:CreateDrawable
+R008 XFree86-DRI:DestroyDrawable
+R009 XFree86-DRI:GetDrawableInfo
+R010 XFree86-DRI:GetDeviceInfo
+R011 XFree86-DRI:AuthConnection
+R012 XFree86-DRI:OpenFullScreen
+R013 XFree86-DRI:CloseFullScreen
+E000 XFree86-DRI:ClientNotLocal
+E001 XFree86-DRI:OperationNotSupported
+R000 XFree86-Misc:QueryVersion
+R001 XFree86-Misc:GetSaver
+R002 XFree86-Misc:SetSaver
+R003 XFree86-Misc:GetMouseSettings
+R004 XFree86-Misc:GetKbdSettings
+R005 XFree86-Misc:SetMouseSettings
+R006 XFree86-Misc:SetKbdSettings
+R007 XFree86-Misc:SetGrabKeysState
+R008 XFree86-Misc:SetClientVersion
+R009 XFree86-Misc:GetFilePaths
+R010 XFree86-Misc:PassMessage
+E000 XFree86-Misc:BadMouseProtocol
+E001 XFree86-Misc:BadMouseBaudRate
+E002 XFree86-Misc:BadMouseFlags
+E003 XFree86-Misc:BadMouseCombo
+E004 XFree86-Misc:BadKbdType
+E005 XFree86-Misc:ModInDevDisabled
+E006 XFree86-Misc:ModInDevClientNotLocal
+E007 XFree86-Misc:NoModule
+R000 XFree86-VidModeExtension:QueryVersion
+R001 XFree86-VidModeExtension:GetModeLine
+R002 XFree86-VidModeExtension:ModModeLine
+R003 XFree86-VidModeExtension:SwitchMode
+R004 XFree86-VidModeExtension:GetMonitor
+R005 XFree86-VidModeExtension:LockModeSwitch
+R006 XFree86-VidModeExtension:GetAllModeLines
+R007 XFree86-VidModeExtension:AddModeLine
+R008 XFree86-VidModeExtension:DeleteModeLine
+R009 XFree86-VidModeExtension:ValidateModeLine
+R010 XFree86-VidModeExtension:SwitchToMode
+R011 XFree86-VidModeExtension:GetViewPort
+R012 XFree86-VidModeExtension:SetViewPort
+R013 XFree86-VidModeExtension:GetDotClocks
+R014 XFree86-VidModeExtension:SetClientVersion
+R015 XFree86-VidModeExtension:SetGamma
+R016 XFree86-VidModeExtension:GetGamma
+R017 XFree86-VidModeExtension:GetGammaRamp
+R018 XFree86-VidModeExtension:SetGammaRamp
+R019 XFree86-VidModeExtension:GetGammaRampSize
+R020 XFree86-VidModeExtension:GetPermissions
+V000 XFree86-VidModeExtension:Notify
+E000 XFree86-VidModeExtension:BadClock
+E001 XFree86-VidModeExtension:BadHTimings
+E002 XFree86-VidModeExtension:BadVTimings
+E003 XFree86-VidModeExtension:ModeUnsuitable
+E004 XFree86-VidModeExtension:ExtensionDisabled
+E005 XFree86-VidModeExtension:ClientNotLocal
+E006 XFree86-VidModeExtension:ZoomLocked
+R001 XIE:QueryImageExtension
+R002 XIE:QueryTechniques
+R003 XIE:CreateColorList
+R004 XIE:DestroyColorList
+R005 XIE:PurgeColorList
+R006 XIE:QueryColorList
+R007 XIE:CreateLUT
+R008 XIE:DestroyLUT
+R009 XIE:CreatePhotomap
+R010 XIE:DestroyPhotomap
+R011 XIE:QueryPhotomap
+R012 XIE:CreateROI
+R013 XIE:DestroyROI
+R014 XIE:CreatePhotospace
+R015 XIE:DestroyPhotospace
+R016 XIE:ExecuteImmediate
+R017 XIE:CreatePhotoflo
+R018 XIE:DestroyPhotoflo
+R019 XIE:ExecutePhotoflo
+R020 XIE:ModifyPhotoflo
+R021 XIE:RedefinePhotoflo
+R022 XIE:PutClientData
+R023 XIE:GetClientData
+R024 XIE:QueryPhotoflo
+R025 XIE:Await
+R026 XIE:Abort
+E000 XIE:ColorListError
+E001 XIE:LUTError
+E002 XIE:PhotofloError
+E003 XIE:PhotomapError
+E004 XIE:PhotospaceError
+E005 XIE:ROIError
+E006 XIE:FloError
+R000 XINERAMA:QueryVersion
+R001 XINERAMA:GetState
+R002 XINERAMA:GetScreenCount
+R003 XINERAMA:GetScreenSize
+R004 XINERAMA:IsActive
+R005 XINERAMA:QueryScreens
+R001 XInputExtension:GetExtensionVersion
+R002 XInputExtension:ListInputDevices
+R003 XInputExtension:OpenDevice
+R004 XInputExtension:CloseDevice
+R005 XInputExtension:SetDeviceMode
+R006 XInputExtension:SelectExtensionEvent
+R007 XInputExtension:GetSelectedExtensionEvents
+R008 XInputExtension:ChangeDeviceDontPropagateList
+R009 XInputExtension:GetDeviceDontPropagageList
+R010 XInputExtension:GetDeviceMotionEvents
+R011 XInputExtension:ChangeKeyboardDevice
+R012 XInputExtension:ChangePointerDevice
+R013 XInputExtension:GrabDevice
+R014 XInputExtension:UngrabDevice
+R015 XInputExtension:GrabDeviceKey
+R016 XInputExtension:UngrabDeviceKey
+R017 XInputExtension:GrabDeviceButton
+R018 XInputExtension:UngrabDeviceButton
+R019 XInputExtension:AllowDeviceEvents
+R020 XInputExtension:GetDeviceFocus
+R021 XInputExtension:SetDeviceFocus
+R022 XInputExtension:GetFeedbackControl
+R023 XInputExtension:ChangeFeedbackControl
+R024 XInputExtension:GetDeviceKeyMapping
+R025 XInputExtension:ChangeDeviceKeyMapping
+R026 XInputExtension:GetDeviceModifierMapping
+R027 XInputExtension:SetDeviceModifierMapping
+R028 XInputExtension:GetDeviceButtonMapping
+R029 XInputExtension:SetDeviceButtonMapping
+R030 XInputExtension:QueryDeviceState
+R031 XInputExtension:SendExtensionEvent
+R032 XInputExtension:DeviceBell
+R033 XInputExtension:SetDeviceValuators
+R034 XInputExtension:GetDeviceControl
+R035 XInputExtension:ChangeDeviceControl
+V000 XInputExtension:DeviceValuator
+V001 XInputExtension:DeviceKeyPress
+V002 XInputExtension:DeviceKeyRelease
+V003 XInputExtension:DeviceButtonPress
+V004 XInputExtension:DeviceButtonRelease
+V005 XInputExtension:DeviceMotionNotify
+V006 XInputExtension:DeviceFocusIn
+V007 XInputExtension:DeviceFocusOut
+V008 XInputExtension:ProximityIn
+V009 XInputExtension:ProximityOut
+V010 XInputExtension:DeviceStateNotify
+V011 XInputExtension:DeviceMappingNotify
+V012 XInputExtension:ChangeDeviceNotify
+V013 XInputExtension:DeviceKeystateNotify
+V014 XInputExtension:DeviceButtonstateNotify
+V015 XInputExtension:DevicePresenceNotify
+E000 XInputExtension:BadDevice
+E001 XInputExtension:BadEvent
+E002 XInputExtension:BadMode
+E003 XInputExtension:DeviceBusy
+E004 XInputExtension:BadClass
+R000 XKEYBOARD:UseExtension
+R001 XKEYBOARD:SelectEvents
+R002 XKEYBOARD:Obsolete
+R003 XKEYBOARD:Bell
+R004 XKEYBOARD:GetState
+R005 XKEYBOARD:LatchLockState
+R006 XKEYBOARD:GetControls
+R007 XKEYBOARD:SetControls
+R008 XKEYBOARD:GetMap
+R009 XKEYBOARD:SetMap
+R010 XKEYBOARD:GetCompatMap
+R011 XKEYBOARD:SetCompatMap
+R012 XKEYBOARD:GetIndicatorState
+R013 XKEYBOARD:GetIndicatorMap
+R014 XKEYBOARD:SetIndicatorMap
+R015 XKEYBOARD:GetNamedIndicator
+R016 XKEYBOARD:SetNamedIndicator
+R017 XKEYBOARD:GetNames
+R018 XKEYBOARD:SetNames
+R019 XKEYBOARD:GetGeometry
+R020 XKEYBOARD:SetGeometry
+R021 XKEYBOARD:PerClientFlags
+R022 XKEYBOARD:ListComponents
+R023 XKEYBOARD:GetKbdByName
+R024 XKEYBOARD:GetDeviceInfo
+R025 XKEYBOARD:SetDeviceInfo
+R101 XKEYBOARD:SetDebuggingFlags
+V000 XKEYBOARD:EventCode
+E000 XKEYBOARD:BadKeyboard
+R000 XTEST:GetVersion
+R001 XTEST:CompareCursor
+R002 XTEST:FakeInput
+R003 XTEST:GrabControl
+R000 XVideo:QueryExtension
+R001 XVideo:QueryAdaptors
+R002 XVideo:QueryEncodings
+R003 XVideo:GrabPort
+R004 XVideo:UngrabPort
+R005 XVideo:PutVideo
+R006 XVideo:PutStill
+R007 XVideo:GetVideo
+R008 XVideo:GetStill
+R009 XVideo:StopVideo
+R010 XVideo:SelectVideoNotify
+R011 XVideo:SelectPortNotify
+R012 XVideo:QueryBestSize
+R013 XVideo:SetPortAttribute
+R014 XVideo:GetPortAttribute
+R015 XVideo:QueryPortAttributes
+R016 XVideo:ListImageFormats
+R017 XVideo:QueryImageAttributes
+R018 XVideo:PutImage
+R019 XVideo:ShmPutImage
+V000 XVideo:VideoNotify
+V001 XVideo:PortNotify
+E000 XVideo:BadPort
+E001 XVideo:BadEncoding
+E002 XVideo:BadControl
+R000 XVideo-MotionCompensation:QueryVersion
+R001 XVideo-MotionCompensation:ListSurfaceTypes
+R002 XVideo-MotionCompensation:CreateContext
+R003 XVideo-MotionCompensation:DestroyContext
+R004 XVideo-MotionCompensation:CreateSurface
+R005 XVideo-MotionCompensation:DestroySurface
+R006 XVideo-MotionCompensation:CreateSubpicture
+R007 XVideo-MotionCompensation:DestroySubpicture
+R008 XVideo-MotionCompensation:ListSubpictureTypes
+R009 XVideo-MotionCompensation:GetDRInfo
+E000 XVideo-MotionCompensation:BadContext
+E001 XVideo-MotionCompensation:BadSurface
+E002 XVideo-MotionCompensation:BadSubpicture
+R000 XpExtension:QueryVersion
+R001 XpExtension:GetPrinterList
+R002 XpExtension:CreateContext
+R003 XpExtension:SetContext
+R004 XpExtension:GetContext
+R005 XpExtension:DestroyContext
+R006 XpExtension:GetContextScreen
+R007 XpExtension:StartJob
+R008 XpExtension:EndJob
+R009 XpExtension:StartDoc
+R010 XpExtension:EndDoc
+R011 XpExtension:PutDocumentData
+R012 XpExtension:GetDocumentData
+R013 XpExtension:StartPage
+R014 XpExtension:EndPage
+R015 XpExtension:SelectInput
+R016 XpExtension:InputSelected
+R017 XpExtension:GetAttributes
+R018 XpExtension:SetAttributes
+R019 XpExtension:GetOneAttribute
+R020 XpExtension:RehashPrinterList
+R021 XpExtension:GetPageDimensions
+R022 XpExtension:QueryScreens
+R023 XpExtension:SetImageResolution
+R024 XpExtension:GetImageResolution
+V000 XpExtension:PrintNotify
+V001 XpExtension:AttributeNotify
+E000 XpExtension:BadContext
+E001 XpExtension:BadSequence
+E002 XpExtension:BadResourceID
commit c0f9e204baf0218466973868c5ea6ed0f78e6b8b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 26 15:24:15 2007 -0500

    registry: rename the SERVERCONFIGdir and relocate it to /usr/lib/xorg
    by default.

diff --git a/configure.ac b/configure.ac
index 477058c..d78bc1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -460,9 +460,10 @@ AC_ARG_WITH(xkb-path,         AS_HELP_STRING([--with-xkb-path=PATH], [Path to XK
 AC_ARG_WITH(xkb-output,       AS_HELP_STRING([--with-xkb-output=PATH], [Path to XKB output dir (default: ${datadir}/X11/xkb/compiled)]),
 				[ XKBOUTPUT="$withval" ],
 				[ XKBOUTPUT="compiled" ])
-AC_ARG_WITH(serverconfig-path, AS_HELP_STRING([--with-serverconfig-path=PATH], [Path to server config (default: ${libdir}/xserver)]),
+AC_ARG_WITH(serverconfig-path, AS_HELP_STRING([--with-serverconfig-path=PATH],
+				   [Directory where ancillary server config files are installed (default: ${libdir}/xorg)]),
 				[ SERVERCONFIG="$withval" ],
-				[ SERVERCONFIG="${libdir}/xserver" ])
+				[ SERVERCONFIG="${libdir}/xorg" ])
 APPLE_APPLICATIONS_DIR="${bindir}/Applications"
 AC_ARG_WITH(apple-applications-dir,AS_HELP_STRING([--with-apple-applications-dir=PATH], [Path to the Applications directory (default: ${bindir}/Applications)]),
                                [ APPLE_APPLICATIONS_DIR="${withval}" ].
@@ -1024,7 +1025,7 @@ fi
 
 AC_DEFINE_DIR(COMPILEDDEFAULTFONTPATH, FONTPATH, [Default font path])
 AC_DEFINE_DIR(PCI_TXT_IDS_PATH, PCI_TXT_IDS_DIR, [Default PCI text file ID path])
-AC_DEFINE_DIR(SERVERCONFIGdir, SERVERCONFIG, [Server config path])
+AC_DEFINE_DIR(SERVER_MISC_CONFIG_PATH, SERVERCONFIG, [Server miscellaneous config path])
 AC_DEFINE_DIR(BASE_FONT_PATH, FONTDIR, [Default base font path])
 AC_DEFINE_DIR(DRI_DRIVER_PATH, DRI_DRIVER_PATH, [Default DRI driver path])
 AC_DEFINE_UNQUOTED(XVENDORNAME, ["$VENDOR_NAME"], [Vendor name])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 8ceeb8d..c442962 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -21,6 +21,9 @@
 /* Default font path */
 #undef COMPILEDDEFAULTFONTPATH
 
+/* Miscellaneous server configuration files path */
+#undef SERVER_MISC_CONFIG_PATH
+
 /* Support Composite Extension */
 #undef COMPOSITE
 
commit 4363d70c6b420648b501126d1fbdebfafc7ae09f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:58:55 2007 -0500

    registry: Fix some mistakes in the reversion of prior commits.

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index fd8bcb8..4f0724b 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -52,7 +52,7 @@ BigReqExtensionInit(INITARGS)
 {
     AddExtension(XBigReqExtensionName, 0, 0,
 		 ProcBigReqDispatch, ProcBigReqDispatch,
-		 BigReqResetProc, StandardMinorOpcode)))
+		 BigReqResetProc, StandardMinorOpcode);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/dpms.c b/Xext/dpms.c
index d518a16..6f01fa3 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -75,7 +75,7 @@ DPMSExtensionInit(INITARGS)
 {
     AddExtension(DPMSExtensionName, 0, 0,
 		 ProcDPMSDispatch, SProcDPMSDispatch,
-		 DPMSResetProc, StandardMinorOpcode)))
+		 DPMSResetProc, StandardMinorOpcode);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/fontcache.c b/Xext/fontcache.c
index 06b0c85..eca7309 100644
--- a/Xext/fontcache.c
+++ b/Xext/fontcache.c
@@ -72,7 +72,7 @@ FontCacheExtensionInit(INITARGS)
 {
     AddExtension(FONTCACHENAME, FontCacheNumberEvents, FontCacheNumberErrors,
 		 ProcFontCacheDispatch, SProcFontCacheDispatch,
-		 FontCacheResetProc, StandardMinorOpcode)))
+		 FontCacheResetProc, StandardMinorOpcode);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/mitmisc.c b/Xext/mitmisc.c
index a5f3b0f..e793d4d 100644
--- a/Xext/mitmisc.c
+++ b/Xext/mitmisc.c
@@ -58,7 +58,7 @@ MITMiscExtensionInit(INITARGS)
 {
     AddExtension(MITMISCNAME, 0, 0,
 		 ProcMITDispatch, SProcMITDispatch,
-		 MITResetProc, StandardMinorOpcode)))
+		 MITResetProc, StandardMinorOpcode);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 44d2b19..a42d2e2 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -66,7 +66,7 @@ XCMiscExtensionInit(INITARGS)
 {
     AddExtension(XCMiscExtensionName, 0, 0,
 		 ProcXCMiscDispatch, SProcXCMiscDispatch,
-		 XCMiscResetProc, StandardMinorOpcode))
+		 XCMiscResetProc, StandardMinorOpcode);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/xres.c b/Xext/xres.c
index 243460c..feadad2 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -17,6 +17,7 @@
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "swaprep.h"
+#include "registry.h"
 #include <X11/extensions/XResproto.h>
 #include "pixmapstr.h"
 #include "windowstr.h"
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 8e1732c..db6d545 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -86,7 +86,7 @@ XTestExtensionInit(INITARGS)
 {
     AddExtension(XTestExtensionName, 0, 0,
 		 ProcXTestDispatch, SProcXTestDispatch,
-		 XTestResetProc, StandardMinorOpcode))
+		 XTestResetProc, StandardMinorOpcode);
 }
 
 /*ARGSUSED*/
commit 140a4660aca1c283613d5b62f51668b44b45baf6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:49:30 2007 -0500

    Revert "registry: Register XTrap extension protocol names."
    
    This reverts commit b38a91993364aa80cfd99721e319e1458d9fb760.
    
    Moving all the names into dix/registry.c

diff --git a/XTrap/xtrapdi.c b/XTrap/xtrapdi.c
index 15a38ea..7dd9584 100644
--- a/XTrap/xtrapdi.c
+++ b/XTrap/xtrapdi.c
@@ -62,7 +62,6 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "misc.h"               /* Server swapping macros */
 #include "dixstruct.h"          /* Server ClientRec definitions */
 #include "resource.h"           /* Used with the MakeAtom call */
-#include "registry.h"
 #ifdef PC
 # include "scrintst.h"          /* Screen struct */
 # include "extnsist.h"
@@ -464,41 +463,6 @@ void DEC_XTRAPInit()
         XETrap_avail.data.xtrap_revision);
 #endif
 
-    RegisterRequestName(extEntry->base, XETrap_Reset,
-			XTrapExtName ":Reset");
-    RegisterRequestName(extEntry->base, XETrap_GetAvailable,
-			XTrapExtName ":GetAvailable");
-    RegisterRequestName(extEntry->base, XETrap_Config,
-			XTrapExtName ":Config");
-    RegisterRequestName(extEntry->base, XETrap_StartTrap,
-			XTrapExtName ":StartTrap");
-    RegisterRequestName(extEntry->base, XETrap_StopTrap,
-			XTrapExtName ":StopTrap");
-    RegisterRequestName(extEntry->base, XETrap_GetCurrent,
-			XTrapExtName ":GetCurrent");
-    RegisterRequestName(extEntry->base, XETrap_GetStatistics,
-			XTrapExtName ":GetStatistics");
-#ifndef _XINPUT
-    RegisterRequestName(extEntry->base, XETrap_SimulateXEvent,
-			XTrapExtName ":SimulateXEvent");
-#endif
-    RegisterRequestName(extEntry->base, XETrap_GetVersion,
-			XTrapExtName ":GetVersion");
-    RegisterRequestName(extEntry->base, XETrap_GetLastInpTime,
-			XTrapExtName ":GetLastInpTime");
-
-    RegisterEventName(extEntry->eventBase, XTrapExtName ":Event");
-
-    RegisterErrorName(extEntry->errorBase + BadIO,
-			XTrapExtName ":BadIO");
-    RegisterErrorName(extEntry->errorBase + BadStatistics,
-			XTrapExtName ":BadStatistics");
-    RegisterErrorName(extEntry->errorBase + BadDevices,
-			XTrapExtName ":BadDevices");
-    RegisterErrorName(extEntry->errorBase + BadScreen,
-			XTrapExtName ":BadScreen");
-    RegisterErrorName(extEntry->errorBase + BadSwapReq,
-			XTrapExtName ":BadSwapReq");
     return;
 }
 
commit ed8a39c48ab9dac085fcf58b9641364b5608f3f4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:47:52 2007 -0500

    Revert "registry: Register XKB extension protocol names."
    
    This reverts commit a5cf3f21f712e46dbf9bca289e67be75f2b531d3.
    
    Moving all the names into dix/registry.c

diff --git a/xkb/xkb.c b/xkb/xkb.c
index 49c63fa..23e1dc7 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -35,7 +35,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xproto.h>
 #include "misc.h"
 #include "inputstr.h"
-#include "registry.h"
 #define	XKBSRV_NEED_FILE_FUNCS
 #include <xkbsrv.h>
 #include "extnsionst.h"
@@ -6227,62 +6226,8 @@ XkbExtensionInit(void)
 	XkbErrorBase = (unsigned char)extEntry->errorBase;
 	XkbKeyboardErrorCode = XkbErrorBase+XkbKeyboard;
 	RT_XKBCLIENT = CreateNewResourceType(XkbClientGone);
-    } else
-	return;
-
-    RegisterRequestName(XkbReqCode, X_kbUseExtension,
-			XkbName ":UseExtension");
-    RegisterRequestName(XkbReqCode, X_kbSelectEvents,
-			XkbName ":SelectEvents");
-    RegisterRequestName(XkbReqCode, X_kbBell,
-			XkbName ":Bell");
-    RegisterRequestName(XkbReqCode, X_kbGetState,
-			XkbName ":GetState");
-    RegisterRequestName(XkbReqCode, X_kbLatchLockState,
-			XkbName ":LatchLockState");
-    RegisterRequestName(XkbReqCode, X_kbGetControls,
-			XkbName ":GetControls");
-    RegisterRequestName(XkbReqCode, X_kbSetControls,
-			XkbName ":SetControls");
-    RegisterRequestName(XkbReqCode, X_kbGetMap,
-			XkbName ":GetMap");
-    RegisterRequestName(XkbReqCode, X_kbSetMap,
-			XkbName ":SetMap");
-    RegisterRequestName(XkbReqCode, X_kbGetCompatMap,
-			XkbName ":GetCompatMap");
-    RegisterRequestName(XkbReqCode, X_kbSetCompatMap,
-			XkbName ":SetCompatMap");
-    RegisterRequestName(XkbReqCode, X_kbGetIndicatorState,
-			XkbName ":GetIndicatorState");
-    RegisterRequestName(XkbReqCode, X_kbGetIndicatorMap,
-			XkbName ":GetIndicatorMap");
-    RegisterRequestName(XkbReqCode, X_kbSetIndicatorMap,
-			XkbName ":SetIndicatorMap");
-    RegisterRequestName(XkbReqCode, X_kbGetNamedIndicator,
-			XkbName ":GetNamedIndicator");
-    RegisterRequestName(XkbReqCode, X_kbSetNamedIndicator,
-			XkbName ":SetNamedIndicator");
-    RegisterRequestName(XkbReqCode, X_kbGetNames,
-			XkbName ":GetNames");
-    RegisterRequestName(XkbReqCode, X_kbSetNames,
-			XkbName ":SetNames");
-    RegisterRequestName(XkbReqCode, X_kbGetGeometry,
-			XkbName ":GetGeometry");
-    RegisterRequestName(XkbReqCode, X_kbSetGeometry,
-			XkbName ":SetGeometry");
-    RegisterRequestName(XkbReqCode, X_kbPerClientFlags,
-			XkbName ":PerClientFlags");
-    RegisterRequestName(XkbReqCode, X_kbListComponents,
-			XkbName ":ListComponents");
-    RegisterRequestName(XkbReqCode, X_kbGetKbdByName,
-			XkbName ":GetKbdByName");
-    RegisterRequestName(XkbReqCode, X_kbGetDeviceInfo,
-			XkbName ":GetDeviceInfo");
-    RegisterRequestName(XkbReqCode, X_kbSetDeviceInfo,
-			XkbName ":SetDeviceInfo");
-    RegisterRequestName(XkbReqCode, X_kbSetDebuggingFlags,
-			XkbName ":SetDebuggingFlags");
-
-    RegisterEventName(extEntry->eventBase, XkbName ":EventCode");
-    RegisterErrorName(extEntry->errorBase, XkbName ":Keyboard");
+    }
+    return;
 }
+
+
commit 17b0c729b553e2f0f8f82497698b282a47db3326
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:46:43 2007 -0500

    registry: Remove registry code from XInput extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xi/extinit.c b/Xi/extinit.c
index bf5ebd2..2ffdafb 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -959,119 +959,4 @@ XInputExtensionInit(void)
     } else {
 	FatalError("IExtensionInit: AddExtensions failed\n");
     }
-
-    RegisterRequestName(IReqCode, X_GetExtensionVersion,
-			INAME ":GetExtensionVersion");
-    RegisterRequestName(IReqCode, X_ListInputDevices,
-			INAME ":ListInputDevices");
-    RegisterRequestName(IReqCode, X_OpenDevice,
-			INAME ":OpenDevice");
-    RegisterRequestName(IReqCode, X_CloseDevice,
-			INAME ":CloseDevice");
-    RegisterRequestName(IReqCode, X_SetDeviceMode,
-			INAME ":SetDeviceMode");
-    RegisterRequestName(IReqCode, X_SelectExtensionEvent,
-			INAME ":SelectExtensionEvent");
-    RegisterRequestName(IReqCode, X_GetSelectedExtensionEvents,
-			INAME ":GetSelectedExtensionEvents");
-    RegisterRequestName(IReqCode, X_ChangeDeviceDontPropagateList,
-			INAME ":ChangeDeviceDontPropagateList");
-    RegisterRequestName(IReqCode, X_GetDeviceDontPropagateList,
-			INAME ":GetDeviceDontPropagageList");
-    RegisterRequestName(IReqCode, X_GetDeviceMotionEvents,
-			INAME ":GetDeviceMotionEvents");
-    RegisterRequestName(IReqCode, X_ChangeKeyboardDevice,
-			INAME ":ChangeKeyboardDevice");
-    RegisterRequestName(IReqCode, X_ChangePointerDevice,
-			INAME ":ChangePointerDevice");
-    RegisterRequestName(IReqCode, X_GrabDevice,
-			INAME ":GrabDevice");
-    RegisterRequestName(IReqCode, X_UngrabDevice,
-			INAME ":UngrabDevice");
-    RegisterRequestName(IReqCode, X_GrabDeviceKey,
-			INAME ":GrabDeviceKey");
-    RegisterRequestName(IReqCode, X_UngrabDeviceKey,
-			INAME ":UngrabDeviceKey");
-    RegisterRequestName(IReqCode, X_GrabDeviceButton,
-			INAME ":GrabDeviceButton");
-    RegisterRequestName(IReqCode, X_UngrabDeviceButton,
-			INAME ":UngrabDeviceButton");
-    RegisterRequestName(IReqCode, X_AllowDeviceEvents,
-			INAME ":AllowDeviceEvents");
-    RegisterRequestName(IReqCode, X_GetDeviceFocus,
-			INAME ":GetDeviceFocus");
-    RegisterRequestName(IReqCode, X_SetDeviceFocus,
-			INAME ":SetDeviceFocus");
-    RegisterRequestName(IReqCode, X_GetFeedbackControl,
-			INAME ":GetFeedbackControl");
-    RegisterRequestName(IReqCode, X_ChangeFeedbackControl,
-			INAME ":ChangeFeedbackControl");
-    RegisterRequestName(IReqCode, X_GetDeviceKeyMapping,
-			INAME ":GetDeviceKeyMapping");
-    RegisterRequestName(IReqCode, X_ChangeDeviceKeyMapping,
-			INAME ":ChangeDeviceKeyMapping");
-    RegisterRequestName(IReqCode, X_GetDeviceModifierMapping,
-			INAME ":GetDeviceModifierMapping");
-    RegisterRequestName(IReqCode, X_SetDeviceModifierMapping,
-			INAME ":SetDeviceModifierMapping");
-    RegisterRequestName(IReqCode, X_GetDeviceButtonMapping,
-			INAME ":GetDeviceButtonMapping");
-    RegisterRequestName(IReqCode, X_SetDeviceButtonMapping,
-			INAME ":SetDeviceButtonMapping");
-    RegisterRequestName(IReqCode, X_QueryDeviceState,
-			INAME ":QueryDeviceState");
-    RegisterRequestName(IReqCode, X_SendExtensionEvent,
-			INAME ":SendExtensionEvent");
-    RegisterRequestName(IReqCode, X_DeviceBell,
-			INAME ":DeviceBell");
-    RegisterRequestName(IReqCode, X_SetDeviceValuators,
-			INAME ":SetDeviceValuators");
-    RegisterRequestName(IReqCode, X_GetDeviceControl,
-			INAME ":GetDeviceControl");
-    RegisterRequestName(IReqCode, X_ChangeDeviceControl,
-			INAME ":ChangeDeviceControl");
-
-    RegisterEventName(extEntry->eventBase + XI_DeviceValuator,
-		      INAME ":DeviceValuator");
-    RegisterEventName(extEntry->eventBase + XI_DeviceKeyPress,
-		      INAME ":DeviceKeyPress");
-    RegisterEventName(extEntry->eventBase + XI_DeviceKeyRelease,
-		      INAME ":DeviceKeyRelease");
-    RegisterEventName(extEntry->eventBase + XI_DeviceButtonPress,
-		      INAME ":DeviceButtonPress");
-    RegisterEventName(extEntry->eventBase + XI_DeviceButtonRelease,
-		      INAME ":DeviceButtonRelease");
-    RegisterEventName(extEntry->eventBase + XI_DeviceMotionNotify,
-		      INAME ":DeviceMotionNotify");
-    RegisterEventName(extEntry->eventBase + XI_DeviceFocusIn,
-		      INAME ":DeviceFocusIn");
-    RegisterEventName(extEntry->eventBase + XI_DeviceFocusOut,
-		      INAME ":DeviceFocusOut");
-    RegisterEventName(extEntry->eventBase + XI_ProximityIn,
-		      INAME ":ProximityIn");
-    RegisterEventName(extEntry->eventBase + XI_ProximityOut,
-		      INAME ":ProximityOut");
-    RegisterEventName(extEntry->eventBase + XI_DeviceStateNotify,
-		      INAME ":DeviceStateNotify");
-    RegisterEventName(extEntry->eventBase + XI_DeviceMappingNotify,
-		      INAME ":DeviceMappingNotify");
-    RegisterEventName(extEntry->eventBase + XI_ChangeDeviceNotify,
-		      INAME ":ChangeDeviceNotify");
-    RegisterEventName(extEntry->eventBase + XI_DeviceKeystateNotify,
-		      INAME ":DeviceKeystateNotify");
-    RegisterEventName(extEntry->eventBase + XI_DeviceButtonstateNotify,
-		      INAME ":DeviceButtonstateNotify");
-    RegisterEventName(extEntry->eventBase + XI_DevicePresenceNotify,
-		      INAME ":DevicePresenceNotify");
-
-    RegisterErrorName(extEntry->errorBase + XI_BadDevice,
-		      INAME ":BadDevice");
-    RegisterErrorName(extEntry->errorBase + XI_BadEvent,
-		      INAME ":BadEvent");
-    RegisterErrorName(extEntry->errorBase + XI_BadMode,
-		      INAME ":BadMode");
-    RegisterErrorName(extEntry->errorBase + XI_DeviceBusy,
-		      INAME ":DeviceBusy");
-    RegisterErrorName(extEntry->errorBase + XI_BadClass,
-		      INAME ":BadClass");
 }
commit e86852aff62a861823b8e419434e0401b8cdc8e0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:44:56 2007 -0500

    Revert "registry: Register XFixes extension protocol names."
    
    This reverts commit 106758893b68033f14f69c4ee6591fb6a149ba37.
    
    Moving all the names into dix/registry.c

diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index ccce7b9..0db4989 100755
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -45,7 +45,6 @@
 #endif
 
 #include "xfixesint.h"
-#include "registry.h"
 
 /*
  * Must use these instead of the constants from xfixeswire.h.  They advertise
@@ -258,80 +257,5 @@ XFixesExtensionInit(void)
 	    (EventSwapPtr) SXFixesSelectionNotifyEvent;
 	EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
 	    (EventSwapPtr) SXFixesCursorNotifyEvent;
-    } else
-	return;
-
-    RegisterRequestName(XFixesReqCode, X_XFixesQueryVersion,
-			XFIXES_NAME ":QueryVersion");
-    RegisterRequestName(XFixesReqCode, X_XFixesChangeSaveSet,
-			XFIXES_NAME ":ChangeSaveSet");
-    RegisterRequestName(XFixesReqCode, X_XFixesSelectSelectionInput,
-			XFIXES_NAME ":SelectSelectionInput");
-    RegisterRequestName(XFixesReqCode, X_XFixesSelectCursorInput,
-			XFIXES_NAME ":SelectCursorInput");
-    RegisterRequestName(XFixesReqCode, X_XFixesGetCursorImage,
-			XFIXES_NAME ":GetCursorImage");
-    /*************** Version 2 ******************/
-    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegion,
-			XFIXES_NAME ":CreateRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromBitmap,
-			XFIXES_NAME ":CreateRegionFromBitmap");
-    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromWindow,
-			XFIXES_NAME ":CreateRegionFromWindow");
-    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromGC,
-			XFIXES_NAME ":CreateRegionFromGC");
-    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromPicture,
-			XFIXES_NAME ":CreateRegionFromPicture");
-    RegisterRequestName(XFixesReqCode, X_XFixesDestroyRegion,
-			XFIXES_NAME ":DestroyRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesSetRegion,
-			XFIXES_NAME ":SetRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesCopyRegion,
-			XFIXES_NAME ":CopyRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesUnionRegion,
-			XFIXES_NAME ":UnionRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesIntersectRegion,
-			XFIXES_NAME ":IntersectRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesSubtractRegion,
-			XFIXES_NAME ":SubtractRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesInvertRegion,
-			XFIXES_NAME ":InvertRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesTranslateRegion,
-			XFIXES_NAME ":TranslateRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesRegionExtents,
-			XFIXES_NAME ":RegionExtents");
-    RegisterRequestName(XFixesReqCode, X_XFixesFetchRegion,
-			XFIXES_NAME ":FetchRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesSetGCClipRegion,
-			XFIXES_NAME ":SetGCClipRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesSetWindowShapeRegion,
-			XFIXES_NAME ":SetWindowShapeRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesSetPictureClipRegion,
-			XFIXES_NAME ":SetPictureClipRegion");
-    RegisterRequestName(XFixesReqCode, X_XFixesSetCursorName,
-			XFIXES_NAME ":SetCursorName");
-    RegisterRequestName(XFixesReqCode, X_XFixesGetCursorName,
-			XFIXES_NAME ":GetCursorName");
-    RegisterRequestName(XFixesReqCode, X_XFixesGetCursorImageAndName,
-			XFIXES_NAME ":GetCursorImageAndName");
-    RegisterRequestName(XFixesReqCode, X_XFixesChangeCursor,
-			XFIXES_NAME ":ChangeCursor");
-    RegisterRequestName(XFixesReqCode, X_XFixesChangeCursorByName,
-			XFIXES_NAME ":ChangeCursorByName");
-    /*************** Version 3 ******************/
-    RegisterRequestName(XFixesReqCode, X_XFixesExpandRegion,
-			XFIXES_NAME ":ExpandRegion");
-    /*************** Version 4 ******************/
-    RegisterRequestName(XFixesReqCode, X_XFixesHideCursor,
-			XFIXES_NAME ":HideCursor");
-    RegisterRequestName(XFixesReqCode, X_XFixesShowCursor,
-			XFIXES_NAME ":ShowCursor");
-
-    RegisterEventName(XFixesEventBase + XFixesSelectionNotify,
-			XFIXES_NAME ":SelectionNotify");
-    RegisterEventName(XFixesEventBase + XFixesCursorNotify,
-			XFIXES_NAME ":CursorNotify");
-
-    RegisterErrorName(XFixesErrorBase + BadRegion,
-			XFIXES_NAME ":BadRegion");
+    }
 }
commit 5269da2bde3cf4feb12fa2bd87bff6ee6d8730a1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:43:38 2007 -0500

    Revert "registry: Register XvMC extension protocol names."
    
    This reverts commit 853ea337bdad17f8f6ec7d940de14ce2cbbbf93e.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index a1e0ed1..7ae8cc0 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -16,7 +16,6 @@
 #include "scrnintstr.h"
 #include "extnsionst.h"
 #include "servermd.h"
-#include "registry.h"
 #include <X11/Xfuncproto.h>
 #include "xvdix.h"
 #include <X11/extensions/XvMC.h>
@@ -701,34 +700,6 @@ XvMCExtensionInit(void)
    XvMCReqCode = extEntry->base;
    XvMCEventBase = extEntry->eventBase;
    XvMCErrorBase = extEntry->errorBase;
-
-    RegisterRequestName(XvMCReqCode, xvmc_QueryVersion,
-			XvMCName ":QueryVersion");
-    RegisterRequestName(XvMCReqCode, xvmc_ListSurfaceTypes,
-			XvMCName ":ListSurfaceTypes");
-    RegisterRequestName(XvMCReqCode, xvmc_CreateContext,
-			XvMCName ":CreateContext");
-    RegisterRequestName(XvMCReqCode, xvmc_DestroyContext,
-			XvMCName ":DestroyContext");
-    RegisterRequestName(XvMCReqCode, xvmc_CreateSurface,
-			XvMCName ":CreateSurface");
-    RegisterRequestName(XvMCReqCode, xvmc_DestroySurface,
-			XvMCName ":DestroySurface");
-    RegisterRequestName(XvMCReqCode, xvmc_CreateSubpicture,
-			XvMCName ":CreateSubpicture");
-    RegisterRequestName(XvMCReqCode, xvmc_DestroySubpicture,
-			XvMCName ":DestroySubpicture");
-    RegisterRequestName(XvMCReqCode, xvmc_ListSubpictureTypes,
-			XvMCName ":ListSubpictureTypes");
-    RegisterRequestName(XvMCReqCode, xvmc_GetDRInfo,
-			XvMCName ":GetDRInfo");
-
-    RegisterErrorName(XvMCErrorBase + XvMCBadContext,
-		      XvMCName ":BadContext");
-    RegisterErrorName(XvMCErrorBase + XvMCBadSurface,
-		      XvMCName ":BadSurface");
-    RegisterErrorName(XvMCErrorBase + XvMCBadSubpicture,
-		      XvMCName ":BadSubpicture");
 }
 
 static Bool
commit 03a86c8d5e20a6e47f3c294f0087f205cf2a72dd
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:42:19 2007 -0500

    Revert "registry: Register Xv extension protocol names."
    
    This reverts commit 12766c5b5ffdab95255a63b2c8421ee773fd43b5.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index b3449b4..a2fc108 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -92,7 +92,6 @@ SOFTWARE.
 #include "resource.h"
 #include "opaque.h"
 #include "input.h"
-#include "registry.h"
 
 #define GLOBAL
 
@@ -196,58 +195,6 @@ XvExtensionInit(void)
 
       (void)MakeAtom(XvName, strlen(XvName), xTrue);
 
-      RegisterRequestName(XvReqCode, xv_QueryExtension,
-			  XvName ":QueryExtension");
-      RegisterRequestName(XvReqCode, xv_QueryAdaptors,
-			  XvName ":QueryAdaptors");
-      RegisterRequestName(XvReqCode, xv_QueryEncodings,
-			  XvName ":QueryEncodings");
-      RegisterRequestName(XvReqCode, xv_GrabPort,
-			  XvName ":GrabPort");
-      RegisterRequestName(XvReqCode, xv_UngrabPort,
-			  XvName ":UngrabPort");
-      RegisterRequestName(XvReqCode, xv_PutVideo,
-			  XvName ":PutVideo");
-      RegisterRequestName(XvReqCode, xv_PutStill,
-			  XvName ":PutStill");
-      RegisterRequestName(XvReqCode, xv_GetVideo,
-			  XvName ":GetVideo");
-      RegisterRequestName(XvReqCode, xv_GetStill,
-			  XvName ":GetStill");
-      RegisterRequestName(XvReqCode, xv_StopVideo,
-			  XvName ":StopVideo");
-      RegisterRequestName(XvReqCode, xv_SelectVideoNotify,
-			  XvName ":SelectVideoNotify");
-      RegisterRequestName(XvReqCode, xv_SelectPortNotify,
-			  XvName ":SelectPortNotify");
-      RegisterRequestName(XvReqCode, xv_QueryBestSize,
-			  XvName ":QueryBestSize");
-      RegisterRequestName(XvReqCode, xv_SetPortAttribute,
-			  XvName ":SetPortAttribute");
-      RegisterRequestName(XvReqCode, xv_GetPortAttribute,
-			  XvName ":GetPortAttribute");
-      RegisterRequestName(XvReqCode, xv_QueryPortAttributes,
-			  XvName ":QueryPortAttributes");
-      RegisterRequestName(XvReqCode, xv_ListImageFormats,
-			  XvName ":ListImageFormats");
-      RegisterRequestName(XvReqCode, xv_QueryImageAttributes,
-			  XvName ":QueryImageAttributes");
-      RegisterRequestName(XvReqCode, xv_PutImage,
-			  XvName ":PutImage");
-      RegisterRequestName(XvReqCode, xv_ShmPutImage,
-			  XvName ":ShmPutImage");
-
-      RegisterEventName(XvEventBase + XvVideoNotify,
-			XvName ":VideoNotify");
-      RegisterEventName(XvEventBase + XvPortNotify,
-			XvName ":PortNotify");
-
-      RegisterErrorName(XvErrorBase + XvBadPort,
-			XvName ":BadPort");
-      RegisterErrorName(XvErrorBase + XvBadEncoding,
-			XvName ":BadEncoding");
-      RegisterErrorName(XvErrorBase + XvBadControl,
-			XvName ":BadControl");
     }
 }
 
commit edcf490cdb965e2a5bfc0169c01732d2924da3ae
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:41:10 2007 -0500

    registry: Remove registry code from XTest extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xtest.c b/Xext/xtest.c
index effa3b9..8e1732c 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -42,7 +42,6 @@ from The Open Group.
 #include "scrnintstr.h"
 #include "dixevents.h"
 #include "sleepuntil.h"
-#include "registry.h"
 #define _XTEST_SERVER_
 #include <X11/extensions/XTest.h>
 #include <X11/extensions/xteststr.h>
@@ -85,21 +84,9 @@ static DISPATCH_PROC(SProcXTestGrabControl);
 void
 XTestExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-
-    if (!(extEntry = AddExtension(XTestExtensionName, 0, 0,
-				  ProcXTestDispatch, SProcXTestDispatch,
-				  XTestResetProc, StandardMinorOpcode)))
-	return;
-
-    RegisterRequestName(extEntry->base, X_XTestGetVersion,
-			XTestExtensionName ":GetVersion");
-    RegisterRequestName(extEntry->base, X_XTestCompareCursor,
-			XTestExtensionName ":CompareCursor");
-    RegisterRequestName(extEntry->base, X_XTestFakeInput,
-			XTestExtensionName ":FakeInput");
-    RegisterRequestName(extEntry->base, X_XTestGrabControl,
-			XTestExtensionName ":GrabControl");
+    AddExtension(XTestExtensionName, 0, 0,
+		 ProcXTestDispatch, SProcXTestDispatch,
+		 XTestResetProc, StandardMinorOpcode))
 }
 
 /*ARGSUSED*/
commit 5fea1ed50f37691a5273bf2897479781de808ff5
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:39:48 2007 -0500

    registry: Remove registry code from SELinux extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index cefde9d..8f52c1e 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1399,28 +1399,4 @@ XSELinuxExtensionInit(INITARGS)
 
     /* Label objects that were created before we could register ourself */
     SELinuxLabelInitial();
-
-    /* Add names to registry */
-    RegisterRequestName(extEntry->base, X_SELinuxQueryVersion,
-			XSELINUX_EXTENSION_NAME ":SELinuxQueryVersion");
-    RegisterRequestName(extEntry->base, X_SELinuxSetSelectionManager,
-			XSELINUX_EXTENSION_NAME ":SELinuxSetSelectionManager");
-    RegisterRequestName(extEntry->base, X_SELinuxGetSelectionManager,
-			XSELINUX_EXTENSION_NAME ":SELinuxGetSelectionManager");
-    RegisterRequestName(extEntry->base, X_SELinuxSetDeviceContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxSetDeviceContext");
-    RegisterRequestName(extEntry->base, X_SELinuxGetDeviceContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxGetDeviceContext");
-    RegisterRequestName(extEntry->base, X_SELinuxSetPropertyCreateContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxSetPropertyCreateContext");
-    RegisterRequestName(extEntry->base, X_SELinuxGetPropertyCreateContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxGetPropertyCreateContext");
-    RegisterRequestName(extEntry->base, X_SELinuxGetPropertyContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxGetPropertyContext");
-    RegisterRequestName(extEntry->base, X_SELinuxSetWindowCreateContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxSetWindowCreateContext");
-    RegisterRequestName(extEntry->base, X_SELinuxGetWindowCreateContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxGetWindowCreateContext");
-    RegisterRequestName(extEntry->base, X_SELinuxGetWindowContext,
-			XSELINUX_EXTENSION_NAME ":SELinuxGetWindowContext");
 }
commit 9a8af33718d085656a672e4c27df200485c84154
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:38:24 2007 -0500

    Revert "registry: Register Resource extension protocol names."
    
    This reverts commit 5c8b1a91726817816d20faefad21c7a68ab634cc.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xres.c b/Xext/xres.c
index efa6c49..243460c 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -17,7 +17,6 @@
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "swaprep.h"
-#include "registry.h"
 #include <X11/extensions/XResproto.h>
 #include "pixmapstr.h"
 #include "windowstr.h"
@@ -388,18 +387,7 @@ SProcResDispatch (ClientPtr client)
 void
 ResExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-
-    extEntry = AddExtension(XRES_NAME, 0, 0,
+    (void) AddExtension(XRES_NAME, 0, 0,
                             ProcResDispatch, SProcResDispatch,
                             ResResetProc, StandardMinorOpcode);
-
-    RegisterRequestName(extEntry->base, X_XResQueryVersion,
-			XRES_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_XResQueryClients,
-			XRES_NAME ":QueryClients");
-    RegisterRequestName(extEntry->base, X_XResQueryClientResources,
-			XRES_NAME ":QueryClientResources");
-    RegisterRequestName(extEntry->base, X_XResQueryClientPixmapBytes,
-			XRES_NAME ":QueryClientPixmapBytes");
 }
commit e6023e0208fae8f19c566f9df1a8aa20494f40ab
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:36:49 2007 -0500

    Revert "registry: Register XPrint extension protocol names."
    
    This reverts commit f077578e42eee424b0e534774574c84af9d6f85b.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xprint.c b/Xext/xprint.c
index 48559dd..ef51118 100644
--- a/Xext/xprint.c
+++ b/Xext/xprint.c
@@ -80,7 +80,6 @@ copyright holders.
 #include "pixmapstr.h"
 #include "extnsionst.h"
 #include "dixstruct.h"
-#include "registry.h"
 #include <X11/Xatom.h>
 #include <X11/extensions/Print.h>
 #include <X11/extensions/Printstr.h>
@@ -311,69 +310,6 @@ XpExtensionInit(INITARGS)
 	    screenInfo.screens[i]->CloseScreen = XpCloseScreen;
 	}
     }
-
-    RegisterRequestName(XpReqCode, X_PrintQueryVersion,
-			XP_PRINTNAME ":QueryVersion");
-    RegisterRequestName(XpReqCode, X_PrintGetPrinterList,
-			XP_PRINTNAME ":GetPrinterList");
-    RegisterRequestName(XpReqCode, X_PrintCreateContext,
-			XP_PRINTNAME ":CreateContext");
-    RegisterRequestName(XpReqCode, X_PrintSetContext,
-			XP_PRINTNAME ":SetContext");
-    RegisterRequestName(XpReqCode, X_PrintGetContext,
-			XP_PRINTNAME ":GetContext");
-    RegisterRequestName(XpReqCode, X_PrintDestroyContext,
-			XP_PRINTNAME ":DestroyContext");
-    RegisterRequestName(XpReqCode, X_PrintGetContextScreen,
-			XP_PRINTNAME ":GetContextScreen");
-    RegisterRequestName(XpReqCode, X_PrintStartJob,
-			XP_PRINTNAME ":StartJob");
-    RegisterRequestName(XpReqCode, X_PrintEndJob,
-			XP_PRINTNAME ":EndJob");
-    RegisterRequestName(XpReqCode, X_PrintStartDoc,
-			XP_PRINTNAME ":StartDoc");
-    RegisterRequestName(XpReqCode, X_PrintEndDoc,
-			XP_PRINTNAME ":EndDoc");
-    RegisterRequestName(XpReqCode, X_PrintPutDocumentData,
-			XP_PRINTNAME ":PutDocumentData");
-    RegisterRequestName(XpReqCode, X_PrintGetDocumentData,
-			XP_PRINTNAME ":GetDocumentData");
-    RegisterRequestName(XpReqCode, X_PrintStartPage,
-			XP_PRINTNAME ":StartPage");
-    RegisterRequestName(XpReqCode, X_PrintEndPage,
-			XP_PRINTNAME ":EndPage");
-    RegisterRequestName(XpReqCode, X_PrintSelectInput,
-			XP_PRINTNAME ":SelectInput");
-    RegisterRequestName(XpReqCode, X_PrintInputSelected,
-			XP_PRINTNAME ":InputSelected");
-    RegisterRequestName(XpReqCode, X_PrintGetAttributes,
-			XP_PRINTNAME ":GetAttributes");
-    RegisterRequestName(XpReqCode, X_PrintSetAttributes,
-			XP_PRINTNAME ":SetAttributes");
-    RegisterRequestName(XpReqCode, X_PrintGetOneAttribute,
-			XP_PRINTNAME ":GetOneAttribute");
-    RegisterRequestName(XpReqCode, X_PrintRehashPrinterList,
-			XP_PRINTNAME ":RehashPrinterList");
-    RegisterRequestName(XpReqCode, X_PrintGetPageDimensions,
-			XP_PRINTNAME ":GetPageDimensions");
-    RegisterRequestName(XpReqCode, X_PrintQueryScreens,
-			XP_PRINTNAME ":QueryScreens");
-    RegisterRequestName(XpReqCode, X_PrintSetImageResolution,
-			XP_PRINTNAME ":SetImageResolution");
-    RegisterRequestName(XpReqCode, X_PrintGetImageResolution,
-			XP_PRINTNAME ":GetImageResolution");
-
-    RegisterEventName(XpEventBase + XPPrintNotify,
-		      XP_PRINTNAME ":PrintNotify");
-    RegisterEventName(XpEventBase + XPAttributeNotify,
-		      XP_PRINTNAME ":AttributeNotify");
-
-    RegisterErrorName(XpErrorBase + XPBadContext,
-		      XP_PRINTNAME ":BadContext");
-    RegisterErrorName(XpErrorBase + XPBadSequence,
-		      XP_PRINTNAME ":BadSequence");
-    RegisterErrorName(XpErrorBase + XPBadResourceID,
-		      XP_PRINTNAME ":BadResourceID");
 }
 
 static void
commit 277345fb7065d74c3b0d076382affb78cbe67569
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:35:57 2007 -0500

    registry: Remove registry code from XF86Bigfont extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index e2f5890..3362742 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -71,7 +71,6 @@
 #include "gcstruct.h"
 #include "dixfontstr.h"
 #include "extnsionst.h"
-#include "registry.h"
 
 #define _XF86BIGFONT_SERVER_
 #include <X11/extensions/xf86bigfstr.h>
@@ -186,13 +185,7 @@ XFree86BigfontExtensionInit()
 # endif
 #endif
 #endif
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_XF86BigfontQueryVersion,
-			XF86BIGFONTNAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_XF86BigfontQueryFont,
-			XF86BIGFONTNAME ":QueryFont");
+    }
 }
 
 
commit bf27edd365ffd275e5453f44d130eeacbfe0ecd9
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:34:14 2007 -0500

    Revert "registry: Register EVIE extension protocol names."
    
    This reverts commit 48891d5696f56711f23743cb03be39cf6b26c522.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xevie.c b/Xext/xevie.c
index 8dc1678..7dd67bb 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -45,7 +45,6 @@ of the copyright holder.
 #include "colormapst.h"
 #include "scrnintstr.h"
 #include "servermd.h"
-#include "registry.h"
 #define  _XEVIE_SERVER_
 #include <X11/extensions/Xeviestr.h>
 #include <X11/Xfuncproto.h>
@@ -147,21 +146,9 @@ XevieExtensionInit (void)
 				StandardMinorOpcode))) {
 	ReqCode = (unsigned char)extEntry->base;
 	ErrorBase = extEntry->errorBase;
-    } else
-	return;
+    }
 
     /* PC servers initialize the desktop colors (citems) here! */
-
-    RegisterRequestName(ReqCode, X_XevieQueryVersion,
-			XEVIENAME ":QueryVersion");
-    RegisterRequestName(ReqCode, X_XevieStart,
-			XEVIENAME ":Start");
-    RegisterRequestName(ReqCode, X_XevieEnd,
-			XEVIENAME ":End");
-    RegisterRequestName(ReqCode, X_XevieSend,
-			XEVIENAME ":Send");
-    RegisterRequestName(ReqCode, X_XevieSelectInput,
-			XEVIENAME ":SelectInput");
 }
 
 /*ARGSUSED*/
commit 687427179420b18a55a1a02b8a9f2a32ea8eac8d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:32:54 2007 -0500

    registry: Remove registry code from XC-MISC extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index ba0402c..44d2b19 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -39,7 +39,6 @@ from The Open Group.
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "swaprep.h"
-#include "registry.h"
 #include <X11/extensions/xcmiscstr.h>
 #include "modinit.h"
 
@@ -65,19 +64,9 @@ static DISPATCH_PROC(SProcXCMiscGetXIDRange);
 void
 XCMiscExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-
-    if (!(extEntry = AddExtension(XCMiscExtensionName, 0, 0,
-				ProcXCMiscDispatch, SProcXCMiscDispatch,
-				XCMiscResetProc, StandardMinorOpcode)))
-	return;
-
-    RegisterRequestName(extEntry->base, X_XCMiscGetVersion,
-			XCMiscExtensionName ":GetVersion");
-    RegisterRequestName(extEntry->base, X_XCMiscGetXIDRange,
-			XCMiscExtensionName ":GetXIDRange");
-    RegisterRequestName(extEntry->base, X_XCMiscGetXIDList,
-			XCMiscExtensionName ":GetXIDList");
+    AddExtension(XCMiscExtensionName, 0, 0,
+		 ProcXCMiscDispatch, SProcXCMiscDispatch,
+		 XCMiscResetProc, StandardMinorOpcode))
 }
 
 /*ARGSUSED*/
commit 4b0274e8f712e51b18618a2a0bdbe03b17b9736b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:25:15 2007 -0500

    Revert "registry: Register SYNC extension protocol names."
    
    This reverts commit 9f597f6c87e0b14cc382d8e5929e42f822db4329.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/sync.c b/Xext/sync.c
index 7290147..10d4481 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -67,7 +67,6 @@ PERFORMANCE OF THIS SOFTWARE.
 #include "dixstruct.h"
 #include "resource.h"
 #include "opaque.h"
-#include "registry.h"
 #define _SYNC_SERVER
 #include <X11/extensions/sync.h>
 #include <X11/extensions/syncstr.h>
@@ -2412,45 +2411,6 @@ SyncExtensionInit(INITARGS)
     fprintf(stderr, "Sync Extension %d.%d\n",
 	    SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION);
 #endif
-
-    RegisterRequestName(extEntry->base, X_SyncInitialize,
-			SYNC_NAME ":Initialize");
-    RegisterRequestName(extEntry->base, X_SyncListSystemCounters,
-			SYNC_NAME ":ListSystemCounters");
-    RegisterRequestName(extEntry->base, X_SyncCreateCounter,
-			SYNC_NAME ":CreateCounter");
-    RegisterRequestName(extEntry->base, X_SyncSetCounter,
-			SYNC_NAME ":SetCounter");
-    RegisterRequestName(extEntry->base, X_SyncChangeCounter,
-			SYNC_NAME ":ChangeCounter");
-    RegisterRequestName(extEntry->base, X_SyncQueryCounter,
-			SYNC_NAME ":QueryCounter");
-    RegisterRequestName(extEntry->base, X_SyncDestroyCounter,
-			SYNC_NAME ":DestroyCounter");
-    RegisterRequestName(extEntry->base, X_SyncAwait,
-			SYNC_NAME ":Await");
-    RegisterRequestName(extEntry->base, X_SyncCreateAlarm,
-			SYNC_NAME ":CreateAlarm");
-    RegisterRequestName(extEntry->base, X_SyncChangeAlarm,
-			SYNC_NAME ":ChangeAlarm");
-    RegisterRequestName(extEntry->base, X_SyncQueryAlarm,
-			SYNC_NAME ":QueryAlarm");
-    RegisterRequestName(extEntry->base, X_SyncDestroyAlarm,
-			SYNC_NAME ":DestroyAlarm");
-    RegisterRequestName(extEntry->base, X_SyncSetPriority,
-			SYNC_NAME ":SetPriority");
-    RegisterRequestName(extEntry->base, X_SyncGetPriority,
-			SYNC_NAME ":GetPriority");
-
-    RegisterEventName(SyncEventBase + XSyncCounterNotify,
-		      SYNC_NAME ":CounterNotify");
-    RegisterEventName(SyncEventBase + XSyncAlarmNotify,
-		      SYNC_NAME ":AlarmNotify");
-
-    RegisterErrorName(SyncErrorBase + XSyncBadCounter,
-		      SYNC_NAME ":BadCounter");
-    RegisterErrorName(SyncErrorBase + XSyncBadAlarm,
-		      SYNC_NAME ":BadAlarm");
 }
 
 
commit 4c7cf5aa4c802dcde895c723879a80a87620c0f7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:23:57 2007 -0500

    Revert "registry: Register SHM extension protocol names."
    
    This reverts commit 2c9646ad4e65bb061d910c9e2b1a8a978f21fa17.
    
    Moving all the names to dix/registry.c

diff --git a/Xext/shm.c b/Xext/shm.c
index dfe759f..e3d7a23 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -59,7 +59,6 @@ in this Software without prior written authorization from The Open Group.
 #include "servermd.h"
 #include "shmint.h"
 #include "xace.h"
-#include "registry.h"
 #define _XSHM_SERVER_
 #include <X11/extensions/shmstr.h>
 #include <X11/Xfuncproto.h>
@@ -274,27 +273,7 @@ ShmExtensionInit(INITARGS)
 	ShmCompletionCode = extEntry->eventBase;
 	BadShmSegCode = extEntry->errorBase;
 	EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent;
-    } else
-	return;
-
-    RegisterRequestName(ShmReqCode, X_ShmQueryVersion,
-			SHMNAME ":QueryVersion");
-    RegisterRequestName(ShmReqCode, X_ShmAttach,
-			SHMNAME ":Attach");
-    RegisterRequestName(ShmReqCode, X_ShmDetach,
-			SHMNAME ":Detach");
-    RegisterRequestName(ShmReqCode, X_ShmPutImage,
-			SHMNAME ":PutImage");
-    RegisterRequestName(ShmReqCode, X_ShmGetImage,
-			SHMNAME ":GetImage");
-    RegisterRequestName(ShmReqCode, X_ShmCreatePixmap,
-			SHMNAME ":CreatePixmap");
-
-    RegisterEventName(extEntry->eventBase + ShmCompletion,
-		      SHMNAME ":Completion");
-
-    RegisterErrorName(extEntry->errorBase + BadShmSeg,
-		      SHMNAME ":BadShmSeg");
+    }
 }
 
 /*ARGSUSED*/
commit 67e82e306f67a215c6c89868cc1d3649747bd93d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:22:59 2007 -0500

    Revert "registry: Register SHAPE extension protocol names."
    
    This reverts commit 4e274e90e16b1d954391e1af3e2074fb10f70ee7.
    
    Moving all the names to dix/registry.c

diff --git a/Xext/shape.c b/Xext/shape.c
index 567737c..e84eb34 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -43,7 +43,6 @@ in this Software without prior written authorization from The Open Group.
 #include "dixstruct.h"
 #include "resource.h"
 #include "opaque.h"
-#include "registry.h"
 #define _SHAPE_SERVER_	/* don't want Xlib structures */
 #include <X11/extensions/shapestr.h>
 #include "regionstr.h"
@@ -112,6 +111,9 @@ static DISPATCH_PROC(SProcShapeSelectInput);
 #include "panoramiXsrv.h"
 #endif
 
+#if 0
+static unsigned char ShapeReqCode = 0;
+#endif
 static int ShapeEventBase = 0;
 static RESTYPE ClientType, EventType; /* resource types for event masks */
 
@@ -152,32 +154,12 @@ ShapeExtensionInit(void)
 				 ProcShapeDispatch, SProcShapeDispatch,
 				 ShapeResetProc, StandardMinorOpcode)))
     {
+#if 0
+	ShapeReqCode = (unsigned char)extEntry->base;
+#endif
 	ShapeEventBase = extEntry->eventBase;
 	EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_ShapeQueryVersion,
-			SHAPENAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_ShapeRectangles,
-			SHAPENAME ":Rectangles");
-    RegisterRequestName(extEntry->base, X_ShapeMask,
-			SHAPENAME ":Mask");
-    RegisterRequestName(extEntry->base, X_ShapeCombine,
-			SHAPENAME ":Combine");
-    RegisterRequestName(extEntry->base, X_ShapeOffset,
-			SHAPENAME ":Offset");
-    RegisterRequestName(extEntry->base, X_ShapeQueryExtents,
-			SHAPENAME ":QueryExtents");
-    RegisterRequestName(extEntry->base, X_ShapeSelectInput,
-			SHAPENAME ":SelectInput");
-    RegisterRequestName(extEntry->base, X_ShapeInputSelected,
-			SHAPENAME ":InputSelected");
-    RegisterRequestName(extEntry->base, X_ShapeGetRectangles,
-			SHAPENAME ":GetRectangles");
-
-    RegisterEventName(ShapeEventBase + ShapeNotify,
-		      SHAPENAME ":Notify");
+    }
 }
 
 /*ARGSUSED*/
commit 8583bf78ad056ffe2d83b54e5c9a0a217e425a7b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:21:09 2007 -0500

    registry: Remove registry code from XC-SECURITY extension.
    
    Moving all the names to dix/registry.c

diff --git a/Xext/security.c b/Xext/security.c
index eef4f69..6aab3a3 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1114,20 +1114,4 @@ SecurityExtensionInit(INITARGS)
 
     /* Label objects that were created before we could register ourself */
     SecurityLabelInitial();
-
-    /* Register protocol names */
-    RegisterRequestName(extEntry->base, X_SecurityQueryVersion,
-			SECURITY_EXTENSION_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_SecurityGenerateAuthorization,
-			SECURITY_EXTENSION_NAME ":GenerateAuthorization");
-    RegisterRequestName(extEntry->base, X_SecurityRevokeAuthorization,
-			SECURITY_EXTENSION_NAME ":RevokeAuthorization");
-
-    RegisterEventName(SecurityEventBase + XSecurityAuthorizationRevoked,
-		      SECURITY_EXTENSION_NAME ":AuthorizationRevoked");
-
-    RegisterErrorName(SecurityErrorBase + XSecurityBadAuthorization,
-		      SECURITY_EXTENSION_NAME ":BadAuthorization");
-    RegisterErrorName(SecurityErrorBase + XSecurityBadAuthorizationProtocol,
-		      SECURITY_EXTENSION_NAME ":BadAuthorizationProtocol");
 }
commit 55744d8e5d7bf1ff27cd25de54e14e799dd1a70a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:19:44 2007 -0500

    Revert "registry: Register MIT-SCREEN-SAVER extension protocol names."
    
    This reverts commit 58c3240fcbec23aad122e1c340f6bb6d3b18f779.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/saver.c b/Xext/saver.c
index 43dd3e2..20dbc92 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -49,7 +49,6 @@ in this Software without prior written authorization from the X Consortium.
 #include "cursorstr.h"
 #include "colormapst.h"
 #include "xace.h"
-#include "registry.h"
 #ifdef PANORAMIX
 #include "panoramiX.h"
 #include "panoramiXsrv.h"
@@ -63,6 +62,9 @@ in this Software without prior written authorization from the X Consortium.
 
 #include "modinit.h"
 
+#if 0
+static unsigned char ScreenSaverReqCode = 0;
+#endif
 static int ScreenSaverEventBase = 0;
 
 static DISPATCH_PROC(ProcScreenSaverQueryInfo);
@@ -272,26 +274,12 @@ ScreenSaverExtensionInit(INITARGS)
 				 ProcScreenSaverDispatch, SProcScreenSaverDispatch,
 				 ScreenSaverResetProc, StandardMinorOpcode)))
     {
+#if 0
+	ScreenSaverReqCode = (unsigned char)extEntry->base;
+#endif
 	ScreenSaverEventBase = extEntry->eventBase;
 	EventSwapVector[ScreenSaverEventBase] = (EventSwapPtr) SScreenSaverNotifyEvent;
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_ScreenSaverQueryVersion,
-			ScreenSaverName ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_ScreenSaverQueryInfo,
-			ScreenSaverName ":QueryInfo");
-    RegisterRequestName(extEntry->base, X_ScreenSaverSelectInput,
-			ScreenSaverName ":SelectInput");
-    RegisterRequestName(extEntry->base, X_ScreenSaverSetAttributes,
-			ScreenSaverName ":SetAttributes");
-    RegisterRequestName(extEntry->base, X_ScreenSaverUnsetAttributes,
-			ScreenSaverName ":UnsetAttributes");
-    RegisterRequestName(extEntry->base, X_ScreenSaverSuspend,
-			ScreenSaverName ":Suspend");
-
-    RegisterEventName(ScreenSaverEventBase + ScreenSaverNotify,
-		      ScreenSaverName ":Notify");
+    }
 }
 
 /*ARGSUSED*/
commit 36ef45928c783292cef18acfdd83ae057826c989
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:18:01 2007 -0500

    registry: Remove registry code from MIT-MISC extension.
    
    Moving all the names to dix/registry.c

diff --git a/Xext/mitmisc.c b/Xext/mitmisc.c
index 0b23152..a5f3b0f 100644
--- a/Xext/mitmisc.c
+++ b/Xext/mitmisc.c
@@ -38,7 +38,6 @@ in this Software without prior written authorization from The Open Group.
 #include "os.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
-#include "registry.h"
 #define _MITMISC_SERVER_
 #include <X11/extensions/mitmiscstr.h>
 #include "modinit.h"
@@ -57,17 +56,9 @@ static DISPATCH_PROC(SProcMITSetBugMode);
 void
 MITMiscExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-
-    if (!(extEntry = AddExtension(MITMISCNAME, 0, 0,
-				  ProcMITDispatch, SProcMITDispatch,
-				  MITResetProc, StandardMinorOpcode)))
-	return;
-
-    RegisterRequestName(extEntry->base, X_MITSetBugMode,
-			MITMISCNAME ":SetBugMode");
-    RegisterRequestName(extEntry->base, X_MITGetBugMode,
-			MITMISCNAME ":GetBugMode");
+    AddExtension(MITMISCNAME, 0, 0,
+		 ProcMITDispatch, SProcMITDispatch,
+		 MITResetProc, StandardMinorOpcode)))
 }
 
 /*ARGSUSED*/
commit 816e6e612e4bc3cea1e67e7ea79d5b640458011f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:15:37 2007 -0500

    Revert "registry: Register Multibuffer extension protocol names."
    
    This reverts commit 3877faf7d9fe00ed634077e38a198ae4b91a2bb4.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/mbuf.c b/Xext/mbuf.c
index ba99f3f..9f17c86 100644
--- a/Xext/mbuf.c
+++ b/Xext/mbuf.c
@@ -43,7 +43,6 @@ in this Software without prior written authorization from The Open Group.
 #include "resource.h"
 #include "opaque.h"
 #include "sleepuntil.h"
-#include "registry.h"
 #define _MULTIBUF_SERVER_	/* don't want Xlib structures */
 #include <X11/extensions/multibufst.h>
 
@@ -255,39 +254,7 @@ MultibufferExtensionInit()
 	MultibufferErrorBase = extEntry->errorBase;
 	EventSwapVector[MultibufferEventBase + MultibufferClobberNotify] = (EventSwapPtr) SClobberNotifyEvent;
 	EventSwapVector[MultibufferEventBase + MultibufferUpdateNotify] = (EventSwapPtr) SUpdateNotifyEvent;
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_MbufGetBufferVersion,
-			MULTIBUFFER_PROTOCOL_NAME ":GetBufferVersion");
-    RegisterRequestName(extEntry->base, X_MbufCreateImageBuffers,
-			MULTIBUFFER_PROTOCOL_NAME ":CreateImageBuffers");
-    RegisterRequestName(extEntry->base, X_MbufDestroyImageBuffers,
-			MULTIBUFFER_PROTOCOL_NAME ":DestroyImageBuffers");
-    RegisterRequestName(extEntry->base, X_MbufDisplayImageBuffers,
-			MULTIBUFFER_PROTOCOL_NAME ":DisplayImageBuffers");
-    RegisterRequestName(extEntry->base, X_MbufSetMBufferAttributes,
-			MULTIBUFFER_PROTOCOL_NAME ":SetMBufferAttributes");
-    RegisterRequestName(extEntry->base, X_MbufGetMBufferAttributes,
-			MULTIBUFFER_PROTOCOL_NAME ":GetMBufferAttributes");
-    RegisterRequestName(extEntry->base, X_MbufSetBufferAttributes,
-			MULTIBUFFER_PROTOCOL_NAME ":SetBufferAttributes");
-    RegisterRequestName(extEntry->base, X_MbufGetBufferAttributes,
-			MULTIBUFFER_PROTOCOL_NAME ":GetBufferAttributes");
-    RegisterRequestName(extEntry->base, X_MbufGetBufferInfo,
-			MULTIBUFFER_PROTOCOL_NAME ":GetBufferInfo");
-    RegisterRequestName(extEntry->base, X_MbufCreateStereoWindow,
-			MULTIBUFFER_PROTOCOL_NAME ":CreateStereoWindow");
-    RegisterRequestName(extEntry->base, X_MbufClearImageBufferArea,
-			MULTIBUFFER_PROTOCOL_NAME ":ClearImageBufferArea");
-
-    RegisterEventName(MultibufferEventBase + MultibufferClobberNotify,
-		      MULTIBUFFER_PROTOCOL_NAME ":ClobberNotify");
-    RegisterEventName(MultibufferEventBase + MultibufferUpdateNotify,
-		      MULTIBUFFER_PROTOCOL_NAME ":UpdateNotify");
-
-    RegisterErrorName(MultibufferErrorBase + BadBuffer,
-		      MULTIBUFFER_PROTOCOL_NAME ":BadBuffer");
+    }
 }
 
 /*ARGSUSED*/
commit 40a0da044e911ea51de003f3621331ffbe2842bc
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:13:43 2007 -0500

    registry: Remove registry code from Fontcache extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/fontcache.c b/Xext/fontcache.c
index 9fae2d7..06b0c85 100644
--- a/Xext/fontcache.c
+++ b/Xext/fontcache.c
@@ -42,7 +42,6 @@
 #include "scrnintstr.h"
 #include "inputstr.h"
 #include "servermd.h"
-#include "registry.h"
 #define _FONTCACHE_SERVER_
 #include <X11/extensions/fontcacheP.h>
 #include <X11/extensions/fontcachstr.h>
@@ -71,31 +70,9 @@ static DISPATCH_PROC(SProcFontCacheChangeCacheSettings);
 void
 FontCacheExtensionInit(INITARGS)
 {
-    ExtensionEntry* extEntry;
-
-    if (!
-	(extEntry = AddExtension(FONTCACHENAME,
-				FontCacheNumberEvents,
-				FontCacheNumberErrors,
-				ProcFontCacheDispatch,
-				SProcFontCacheDispatch,
-				FontCacheResetProc,
-				StandardMinorOpcode)))
-	return;
-
-    RegisterRequestName(extEntry->base, X_FontCacheQueryVersion,
-			FONTCACHENAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_FontCacheGetCacheSettings,
-			FONTCACHENAME ":GetCacheSettings");
-    RegisterRequestName(extEntry->base, X_FontCacheChangeCacheSettings,
-			FONTCACHENAME ":ChangeCacheSettings");
-    RegisterRequestName(extEntry->base, X_FontCacheGetCacheStatistics,
-			FONTCACHENAME ":GetCacheStatistics");
-
-    RegisterErrorName(extEntry->errorBase + FontCacheBadProtocol,
-		      FONTCACHENAME ":BadProtocol");
-    RegisterErrorName(extEntry->errorBase + FontCacheCannotAllocMemory,
-		      FONTCACHENAME ":CannotAllocMemory");
+    AddExtension(FONTCACHENAME, FontCacheNumberEvents, FontCacheNumberErrors,
+		 ProcFontCacheDispatch, SProcFontCacheDispatch,
+		 FontCacheResetProc, StandardMinorOpcode)))
 }
 
 /*ARGSUSED*/
commit 46412baf60ed639ddc1d5fb601f73a75e39737f7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:11:06 2007 -0500

    registry: Remove registry code from EVI extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/EVI.c b/Xext/EVI.c
index b6752c0..6abd508 100644
--- a/Xext/EVI.c
+++ b/Xext/EVI.c
@@ -30,7 +30,6 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "dix.h"
-#include "registry.h"
 #define _XEVI_SERVER_
 #include <X11/extensions/XEVIstr.h>
 #include "EVIstruct.h"
@@ -189,9 +188,4 @@ EVIExtensionInit(INITARGS)
 	return;
 
     eviPriv = eviDDXInit();
-
-    RegisterRequestName(extEntry->base, X_EVIQueryVersion,
-			EVINAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_EVIGetVisualInfo,
-			EVINAME ":GetVisualInfo");
 }
commit 460c43032f05aad3f0f552901a52d199f61c7f4f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:08:18 2007 -0500

    registry: Remove registry code from DPMS extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/dpms.c b/Xext/dpms.c
index 613493a..d518a16 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -44,7 +44,6 @@ Equipment Corporation.
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "opaque.h"
-#include "registry.h"
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 #include <X11/extensions/dpmsstr.h>
@@ -74,29 +73,9 @@ static void DPMSResetProc(ExtensionEntry* extEntry);
 void
 DPMSExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-    
-    if (!(extEntry = AddExtension(DPMSExtensionName, 0, 0,
-				  ProcDPMSDispatch, SProcDPMSDispatch,
-				  DPMSResetProc, StandardMinorOpcode)))
-	return;
-
-    RegisterRequestName(extEntry->base, X_DPMSGetVersion,
-			DPMSExtensionName ":GetVersion");
-    RegisterRequestName(extEntry->base, X_DPMSCapable,
-			DPMSExtensionName ":Capable");
-    RegisterRequestName(extEntry->base, X_DPMSGetTimeouts,
-			DPMSExtensionName ":GetTimeouts");
-    RegisterRequestName(extEntry->base, X_DPMSSetTimeouts,
-			DPMSExtensionName ":SetTimeouts");
-    RegisterRequestName(extEntry->base, X_DPMSEnable,
-			DPMSExtensionName ":Enable");
-    RegisterRequestName(extEntry->base, X_DPMSDisable,
-			DPMSExtensionName ":Disable");
-    RegisterRequestName(extEntry->base, X_DPMSForceLevel,
-			DPMSExtensionName ":ForceLevel");
-    RegisterRequestName(extEntry->base, X_DPMSInfo,
-			DPMSExtensionName ":Info");
+    AddExtension(DPMSExtensionName, 0, 0,
+		 ProcDPMSDispatch, SProcDPMSDispatch,
+		 DPMSResetProc, StandardMinorOpcode)))
 }
 
 /*ARGSUSED*/
commit 76e89d45b497d4afa4e60e1d0ec50b62f54f6b88
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:06:40 2007 -0500

    registry: Remove registry code from TOG-CUP extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/cup.c b/Xext/cup.c
index 4adfc61..44c9664 100644
--- a/Xext/cup.c
+++ b/Xext/cup.c
@@ -39,7 +39,6 @@ in this Software without prior written authorization from The Open Group.
 #include "scrnintstr.h"
 #include "servermd.h"
 #include "swapreq.h"
-#include "registry.h"
 #define _XCUP_SERVER_
 #include <X11/extensions/Xcupstr.h>
 #include <X11/Xfuncproto.h>
@@ -136,13 +135,6 @@ XcupExtensionInit (INITARGS)
 	return;
 
     /* PC servers initialize the desktop colors (citems) here! */
-
-    RegisterRequestName(extEntry->base, X_XcupQueryVersion,
-			XCUPNAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_XcupGetReservedColormapEntries,
-			XCUPNAME ":GetReservedColormapEntries");
-    RegisterRequestName(extEntry->base, X_XcupStoreColors,
-			XCUPNAME ":StoreColors");
 }
 
 /*ARGSUSED*/
commit ce93c5772da52ab88faef7e5b661b681d5b60b1e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 18:03:57 2007 -0500

    registry: Remove registry code from BigRequests extension.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index 6303f38..fd8bcb8 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -37,7 +37,6 @@ from The Open Group.
 #include "os.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
-#include "registry.h"
 #include <X11/extensions/bigreqstr.h>
 #include "opaque.h"
 #include "modinit.h"
@@ -51,15 +50,9 @@ static DISPATCH_PROC(ProcBigReqDispatch);
 void
 BigReqExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-
-    if (!(extEntry = AddExtension(XBigReqExtensionName, 0, 0,
-				  ProcBigReqDispatch, ProcBigReqDispatch,
-				  BigReqResetProc, StandardMinorOpcode)))
-	return;
-
-    RegisterRequestName(extEntry->base, X_BigReqEnable,
-			XBigReqExtensionName ":Enable");
+    AddExtension(XBigReqExtensionName, 0, 0,
+		 ProcBigReqDispatch, ProcBigReqDispatch,
+		 BigReqResetProc, StandardMinorOpcode)))
 }
 
 /*ARGSUSED*/
commit 0756d1271209e6ae14cc641dddca095271b43150
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:59:40 2007 -0500

    Revert "registry: Register APPGROUP extension protocol names."
    
    This reverts commit b504678ba5407a6fd8d47d051305f7c3d5606dfe.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/appgroup.c b/Xext/appgroup.c
index 4fb4020..c40782d 100644
--- a/Xext/appgroup.c
+++ b/Xext/appgroup.c
@@ -39,7 +39,6 @@ from The Open Group.
 #include "windowstr.h"
 #include "colormapst.h"
 #include "servermd.h"
-#include "registry.h"
 #define _XAG_SERVER_
 #include <X11/extensions/Xagstr.h>
 #include "xacestr.h"
@@ -763,35 +762,14 @@ static void XagCallClientStateChange(
 void
 XagExtensionInit(INITARGS)
 {
-    ExtensionEntry *extEntry;
-
-    if ((extEntry = AddExtension (XAGNAME,
-				  0,
-				  XagNumberErrors,
-				  ProcXagDispatch,
-				  SProcXagDispatch,
-				  XagResetProc,
-				  StandardMinorOpcode))) {
+    if (AddExtension (XAGNAME,
+		      0,
+		      XagNumberErrors,
+		      ProcXagDispatch,
+		      SProcXagDispatch,
+		      XagResetProc,
+		      StandardMinorOpcode)) {
 	RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);
 	XaceRegisterCallback(XACE_AUTH_AVAIL, XagCallClientStateChange, NULL);
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_XagQueryVersion,
-			XAGNAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_XagCreate,
-			XAGNAME ":Create");
-    RegisterRequestName(extEntry->base, X_XagDestroy,
-			XAGNAME ":Destroy");
-    RegisterRequestName(extEntry->base, X_XagGetAttr,
-			XAGNAME ":GetAttr");
-    RegisterRequestName(extEntry->base, X_XagQuery,
-			XAGNAME ":Query");
-    RegisterRequestName(extEntry->base, X_XagCreateAssoc,
-			XAGNAME ":CreateAssoc");
-    RegisterRequestName(extEntry->base, X_XagDestroyAssoc,
-			XAGNAME ":DestroyAssoc");
-
-    RegisterErrorName(extEntry->errorBase + XagBadAppGroup,
-			XAGNAME ":BadAppGroup");
+    }
 }
commit 5aff37d1d69be493727856a29628bd782d50b90f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:57:06 2007 -0500

    Revert "registry: Register RENDER extension protocol names."
    
    This reverts commit 8964c6d8e14ae47798762191e359b2bf138ca32e.
    
    Moving all the names into dix/registry.c

diff --git a/render/render.c b/render/render.c
index 5fc91a9..db9168b 100644
--- a/render/render.c
+++ b/render/render.c
@@ -40,7 +40,6 @@
 #include "colormapst.h"
 #include "extnsionst.h"
 #include "servermd.h"
-#include "registry.h"
 #include <X11/extensions/render.h>
 #include <X11/extensions/renderproto.h>
 #include "picturestr.h"
@@ -263,95 +262,6 @@ RenderExtensionInit (void)
     RenderReqCode = (CARD8) extEntry->base;
 #endif
     RenderErrBase = extEntry->errorBase;
-
-    RegisterRequestName(extEntry->base, X_RenderQueryVersion,
-			RENDER_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_RenderQueryPictFormats,
-			RENDER_NAME ":QueryPictFormats");
-    RegisterRequestName(extEntry->base, X_RenderQueryPictIndexValues,
-			RENDER_NAME ":QueryPictIndexValues");
-    RegisterRequestName(extEntry->base, X_RenderQueryDithers,
-			RENDER_NAME ":QueryDithers");
-    RegisterRequestName(extEntry->base, X_RenderCreatePicture,
-			RENDER_NAME ":CreatePicture");
-    RegisterRequestName(extEntry->base, X_RenderChangePicture,
-			RENDER_NAME ":ChangePicture");
-    RegisterRequestName(extEntry->base, X_RenderSetPictureClipRectangles,
-			RENDER_NAME ":SetPictureClipRectangles");
-    RegisterRequestName(extEntry->base, X_RenderFreePicture,
-			RENDER_NAME ":FreePicture");
-    RegisterRequestName(extEntry->base, X_RenderComposite,
-			RENDER_NAME ":Composite");
-    RegisterRequestName(extEntry->base, X_RenderScale,
-			RENDER_NAME ":Scale");
-    RegisterRequestName(extEntry->base, X_RenderTrapezoids,
-			RENDER_NAME ":Trapezoids");
-    RegisterRequestName(extEntry->base, X_RenderTriangles,
-			RENDER_NAME ":Triangles");
-    RegisterRequestName(extEntry->base, X_RenderTriStrip,
-			RENDER_NAME ":TriStrip");
-    RegisterRequestName(extEntry->base, X_RenderTriFan,
-			RENDER_NAME ":TriFan");
-    RegisterRequestName(extEntry->base, X_RenderColorTrapezoids,
-			RENDER_NAME ":ColorTrapezoids");
-    RegisterRequestName(extEntry->base, X_RenderColorTriangles,
-			RENDER_NAME ":ColorTriangles");
-    RegisterRequestName(extEntry->base, X_RenderCreateGlyphSet,
-			RENDER_NAME ":CreateGlyphSet");
-    RegisterRequestName(extEntry->base, X_RenderReferenceGlyphSet,
-			RENDER_NAME ":ReferenceGlyphSet");
-    RegisterRequestName(extEntry->base, X_RenderFreeGlyphSet,
-			RENDER_NAME ":FreeGlyphSet");
-    RegisterRequestName(extEntry->base, X_RenderAddGlyphs,
-			RENDER_NAME ":AddGlyphs");
-    RegisterRequestName(extEntry->base, X_RenderAddGlyphsFromPicture,
-			RENDER_NAME ":AddGlyphsFromPicture");
-    RegisterRequestName(extEntry->base, X_RenderFreeGlyphs,
-			RENDER_NAME ":FreeGlyphs");
-    RegisterRequestName(extEntry->base, X_RenderCompositeGlyphs8,
-			RENDER_NAME ":CompositeGlyphs8");
-    RegisterRequestName(extEntry->base, X_RenderCompositeGlyphs16,
-			RENDER_NAME ":CompositeGlyphs16");
-    RegisterRequestName(extEntry->base, X_RenderCompositeGlyphs32,
-			RENDER_NAME ":CompositeGlyphs32");
-    RegisterRequestName(extEntry->base, X_RenderFillRectangles,
-			RENDER_NAME ":FillRectangles");
-    /* 0.5 */
-    RegisterRequestName(extEntry->base, X_RenderCreateCursor,
-			RENDER_NAME ":CreateCursor");
-    /* 0.6 */
-    RegisterRequestName(extEntry->base, X_RenderSetPictureTransform,
-			RENDER_NAME ":SetPictureTransform");
-    RegisterRequestName(extEntry->base, X_RenderQueryFilters,
-			RENDER_NAME ":QueryFilters");
-    RegisterRequestName(extEntry->base, X_RenderSetPictureFilter,
-			RENDER_NAME ":SetPictureFilter");
-    /* 0.8 */
-    RegisterRequestName(extEntry->base, X_RenderCreateAnimCursor,
-			RENDER_NAME ":CreateAnimCursor");
-    /* 0.9 */
-    RegisterRequestName(extEntry->base, X_RenderAddTraps,
-			RENDER_NAME ":AddTraps");
-    /* 0.10 */
-    RegisterRequestName(extEntry->base, X_RenderCreateSolidFill,
-			RENDER_NAME ":CreateSolidFill");
-    RegisterRequestName(extEntry->base, X_RenderCreateLinearGradient,
-			RENDER_NAME ":CreateLinearGradient");
-    RegisterRequestName(extEntry->base, X_RenderCreateRadialGradient,
-			RENDER_NAME ":CreateRadialGradient");
-    RegisterRequestName(extEntry->base, X_RenderCreateConicalGradient,
-			RENDER_NAME ":CreateConicalGradient");
-
-    RegisterErrorName(RenderErrBase + BadPictFormat,
-		      RENDER_NAME ":BadPictFormat");
-    RegisterErrorName(RenderErrBase + BadPicture,
-		      RENDER_NAME ":BadPicture");
-    RegisterErrorName(RenderErrBase + BadPictOp,
-		      RENDER_NAME ":BadPictOp");
-    RegisterErrorName(RenderErrBase + BadGlyphSet,
-		      RENDER_NAME ":BadGlyphSet");
-    RegisterErrorName(RenderErrBase + BadGlyph,
-		      RENDER_NAME ":BadGlyph");
 }
 
 static void
commit e585a2ddb495b50a53e15cccc368ca0858fc9d23
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:55:47 2007 -0500

    Revert "registry: Register Record extension protocol names."
    
    This reverts commit ea09c9acc8f0d5577f54c864ff88b7f03d93b2f4.
    
    Moving all the names into dix/registry.c

diff --git a/record/record.c b/record/record.c
index 2ca3782..debe3c4 100644
--- a/record/record.c
+++ b/record/record.c
@@ -43,7 +43,6 @@ and Jim Haggerty of Metheus.
 #include <X11/extensions/recordstr.h>
 #include "set.h"
 #include "swaprep.h"
-#include "registry.h"
 
 #include <stdio.h>
 #include <assert.h>
@@ -2966,24 +2965,5 @@ RecordExtensionInit(void)
     }
     RecordErrorBase = extentry->errorBase;
 
-    RegisterRequestName(extentry->base, X_RecordQueryVersion,
-			RECORD_NAME ":QueryVersion");
-    RegisterRequestName(extentry->base, X_RecordCreateContext,
-			RECORD_NAME ":CreateContext");
-    RegisterRequestName(extentry->base, X_RecordRegisterClients,
-			RECORD_NAME ":RegisterClients");
-    RegisterRequestName(extentry->base, X_RecordUnregisterClients,
-			RECORD_NAME ":UnregisterClients");
-    RegisterRequestName(extentry->base, X_RecordGetContext,
-			RECORD_NAME ":GetContext");
-    RegisterRequestName(extentry->base, X_RecordEnableContext,
-			RECORD_NAME ":EnableContext");
-    RegisterRequestName(extentry->base, X_RecordDisableContext,
-			RECORD_NAME ":DisableContext");
-    RegisterRequestName(extentry->base, X_RecordFreeContext,
-			RECORD_NAME ":FreeContext");
-
-    RegisterErrorName(RecordErrorBase + XRecordBadContext,
-			RECORD_NAME ":BadContext");
 } /* RecordExtensionInit */
 
commit d4577e485367468227e031eb434b739eff7b5e9a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:51:27 2007 -0500

    Revert "registry: Register RANDR extension protocol names."
    
    This reverts commit c827db57e4d9ca14c82b099dcfc9b7a0c0b5ba0a.
    
    Moving all the names into dix/registry.c

diff --git a/randr/randr.c b/randr/randr.c
index d5b9819..bc2b995 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -32,7 +32,6 @@
 #endif
 
 #include "randrstr.h"
-#include "registry.h"
 
 /* From render.h */
 #ifndef SubPixelUnknown
@@ -352,73 +351,6 @@ RRExtensionInit (void)
 #ifdef PANORAMIX
     RRXineramaExtensionInit();
 #endif
-
-    RegisterRequestName(extEntry->base, X_RRQueryVersion,
-			RANDR_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_RROldGetScreenInfo,
-			RANDR_NAME ":OldGetScreenInfo");
-    RegisterRequestName(extEntry->base, X_RR1_0SetScreenConfig,
-			RANDR_NAME ":1_0SetScreenConfig");
-    RegisterRequestName(extEntry->base, X_RRSetScreenConfig,
-			RANDR_NAME ":SetScreenConfig");
-    RegisterRequestName(extEntry->base, X_RROldScreenChangeSelectInput,
-			RANDR_NAME ":OldScreenChangeSelectInput");
-    RegisterRequestName(extEntry->base, X_RRSelectInput,
-			RANDR_NAME ":SelectInput");
-    RegisterRequestName(extEntry->base, X_RRGetScreenInfo,
-			RANDR_NAME ":GetScreenInfo");
-    /* V1.2 additions */
-    RegisterRequestName(extEntry->base, X_RRGetScreenSizeRange,
-			RANDR_NAME ":GetScreenSizeRange");
-    RegisterRequestName(extEntry->base, X_RRSetScreenSize,
-			RANDR_NAME ":SetScreenSize");
-    RegisterRequestName(extEntry->base, X_RRGetScreenResources,
-			RANDR_NAME ":GetScreenResources");
-    RegisterRequestName(extEntry->base, X_RRGetOutputInfo,
-			RANDR_NAME ":GetOutputInfo");
-    RegisterRequestName(extEntry->base, X_RRListOutputProperties,
-			RANDR_NAME ":ListOutputProperties");
-    RegisterRequestName(extEntry->base, X_RRQueryOutputProperty,
-			RANDR_NAME ":QueryOutputProperty");
-    RegisterRequestName(extEntry->base, X_RRConfigureOutputProperty,
-			RANDR_NAME ":ConfigureOutputProperty");
-    RegisterRequestName(extEntry->base, X_RRChangeOutputProperty,
-			RANDR_NAME ":ChangeOutputProperty");
-    RegisterRequestName(extEntry->base, X_RRDeleteOutputProperty,
-			RANDR_NAME ":DeleteOutputProperty");
-    RegisterRequestName(extEntry->base, X_RRGetOutputProperty,
-			RANDR_NAME ":GetOutputProperty");
-    RegisterRequestName(extEntry->base, X_RRCreateMode,
-			RANDR_NAME ":CreateMode");
-    RegisterRequestName(extEntry->base, X_RRDestroyMode,
-			RANDR_NAME ":DestroyMode");
-    RegisterRequestName(extEntry->base, X_RRAddOutputMode,
-			RANDR_NAME ":AddOutputMode");
-    RegisterRequestName(extEntry->base, X_RRDeleteOutputMode,
-			RANDR_NAME ":DeleteOutputMode");
-    RegisterRequestName(extEntry->base, X_RRGetCrtcInfo,
-			RANDR_NAME ":GetCrtcInfo");
-    RegisterRequestName(extEntry->base, X_RRSetCrtcConfig,
-			RANDR_NAME ":SetCrtcConfig");
-    RegisterRequestName(extEntry->base, X_RRGetCrtcGammaSize,
-			RANDR_NAME ":GetCrtcGammaSize");
-    RegisterRequestName(extEntry->base, X_RRGetCrtcGamma,
-			RANDR_NAME ":GetCrtcGamma");
-    RegisterRequestName(extEntry->base, X_RRSetCrtcGamma,
-			RANDR_NAME ":SetCrtcGamma");
-
-    RegisterEventName(RREventBase + RRScreenChangeNotify,
-		      RANDR_NAME ":ScreenChangeNotify");
-    /* V1.2 additions */
-    RegisterEventName(RREventBase + RRNotify,
-		      RANDR_NAME ":Notify");
-
-    RegisterErrorName(RRErrorBase + BadRROutput,
-		      RANDR_NAME ":BadRROutput");
-    RegisterErrorName(RRErrorBase + BadRRCrtc,
-		      RANDR_NAME ":BadRRCrtc");
-    RegisterErrorName(RRErrorBase + BadRRMode,
-		      RANDR_NAME ":BadRRMode");
 }
 
 static int
commit a541e826c9310d3051e53834833c6c3a08654148
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:50:26 2007 -0500

    Revert "registry: Register WINDOWSWM extension protocol names."
    
    This reverts commit 4c3285c883cc50a91bc5262bbc9d073d816f860a.
    
    Moving all the names into dix/registry.c

diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c
index 1356465..e1994de 100755
--- a/hw/xwin/winwindowswm.c
+++ b/hw/xwin/winwindowswm.c
@@ -41,7 +41,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "scrnintstr.h"
 #include "servermd.h"
 #include "swaprep.h"
-#include "registry.h"
 #define _WINDOWSWM_SERVER_
 #include "windowswmstr.h"
 
@@ -106,35 +105,7 @@ winWindowsWMExtensionInit ()
       WMErrorBase = extEntry->errorBase;
       WMEventBase = extEntry->eventBase;
       EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
-    } else
-      return;
-
-  RegisterRequestName(WMReqCode, X_WindowsWMQueryVersion,
-		      WINDOWSWMNAME ":QueryVersion");
-  RegisterRequestName(WMReqCode, X_WindowsWMFrameGetRect,
-		      WINDOWSWMNAME ":FrameGetRect");
-  RegisterRequestName(WMReqCode, X_WindowsWMFrameDraw,
-		      WINDOWSWMNAME ":FrameDraw");
-  RegisterRequestName(WMReqCode, X_WindowsWMFrameSetTitle,
-		      WINDOWSWMNAME ":FrameSetTitle");
-  RegisterRequestName(WMReqCode, X_WindowsWMDisableUpdate,
-		      WINDOWSWMNAME ":DisableUpdate");
-  RegisterRequestName(WMReqCode, X_WindowsWMReenableUpdate,
-		      WINDOWSWMNAME ":ReenableUpdate");
-  RegisterRequestName(WMReqCode, X_WindowsWMSelectInput,
-		      WINDOWSWMNAME ":SelectInput");
-  RegisterRequestName(WMReqCode, X_WindowsWMSetFrontProcess,
-		      WINDOWSWMNAME ":SetFrontProcess");
-
-  RegisterEventName(WMEventBase + WindowsWMControllerNotify,
-		    WINDOWSWMNAME ":ControllerNotify");
-  RegisterEventName(WMEventBase + WindowsWMActivationNotify,
-		    WINDOWSWMNAME ":ActivationNotify");
-
-  RegisterErrorName(WMErrorBase + WindowsWMClientNotLocal,
-		    WINDOWSWMNAME ":ClientNotLocal");
-  RegisterErrorName(WMErrorBase + WindowsWMOperationNotSupported,
-		    WINDOWSWMNAME ":OperationNotSupported");
+    }
 }
 
 /*ARGSUSED*/
commit 993595430bd0580ab4d936be6b70fb91b8bb1d16
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:48:46 2007 -0500

    Revert "registry: Register XF86DRI extension protocol names."
    
    This reverts commit b7786724080fd3928ef7b8c294346661d7ffd90b.
    
    Moving all the names into dix/registry.c

diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index d16910f..ea11b38 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -53,7 +53,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "cursorstr.h"
 #include "scrnintstr.h"
 #include "servermd.h"
-#include "registry.h"
 #define _XF86DRI_SERVER_
 #include "xf86dristr.h"
 #include "swaprep.h"
@@ -113,42 +112,7 @@ XFree86DRIExtensionInit(void)
 				 StandardMinorOpcode))) {
 	DRIReqCode = (unsigned char)extEntry->base;
 	DRIErrorBase = extEntry->errorBase;
-    } else
-	return;
-
-    RegisterRequestName(DRIReqCode, X_XF86DRIQueryVersion,
-			XF86DRINAME ":QueryVersion");
-    RegisterRequestName(DRIReqCode, X_XF86DRIQueryDirectRenderingCapable,
-			XF86DRINAME ":QueryDirectRenderingCapable");
-    RegisterRequestName(DRIReqCode, X_XF86DRIOpenConnection,
-			XF86DRINAME ":OpenConnection");
-    RegisterRequestName(DRIReqCode, X_XF86DRICloseConnection,
-			XF86DRINAME ":CloseConnection");
-    RegisterRequestName(DRIReqCode, X_XF86DRIGetClientDriverName,
-			XF86DRINAME ":GetClientDriverName");
-    RegisterRequestName(DRIReqCode, X_XF86DRICreateContext,
-			XF86DRINAME ":CreateContext");
-    RegisterRequestName(DRIReqCode, X_XF86DRIDestroyContext,
-			XF86DRINAME ":DestroyContext");
-    RegisterRequestName(DRIReqCode, X_XF86DRICreateDrawable,
-			XF86DRINAME ":CreateDrawable");
-    RegisterRequestName(DRIReqCode, X_XF86DRIDestroyDrawable,
-			XF86DRINAME ":DestroyDrawable");
-    RegisterRequestName(DRIReqCode, X_XF86DRIGetDrawableInfo,
-			XF86DRINAME ":GetDrawableInfo");
-    RegisterRequestName(DRIReqCode, X_XF86DRIGetDeviceInfo,
-			XF86DRINAME ":GetDeviceInfo");
-    RegisterRequestName(DRIReqCode, X_XF86DRIAuthConnection,
-			XF86DRINAME ":AuthConnection");
-    RegisterRequestName(DRIReqCode, X_XF86DRIOpenFullScreen,
-			XF86DRINAME ":OpenFullScreen");
-    RegisterRequestName(DRIReqCode, X_XF86DRICloseFullScreen,
-			XF86DRINAME ":CloseFullScreen");
-
-    RegisterErrorName(DRIErrorBase + XF86DRIClientNotLocal,
-		      XF86DRINAME ":ClientNotLocal");
-    RegisterErrorName(DRIErrorBase + XF86DRIOperationNotSupported,
-		      XF86DRINAME ":OperationNotSupported");
+    }
 }
 
 /*ARGSUSED*/
commit 6b73c215c9d612534af290230b2e914d42d819cd
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:47:30 2007 -0500

    Revert "registry: Register XF86VidMode extension protocol names."
    
    This reverts commit 960677e876c068400fb45e1764bb5470cd8c389f.
    
    Moving all the names into dix/registry.c

diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 17ba44a..718d40f 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -43,7 +43,6 @@ from Kaleb S. KEITHLEY
 #include "extnsionst.h"
 #include "scrnintstr.h"
 #include "servermd.h"
-#include "registry.h"
 #define _XF86VIDMODE_SERVER_
 #include <X11/extensions/xf86vmstr.h>
 #include "swaprep.h"
@@ -210,71 +209,7 @@ XFree86VidModeExtensionInit(void)
 	XF86VidModeEventBase = extEntry->eventBase;
 	EventSwapVector[XF86VidModeEventBase] = (EventSwapPtr)SXF86VidModeNotifyEvent;
 #endif
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_XF86VidModeQueryVersion,
-			XF86VIDMODENAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetModeLine,
-			XF86VIDMODENAME ":GetModeLine");
-    RegisterRequestName(extEntry->base, X_XF86VidModeModModeLine,
-			XF86VIDMODENAME ":ModModeLine");
-    RegisterRequestName(extEntry->base, X_XF86VidModeSwitchMode,
-			XF86VIDMODENAME ":SwitchMode");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetMonitor,
-			XF86VIDMODENAME ":GetMonitor");
-    RegisterRequestName(extEntry->base, X_XF86VidModeLockModeSwitch,
-			XF86VIDMODENAME ":LockModeSwitch");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetAllModeLines,
-			XF86VIDMODENAME ":GetAllModeLines");
-    RegisterRequestName(extEntry->base, X_XF86VidModeAddModeLine,
-			XF86VIDMODENAME ":AddModeLine");
-    RegisterRequestName(extEntry->base, X_XF86VidModeDeleteModeLine,
-			XF86VIDMODENAME ":DeleteModeLine");
-    RegisterRequestName(extEntry->base, X_XF86VidModeValidateModeLine,
-			XF86VIDMODENAME ":ValidateModeLine");
-    RegisterRequestName(extEntry->base, X_XF86VidModeSwitchToMode,
-			XF86VIDMODENAME ":SwitchToMode");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetViewPort,
-			XF86VIDMODENAME ":GetViewPort");
-    RegisterRequestName(extEntry->base, X_XF86VidModeSetViewPort,
-			XF86VIDMODENAME ":SetViewPort");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetDotClocks,
-			XF86VIDMODENAME ":GetDotClocks");
-    RegisterRequestName(extEntry->base, X_XF86VidModeSetClientVersion,
-			XF86VIDMODENAME ":SetClientVersion");
-    RegisterRequestName(extEntry->base, X_XF86VidModeSetGamma,
-			XF86VIDMODENAME ":SetGamma");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetGamma,
-			XF86VIDMODENAME ":GetGamma");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetGammaRamp,
-			XF86VIDMODENAME ":GetGammaRamp");
-    RegisterRequestName(extEntry->base, X_XF86VidModeSetGammaRamp,
-			XF86VIDMODENAME ":SetGammaRamp");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetGammaRampSize,
-			XF86VIDMODENAME ":GetGammaRampSize");
-    RegisterRequestName(extEntry->base, X_XF86VidModeGetPermissions,
-			XF86VIDMODENAME ":GetPermissions");
-
-#ifdef XF86VIDMODE_EVENTS
-    RegisterEventName(extEntry->eventBase + XF86VidModeNotify,
-		      XF86VIDMODENAME ":Notify");
-#endif
-
-    RegisterErrorName(extEntry->errorBase + XF86VidModeBadClock,
-		      XF86VIDMODENAME ":BadClock");
-    RegisterErrorName(extEntry->errorBase + XF86VidModeBadHTimings,
-		      XF86VIDMODENAME ":BadHTimings");
-    RegisterErrorName(extEntry->errorBase + XF86VidModeBadVTimings,
-		      XF86VIDMODENAME ":BadVTimings");
-    RegisterErrorName(extEntry->errorBase + XF86VidModeModeUnsuitable,
-		      XF86VIDMODENAME ":ModeUnsuitable");
-    RegisterErrorName(extEntry->errorBase + XF86VidModeExtensionDisabled,
-		      XF86VIDMODENAME ":ExtensionDisabled");
-    RegisterErrorName(extEntry->errorBase + XF86VidModeClientNotLocal,
-		      XF86VIDMODENAME ":ClientNotLocal");
-    RegisterErrorName(extEntry->errorBase + XF86VidModeZoomLocked,
-		      XF86VIDMODENAME ":ZoomLocked");
+    }
 }
 
 /*ARGSUSED*/
commit 8e2cd7a804664bbd2d03789dcd5c93223122e929
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:45:30 2007 -0500

    Revert "registry: Register XF86Misc extension protocol names."
    
    This reverts commit 2cd1b32b77e0ceeaccb3f01c4ac13a97c557668c.
    
    Moving all the names into dix/registry.c

diff --git a/hw/xfree86/dixmods/extmod/xf86misc.c b/hw/xfree86/dixmods/extmod/xf86misc.c
index 274b1d3..66278a2 100644
--- a/hw/xfree86/dixmods/extmod/xf86misc.c
+++ b/hw/xfree86/dixmods/extmod/xf86misc.c
@@ -19,7 +19,6 @@
 #include "scrnintstr.h"
 #include "inputstr.h"
 #include "servermd.h"
-#include "registry.h"
 #define _XF86MISC_SERVER_
 #undef _XF86MISC_SAVER_COMPAT_
 #include <X11/extensions/xf86mscstr.h>
@@ -138,50 +137,7 @@ XFree86MiscExtensionInit(void)
 	XF86MiscReqCode = (unsigned char)extEntry->base;
 #endif
 	miscErrorBase = extEntry->errorBase;
-    } else
-	return;
-
-    RegisterRequestName(extEntry->base, X_XF86MiscQueryVersion,
-			XF86MISCNAME ":QueryVersion");
-#ifdef _XF86MISC_SAVER_COMPAT_
-    RegisterRequestName(extEntry->base, X_XF86MiscGetSaver,
-			XF86MISCNAME ":GetSaver");
-    RegisterRequestName(extEntry->base, X_XF86MiscSetSaver,
-			XF86MISCNAME ":SetSaver");
-#endif
-    RegisterRequestName(extEntry->base, X_XF86MiscGetMouseSettings,
-			XF86MISCNAME ":GetMouseSettings");
-    RegisterRequestName(extEntry->base, X_XF86MiscGetKbdSettings,
-			XF86MISCNAME ":GetKbdSettings");
-    RegisterRequestName(extEntry->base, X_XF86MiscSetMouseSettings,
-			XF86MISCNAME ":SetMouseSettings");
-    RegisterRequestName(extEntry->base, X_XF86MiscSetKbdSettings,
-			XF86MISCNAME ":SetKbdSettings");
-    RegisterRequestName(extEntry->base, X_XF86MiscSetGrabKeysState,
-			XF86MISCNAME ":SetGrabKeysState");
-    RegisterRequestName(extEntry->base, X_XF86MiscSetClientVersion,
-			XF86MISCNAME ":SetClientVersion");
-    RegisterRequestName(extEntry->base, X_XF86MiscGetFilePaths,
-			XF86MISCNAME ":GetFilePaths");
-    RegisterRequestName(extEntry->base, X_XF86MiscPassMessage,
-			XF86MISCNAME ":PassMessage");
-
-    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseProtocol,
-			XF86MISCNAME ":BadMouseProtocol");
-    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseBaudRate,
-			XF86MISCNAME ":BadMouseBaudRate");
-    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseFlags,
-			XF86MISCNAME ":BadMouseFlags");
-    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseCombo,
-			XF86MISCNAME ":BadMouseCombo");
-    RegisterErrorName(extEntry->errorBase + XF86MiscBadKbdType,
-			XF86MISCNAME ":BadKbdType");
-    RegisterErrorName(extEntry->errorBase + XF86MiscModInDevDisabled,
-			XF86MISCNAME ":ModInDevDisabled");
-    RegisterErrorName(extEntry->errorBase + XF86MiscModInDevClientNotLocal,
-			XF86MISCNAME ":ModInDevClientNotLocal");
-    RegisterErrorName(extEntry->errorBase + XF86MiscNoModule,
-			XF86MISCNAME ":NoModule");
+    }
 }
 
 /*ARGSUSED*/
commit 0356153a58cef87d655bccacd8e2cf03d577bd19
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:43:18 2007 -0500

    Revert "registry: Register XF86DGA extension protocol names."
    
    This reverts commit 3815284e899b61731b6a63c4ba14c5d773e24eb6.
    
    Moving all the names into dix/registry.c

diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 3b866c7..295e05e 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -22,7 +22,6 @@
 #include "cursorstr.h"
 #include "scrnintstr.h"
 #include "servermd.h"
-#include "registry.h"
 #define _XF86DGA_SERVER_
 #include <X11/extensions/xf86dga.h>
 #include <X11/extensions/xf86dgastr.h>
@@ -100,72 +99,7 @@ XFree86DGAExtensionInit(INITARGS)
 	DGAEventBase = extEntry->eventBase;
 	for (i = KeyPress; i <= MotionNotify; i++)
 	    SetCriticalEvent (DGAEventBase + i);
-    } else
-	return;
-
-    RegisterRequestName(DGAReqCode, X_XF86DGAQueryVersion,
-			XF86DGANAME ":QueryVersion");
-    RegisterRequestName(DGAReqCode, X_XF86DGAGetVideoLL,
-			XF86DGANAME ":GetVideoLL");
-    RegisterRequestName(DGAReqCode, X_XF86DGADirectVideo,
-			XF86DGANAME ":DirectVideo");
-    RegisterRequestName(DGAReqCode, X_XF86DGAGetViewPortSize,
-			XF86DGANAME ":GetViewPortSize");
-    RegisterRequestName(DGAReqCode, X_XF86DGASetViewPort,
-			XF86DGANAME ":SetViewPort");
-    RegisterRequestName(DGAReqCode, X_XF86DGAGetVidPage,
-			XF86DGANAME ":GetVidPage");
-    RegisterRequestName(DGAReqCode, X_XF86DGASetVidPage,
-			XF86DGANAME ":SetVidPage");
-    RegisterRequestName(DGAReqCode, X_XF86DGAInstallColormap,
-			XF86DGANAME ":InstallColormap");
-    RegisterRequestName(DGAReqCode, X_XF86DGAQueryDirectVideo,
-			XF86DGANAME ":QueryDirectVideo");
-    RegisterRequestName(DGAReqCode, X_XF86DGAViewPortChanged,
-			XF86DGANAME ":ViewPortChanged");
-    RegisterRequestName(DGAReqCode, X_XDGAQueryModes,
-			XF86DGANAME ":QueryModes");
-    RegisterRequestName(DGAReqCode, X_XDGASetMode,
-			XF86DGANAME ":SetMode");
-    RegisterRequestName(DGAReqCode, X_XDGASetViewport,
-			XF86DGANAME ":SetViewport");
-    RegisterRequestName(DGAReqCode, X_XDGAInstallColormap,
-			XF86DGANAME ":InstallColormap");
-    RegisterRequestName(DGAReqCode, X_XDGASelectInput,
-			XF86DGANAME ":SelectInput");
-    RegisterRequestName(DGAReqCode, X_XDGAFillRectangle,
-			XF86DGANAME ":FillRectangle");
-    RegisterRequestName(DGAReqCode, X_XDGACopyArea,
-			XF86DGANAME ":CopyArea");
-    RegisterRequestName(DGAReqCode, X_XDGACopyTransparentArea,
-			XF86DGANAME ":CopyTransparentArea");
-    RegisterRequestName(DGAReqCode, X_XDGAGetViewportStatus,
-			XF86DGANAME ":GetViewportStatus");
-    RegisterRequestName(DGAReqCode, X_XDGASync,
-			XF86DGANAME ":Sync");
-    RegisterRequestName(DGAReqCode, X_XDGAOpenFramebuffer,
-			XF86DGANAME ":OpenFramebuffer");
-    RegisterRequestName(DGAReqCode, X_XDGACloseFramebuffer,
-			XF86DGANAME ":CloseFramebuffer");
-    RegisterRequestName(DGAReqCode, X_XDGASetClientVersion,
-			XF86DGANAME ":SetClientVersion");
-    RegisterRequestName(DGAReqCode, X_XDGAChangePixmapMode,
-			XF86DGANAME ":ChangePixmapMode");
-    RegisterRequestName(DGAReqCode, X_XDGACreateColormap,
-			XF86DGANAME ":CreateColormap");
-
-    /* 7 Events: Don't know where they are defined. EFW */
-
-    RegisterErrorName(extEntry->errorBase + XF86DGAClientNotLocal,
-		      XF86DGANAME ":ClientNotLocal");
-    RegisterErrorName(extEntry->errorBase + XF86DGANoDirectVideoMode,
-		      XF86DGANAME ":NoDirectVideoMode");
-    RegisterErrorName(extEntry->errorBase + XF86DGAScreenNotActive,
-		      XF86DGANAME ":ScreenNotActive");
-    RegisterErrorName(extEntry->errorBase + XF86DGADirectNotActivated,
-		      XF86DGANAME ":DirectNotActivated");
-    RegisterErrorName(extEntry->errorBase + XF86DGAOperationNotSupported,
-		      XF86DGANAME ":OperationNotSupported");
+    }
 }
 
 
commit de93c1e9df14577e158b6dc3ccec7ee48f592386
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:40:57 2007 -0500

    Revert "registry: Register DMX extension protocol names."
    
    This reverts commit 32f3f5a1e7654f8bb43ea16b9227b3994e616739.
    
    Moving all the names into dix/registry.c

diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 840356f..5f1fc05 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -54,7 +54,6 @@
 #define EXTENSION_PROC_ARGS void *
 #include "extnsionst.h"
 #include "opaque.h"
-#include "registry.h"
 
 #include "dmxextension.h"
 #include <X11/extensions/dmxproto.h>
@@ -127,45 +126,6 @@ void DMXExtensionInit(void)
                                  ProcDMXDispatch, SProcDMXDispatch,
                                  DMXResetProc, StandardMinorOpcode)))
 	DMXCode = extEntry->base;
-    else
-	return;
-
-    RegisterRequestName(DMXCode, X_DMXQueryVersion,
-			DMX_EXTENSION_NAME ":DMXQueryVersion");
-    RegisterRequestName(DMXCode, X_DMXGetScreenCount,
-			DMX_EXTENSION_NAME ":DMXGetScreenCount");
-    RegisterRequestName(DMXCode, X_DMXGetScreenInformationDEPRECATED,
-			DMX_EXTENSION_NAME ":DMXGetScreenInfoDEPRECATED");
-    RegisterRequestName(DMXCode, X_DMXGetWindowAttributes,
-			DMX_EXTENSION_NAME ":DMXGetWindowAttributes");
-    RegisterRequestName(DMXCode, X_DMXGetInputCount,
-			DMX_EXTENSION_NAME ":DMXGetInputCount");
-    RegisterRequestName(DMXCode, X_DMXGetInputAttributes,
-			DMX_EXTENSION_NAME ":DMXGetInputAttributes");
-    RegisterRequestName(DMXCode, X_DMXForceWindowCreationDEPRECATED,
-			DMX_EXTENSION_NAME ":DMXForceWindowCreationDEPRECATED");
-    RegisterRequestName(DMXCode, X_DMXReconfigureScreenDEPRECATED,
-			DMX_EXTENSION_NAME ":DMXReconfigureScreenDEPRECATED");
-    RegisterRequestName(DMXCode, X_DMXSync,
-			DMX_EXTENSION_NAME ":DMXSync");
-    RegisterRequestName(DMXCode, X_DMXForceWindowCreation,
-			DMX_EXTENSION_NAME ":DMXForceWindowCreation");
-    RegisterRequestName(DMXCode, X_DMXGetScreenAttributes,
-			DMX_EXTENSION_NAME ":DMXGetScreenAttributes");
-    RegisterRequestName(DMXCode, X_DMXChangeScreensAttributes,
-			DMX_EXTENSION_NAME ":DMXChangeScreensAttributes");
-    RegisterRequestName(DMXCode, X_DMXAddScreen,
-			DMX_EXTENSION_NAME ":DMXAddScreen");
-    RegisterRequestName(DMXCode, X_DMXRemoveScreen,
-			DMX_EXTENSION_NAME ":DMXRemoveScreen");
-    RegisterRequestName(DMXCode, X_DMXGetDesktopAttributes,
-			DMX_EXTENSION_NAME ":DMXGetDesktopAttributes");
-    RegisterRequestName(DMXCode, X_DMXChangeDesktopAttributes,
-			DMX_EXTENSION_NAME ":DMXChangeDesktopAttributes");
-    RegisterRequestName(DMXCode, X_DMXAddInput,
-			DMX_EXTENSION_NAME ":DMXAddInput");
-    RegisterRequestName(DMXCode, X_DMXRemoveInput,
-			DMX_EXTENSION_NAME ":DMXRemoveInput");
 }
 
 static void dmxSetScreenAttribute(int bit, DMXScreenAttributesPtr attr,
commit 2d3e0cdf4bd7ab069bad7244ede7c2d489e92b17
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:39:56 2007 -0500

    Revert "registry: Register APPLEDRI extension protocol names."
    
    This reverts commit 3464b419230c6d17e940d967b567c5d2cb22d232.
    
    Moving all the names into dix/registry.c

diff --git a/hw/darwin/quartz/xpr/appledri.c b/hw/darwin/quartz/xpr/appledri.c
index d9690fd..70b7400 100644
--- a/hw/darwin/quartz/xpr/appledri.c
+++ b/hw/darwin/quartz/xpr/appledri.c
@@ -53,7 +53,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "swaprep.h"
 #include "dri.h"
 #include "dristruct.h"
-#include "registry.h"
 
 static int DRIErrorBase = 0;
 
@@ -93,33 +92,7 @@ AppleDRIExtensionInit(void)
         DRIErrorBase = extEntry->errorBase;
         DRIEventBase = extEntry->eventBase;
         EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
-    } else
-	return;
-
-    RegisterRequestName(DRIReqCode, X_AppleDRIQueryVersion,
-			APPLEDRINAME ":QueryVersion");
-    RegisterRequestName(DRIReqCode, X_AppleDRIQueryDirectRenderingCapable,
-			APPLEDRINAME ":QueryDirectRenderingCapable");
-    RegisterRequestName(DRIReqCode, X_AppleDRICreateSurface,
-			APPLEDRINAME ":CreateSurface");
-    RegisterRequestName(DRIReqCode, X_AppleDRIDestroySurface,
-			APPLEDRINAME ":DestroySurface");
-    RegisterRequestName(DRIReqCode, X_AppleDRIAuthConnection,
-			APPLEDRINAME ":AuthConnection");
-
-    RegisterEventName(DRIEventBase + AppleDRIObsoleteEvent1,
-		      APPLEDRINAME ":ObsoleteEvent1");
-    RegisterEventName(DRIEventBase + AppleDRIObsoleteEvent2,
-		      APPLEDRINAME ":ObsoleteEvent2");
-    RegisterEventName(DRIEventBase + AppleDRIObsoleteEvent3,
-		      APPLEDRINAME ":ObsoleteEvent3");
-    RegisterEventName(DRIEventBase + AppleDRISurfaceNotify,
-		      APPLEDRINAME ":SurfaceNotify");
-
-    RegisterErrorName(DRIEventBase + AppleDRIClientNotLocal,
-		      APPLEDRINAME ":ClientNotLocal");
-    RegisterErrorName(DRIEventBase + AppleDRIOperationNotSupported,
-		      APPLEDRINAME ":OperationNotSupported");
+    }
 }
 
 /*ARGSUSED*/
commit 546d46224e355d4f00232da5538548e3c8853e40
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:37:48 2007 -0500

    Revert "registry: Register XINERAMA extension protocol names."
    
    This reverts commit b9f5ab98c8dea36dcce1ad15fd2e059a77e77c39.
    
    Moving all the names into dix/registry.c

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 1ba0c4d..26c2809 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -53,7 +53,6 @@ Equipment Corporation.
 #include "globals.h"
 #include "servermd.h"
 #include "resource.h"
-#include "registry.h"
 #ifdef RENDER
 #include "picturestr.h"
 #endif
@@ -590,19 +589,6 @@ void PanoramiXExtensionInit(int argc, char *argv[])
 #ifdef RENDER
     PanoramiXRenderInit ();
 #endif
-
-    RegisterRequestName(extEntry->base, X_PanoramiXQueryVersion,
-			PANORAMIX_PROTOCOL_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetState,
-			PANORAMIX_PROTOCOL_NAME ":GetState");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenCount,
-			PANORAMIX_PROTOCOL_NAME ":GetScreenCount");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenSize,
-			PANORAMIX_PROTOCOL_NAME ":GetScreenSize");
-    RegisterRequestName(extEntry->base, X_XineramaIsActive,
-			PANORAMIX_PROTOCOL_NAME ":IsActive");
-    RegisterRequestName(extEntry->base, X_XineramaQueryScreens,
-			PANORAMIX_PROTOCOL_NAME ":QueryScreens");
 }
 
 extern Bool CreateConnectionBlock(void);
diff --git a/hw/darwin/quartz/pseudoramiX.c b/hw/darwin/quartz/pseudoramiX.c
index cdd4fff..787601b 100644
--- a/hw/darwin/quartz/pseudoramiX.c
+++ b/hw/darwin/quartz/pseudoramiX.c
@@ -42,7 +42,6 @@ Equipment Corporation.
 #include "window.h"
 #include <X11/extensions/panoramiXproto.h>
 #include "globals.h"
-#include "registry.h"
 
 extern int noPseudoramiXExtension;
 extern int noPanoramiXExtension;
@@ -148,19 +147,6 @@ void PseudoramiXExtensionInit(int argc, char *argv[])
                PANORAMIX_PROTOCOL_NAME);
         return;
     }
-
-    RegisterRequestName(extEntry->base, X_PanoramiXQueryVersion,
-			PANORAMIX_PROTOCOL_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetState,
-			PANORAMIX_PROTOCOL_NAME ":GetState");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenCount,
-			PANORAMIX_PROTOCOL_NAME ":GetScreenCount");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenSize,
-			PANORAMIX_PROTOCOL_NAME ":GetScreenSize");
-    RegisterRequestName(extEntry->base, X_XineramaIsActive,
-			PANORAMIX_PROTOCOL_NAME ":IsActive");
-    RegisterRequestName(extEntry->base, X_XineramaQueryScreens,
-			PANORAMIX_PROTOCOL_NAME ":QueryScreens");
 }
 
 
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index c499802..896f61f 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -71,7 +71,6 @@
 #include "randrstr.h"
 #include "swaprep.h"
 #include <X11/extensions/panoramiXproto.h>
-#include "registry.h"
 
 #define RR_XINERAMA_MAJOR_VERSION   1
 #define RR_XINERAMA_MINOR_VERSION   1
@@ -424,8 +423,6 @@ RRXineramaResetProc(ExtensionEntry* extEntry)
 void
 RRXineramaExtensionInit(void)
 {
-    ExtensionEntry *extEntry;
-
 #ifdef PANORAMIX
     if(!noPanoramiXExtension)
 	return;
@@ -439,22 +436,9 @@ RRXineramaExtensionInit(void)
     if (screenInfo.numScreens > 1)
 	return;
 
-    extEntry = AddExtension(PANORAMIX_PROTOCOL_NAME, 0, 0,
-			    ProcRRXineramaDispatch,
-			    SProcRRXineramaDispatch,
-			    RRXineramaResetProc,
-			    StandardMinorOpcode);
-
-    RegisterRequestName(extEntry->base, X_PanoramiXQueryVersion,
-			PANORAMIX_PROTOCOL_NAME ":QueryVersion");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetState,
-			PANORAMIX_PROTOCOL_NAME ":GetState");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenCount,
-			PANORAMIX_PROTOCOL_NAME ":GetScreenCount");
-    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenSize,
-			PANORAMIX_PROTOCOL_NAME ":GetScreenSize");
-    RegisterRequestName(extEntry->base, X_XineramaIsActive,
-			PANORAMIX_PROTOCOL_NAME ":IsActive");
-    RegisterRequestName(extEntry->base, X_XineramaQueryScreens,
-			PANORAMIX_PROTOCOL_NAME ":QueryScreens");
+    (void) AddExtension(PANORAMIX_PROTOCOL_NAME, 0,0,
+			ProcRRXineramaDispatch,
+			SProcRRXineramaDispatch,
+			RRXineramaResetProc,
+			StandardMinorOpcode);
 }
commit fd2d83d5bf5b35c8a2b05f725486be166783921e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:34:48 2007 -0500

    Revert "registry: Register APPLEWM extension protocol names."
    
    This reverts commit eee46b4681ec55297604b0425705f2b18381f7ca.
    
    Moving all the names into dix/registry.c

diff --git a/hw/darwin/quartz/applewm.c b/hw/darwin/quartz/applewm.c
index fecafe8..308c510 100644
--- a/hw/darwin/quartz/applewm.c
+++ b/hw/darwin/quartz/applewm.c
@@ -42,7 +42,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "servermd.h"
 #include "swaprep.h"
 #include "propertyst.h"
-#include "registry.h"
 #include <X11/Xatom.h>
 #include "darwin.h"
 #define _APPLEWM_SERVER_
@@ -128,45 +127,7 @@ AppleWMExtensionInit(
         WMEventBase = extEntry->eventBase;
         EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
         appleWMProcs = procsPtr;
-    } else
-	return;
-
-    RegisterRequestName(WMReqCode, X_AppleWMQueryVersion,
-			APPLEWMNAME ":QueryVersion");
-    RegisterRequestName(WMReqCode, X_AppleWMFrameGetRect,
-			APPLEWMNAME ":FrameGetRect");
-    RegisterRequestName(WMReqCode, X_AppleWMFrameHitTest,
-			APPLEWMNAME ":FrameHitTest");
-    RegisterRequestName(WMReqCode, X_AppleWMFrameDraw,
-			APPLEWMNAME ":FrameDraw");
-    RegisterRequestName(WMReqCode, X_AppleWMDisableUpdate,
-			APPLEWMNAME ":DisableUpdate");
-    RegisterRequestName(WMReqCode, X_AppleWMReenableUpdate,
-			APPLEWMNAME ":ReenableUpdate");
-    RegisterRequestName(WMReqCode, X_AppleWMSelectInput,
-			APPLEWMNAME ":SelectInput");
-    RegisterRequestName(WMReqCode, X_AppleWMSetWindowMenuCheck,
-			APPLEWMNAME ":SetWindowMenuCheck");
-    RegisterRequestName(WMReqCode, X_AppleWMSetFrontProcess,
-			APPLEWMNAME ":SetFrontProcess");
-    RegisterRequestName(WMReqCode, X_AppleWMSetWindowLevel,
-			APPLEWMNAME ":SetWindowLevel");
-    RegisterRequestName(WMReqCode, X_AppleWMSetCanQuit,
-			APPLEWMNAME ":SetCanQuit");
-    RegisterRequestName(WMReqCode, X_AppleWMSetWindowMenu,
-			APPLEWMNAME ":SetWindowMenu");
-
-    RegisterEventName(WMEventBase + AppleWMControllerNotify,
-		      APPLEWMNAME ":ControllerNotify");
-    RegisterEventName(WMEventBase + AppleWMActivationNotify,
-		      APPLEWMNAME ":ActivationNotify");
-    RegisterEventName(WMEventBase + AppleWMPasteboardNotify,
-		      APPLEWMNAME ":PasteboardNotify");
-
-    RegisterErrorName(WMErrorBase + AppleWMClientNotLocal,
-		      APPLEWMNAME ":ClientNotLocal");
-    RegisterErrorName(WMErrorBase + AppleWMOperationNotSupported,
-		      APPLEWMNAME ":OperationNotSupported");
+    }
 }
 
 /*ARGSUSED*/
commit c934e1af27189571c1e7dd838872e380c3580eeb
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:32:35 2007 -0500

    Revert "registry: Register DBE extension protocol names."
    
    This reverts commit 2e1e5be1d9067816525aa13a1d818e8ca6899599.
    
    Moving all the names into dix/registry.c

diff --git a/dbe/dbe.c b/dbe/dbe.c
index a872544..8175a35 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -51,7 +51,6 @@
 #include "extnsionst.h"
 #include "gcstruct.h"
 #include "dixstruct.h"
-#include "registry.h"
 #define NEED_DBE_PROTOCOL
 #include "dbestruct.h"
 #include "midbe.h"
@@ -1748,25 +1747,5 @@ DbeExtensionInit(void)
 
     dbeErrorBase = extEntry->errorBase;
 
-    RegisterRequestName(extEntry->base, X_DbeGetVersion,
-			DBE_PROTOCOL_NAME ":GetVersion");
-    RegisterRequestName(extEntry->base, X_DbeAllocateBackBufferName,
-			DBE_PROTOCOL_NAME ":AllocateBackBufferName");
-    RegisterRequestName(extEntry->base, X_DbeDeallocateBackBufferName,
-			DBE_PROTOCOL_NAME ":DeallocateBackBufferName");
-    RegisterRequestName(extEntry->base, X_DbeSwapBuffers,
-			DBE_PROTOCOL_NAME ":SwapBuffers");
-    RegisterRequestName(extEntry->base, X_DbeBeginIdiom,
-			DBE_PROTOCOL_NAME ":BeginIdiom");
-    RegisterRequestName(extEntry->base, X_DbeEndIdiom,
-			DBE_PROTOCOL_NAME ":EndIdiom");
-    RegisterRequestName(extEntry->base, X_DbeGetVisualInfo,
-			DBE_PROTOCOL_NAME ":GetVisualInfo");
-    RegisterRequestName(extEntry->base, X_DbeGetBackBufferAttributes,
-			DBE_PROTOCOL_NAME ":GetBackBufferAttributes");
-
-    RegisterErrorName(dbeErrorBase + DbeBadBuffer,
-		      DBE_PROTOCOL_NAME ":BadBuffer");
-
 } /* DbeExtensionInit() */
 
commit b9ab6f300a46aa8879b11eac51857357cc379c2f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:31:00 2007 -0500

    Revert "registry: Register DAMAGE extension protocol names."
    
    This reverts commit 20db50b4c44a14f7eeac2b1de17ada68482521da.
    
    Moving all the names into dix/registry.c

diff --git a/damageext/damageext.c b/damageext/damageext.c
index ac2198b..517c72d 100755
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -25,7 +25,6 @@
 #endif
 
 #include "damageextint.h"
-#include "registry.h"
 
 static unsigned char	DamageReqCode;
 static int		DamageEventBase;
@@ -527,23 +526,5 @@ DamageExtensionInit(void)
 	DamageErrorBase = extEntry->errorBase;
 	EventSwapVector[DamageEventBase + XDamageNotify] =
 			(EventSwapPtr) SDamageNotifyEvent;
-    } else
-	return;
-
-    RegisterRequestName(DamageReqCode, X_DamageQueryVersion,
-			DAMAGE_NAME ":QueryVersion");
-    RegisterRequestName(DamageReqCode, X_DamageCreate,
-			DAMAGE_NAME ":Create");
-    RegisterRequestName(DamageReqCode, X_DamageDestroy,
-			DAMAGE_NAME ":Destroy");
-    RegisterRequestName(DamageReqCode, X_DamageSubtract,
-			DAMAGE_NAME ":Subtract");
-    RegisterRequestName(DamageReqCode, X_DamageAdd,
-			DAMAGE_NAME ":Add");
-
-    RegisterEventName(DamageEventBase + XDamageNotify,
-			DAMAGE_NAME ":Notify");
-
-    RegisterErrorName(extEntry->errorBase + BadDamage,
-			DAMAGE_NAME ":BadDamage");
+    }
 }
commit 26586a7ad5e999b34996d147fb43998deea89178
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 17:27:37 2007 -0500

    Revert "registry: Register composite extension protocol names."
    
    This reverts commit 166ef972febc00c665e1d5aeb68e75d7bbcf9879.
    
    Moving all the names into dix/registry.c

diff --git a/composite/compext.c b/composite/compext.c
index 98adabb..2918556 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -46,7 +46,6 @@
 
 #include "compint.h"
 #include "xace.h"
-#include "registry.h"
 
 #define SERVER_COMPOSITE_MAJOR	0
 #define SERVER_COMPOSITE_MINOR	4
@@ -755,23 +754,4 @@ CompositeExtensionInit (void)
 
     /* Initialization succeeded */
     noCompositeExtension = FALSE;
-
-    RegisterRequestName(CompositeReqCode, X_CompositeQueryVersion,
-			COMPOSITE_NAME ":CompositeQueryVersion");
-    RegisterRequestName(CompositeReqCode, X_CompositeRedirectWindow,
-			COMPOSITE_NAME ":CompositeRedirectWindow");
-    RegisterRequestName(CompositeReqCode, X_CompositeRedirectSubwindows,
-			COMPOSITE_NAME ":CompositeRedirectSubwindows");
-    RegisterRequestName(CompositeReqCode, X_CompositeUnredirectWindow,
-			COMPOSITE_NAME ":CompositeUnredirectWindow");
-    RegisterRequestName(CompositeReqCode, X_CompositeUnredirectSubwindows,
-			COMPOSITE_NAME ":CompositeUnredirectSubwindows");
-    RegisterRequestName(CompositeReqCode, X_CompositeCreateRegionFromBorderClip,
-			COMPOSITE_NAME ":CompositeCreateRegionFromBorderClip");
-    RegisterRequestName(CompositeReqCode, X_CompositeNameWindowPixmap,
-			COMPOSITE_NAME ":CompositeNameWindowPixmap");
-    RegisterRequestName(CompositeReqCode, X_CompositeGetOverlayWindow,
-			COMPOSITE_NAME ":CompositeGetOverlayWindow");
-    RegisterRequestName(CompositeReqCode, X_CompositeReleaseOverlayWindow,
-			COMPOSITE_NAME ":CompositeReleaseOverlayWindow");
 }
commit fae39db7957c0ebdc7af36f8d8f484473beb6d38
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 15:21:31 2007 -0500

    devPrivates rework: put back some changes that were mistakenly removed
    	during merge conflict resolution.

diff --git a/mfb/mfbbitblt.c b/mfb/mfbbitblt.c
index 0c23ba7..344c655 100644
--- a/mfb/mfbbitblt.c
+++ b/mfb/mfbbitblt.c
@@ -399,22 +399,20 @@ int dstx, dsty;
 
 static DevPrivateKey copyPlaneScreenKey = &copyPlaneScreenKey;
 
-typedef RegionPtr (*CopyPlaneFuncPtr)(
-    DrawablePtr         /* pSrcDrawable */,
-    DrawablePtr         /* pDstDrawable */,
-    GCPtr               /* pGC */,
-    int                 /* srcx */,
-    int                 /* srcy */,
-    int                 /* width */,
-    int                 /* height */,
-    int                 /* dstx */,
-    int                 /* dsty */,
-    unsigned long       /* bitPlane */);
-
 Bool
 mfbRegisterCopyPlaneProc (pScreen, proc)
     ScreenPtr	pScreen;
-    CopyPlaneFuncPtr proc;
+    RegionPtr	(*proc)(
+        DrawablePtr         /* pSrcDrawable */,
+        DrawablePtr         /* pDstDrawable */,
+        GCPtr               /* pGC */,
+        int                 /* srcx */,
+        int                 /* srcy */,
+        int                 /* width */,
+        int                 /* height */,
+        int                 /* dstx */,
+        int                 /* dsty */,
+        unsigned long       /* bitPlane */);
 {
     dixSetPrivate(&pScreen->devPrivates, copyPlaneScreenKey, proc);
     return TRUE;
@@ -461,10 +459,8 @@ unsigned long plane;
 
     if (pSrcDrawable->depth != 1)
     {
-	if ((copyPlane = (CopyPlaneFuncPtr)
-	     dixLookupPrivate(&pSrcDrawable->pScreen->devPrivates,
-			      copyPlaneScreenKey))
-	    )
+	if ((copyPlane = dixLookupPrivate(&pSrcDrawable->pScreen->devPrivates,
+					  copyPlaneScreenKey)))
 	{
 	    return (*copyPlane) (pSrcDrawable, pDstDrawable,
 			   pGC, srcx, srcy, width, height, dstx, dsty, plane);
commit 709c1a70c8c6a9e132bf0d92f78a12be72beee51
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Nov 20 15:18:02 2007 -0500

    Remove some duplicate include statements.

diff --git a/Xext/xres.c b/Xext/xres.c
index 281ba20..efa6c49 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -23,7 +23,6 @@
 #include "windowstr.h"
 #include "gcstruct.h"
 #include "modinit.h"
-#include "registry.h"
 
 static int
 ProcXResQueryVersion (ClientPtr client)
diff --git a/dix/main.c b/dix/main.c
index bc00ac5..335706b 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -87,7 +87,6 @@ Equipment Corporation.
 #include "os.h"
 #include "windowstr.h"
 #include "resource.h"
-#include "privates.h"
 #include "dixstruct.h"
 #include "gcstruct.h"
 #include "extension.h"
diff --git a/fb/fb.h b/fb/fb.h
index af2b4a1..5b56d96 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -41,7 +41,6 @@
 #include "mi.h"
 #include "migc.h"
 #include "mibstore.h"
-#include "privates.h"
 #ifdef RENDER
 #include "picturestr.h"
 #else
commit 5b0dfb73ca4699cc4b33720f10416de7440081b7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 19 21:01:22 2007 -0500

    devPrivates rework: put back a comment that was mistakenly removed
    	during merge conflict resolution.

diff --git a/cfb/cfb.h b/cfb/cfb.h
index e80a427..aece133 100644
--- a/cfb/cfb.h
+++ b/cfb/cfb.h
@@ -81,6 +81,8 @@ typedef struct {
     CfbBits	xor, and;
 } cfbRRopRec, *cfbRRopPtr;
 
+/* cfb8bit.c */
+
 extern int cfbSetStipple(
     int /*alu*/,
     CfbBits /*fg*/,
commit 2d17f47cc7d6b174857617d31ad1b437d8e97d94
Merge: 60be452... ea9c63e...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 19 18:10:46 2007 -0500

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	hw/xnest/Pixmap.c
    	include/dix.h

diff --cc hw/xfree86/common/xf86Init.c
index b3cae27,b5ee21d..f040ead
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@@ -1299,13 -1307,9 +1299,9 @@@ AbortDDX(
    /*
     * try to restore the original video state
     */
- #ifdef HAS_USL_VTS
-   /* Need the sleep when starting X from within another X session */
-   sleep(1);
- #endif
  #ifdef DPMSExtension /* Turn screens back on */
    if (DPMSPowerLevel != DPMSModeOn)
 -      DPMSSet(DPMSModeOn);
 +      DPMSSet(serverClient, DPMSModeOn);
  #endif
    if (xf86Screens) {
        if (xf86Screens[0]->vtSema)
diff --cc hw/xnest/Pixmap.c
index 57bebc6,9229752..0431196
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@@ -57,8 -56,9 +57,9 @@@ xnestCreatePixmap(ScreenPtr pScreen, in
    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
    pPixmap->refcnt = 1;
    pPixmap->devKind = PixmapBytePad(width, depth);
 -  pPixmap->devPrivates[xnestPixmapPrivateIndex].ptr =
 -      (pointer)((char *)pPixmap + pScreen->totalPixmapSize);
+   pPixmap->usage_hint = usage_hint;
 +  dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey,
 +		(char *)pPixmap + pScreen->totalPixmapSize);
    if (width && height)
        xnestPixmapPriv(pPixmap)->pixmap = 
  	  XCreatePixmap(xnestDisplay, 
diff --cc include/dix.h
index 30fdc45,c987548..8cfbbc4
--- a/include/dix.h
+++ b/include/dix.h
@@@ -145,8 -158,8 +145,6 @@@ extern void UpdateCurrentTime(void)
  
  extern void UpdateCurrentTimeIf(void);
  
- extern void InitSelections(void);
- 
 -extern void FlushClientCaches(XID /*id*/);
 -
  extern int dixDestroyPixmap(
      pointer /*value*/,
      XID /*pid*/);
diff --cc os/Makefile.am
index 9b8e08d,8ed12e4..a119824
--- a/os/Makefile.am
+++ b/os/Makefile.am
@@@ -2,10 -2,8 +2,7 @@@ noinst_LTLIBRARIES = libos.la libcwrapp
  
  AM_CFLAGS = $(DIX_CFLAGS)
  
- # FIXME: Add support for these in configure.ac
- INTERNALMALLOC_SRCS = xalloc.c
- 
  SECURERPC_SRCS = rpcauth.c
 -XCSECURITY_SRCS = secauth.c
  XDMCP_SRCS = xdmcp.c
  STRLCAT_SRCS = strlcat.c strlcpy.c
  XORG_SRCS = log.c
commit 60be452c2e88342f92a76ba5ec7d90b5b0211aaf
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 19 16:55:09 2007 -0500

    xace: restore the old SaveScreens function and introduce new API, since the
    old version is called from drivers...

diff --git a/Xext/saver.c b/Xext/saver.c
index 6905fc6..43dd3e2 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -468,8 +468,8 @@ ScreenSaverFreeAttr (value, id)
     pPriv->attr = NULL;
     if (pPriv->hasWindow)
     {
-	SaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
-	SaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverActive);
+	dixSaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
+	dixSaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverActive);
     }
     CheckScreenPrivate (pScreen);
     return TRUE;
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 3895a00..effa3b9 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -459,7 +459,7 @@ ProcXTestFakeInput(client)
 	break;
     }
     if (screenIsSaved == SCREEN_SAVER_ON)
-	SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+	dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
     ev->u.keyButtonPointer.time = currentTime.milliseconds;
     (*dev->public.processInputProc)(ev, dev, nev);
     return client->noClientException;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index f7196fd..0c8e6b1 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3582,7 +3582,7 @@ int ProcForceScreenSaver(ClientPtr client)
 	client->errorValue = stuff->mode;
         return BadValue;
     }
-    rc = SaveScreens(client, SCREEN_SAVER_FORCER, (int)stuff->mode);
+    rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, (int)stuff->mode);
     if (rc != Success)
 	return rc;
     return client->noClientException;
diff --git a/dix/main.c b/dix/main.c
index 543e94c..bc00ac5 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -425,7 +425,7 @@ main(int argc, char *argv[], char *envp[])
 	for (i = 0; i < screenInfo.numScreens; i++)
 	    InitRootWindow(WindowTable[i]);
 	DefineInitialRootWindow(WindowTable[0]);
-	SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
+	dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
 #ifdef PANORAMIX
 	if (!noPanoramiXExtension) {
@@ -446,7 +446,7 @@ main(int argc, char *argv[], char *envp[])
 
 	/* Now free up whatever must be freed */
 	if (screenIsSaved == SCREEN_SAVER_ON)
-	    SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+	    dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 	FreeScreenSaverTimer();
 	CloseDownExtensions();
 
diff --git a/dix/window.c b/dix/window.c
index f183aa3..f12c82b 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3337,7 +3337,7 @@ static void DrawLogo(
 #endif
 
 _X_EXPORT int
-SaveScreens(ClientPtr client, int on, int mode)
+dixSaveScreens(ClientPtr client, int on, int mode)
 {
     int rc, i, what, type;
 
@@ -3455,6 +3455,12 @@ SaveScreens(ClientPtr client, int on, int mode)
     return Success;
 }
 
+_X_EXPORT int
+SaveScreens(int on, int mode)
+{
+    return dixSaveScreens(serverClient, on, mode);
+}
+
 static Bool
 TileScreenSaver(int i, int kind)
 {
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index 97ad857..4980cf2 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -276,7 +276,7 @@ void ProcessInputEvents(void) {
     while (darwinEventQueue.head != darwinEventQueue.tail)
     {
         if (screenIsSaved == SCREEN_SAVER_ON)
-            SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+            dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 
         e = &darwinEventQueue.events[darwinEventQueue.head];
         xe = e->event;
diff --git a/hw/dmx/dmxdpms.c b/hw/dmx/dmxdpms.c
index 8c745a6..2af1605 100644
--- a/hw/dmx/dmxdpms.c
+++ b/hw/dmx/dmxdpms.c
@@ -175,7 +175,7 @@ void dmxDPMSTerm(DMXScreenInfo *dmxScreen)
 void dmxDPMSWakeup(void)
 {
     if (screenIsSaved == SCREEN_SAVER_ON)
-        SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+        dixSaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 #ifdef DPMSExtension
     if (DPMSPowerLevel) DPMSSet(serverClient, 0);
 #endif
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index 536d38e..43efb8e 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -153,7 +153,7 @@ DPMSSet(ClientPtr client, int level)
 	return Success;
 
     if (level != DPMSModeOn) {
-	rc = SaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
+	rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
 	if (rc != Success)
 	    return rc;
     }
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index bc2fe09..2b7cb12 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -906,7 +906,7 @@ xf86VTSwitch()
 	    (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
 	}
       }
-      SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
+      dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
       pInfo = xf86InputDevs;
       while (pInfo) {
@@ -970,7 +970,7 @@ xf86VTSwitch()
     }
 
     /* Turn screen saver off when switching back */
-    SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
+    dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
     pInfo = xf86InputDevs;
     while (pInfo) {
diff --git a/hw/xfree86/common/xf86PM.c b/hw/xfree86/common/xf86PM.c
index 278a514..7c8320d 100644
--- a/hw/xfree86/common/xf86PM.c
+++ b/hw/xfree86/common/xf86PM.c
@@ -116,7 +116,7 @@ resume(pmEvent event, Bool undo)
 	if (xf86Screens[i]->EnableDisableFBAccess)
 	    (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
     }
-    SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
+    dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
     pInfo = xf86InputDevs;
     while (pInfo) {
 	EnableDevice(pInfo->dev);
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 139e23c..1a259f5 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -319,6 +319,7 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(NotClippedByChildren)
     SYMFUNC(ResizeChildrenWinSize)
     SYMFUNC(SaveScreens)
+    SYMFUNC(dixSaveScreens)
     SYMFUNC(SendVisibilityNotify)
     SYMFUNC(SetWinSize)
     SYMFUNC(SetBorderSize)
diff --git a/include/window.h b/include/window.h
index f85eceb..9943f90 100644
--- a/include/window.h
+++ b/include/window.h
@@ -204,11 +204,15 @@ extern RegionPtr NotClippedByChildren(
 extern void SendVisibilityNotify(
     WindowPtr /*pWin*/);
 
-extern int SaveScreens(
+extern int dixSaveScreens(
     ClientPtr client,
     int on,
     int mode);
 
+extern int SaveScreens(
+    int on,
+    int mode);
+
 extern WindowPtr FindWindowWithOptional(
     WindowPtr /*w*/);
 
diff --git a/mi/mieq.c b/mi/mieq.c
index 5093023..d946e7d 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -200,7 +200,7 @@ mieqProcessInputEvents(void)
 
     while (miEventQueue.head != miEventQueue.tail) {
         if (screenIsSaved == SCREEN_SAVER_ON)
-            SaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
+            dixSaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 #ifdef DPMSExtension
         else if (DPMSPowerLevel != DPMSModeOn)
             SetScreenSaverTimer();
diff --git a/os/WaitFor.c b/os/WaitFor.c
index 9281ba8..cfba251 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -647,7 +647,7 @@ ScreenSaverTimeoutExpire(OsTimerPtr timer,CARD32 now,pointer arg)
     }
 
     ResetOsBuffers(); /* not ideal, but better than nothing */
-    SaveScreens(serverClient, SCREEN_SAVER_ON, ScreenSaverActive);
+    dixSaveScreens(serverClient, SCREEN_SAVER_ON, ScreenSaverActive);
 
     if (ScreenSaverInterval > 0)
     {
commit a95bb52b4366d85fc049130c60af5c9e727c565b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 19 16:34:38 2007 -0500

    devPrivates rework: add missing include of dix/privates.h

diff --git a/mi/miline.h b/mi/miline.h
index ffa4b27..036c2b5 100644
--- a/mi/miline.h
+++ b/mi/miline.h
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
 #ifndef MILINE_H
 
 #include "screenint.h"
+#include "privates.h"
 
 /*
  * Public definitions used for configuring basic pixelization aspects
commit 1603130236c55ddabc3854d4ba62d544debcf1f5
Merge: f207e69... f7dd0c7...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Nov 14 13:35:50 2007 -0500

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	Xext/xace.c
    	Xext/xace.h

diff --cc Xext/xace.c
index 11145d1,b4e0eee..9f8a8cc
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@@ -213,22 -189,14 +209,6 @@@ int XaceHook(int hook, ...
  	    calldata = &rec;
  	    break;
  	}
- 	case XACE_AUDIT_BEGIN: {
- 	    XaceAuditRec rec = {
- 		va_arg(ap, ClientPtr),
- 		0
- 	    };
- 	    calldata = &rec;
- 	    break;
- 	}
- 	case XACE_AUDIT_END: {
- 	    XaceAuditRec rec = {
- 		va_arg(ap, ClientPtr),
- 		va_arg(ap, int)
- 	    };
- 	    calldata = &rec;
- 	    break;
- 	}
 -	case XACE_WINDOW_INIT: {
 -	    XaceWindowRec rec = {
 -		va_arg(ap, ClientPtr),
 -		va_arg(ap, WindowPtr)
 -	    };
 -	    calldata = &rec;
 -	    break;
 -	}
  	default: {
  	    va_end(ap);
  	    return 0;	/* unimplemented hook number */
@@@ -293,14 -261,17 +273,17 @@@ static in
  XaceCatchDispatchProc(ClientPtr client)
  {
      REQUEST(xReq);
-     int rc, major = stuff->reqType;
+     int major = stuff->reqType;
 -    XaceCoreDispatchRec rec = { client, TRUE /* default allow */ };
++    XaceCoreDispatchRec rec = { client, Success /* default allow */ };
  
      if (!ProcVector[major])
--	return (BadRequest);
++	return BadRequest;
  
-     rc = XaceHook(XACE_CORE_DISPATCH, client);
-     if (rc != Success)
-         return rc;
+     /* call callbacks and return result, if any. */
+     CallCallbacks(&XaceHooks[XACE_CORE_DISPATCH], &rec);
+ 
 -    if (!rec.rval)
 -	return (BadAccess);
++    if (rec.status != Success)
++	return rec.status;
  
      return client->swapped ? 
  	(* SwappedProcVector[major])(client) :
@@@ -313,12 -284,12 +296,16 @@@ XaceCatchExtProc(ClientPtr client
      REQUEST(xReq);
      int major = stuff->reqType;
      ExtensionEntry *ext = GetExtensionEntry(major);
++    XaceExtAccessRec rec = { client, ext, DixUseAccess, Success };
  
      if (!ext || !ProcVector[major])
--	return (BadRequest);
++	return BadRequest;
++
++    /* call callbacks and return result, if any. */
++    CallCallbacks(&XaceHooks[XACE_EXT_DISPATCH], &rec);
  
-     if (XaceHook(XACE_EXT_DISPATCH, client, ext) != Success)
- 	return (BadRequest); /* pretend extension doesn't exist */
 -    if (!XaceHook(XACE_EXT_DISPATCH, client, ext))
 -	return (BadRequest); /* pretend extension doesn't exist */
++    if (rec.status != Success)
++	return BadRequest; /* pretend extension doesn't exist */
  
      return client->swapped ?
  	(* SwappedProcVector[major])(client) :
diff --cc Xext/xace.h
index fc96458,273635c..de0e8fe
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@@ -92,10 -102,14 +97,14 @@@ extern void XaceCensorImage
  /* Define calls away when XACE is not being built. */
  
  #ifdef __GNUC__
 -#define XaceHook(args...) XaceAllowOperation
 +#define XaceHook(args...) Success
+ #define XaceHookAuditEnd(args...) { ; }
+ #define XaceHookAuditBegin(args...) { ; }
  #define XaceCensorImage(args...) { ; }
  #else
 -#define XaceHook(...) XaceAllowOperation
 +#define XaceHook(...) Success
+ #define XaceHookAuditEnd(...) { ; }
+ #define XaceHookAuditBegin(...) { ; }
  #define XaceCensorImage(...) { ; }
  #endif
  
commit f207e69d62bc04c7f254347b03e6d8fa8b569d66
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Nov 14 12:23:29 2007 -0500

    xselinux: adjust receive hook to use new synthetic_event class.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index eed78f4..cefde9d 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -532,7 +532,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (rc != Success)
 	    goto err;
 
-	auditdata.event = rec->events[i].u.u.type;
+	auditdata.event = type;
 	rc = SELinuxDoCheck(clientIndex, subj, &ev_sid, class,
 			    DixSendAccess, &auditdata);
 	if (rc != Success)
@@ -547,9 +547,10 @@ static void
 SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceReceiveAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxStateRec *subj, *obj, ev_sid;
     SELinuxAuditRec auditdata = { .client = NULL };
-    int rc, i;
+    security_class_t class;
+    int rc, i, type;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
     obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
@@ -562,14 +563,15 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     /* Check receive permission on specific event types */
     for (i = 0; i < rec->count; i++) {
-	SELinuxStateRec ev_sid;
+	type = rec->events[i].u.u.type;
+	class = (type & 128) ? SECCLASS_X_FAKEEVENT : SECCLASS_X_EVENT;
 
-	rc = SELinuxEventToSID(rec->events[i].u.u.type, obj->sid, &ev_sid);
+	rc = SELinuxEventToSID(type, obj->sid, &ev_sid);
 	if (rc != Success)
 	    goto err;
 
-	auditdata.event = rec->events[i].u.u.type;
-	rc = SELinuxDoCheck(rec->client->index, subj, &ev_sid, SECCLASS_X_EVENT,
+	auditdata.event = type;
+	rc = SELinuxDoCheck(rec->client->index, subj, &ev_sid, class,
 			    DixReceiveAccess, &auditdata);
 	if (rc != Success)
 	    goto err;
commit 45f884d79c0eebaa1eb24d7db76c1177f6b710c9
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Nov 9 14:45:27 2007 -0500

    xselinux: add new synthetic_event security class, and fix registry code.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index f6d1dcd..eed78f4 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -129,6 +129,7 @@ static struct security_class_mapping map[] = {
     { "x_server", { "record", "", "", "", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "grab", "", "", "", "", "", "", "", "manage", "debug", NULL }},
     { "x_extension", { "", "", "", "", "query", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
     { "x_event", { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "send", "receive", NULL }},
+    { "x_synthetic_event", { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "send", "receive", NULL }},
     { "x_resource", { "read", "write", "write", "write", "read", "write", "read", "read", "write", "read", "write", "read", "write", "write", "write", "read", "read", "write", "write", "write", "write", "write", "write", "read", "read", "write", "read", "write", NULL }},
     { NULL }
 };
@@ -501,9 +502,10 @@ static void
 SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceSendAccessRec *rec = calldata;
-    SELinuxStateRec *subj, *obj;
+    SELinuxStateRec *subj, *obj, ev_sid;
     SELinuxAuditRec auditdata = { .client = rec->client };
-    int rc, i, clientIndex;
+    security_class_t class;
+    int rc, i, type, clientIndex;
 
     if (rec->dev) {
 	subj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
@@ -523,14 +525,15 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     /* Check send permission on specific event types */
     for (i = 0; i < rec->count; i++) {
-	SELinuxStateRec ev_sid;
+	type = rec->events[i].u.u.type;
+	class = (type & 128) ? SECCLASS_X_FAKEEVENT : SECCLASS_X_EVENT;
 
-	rc = SELinuxEventToSID(rec->events[i].u.u.type, obj->sid, &ev_sid);
+	rc = SELinuxEventToSID(type, obj->sid, &ev_sid);
 	if (rc != Success)
 	    goto err;
 
 	auditdata.event = rec->events[i].u.u.type;
-	rc = SELinuxDoCheck(clientIndex, subj, &ev_sid, SECCLASS_X_EVENT,
+	rc = SELinuxDoCheck(clientIndex, subj, &ev_sid, class,
 			    DixSendAccess, &auditdata);
 	if (rc != Success)
 	    goto err;
@@ -1073,7 +1076,6 @@ ProcSELinuxSetDeviceContext(ClientPtr client)
     state = dixLookupPrivate(&dev->devPrivates, stateKey);
     sidput(state->sid);
     state->sid = sid;
-    ErrorF("I really, actually did relabel a device to %s\n", ctx);
     return Success;
 }
 
@@ -1397,26 +1399,26 @@ XSELinuxExtensionInit(INITARGS)
     SELinuxLabelInitial();
 
     /* Add names to registry */
-    RegisterRequestName(X_SELinuxQueryVersion, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxQueryVersion,
 			XSELINUX_EXTENSION_NAME ":SELinuxQueryVersion");
-    RegisterRequestName(X_SELinuxSetSelectionManager, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxSetSelectionManager,
 			XSELINUX_EXTENSION_NAME ":SELinuxSetSelectionManager");
-    RegisterRequestName(X_SELinuxGetSelectionManager, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxGetSelectionManager,
 			XSELINUX_EXTENSION_NAME ":SELinuxGetSelectionManager");
-    RegisterRequestName(X_SELinuxSetDeviceContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxSetDeviceContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxSetDeviceContext");
-    RegisterRequestName(X_SELinuxGetDeviceContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxGetDeviceContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxGetDeviceContext");
-    RegisterRequestName(X_SELinuxSetPropertyCreateContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxSetPropertyCreateContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxSetPropertyCreateContext");
-    RegisterRequestName(X_SELinuxGetPropertyCreateContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxGetPropertyCreateContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxGetPropertyCreateContext");
-    RegisterRequestName(X_SELinuxGetPropertyContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxGetPropertyContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxGetPropertyContext");
-    RegisterRequestName(X_SELinuxSetWindowCreateContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxSetWindowCreateContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxSetWindowCreateContext");
-    RegisterRequestName(X_SELinuxGetWindowCreateContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxGetWindowCreateContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxGetWindowCreateContext");
-    RegisterRequestName(X_SELinuxGetWindowContext, 0,
+    RegisterRequestName(extEntry->base, X_SELinuxGetWindowContext,
 			XSELINUX_EXTENSION_NAME ":SELinuxGetWindowContext");
 }
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index 50838d7..ea8d9e4 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -187,6 +187,7 @@ typedef struct {
 #define SECCLASS_X_SERVER		11
 #define SECCLASS_X_EXTENSION		12
 #define SECCLASS_X_EVENT		13
-#define SECCLASS_X_RESOURCE		14
+#define SECCLASS_X_FAKEEVENT		14
+#define SECCLASS_X_RESOURCE		15
 
 #endif /* _XSELINUX_H */
commit b092856baba5bd43b23950f23236b5cc3ce78c1e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Nov 9 14:45:02 2007 -0500

    registry: Register XC-SECURITY extension protocol names.

diff --git a/Xext/security.c b/Xext/security.c
index 6aab3a3..eef4f69 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1114,4 +1114,20 @@ SecurityExtensionInit(INITARGS)
 
     /* Label objects that were created before we could register ourself */
     SecurityLabelInitial();
+
+    /* Register protocol names */
+    RegisterRequestName(extEntry->base, X_SecurityQueryVersion,
+			SECURITY_EXTENSION_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_SecurityGenerateAuthorization,
+			SECURITY_EXTENSION_NAME ":GenerateAuthorization");
+    RegisterRequestName(extEntry->base, X_SecurityRevokeAuthorization,
+			SECURITY_EXTENSION_NAME ":RevokeAuthorization");
+
+    RegisterEventName(SecurityEventBase + XSecurityAuthorizationRevoked,
+		      SECURITY_EXTENSION_NAME ":AuthorizationRevoked");
+
+    RegisterErrorName(SecurityErrorBase + XSecurityBadAuthorization,
+		      SECURITY_EXTENSION_NAME ":BadAuthorization");
+    RegisterErrorName(SecurityErrorBase + XSecurityBadAuthorizationProtocol,
+		      SECURITY_EXTENSION_NAME ":BadAuthorizationProtocol");
 }
commit 1c6cb353f77747c101ce47716ff1fa055fbf85a4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Nov 8 16:46:49 2007 -0500

    Restore the XC-SECURITY option in configure.ac, but disabled by default.

diff --git a/configure.ac b/configure.ac
index 278dcac..84b24cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -514,8 +514,8 @@ AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF8
 AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: auto)]), [XF86MISC=$enableval], [XF86MISC=auto])
 AC_ARG_ENABLE(xace,           AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
 AC_ARG_ENABLE(xselinux,       AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: disabled)]), [XSELINUX=$enableval], [XSELINUX=no])
-AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (TEMPORARILY DISABLED)]), [XCSECURITY=no], [XCSECURITY=no])
-AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
+AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (default: disabled)]), [XCSECURITY=$enableval], [XCSECURITY=no])
+AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: disabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
 AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
 AC_ARG_ENABLE(tslib,          AS_HELP_STRING([--enable-tslib], [Build kdrive tslib touchscreen support (default: disabled)]), [TSLIB=$enableval], [TSLIB=no])
 AC_ARG_ENABLE(xevie,          AS_HELP_STRING([--disable-xevie], [Build XEvIE extension (default: enabled)]), [XEVIE=$enableval], [XEVIE=yes])
commit 9d03cad1446c27b397c198cf6247e71e46bc9e6d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Nov 8 16:41:47 2007 -0500

    Remove SecurityPolicy file and associated references in the manpages.

diff --git a/.gitignore b/.gitignore
index 27132c0..1213d99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -92,8 +92,6 @@ cfb32/cfbzerarcG.c
 cfb32/cfbzerarcX.c
 doc/Xserver.1x
 doc/Xserver.man
-doc/SecurityPolicy.5
-doc/SecurityPolicy.man
 hw/dmx/Xdmx
 hw/dmx/Xdmx.1x
 hw/dmx/config/dmxtodmx
diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 6fe1c34..f57e599 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -33,9 +33,6 @@ MODULE_SRCS =			\
 	sync.c			\
 	xcmisc.c
 
-# Extra configuration files ship with some extensions
-SERVERCONFIG_DATA =
-
 # Optional sources included if extension enabled by configure.ac rules
 
 # MIT Shared Memory extension
@@ -86,9 +83,6 @@ endif
 XCSECURITY_SRCS = security.c securitysrv.h
 if XCSECURITY   
 BUILTIN_SRCS += $(XCSECURITY_SRCS)
-
-SERVERCONFIG_DATA += SecurityPolicy
-AM_CFLAGS += -DDEFAULTPOLICYFILE=\"$(SERVERCONFIGdir)/SecurityPolicy\"
 endif
 
 XCALIBRATE_SRCS = xcalibrate.c
@@ -166,7 +160,6 @@ libXextmodule_la_SOURCES =	$(MODULE_SRCS)
 endif
 
 EXTRA_DIST = \
-	$(SERVERCONFIG_DATA) \
 	$(MITSHM_SRCS) \
 	$(XV_SRCS) \
 	$(RES_SRCS) \
diff --git a/Xext/SecurityPolicy b/Xext/SecurityPolicy
deleted file mode 100644
index 04dfb0e..0000000
--- a/Xext/SecurityPolicy
+++ /dev/null
@@ -1,86 +0,0 @@
-version-1 
-
-# $Xorg: SecurityPolicy,v 1.3 2000/08/17 19:47:56 cpqbld Exp $
-
-# Property access rules:
-# property <property> <window> <permissions>
-# <window> ::= any | root | <propertyselector>
-# <propertyselector> ::= <property> | <property>=<value>
-# <permissions> :== [ <operation> | <action> | <space> ]*
-# <operation> :== r | w | d
-#	r	read
-#	w	write
-#	d	delete
-# <action> :== a | i | e
-#	a	allow
-#	i	ignore
-#	e	error
-
-# Allow reading of application resources, but not writing.
-property RESOURCE_MANAGER	root	ar iw
-property SCREEN_RESOURCES	root	ar iw
-
-# Ignore attempts to use cut buffers.  Giving errors causes apps to crash,
-# and allowing access may give away too much information.
-property CUT_BUFFER0	root	irw
-property CUT_BUFFER1	root	irw
-property CUT_BUFFER2	root	irw
-property CUT_BUFFER3	root	irw
-property CUT_BUFFER4	root	irw
-property CUT_BUFFER5	root	irw
-property CUT_BUFFER6	root	irw
-property CUT_BUFFER7	root	irw
-
-# If you are using Motif, you probably want these.
-property _MOTIF_DEFAULT_BINDINGS	root	ar iw
-property _MOTIF_DRAG_WINDOW	root	ar iw
-property _MOTIF_DRAG_TARGETS	any 	ar iw
-property _MOTIF_DRAG_ATOMS	any 	ar iw
-property _MOTIF_DRAG_ATOM_PAIRS	any 	ar iw
-
-# If you are running CDE you also need these
-property _MOTIF_WM_INFO		root	arw
-property TT_SESSION		root	irw
-property WM_ICON_SIZE		root	irw
-property "SDT Pixel Set"	any	irw
-
-# The next two rules let xwininfo -tree work when untrusted.
-property WM_NAME	any	ar
-
-# Allow read of WM_CLASS, but only for windows with WM_NAME.
-# This might be more restrictive than necessary, but demonstrates
-# the <required property> facility, and is also an attempt to
-# say "top level windows only."
-property WM_CLASS	WM_NAME	ar
-
-# These next three let xlsclients work untrusted.  Think carefully
-# before including these; giving away the client machine name and command
-# may be exposing too much.
-property WM_STATE	WM_NAME	ar
-property WM_CLIENT_MACHINE	WM_NAME	ar
-property WM_COMMAND	WM_NAME	ar
-
-# To let untrusted clients use the standard colormaps created by
-# xstdcmap, include these lines.
-property RGB_DEFAULT_MAP	root	ar
-property RGB_BEST_MAP	root	ar
-property RGB_RED_MAP	root	ar
-property RGB_GREEN_MAP	root	ar
-property RGB_BLUE_MAP	root	ar
-property RGB_GRAY_MAP	root	ar
-
-# To let untrusted clients use the color management database created
-# by xcmsdb, include these lines.
-property XDCCC_LINEAR_RGB_CORRECTION	root	ar
-property XDCCC_LINEAR_RGB_MATRICES	root	ar
-property XDCCC_GRAY_SCREENWHITEPOINT	root	ar
-property XDCCC_GRAY_CORRECTION	root	ar
-
-# To let untrusted clients use the overlay visuals that many vendors
-# support, include this line.
-property SERVER_OVERLAY_VISUALS	root	ar
-
-# Only trusted extensions can be used by untrusted clients
-trust extension XC-MISC
-trust extension BIG-REQUESTS
-trust extension XpExtension
diff --git a/doc/Makefile.am b/doc/Makefile.am
index ce1979d..d3911c9 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -5,7 +5,7 @@ filemandir = $(FILE_MAN_DIR)
 # (i.e. those handled in the os/utils.c options processing instead of in
 #  the DDX-level options processing)
 appman_PRE = Xserver.man.pre
-fileman_PRE = SecurityPolicy.man.pre
+fileman_PRE =
 
 appman_PROCESSED = $(appman_PRE:man.pre=man)
 fileman_PROCESSED = $(fileman_PRE:man.pre=man)
diff --git a/doc/SecurityPolicy.man.pre b/doc/SecurityPolicy.man.pre
deleted file mode 100644
index f5aff0c..0000000
--- a/doc/SecurityPolicy.man.pre
+++ /dev/null
@@ -1,258 +0,0 @@
-.\" Split out of Xserver.man, which was covered by this notice:
-.\" Copyright 1984 - 1991, 1993, 1994, 1998  The Open Group
-.\"
-.\" Permission to use, copy, modify, distribute, and sell this software and its
-.\" documentation for any purpose is hereby granted without fee, provided that
-.\" the above copyright notice appear in all copies and that both that
-.\" copyright notice and this permission notice appear in supporting
-.\" documentation.
-.\"
-.\" The above copyright notice and this permission notice shall be included
-.\" in all copies or substantial portions of the Software.
-.\"
-.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-.\" IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-.\" OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-.\" ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-.\" OTHER DEALINGS IN THE SOFTWARE.
-.\"
-.\" Except as contained in this notice, the name of The Open Group shall
-.\" not be used in advertising or otherwise to promote the sale, use or
-.\" other dealings in this Software without prior written authorization
-.\" from The Open Group.
-.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.31 2004/01/10 22:27:46 dawes Exp $
-.\" shorthand for double quote that works everywhere.
-.ds q \N'34'
-.TH SecurityPolicy __filemansuffix__ __xorgversion__
-.SH NAME
-SecurityPolicy \- X Window System SECURITY Extension Policy file format
-.SH DESCRIPTION
-The SECURITY extension to the X Window System uses a policy file to determine
-which operations should be allowed or denied.   The default location for this
-file is
-.IR __projectroot__/lib/xserver/SecurityPolicy .
-.PP
-The syntax of the security policy file is as follows.
-Notation: "*" means zero or more occurrences of the preceding element,
-and "+" means one or more occurrences.  To interpret <foo/bar>, ignore
-the text after the /; it is used to distinguish between instances of
-<foo> in the next section.
-.PP
-.nf
-<policy file> ::= <version line> <other line>*
-
-<version line> ::= <string/v> '\en'
-
-<other line > ::= <comment> | <access rule> | <site policy> | <blank line>
-
-<comment> ::= # <not newline>* '\en'
-
-<blank line> ::= <space> '\en'
-
-<site policy> ::= sitepolicy <string/sp> '\en'
-
-<access rule> ::= property <property/ar> <window> <perms> '\en'
-
-<property> ::= <string>
-
-<window> ::= any | root | <required property>
-
-<required property> ::= <property/rp> | <property with value>
-
-<property with value> ::= <property/rpv> = <string/rv>
-
-<perms> ::= [ <operation> | <action> | <space> ]*
-
-<operation> ::= r | w | d
-
-<action> ::= a | i | e
-
-<string> ::= <dbl quoted string> | <single quoted string> | <unquoted string>
-
-<dbl quoted string> ::= <space> " <not dquote>* " <space>
-
-<single quoted string> ::= <space> ' <not squote>* ' <space>
-
-<unquoted string> ::= <space> <not space>+ <space>
-
-<space> ::= [ ' ' | '\et' ]*
-
-Character sets:
-
-<not newline> ::= any character except '\en'
-<not dquote>  ::= any character except "
-<not squote>  ::= any character except '
-<not space>   ::= any character except those in <space>
-.fi
-.PP
-The semantics associated with the above syntax are as follows.
-.PP
-<version line>, the first line in the file, specifies the file format
-version.  If the server does not recognize the version <string/v>, it
-ignores the rest of the file.  The version string for the file format
-described here is "version-1" .
-.PP
-Once past the <version line>, lines that do not match the above syntax
-are ignored.
-.PP
-<comment> lines are ignored.
-.PP
-<sitepolicy> lines are currently ignored.  They are intended to
-specify the site policies used by the XC-QUERY-SECURITY-1
-authorization method.
-.PP
-<access rule> lines specify how the server should react to untrusted
-client requests that affect the X Window property named <property/ar>.
-The rest of this section describes the interpretation of an
-<access rule>.
-.PP
-For an <access rule> to apply to a given instance of <property/ar>,
-<property/ar> must be on a window that is in the set of windows
-specified by <window>.  If <window> is any, the rule applies to
-<property/ar> on any window.  If <window> is root, the rule applies to
-<property/ar> only on root windows.
-.PP
-If <window> is <required property>, the following apply.  If <required
-property> is a <property/rp>, the rule applies when the window also
-has that <property/rp>, regardless of its value.  If <required
-property> is a <property with value>, <property/rpv> must also have
-the value specified by <string/rv>.  In this case, the property must
-have type STRING and format 8, and should contain one or more
-null-terminated strings.  If any of the strings match <string/rv>, the
-rule applies.
-.PP
-The definition of string matching is simple case-sensitive string
-comparison with one elaboration: the occurrence of the character '*' in
-<string/rv> is a wildcard meaning "any string."  A <string/rv> can
-contain multiple wildcards anywhere in the string.  For example, "x*"
-matches strings that begin with x, "*x" matches strings that end with
-x, "*x*" matches strings containing x, and "x*y*" matches strings that
-start with x and subsequently contain y.
-.PP
-There may be multiple <access rule> lines for a given <property/ar>.
-The rules are tested in the order that they appear in the file.  The
-first rule that applies is used.
-.PP
-<perms> specify operations that untrusted clients may attempt, and
-the actions that the server should take in response to those operations.
-.PP
-<operation> can be r (read), w (write), or d (delete).  The following
-table shows how X Protocol property requests map to these operations
-in the X.Org server implementation.
-.PP
-.nf
-GetProperty	r, or r and d if delete = True
-ChangeProperty	w
-RotateProperties	r and w
-DeleteProperty	d
-ListProperties	none, untrusted clients can always list all properties
-.fi
-.PP
-<action> can be a (allow), i (ignore), or e (error).  Allow means
-execute the request as if it had been issued by a trusted client.
-Ignore means treat the request as a no-op.  In the case of
-GetProperty, ignore means return an empty property value if the
-property exists, regardless of its actual value.  Error means do not
-execute the request and return a BadAtom error with the atom set to
-the property name.  Error is the default action for all properties,
-including those not listed in the security policy file.
-.PP
-An <action> applies to all <operation>s that follow it, until the next
-<action> is encountered.  Thus, irwad  means ignore read and write,
-allow delete.
-.PP
-GetProperty and RotateProperties may do multiple operations (r and d,
-or r and w).  If different actions apply to the operations, the most
-severe action is applied to the whole request; there is no partial
-request execution.  The severity ordering is: allow < ignore < error.
-Thus, if the <perms> for a property are ired (ignore read, error
-delete), and an untrusted client attempts GetProperty on that property
-with delete = True, an error is returned, but the property value is
-not.  Similarly, if any of the properties in a RotateProperties do not
-allow both read and write, an error is returned without changing any
-property values.
-.PP
-Here is an example security policy file.
-.PP
-.ta 3i 4i
-.nf
-version-1
-
-XCOMM Allow reading of application resources, but not writing.
-property RESOURCE_MANAGER	root	ar iw
-property SCREEN_RESOURCES	root	ar iw
-
-XCOMM Ignore attempts to use cut buffers.  Giving errors causes apps to crash,
-XCOMM and allowing access may give away too much information.
-property CUT_BUFFER0	root	irw
-property CUT_BUFFER1	root	irw
-property CUT_BUFFER2	root	irw
-property CUT_BUFFER3	root	irw
-property CUT_BUFFER4	root	irw
-property CUT_BUFFER5	root	irw
-property CUT_BUFFER6	root	irw
-property CUT_BUFFER7	root	irw
-
-XCOMM If you are using Motif, you probably want these.
-property _MOTIF_DEFAULT_BINDINGS	root	ar iw
-property _MOTIF_DRAG_WINDOW	root	ar iw
-property _MOTIF_DRAG_TARGETS	any 	ar iw
-property _MOTIF_DRAG_ATOMS	any 	ar iw
-property _MOTIF_DRAG_ATOM_PAIRS	any 	ar iw
-
-XCOMM The next two rules let xwininfo -tree work when untrusted.
-property WM_NAME	any	ar
-
-XCOMM Allow read of WM_CLASS, but only for windows with WM_NAME.
-XCOMM This might be more restrictive than necessary, but demonstrates
-XCOMM the <required property> facility, and is also an attempt to
-XCOMM say "top level windows only."
-property WM_CLASS	WM_NAME	ar
-
-XCOMM These next three let xlsclients work untrusted.  Think carefully
-XCOMM before including these; giving away the client machine name and command
-XCOMM may be exposing too much.
-property WM_STATE	WM_NAME	ar
-property WM_CLIENT_MACHINE	WM_NAME	ar
-property WM_COMMAND	WM_NAME	ar
-
-XCOMM To let untrusted clients use the standard colormaps created by
-XCOMM xstdcmap, include these lines.
-property RGB_DEFAULT_MAP	root	ar
-property RGB_BEST_MAP	root	ar
-property RGB_RED_MAP	root	ar
-property RGB_GREEN_MAP	root	ar
-property RGB_BLUE_MAP	root	ar
-property RGB_GRAY_MAP	root	ar
-
-XCOMM To let untrusted clients use the color management database created
-XCOMM by xcmsdb, include these lines.
-property XDCCC_LINEAR_RGB_CORRECTION	root	ar
-property XDCCC_LINEAR_RGB_MATRICES	root	ar
-property XDCCC_GRAY_SCREENWHITEPOINT	root	ar
-property XDCCC_GRAY_CORRECTION	root	ar
-
-XCOMM To let untrusted clients use the overlay visuals that many vendors
-XCOMM support, include this line.
-property SERVER_OVERLAY_VISUALS	root	ar
-
-XCOMM Dumb examples to show other capabilities.
-
-XCOMM oddball property names and explicit specification of error conditions
-property "property with spaces"	'property with "'	aw er ed
-
-XCOMM Allow deletion of Woo-Hoo if window also has property OhBoy with value
-XCOMM ending in "son".  Reads and writes will cause an error.
-property Woo-Hoo	OhBoy = "*son"	ad
-
-.fi
-.SH FILES
-.TP 30
-.I __projectroot__/lib/xserver/SecurityPolicy
-Default X server security policy
-.SH "SEE ALSO"
-.PP
-\fIXserver\fp(__appmansuffix__),
-.I "Security Extension Specification"
diff --git a/doc/Xserver.man.pre b/doc/Xserver.man.pre
index c9ee019..c47a396 100644
--- a/doc/Xserver.man.pre
+++ b/doc/Xserver.man.pre
@@ -407,15 +407,6 @@ elapse between autorepeat-generated keystrokes).
 .TP 8
 .B \-xkbmap \fIfilename\fP
 loads keyboard description in \fIfilename\fP on server startup.
-.SH SECURITY EXTENSION OPTIONS
-X servers that support the SECURITY extension accept the following option:
-.TP 8
-.B \-sp \fIfilename\fP
-causes the server to attempt to read and interpret filename as a security
-policy file with the format described below.  The file is read at server
-startup and reread at each server reset.
-The syntax of the security policy file is described in 
-\fISecurityPolicy\fP(__filemansuffix__).
 .SH "NETWORK CONNECTIONS"
 The X server supports client connections via a platform-dependent subset of
 the following transport types: TCP\/IP, Unix Domain sockets, DECnet,
@@ -580,9 +571,6 @@ Error log file for display number \fBn\fP if run from \fIinit\fP(__adminmansuffi
 .TP 30
 .I __projectroot__/lib/X11/xdm/xdm-errors
 Default error log file if the server is run from \fIxdm\fP(1)
-.TP 30
-.I __projectroot__/lib/xserver/SecurityPolicy
-Default X server security policy
 .SH "SEE ALSO"
 General information: \fIX\fP(__miscmansuffix__)
 .PP
@@ -597,7 +585,6 @@ Fonts: \fIbdftopcf\fP(1), \fImkfontdir\fP(1), \fImkfontscale\fP(1),
 .PP
 Security: \fIXsecurity\fP(__miscmansuffix__), \fIxauth\fP(1), \fIXau\fP(1), 
 \fIxdm\fP(1), \fIxhost\fP(1), \fIxfwp\fP(1),
-\fISecurityPolicy\fP(__filemansuffix__),
 .I "Security Extension Specification"
 .PP
 Starting the server: \fIxdm\fP(1), \fIxinit\fP(1)
commit 8b5d21cc1d1f4e9d20e5d5eca44cb1e60a419763
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Nov 8 16:32:42 2007 -0500

    Rework of the XC-SECURITY extension.  The gen-auth protocol has not changed,
    but the XC-QUERY-SECURITY-1 authorization method and the SecurityPolicy
    configuration file have been removed.  The semantics of the trusted vs.
    untrusted split have been changed.  This will be documented in a future
    commit.

diff --git a/Xext/security.c b/Xext/security.c
index ec414a0..6aab3a3 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -31,53 +31,47 @@ in this Software without prior written authorization from The Open Group.
 #include "scrnintstr.h"
 #include "colormapst.h"
 #include "privates.h"
+#include "registry.h"
 #include "xacestr.h"
 #include "securitysrv.h"
 #include <X11/extensions/securstr.h>
-#include <assert.h>
-#include <stdarg.h>
 #ifdef XAPPGROUP
 #include "appgroup.h"
 #endif
-#include <stdio.h>  /* for file reading operations */
-#include <X11/Xatom.h>  /* for XA_STRING */
-
-#ifndef DEFAULTPOLICYFILE
-# define DEFAULTPOLICYFILE NULL
-#endif
-#if defined(WIN32) || defined(__CYGWIN__)
-#include <X11/Xos.h>
-#undef index
-#endif
-
 #include "modinit.h"
 
+/* Extension stuff */
 static int SecurityErrorBase;  /* first Security error number */
 static int SecurityEventBase;  /* first Security event number */
-static const DevPrivateKey stateKey = &stateKey;
 
-/* this is what we store as client security state */
+RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
+static RESTYPE RTEventClient;
+
+static CallbackListPtr SecurityValidateGroupCallback = NULL;
+
+/* Private state record */
+static DevPrivateKey stateKey = &stateKey;
+
+/* This is what we store as client security state */
 typedef struct {
     int haveState;
     unsigned int trustLevel;
     XID authId;
-} SecurityClientStateRec;
-
-#define HAVESTATE(client) (((SecurityClientStateRec *) \
-    dixLookupPrivate(DEVPRIV_PTR(client), stateKey))->haveState)
-#define TRUSTLEVEL(client) (((SecurityClientStateRec *) \
-    dixLookupPrivate(DEVPRIV_PTR(client), stateKey))->trustLevel)
-#define AUTHID(client)(((SecurityClientStateRec *) \
-    dixLookupPrivate(DEVPRIV_PTR(client), stateKey))->authId)
-
-static CallbackListPtr SecurityValidateGroupCallback = NULL;
-
-static char **SecurityTrustedExtensions = NULL;
-static int nSecurityTrustedExtensions = 0;
+} SecurityStateRec;
+
+/* Extensions that untrusted clients shouldn't have access to */
+static char *SecurityUntrustedExtensions[] = {
+    "RandR",
+    "SECURITY",
+    "XFree86-DGA",
+    NULL
+};
 
-RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
+/* Access modes that untrusted clients can do to trusted stuff */
+static const Mask SecurityAllowedMask =
+    DixGetAttrAccess | DixListPropAccess | DixGetPropAccess |
+    DixGetFocusAccess | DixListAccess | DixReceiveAccess;
 
-static RESTYPE RTEventClient;
 
 /* SecurityAudit
  *
@@ -103,6 +97,51 @@ SecurityAudit(char *format, ...)
     va_end(args);
 } /* SecurityAudit */
 
+/*
+ * Performs a Security permission check.
+ */
+static int
+SecurityDoCheck(SecurityStateRec *subj, SecurityStateRec *obj,
+		Mask requested, Mask allowed)
+{
+    if (!subj->haveState || !obj->haveState)
+	return Success;
+    if (subj->trustLevel == XSecurityClientTrusted)
+	return Success;
+    if (obj->trustLevel != XSecurityClientTrusted)
+	return Success;
+    if ((requested | allowed) == allowed)
+	return Success;
+
+    return BadAccess;
+}
+
+/*
+ * Labels initial server objects.
+ */
+static void
+SecurityLabelInitial(void)
+{
+    SecurityStateRec *state;
+
+    /* Do the serverClient */
+    state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+    state->trustLevel = XSecurityClientTrusted;
+    state->haveState = TRUE;
+}
+
+/*
+ * Looks up a request name
+ */
+static _X_INLINE const char *
+SecurityLookupRequestName(ClientPtr client)
+{
+    int major = ((xReq *)client->requestBuffer)->reqType;
+    int minor = MinorOpcodeOfRequest(client);
+    return LookupRequestName(major, minor);
+}
+
+
 #define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
 
 /* SecurityDeleteAuthorization
@@ -163,10 +202,12 @@ SecurityDeleteAuthorization(
     /* kill all clients using this auth */
 
     for (i = 1; i<currentMaxClients; i++)
-    {
-	if (clients[i] && (AUTHID(clients[i]) == pAuth->id))
-	    CloseDownClient(clients[i]);
-    }
+	if (clients[i]) {
+	    SecurityStateRec *state;
+	    state = dixLookupPrivate(&clients[i]->devPrivates, stateKey);
+	    if (state->haveState && state->authId == pAuth->id)
+		CloseDownClient(clients[i]);
+	}
 
     SecurityAudit("revoked authorization ID %d\n", pAuth->id);
     xfree(pAuth);
@@ -315,12 +356,6 @@ ProcSecurityQueryVersion(
     /* REQUEST(xSecurityQueryVersionReq); */
     xSecurityQueryVersionReply 	rep;
 
-    /* paranoia: this "can't happen" because this extension is hidden
-     * from untrusted clients, but just in case...
-     */
-    if (TRUSTLEVEL(client) != XSecurityClientTrusted)
-	return BadRequest;
-
     REQUEST_SIZE_MATCH(xSecurityQueryVersionReq);
     rep.type        	= X_Reply;
     rep.sequenceNumber 	= client->sequence;
@@ -401,12 +436,6 @@ ProcSecurityGenerateAuthorization(
     char *pAuthdata;		/* generated auth data */
     Mask eventMask;		/* what events on this auth does client want */
 
-    /* paranoia: this "can't happen" because this extension is hidden
-     * from untrusted clients, but just in case...
-     */
-    if (TRUSTLEVEL(client) != XSecurityClientTrusted)
-	return BadRequest;
-
     /* check request length */
 
     REQUEST_AT_LEAST_SIZE(xSecurityGenerateAuthorizationReq);
@@ -584,12 +613,6 @@ ProcSecurityRevokeAuthorization(
     REQUEST(xSecurityRevokeAuthorizationReq);
     SecurityAuthorizationPtr pAuth;
 
-    /* paranoia: this "can't happen" because this extension is hidden
-     * from untrusted clients, but just in case...
-     */
-    if (TRUSTLEVEL(client) != XSecurityClientTrusted)
-	return BadRequest;
-
     REQUEST_SIZE_MATCH(xSecurityRevokeAuthorizationReq);
 
     pAuth = (SecurityAuthorizationPtr)SecurityLookupIDByType(client,
@@ -703,59 +726,6 @@ SwapSecurityAuthorizationRevokedEvent(
     cpswapl(from->authId, to->authId);
 }
 
-/* SecurityDetermineEventPropogationLimits
- *
- * This is a helper function for SecurityCheckDeviceAccess.
- *
- * Arguments:
- *	dev is the device for which the starting and stopping windows for
- *	event propogation should be determined.
- *	The values pointed to by ppWin and ppStopWin are not used.
- *
- * Returns:
- *	ppWin is filled in with a pointer to the window at which event
- *	propogation for the given device should start given the current
- *	state of the server (pointer position, window layout, etc.)
- *	ppStopWin is filled in with the window at which event propogation
- *	should stop; events should not go to ppStopWin.
- *
- * Side Effects: none.
- */
-
-static void
-SecurityDetermineEventPropogationLimits(
-    DeviceIntPtr dev,
-    WindowPtr *ppWin,
-    WindowPtr *ppStopWin)
-{
-    WindowPtr pFocusWin = dev->focus ? dev->focus->win : NoneWin;
-
-    if (pFocusWin == NoneWin)
-    { /* no focus -- events don't go anywhere */
-	*ppWin = *ppStopWin = NULL;
-	return;
-    }
-
-    if (pFocusWin == PointerRootWin)
-    { /* focus follows the pointer */
-	*ppWin = GetSpriteWindow();
-	*ppStopWin = NULL; /* propogate all the way to the root */
-    }
-    else
-    { /* a real window is set for the focus */
-	WindowPtr pSpriteWin = GetSpriteWindow();
-	*ppStopWin = pFocusWin->parent; /* don't go past the focus window */
-
-	/* if the pointer is in a subwindow of the focus window, start
-	 * at that subwindow, else start at the focus window itself
-	 */
-	if (IsParent(pFocusWin, pSpriteWin))
-	     *ppWin = pSpriteWin;
-	else *ppWin = pFocusWin;
-    }
-} /* SecurityDetermineEventPropogationLimits */
-
-
 /* SecurityCheckDeviceAccess
  *
  * Arguments:
@@ -773,163 +743,25 @@ SecurityDetermineEventPropogationLimits(
  */
 
 static void
-SecurityCheckDeviceAccess(CallbackListPtr *pcbl, pointer unused,
-			  pointer calldata)
+SecurityDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceDeviceAccessRec *rec = (XaceDeviceAccessRec*)calldata;
-    ClientPtr client = rec->client;
-    DeviceIntPtr dev = rec->dev;
-    Bool fromRequest = rec->fromRequest;
-    WindowPtr pWin, pStopWin;
-    Bool untrusted_got_event;
-    Bool found_event_window;
-    Mask eventmask;
-    int reqtype = 0;
-
-    /* trusted clients always allowed to do anything */
-    if (TRUSTLEVEL(client) == XSecurityClientTrusted)
-	return;
-
-    /* device security other than keyboard is not implemented yet */
-    if (dev != inputInfo.keyboard)
-	return;
-
-    /* some untrusted client wants access */
-
-    if (fromRequest)
-    {
-	reqtype = ((xReq *)client->requestBuffer)->reqType;
-	switch (reqtype)
-	{
-	    /* never allow these */
-	    case X_ChangeKeyboardMapping:
-	    case X_ChangeKeyboardControl:
-	    case X_SetModifierMapping:
-		SecurityAudit("client %d attempted request %d\n",
-			      client->index, reqtype);
-		rec->status = BadAccess;
-		return;
-	    default:
-		break;
-	}
-    }
-
-    untrusted_got_event = FALSE;
-    found_event_window = FALSE;
-
-    if (dev->grab)
-    {
-	untrusted_got_event =
-	    (TRUSTLEVEL(rClient(dev->grab)) != XSecurityClientTrusted);
-    }
-    else
-    {
-	SecurityDetermineEventPropogationLimits(dev, &pWin, &pStopWin);
-
-	eventmask = KeyPressMask | KeyReleaseMask;
-	while ( (pWin != pStopWin) && !found_event_window)
-	{
-	    OtherClients *other;
-
-	    if (pWin->eventMask & eventmask)
-	    {
-		found_event_window = TRUE;
-		client = wClient(pWin);
-		if (TRUSTLEVEL(client) != XSecurityClientTrusted)
-		{
-		    untrusted_got_event = TRUE;
-		}
-	    }
-	    if (wOtherEventMasks(pWin) & eventmask)
-	    {
-		found_event_window = TRUE;
-		for (other = wOtherClients(pWin); other; other = other->next)
-		{
-		    if (other->mask & eventmask)
-		    {
-			client = rClient(other);
-			if (TRUSTLEVEL(client) != XSecurityClientTrusted)
-			{
-			    untrusted_got_event = TRUE;
-			    break;
-			}
-		    }
-		}
-	    }
-	    if (wDontPropagateMask(pWin) & eventmask)
-		break;
-	    pWin = pWin->parent;
-	} /* while propogating the event */
-    }
-
-    /* allow access by untrusted clients only if an event would have gone 
-     * to an untrusted client
-     */
-    
-    if (!untrusted_got_event)
-    {
-	char *devname = dev->name;
-	if (!devname) devname = "unnamed";
-	if (fromRequest)
-	    SecurityAudit("client %d attempted request %d device %d (%s)\n",
-			  client->index, reqtype, dev->id, devname);
-	else
-	    SecurityAudit("client %d attempted to access device %d (%s)\n",
-			  client->index, dev->id, devname);
+    XaceDeviceAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
+    Mask requested = rec->access_mode;
+    Mask allowed = SecurityAllowedMask;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+
+    if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
+	SecurityAudit("Security denied client %d keyboard access on request "
+		      "%s\n", rec->client->index,
+		      SecurityLookupRequestName(rec->client));
 	rec->status = BadAccess;
     }
-    return;
-} /* SecurityCheckDeviceAccess */
-
-
-
-/* SecurityAuditResourceIDAccess
- *
- * Arguments:
- *	client is the client doing the resource access.
- *	id is the resource id.
- *
- * Returns: NULL
- *
- * Side Effects:
- *	An audit message is generated with details of the denied
- *	resource access.
- */
-
-static pointer
-SecurityAuditResourceIDAccess(
-    ClientPtr client,
-    XID id)
-{
-    int cid = CLIENT_ID(id);
-    int reqtype = ((xReq *)client->requestBuffer)->reqType;
-    switch (reqtype)
-    {
-	case X_ChangeProperty:
-	case X_DeleteProperty:
-	case X_GetProperty:
-	{
-	    xChangePropertyReq *req =
-		(xChangePropertyReq *)client->requestBuffer;
-	    int propertyatom = req->property;
-	    char *propertyname = NameForAtom(propertyatom);
-
-	    SecurityAudit("client %d attempted request %d with window 0x%x property %s of client %d\n",
-		   client->index, reqtype, id, propertyname, cid);
-	    break;
-	}
-	default:
-	{
-	    SecurityAudit("client %d attempted request %d with resource 0x%x of client %d\n",
-		   client->index, reqtype, id, cid);
-	    break;
-	}   
-    }
-    return NULL;
-} /* SecurityAuditResourceIDAccess */
-
+}
 
-/* SecurityCheckResourceIDAccess
+/* SecurityResource
  *
  * This function gets plugged into client->CheckAccess and is called from
  * SecurityLookupIDByType/Class to determine if the client can access the
@@ -951,803 +783,245 @@ SecurityAuditResourceIDAccess(
  */
 
 static void
-SecurityCheckResourceIDAccess(CallbackListPtr *pcbl, pointer unused,
-			      pointer calldata)
+SecurityResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceResourceAccessRec *rec = (XaceResourceAccessRec*)calldata;
-    ClientPtr client = rec->client;
-    XID id = rec->id;
-    RESTYPE rtype = rec->rtype;
-    Mask access_mode = rec->access_mode;
-    pointer rval = rec->res;
-    int cid, reqtype;
-
-    if (TRUSTLEVEL(client) == XSecurityClientTrusted ||
-	DixUnknownAccess == access_mode)
-	return;       /* for compatibility, we have to allow access */
-
-    cid = CLIENT_ID(id);
-    reqtype = ((xReq *)client->requestBuffer)->reqType;
-    switch (reqtype)
-    { /* these are always allowed */
-	case X_QueryTree:
-        case X_TranslateCoords:
-        case X_GetGeometry:
-	/* property access is controlled in SecurityCheckPropertyAccess */
-	case X_GetProperty:
-	case X_ChangeProperty:
-	case X_DeleteProperty:
-	case X_RotateProperties:
-        case X_ListProperties:
-	    return;
-	default:
-	    break;
+    XaceResourceAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
+    int cid = CLIENT_ID(rec->id);
+    Mask requested = rec->access_mode;
+    Mask allowed = SecurityAllowedMask;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&clients[cid]->devPrivates, stateKey);
+
+    /* special checks for server-owned resources */
+    if (cid == 0) {
+	if (rec->rtype & RC_DRAWABLE)
+	    /* additional operations allowed on root windows */
+	    allowed |= DixReadAccess|DixSendAccess;
+
+	else if (rec->rtype == RT_COLORMAP)
+	    /* allow access to default colormaps */
+	    allowed = requested;
     }
 
-    if (cid != 0)
-    { /* not a server-owned resource */
-     /*
-      * The following 'if' restricts clients to only access resources at
-      * the same trustLevel.  Since there are currently only two trust levels,
-      * and trusted clients never call this function, this degenerates into
-      * saying that untrusted clients can only access resources of other
-      * untrusted clients.  One way to add the notion of groups would be to
-      * allow values other than Trusted (0) and Untrusted (1) for this field.
-      * Clients at the same trust level would be able to use each other's
-      * resources, but not those of clients at other trust levels.  I haven't
-      * tried it, but this probably mostly works already.  The obvious
-      * competing alternative for grouping clients for security purposes is to
-      * use app groups.  dpw
-      */
-	if (TRUSTLEVEL(client) == TRUSTLEVEL(clients[cid])
+    if (SecurityDoCheck(subj, obj, requested, allowed) == Success)
+	return;
+
 #ifdef XAPPGROUP
-	    || (RT_COLORMAP == rtype && 
-		XagDefaultColormap (client) == (Colormap) id)
+    if (rec->id == XagDefaultColormap(rec->client))
+	return;
 #endif
-	)
-	    return;
-	else
-	    goto deny;
-    }
-    else /* server-owned resource - probably a default colormap or root window */
-    {
-	if (RT_WINDOW == rtype || RC_DRAWABLE == rtype)
-	{
-	    switch (reqtype)
-	    {   /* the following operations are allowed on root windows */
-	        case X_CreatePixmap:
-	        case X_CreateGC:
-	        case X_CreateWindow:
-	        case X_CreateColormap:
-		case X_ListProperties:
-		case X_GrabPointer:
-	        case X_UngrabButton:
-		case X_QueryBestSize:
-		case X_GetWindowAttributes:
-		    break;
-		case X_SendEvent:
-		{ /* see if it is an event specified by the ICCCM */
-		    xSendEventReq *req = (xSendEventReq *)
-						(client->requestBuffer);
-		    if (req->propagate == xTrue
-			||
-			  (req->eventMask != ColormapChangeMask &&
-			   req->eventMask != StructureNotifyMask &&
-			   req->eventMask !=
-			      (SubstructureRedirectMask|SubstructureNotifyMask)
-			  )
-			||
-			  (req->event.u.u.type != UnmapNotify &&
-			   req->event.u.u.type != ConfigureRequest &&
-			   req->event.u.u.type != ClientMessage
-			  )
-		       )
-		    { /* not an ICCCM event */
-			goto deny;
-		    }
-		    break;
-		} /* case X_SendEvent on root */
-
-		case X_ChangeWindowAttributes:
-		{ /* Allow selection of PropertyNotify and StructureNotify
-		   * events on the root.
-		   */
-		    xChangeWindowAttributesReq *req =
-			(xChangeWindowAttributesReq *)(client->requestBuffer);
-		    if (req->valueMask == CWEventMask)
-		    {
-			CARD32 value = *((CARD32 *)(req + 1));
-			if ( (value &
-			      ~(PropertyChangeMask|StructureNotifyMask)) == 0)
-			    break;
-		    }
-		    goto deny;
-		} /* case X_ChangeWindowAttributes on root */
-
-		default:
-		{
-		    /* others not allowed */
-		    goto deny;
-		}
-	    }
-	} /* end server-owned window or drawable */
-	else if (SecurityAuthorizationResType == rtype)
-	{
-	    SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)rval;
-	    if (pAuth->trustLevel != TRUSTLEVEL(client))
-		goto deny;
-	}
-	else if (RT_COLORMAP != rtype)
-	{ /* don't allow anything else besides colormaps */
-	    goto deny;
-	}
-    }
-    return;
-  deny:
-    SecurityAuditResourceIDAccess(client, id);
-    rec->status = BadAccess; /* deny access */
-} /* SecurityCheckResourceIDAccess */
 
+    SecurityAudit("Security: denied client %d access to resource 0x%x "
+		  "of client %d on request %s\n", rec->client->index, rec->id,
+		  cid, SecurityLookupRequestName(rec->client));
+    rec->status = BadAccess; /* deny access */
+}
 
-/* SecurityClientStateCallback
- *
- * Arguments:
- *	pcbl is &ClientStateCallback.
- *	nullata is NULL.
- *	calldata is a pointer to a NewClientInfoRec (include/dixstruct.h)
- *	which contains information about client state changes.
- *
- * Returns: nothing.
- *
- * Side Effects:
- * 
- * If a new client is connecting, its authorization ID is copied to
- * client->authID.  If this is a generated authorization, its reference
- * count is bumped, its timer is cancelled if it was running, and its
- * trustlevel is copied to TRUSTLEVEL(client).
- * 
- * If a client is disconnecting and the client was using a generated
- * authorization, the authorization's reference count is decremented, and
- * if it is now zero, the timer for this authorization is started.
- */
 
 static void
-SecurityClientStateCallback(CallbackListPtr *pcbl, pointer unused,
-			    pointer calldata)
+SecurityExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
-    ClientPtr client = pci->client;
-
-    switch (client->clientState)
-    {
-    case ClientStateInitial:
-	TRUSTLEVEL(client) = XSecurityClientTrusted;
-	AUTHID(client) = None;
-	break;
-
-    case ClientStateRunning:
-	{ 
-	    XID authId = AuthorizationIDOfClient(client);
-	    SecurityAuthorizationPtr pAuth;
-
-	    TRUSTLEVEL(client) = XSecurityClientTrusted;
-	    AUTHID(client) = authId;
-	    pAuth = (SecurityAuthorizationPtr)LookupIDByType(authId,
-						SecurityAuthorizationResType);
-	    if (pAuth)
-	    { /* it is a generated authorization */
-		pAuth->refcnt++;
-		if (pAuth->refcnt == 1)
-		{
-		    if (pAuth->timer) TimerCancel(pAuth->timer);
-		}
-		TRUSTLEVEL(client) = pAuth->trustLevel;
+    XaceExtAccessRec *rec = calldata;
+    SecurityStateRec *subj;
+    int i = 0;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+
+    if (subj->haveState && subj->trustLevel != XSecurityClientTrusted)
+	while (SecurityUntrustedExtensions[i])
+	    if (!strcmp(SecurityUntrustedExtensions[i++], rec->ext->name)) {
+		SecurityAudit("Security: denied client %d access to extension "
+			      "%s on request %s\n",
+			      rec->client->index, rec->ext->name,
+			      SecurityLookupRequestName(rec->client));
+		rec->status = BadAccess;
+		return;
 	    }
-	    break;
-	}
-    case ClientStateGone:
-    case ClientStateRetained: /* client disconnected */
-	{
-	    SecurityAuthorizationPtr pAuth;
-
-	    /* client may not have any state (bad authorization) */
-	    if (!HAVESTATE(client))
-		break;
-
-	    pAuth = (SecurityAuthorizationPtr)LookupIDByType(AUTHID(client),
-						SecurityAuthorizationResType);
-	    if (pAuth)
-	    { /* it is a generated authorization */
-		pAuth->refcnt--;
-		if (pAuth->refcnt == 0)
-		{
-		    SecurityStartAuthorizationTimer(pAuth);
-		}
-	    }	    
-	    break;
-	}
-    default: break; 
-    }
-} /* SecurityClientStateCallback */
-
-static void
-SecurityCheckDrawableAccess(CallbackListPtr *pcbl, pointer unused,
-			    pointer calldata)
-{
-    XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
-
-    if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
-	rec->status = BadAccess;
 }
 
 static void
-SecurityCheckMapAccess(CallbackListPtr *pcbl, pointer unused,
-		       pointer calldata)
+SecurityServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
-    WindowPtr pWin = rec->pWin;
-
-    if (HAVESTATE(rec->client) &&
-	(TRUSTLEVEL(rec->client) != XSecurityClientTrusted) &&
-	(pWin->drawable.class == InputOnly) &&
-	pWin->parent && pWin->parent->parent &&
-	(TRUSTLEVEL(wClient(pWin->parent)) == XSecurityClientTrusted))
+    XaceServerAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
+    Mask requested = rec->access_mode;
+    Mask allowed = SecurityAllowedMask;
 
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+ 
+    if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
+	SecurityAudit("Security: denied client %d access to server "
+		      "configuration request %s\n", rec->client->index,
+		      SecurityLookupRequestName(rec->client));
 	rec->status = BadAccess;
+    }
 }
 
 static void
-SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
-		       pointer calldata)
+SecurityClient(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
-    int i, trusted = 0;
-
-    for (i = 0; i < nSecurityTrustedExtensions; i++)
-	if (!strcmp(SecurityTrustedExtensions[i], rec->ext->name))
-	    trusted = 1;
-
-    if ((TRUSTLEVEL(rec->client) != XSecurityClientTrusted) && !trusted)
+    XaceClientAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
+    Mask requested = rec->access_mode;
+    Mask allowed = SecurityAllowedMask;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->target->devPrivates, stateKey);
+
+    if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
+	SecurityAudit("Security: denied client %d access to client %d on "
+		      "request %s\n", rec->client->index, rec->target->index,
+		      SecurityLookupRequestName(rec->client));
 	rec->status = BadAccess;
+    }
 }
 
 static void
-SecurityCheckServerAccess(CallbackListPtr *pcbl, pointer unused,
-			  pointer calldata)
-{
-    XaceServerAccessRec *rec = (XaceServerAccessRec*)calldata;
- 
-    if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
-    {
+SecurityProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{    
+    XacePropertyAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
+    ATOM name = rec->pProp->propertyName;
+    Mask requested = rec->access_mode;
+    Mask allowed = SecurityAllowedMask | DixReadAccess;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey);
+
+    if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
+	SecurityAudit("Security: denied client %d access to property %s "
+		      "(atom 0x%x) window 0x%x of client %d on request %s\n",
+		      rec->client->index, NameForAtom(name), name,
+		      rec->pWin->drawable.id, wClient(rec->pWin)->index,
+		      SecurityLookupRequestName(rec->client));
 	rec->status = BadAccess;
-	if (rec->access_mode == DixWriteAccess)
-	    SecurityAudit("client %d attempted to change host access\n",
-			  rec->client->index);
-	else
-	    SecurityAudit("client %d attempted to list hosts\n",
-			  rec->client->index);
     }
 }
 
-/**********************************************************************/
-
-typedef struct _PropertyAccessRec {
-    ATOM name;
-    ATOM mustHaveProperty;
-    char *mustHaveValue;
-    char windowRestriction;
-#define SecurityAnyWindow          0
-#define SecurityRootWindow         1
-#define SecurityWindowWithProperty 2
-    int readAction;
-    int writeAction;
-    int destroyAction;
-    struct _PropertyAccessRec *next;
-} PropertyAccessRec, *PropertyAccessPtr;
-
-static PropertyAccessPtr PropertyAccessList = NULL;
-static int SecurityDefaultAction = BadAtom;
-static char *SecurityPolicyFile = DEFAULTPOLICYFILE;
-static ATOM SecurityMaxPropertyName = 0;
-
-static char *SecurityKeywords[] = {
-#define SecurityKeywordComment 0
-    "#",
-#define SecurityKeywordProperty 1
-    "property",
-#define SecurityKeywordSitePolicy 2
-    "sitepolicy",
-#define SecurityKeywordRoot 3
-    "root",
-#define SecurityKeywordAny 4
-    "any",
-#define SecurityKeywordExtension 5
-    "trust extension",
-};
-
-#define NUMKEYWORDS (sizeof(SecurityKeywords) / sizeof(char *))
-
 static void
-SecurityFreePropertyAccessList(void)
+SecuritySend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    while (PropertyAccessList)
-    {
-	PropertyAccessPtr freeit = PropertyAccessList;
-	PropertyAccessList = PropertyAccessList->next;
-	xfree(freeit);
-    }
-} /* SecurityFreePropertyAccessList */
+    XaceSendAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
 
-#define SecurityIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') )
-
-static char *
-SecuritySkipWhitespace(
-    char *p)
-{
-    while (SecurityIsWhitespace(*p))
-	p++;
-    return p;
-} /* SecuritySkipWhitespace */
-
-
-static char *
-SecurityParseString(
-    char **rest)
-{
-    char *startOfString;
-    char *s = *rest;
-    char endChar = 0;
-
-    s = SecuritySkipWhitespace(s);
-
-    if (*s == '"' || *s == '\'')
-    {
-	endChar = *s++;
-	startOfString = s;
-	while (*s && (*s != endChar))
-	    s++;
-    }
-    else
-    {
-	startOfString = s;
-	while (*s && !SecurityIsWhitespace(*s))
-	    s++;
-    }
-    if (*s)
-    {
-	*s = '\0';
-	*rest = s + 1;
-	return startOfString;
-    }
-    else
-    {
-	*rest = s;
-	return (endChar) ? NULL : startOfString;
-    }
-} /* SecurityParseString */
-
-
-static int
-SecurityParseKeyword(
-    char **p)
-{
-    int i;
-    char *s = *p;
-    s = SecuritySkipWhitespace(s);
-    for (i = 0; i < NUMKEYWORDS; i++)
-    {
-	int len = strlen(SecurityKeywords[i]);
-	if (strncmp(s, SecurityKeywords[i], len) == 0)
-	{
-	    *p = s + len;
-	    return (i);
-	}
-    }
-    *p = s;
-    return -1;
-} /* SecurityParseKeyword */
+    if (rec->client) {
+	int i;
 
+	subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+	obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey);
 
-static Bool
-SecurityParsePropertyAccessRule(
-    char *p)
-{
-    char *propname;
-    char c;
-    int action = SecurityDefaultAction;
-    int readAction, writeAction, destroyAction;
-    PropertyAccessPtr pacl, prev, cur;
-    char *mustHaveProperty = NULL;
-    char *mustHaveValue = NULL;
-    Bool invalid;
-    char windowRestriction;
-    int size;
-    int keyword;
-
-    /* get property name */
-    propname = SecurityParseString(&p);
-    if (!propname || (strlen(propname) == 0))
-	return FALSE;
-
-    /* get window on which property must reside for rule to apply */
-
-    keyword = SecurityParseKeyword(&p);
-    if (keyword == SecurityKeywordRoot)
-	windowRestriction = SecurityRootWindow;
-    else if (keyword == SecurityKeywordAny) 
-	windowRestriction = SecurityAnyWindow;
-    else /* not root or any, must be a property name */
-    {
-	mustHaveProperty = SecurityParseString(&p);
-	if (!mustHaveProperty || (strlen(mustHaveProperty) == 0))
-	    return FALSE;
-	windowRestriction = SecurityWindowWithProperty;
-	p = SecuritySkipWhitespace(p);
-	if (*p == '=')
-	{ /* property value is specified too */
-	    p++; /* skip over '=' */
-	    mustHaveValue = SecurityParseString(&p);
-	    if (!mustHaveValue)
-		return FALSE;
-	}
-    }
-
-    /* get operations and actions */
-
-    invalid = FALSE;
-    readAction = writeAction = destroyAction = SecurityDefaultAction;
-    while ( (c = *p++) && !invalid)
-    {
-	switch (c)
-	{
-	    case 'i': action = XaceIgnoreError; break;
-	    case 'a': action = Success;  break;
-	    case 'e': action = BadAtom;  break;
-
-	    case 'r': readAction    = action; break;
-	    case 'w': writeAction   = action; break;
-	    case 'd': destroyAction = action; break;
-
-	    default :
-		if (!SecurityIsWhitespace(c))
-		    invalid = TRUE;
-	    break;
-	}
-    }
-    if (invalid)
-	return FALSE;
-
-    /* We've successfully collected all the information needed for this
-     * property access rule.  Now record it in a PropertyAccessRec.
-     */
-    size = sizeof(PropertyAccessRec);
-
-    /* If there is a property value string, allocate space for it 
-     * right after the PropertyAccessRec.
-     */
-    if (mustHaveValue)
-	size += strlen(mustHaveValue) + 1;
-    pacl = (PropertyAccessPtr)Xalloc(size);
-    if (!pacl)
-	return FALSE;
-
-    pacl->name = MakeAtom(propname, strlen(propname), TRUE);
-    if (pacl->name == BAD_RESOURCE)
-    {
-	Xfree(pacl);
-	return FALSE;
-    }
-    if (mustHaveProperty)
-    {
-	pacl->mustHaveProperty = MakeAtom(mustHaveProperty,
-					  strlen(mustHaveProperty), TRUE);
-	if (pacl->mustHaveProperty == BAD_RESOURCE)
-	{
-	    Xfree(pacl);
-	    return FALSE;
-	}
-    }
-    else
-	pacl->mustHaveProperty = 0;
-
-    if (mustHaveValue)
-    {
-	pacl->mustHaveValue = (char *)(pacl + 1);
-	strcpy(pacl->mustHaveValue, mustHaveValue);
-    }
-    else
-	pacl->mustHaveValue = NULL;
-
-    SecurityMaxPropertyName = max(SecurityMaxPropertyName, pacl->name);
-
-    pacl->windowRestriction = windowRestriction;
-    pacl->readAction  = readAction;
-    pacl->writeAction = writeAction;
-    pacl->destroyAction = destroyAction;
+	if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success)
+	    return;
 
-    /* link the new rule into the list of rules in order of increasing
-     * property name (atom) value to make searching easier
-     */
+	for (i = 0; i < rec->count; i++)
+	    if (rec->events[i].u.u.type != UnmapNotify &&
+		rec->events[i].u.u.type != ConfigureRequest &&
+		rec->events[i].u.u.type != ClientMessage) {
 
-    for (prev = NULL,  cur = PropertyAccessList;
-	 cur && cur->name <= pacl->name;
-	 prev = cur, cur = cur->next)
-	;
-    if (!prev)
-    {
-	pacl->next = cur;
-	PropertyAccessList = pacl;
-    }
-    else
-    {
-	prev->next = pacl;
-	pacl->next = cur;
+		SecurityAudit("Security: denied client %d from sending event "
+			      "of type %s to window 0x%x of client %d\n",
+			      rec->client->index, rec->pWin->drawable.id,
+			      wClient(rec->pWin)->index,
+			      LookupEventName(rec->events[i].u.u.type));
+		rec->status = BadAccess;
+		return;
+	    }
     }
-    return TRUE;
-} /* SecurityParsePropertyAccessRule */
+}
 
-static Bool
-SecurityParseExtensionRule(
-    char *p)
+static void
+SecurityReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    char *extName = SecurityParseString(&p);
-    char *copyExtName;
-    char **newStrings;
-
-    if (!extName)
-	return FALSE;
-
-    copyExtName = (char *)Xalloc(strlen(extName) + 1);
-    if (!copyExtName)
-	return TRUE;
-    strcpy(copyExtName, extName);
-    newStrings = (char **)Xrealloc(SecurityTrustedExtensions,
-			  sizeof (char *) * (nSecurityTrustedExtensions + 1));
-    if (!newStrings)
-    {
-	Xfree(copyExtName);
-	return TRUE;
-    }
+    XaceReceiveAccessRec *rec = calldata;
+    SecurityStateRec *subj, *obj;
 
-    SecurityTrustedExtensions = newStrings;
-    SecurityTrustedExtensions[nSecurityTrustedExtensions++] = copyExtName;
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey);
 
-    return TRUE;
+    if (SecurityDoCheck(subj, obj, DixReceiveAccess, 0) == Success)
+	return;
 
-} /* SecurityParseExtensionRule */
+    SecurityAudit("Security: denied client %d from receiving an event "
+		  "sent to window 0x%x of client %d\n",
+		  rec->client->index, rec->pWin->drawable.id,
+		  wClient(rec->pWin)->index);
+    rec->status = BadAccess;
+}
 
-static void
-SecurityFreeTrustedExtensionStrings(void)
-{
-    if (SecurityTrustedExtensions)
-    {
-	assert(nSecurityTrustedExtensions);
-	while (nSecurityTrustedExtensions--)
-	{
-	    Xfree(SecurityTrustedExtensions[nSecurityTrustedExtensions]);
-	}
-	Xfree(SecurityTrustedExtensions);
-	SecurityTrustedExtensions = NULL;
-	nSecurityTrustedExtensions = 0;
-    }
-} /* SecurityFreeSiteTrustedExtensions */
+/* SecurityClientStateCallback
+ *
+ * Arguments:
+ *	pcbl is &ClientStateCallback.
+ *	nullata is NULL.
+ *	calldata is a pointer to a NewClientInfoRec (include/dixstruct.h)
+ *	which contains information about client state changes.
+ *
+ * Returns: nothing.
+ *
+ * Side Effects:
+ * 
+ * If a new client is connecting, its authorization ID is copied to
+ * client->authID.  If this is a generated authorization, its reference
+ * count is bumped, its timer is cancelled if it was running, and its
+ * trustlevel is copied to TRUSTLEVEL(client).
+ * 
+ * If a client is disconnecting and the client was using a generated
+ * authorization, the authorization's reference count is decremented, and
+ * if it is now zero, the timer for this authorization is started.
+ */
 
 static void
-SecurityLoadPropertyAccessList(void)
+SecurityClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    FILE *f;
-    int lineNumber = 0;
-
-    SecurityMaxPropertyName = 0;
-
-    if (!SecurityPolicyFile)
-	return;
-
-    f = fopen(SecurityPolicyFile, "r");
-    if (!f)
-    {
-	ErrorF("error opening security policy file %s\n",
-	       SecurityPolicyFile);
-	return;
-    }
+    NewClientInfoRec *pci = calldata;
+    SecurityStateRec *state;
+    SecurityAuthorizationPtr pAuth;
+    int rc;
 
-    while (!feof(f))
-    {
-	char buf[200];
-	Bool validLine;
-	char *p;
+    state = dixLookupPrivate(&pci->client->devPrivates, stateKey);
 
-	if (!(p = fgets(buf, sizeof(buf), f)))
-	    break;
-	lineNumber++;
+    switch (pci->client->clientState) {
+    case ClientStateInitial:
+	state->trustLevel = XSecurityClientTrusted;
+	state->authId = None;
+	state->haveState = TRUE;
+	break;
 
-	/* if first line, check version number */
-	if (lineNumber == 1)
-	{
-	    char *v = SecurityParseString(&p);
-	    if (strcmp(v, SECURITY_POLICY_FILE_VERSION) != 0)
-	    {
-		ErrorF("%s: invalid security policy file version, ignoring file\n",
-		       SecurityPolicyFile);
-		break;
-	    }
-	    validLine = TRUE;
-	}
-	else
-	{
-	    switch (SecurityParseKeyword(&p))
-	    {
-		case SecurityKeywordComment:
-		case SecurityKeywordSitePolicy:
-		    validLine = TRUE;
-		break;
-
-		case SecurityKeywordProperty:
-		    validLine = SecurityParsePropertyAccessRule(p);
-		break;
-
-		case SecurityKeywordExtension:
-		    validLine = SecurityParseExtensionRule(p);
-		break;
-
-		default:
-		    validLine = (*p == '\0'); /* blank lines OK, others not */
-		break;
-	    }
+    case ClientStateRunning:
+	state->authId = AuthorizationIDOfClient(pci->client);
+	rc = dixLookupResource((pointer *)&pAuth, state->authId,
+			       SecurityAuthorizationResType, serverClient,
+			       DixGetAttrAccess);
+	if (rc == Success) {
+	    /* it is a generated authorization */
+	    pAuth->refcnt++;
+	    if (pAuth->refcnt == 1 && pAuth->timer)
+		TimerCancel(pAuth->timer);
+
+	    state->trustLevel = pAuth->trustLevel;
 	}
+	break;
 
-	if (!validLine)
-	    ErrorF("Line %d of %s invalid, ignoring\n",
-		   lineNumber, SecurityPolicyFile);
-    } /* end while more input */
-
-    fclose(f);
-} /* SecurityLoadPropertyAccessList */
-
-
-static Bool
-SecurityMatchString(
-    char *ws,
-    char *cs)
-{
-    while (*ws && *cs)
-    {
-	if (*ws == '*')
-	{
-	    Bool match = FALSE;
-	    ws++;
-	    while (!(match = SecurityMatchString(ws, cs)) && *cs)
-	    {
-		cs++;
-	    }
-	    return match;
-	}
-	else if (*ws == *cs)
-	{
-	    ws++;
-	    cs++;
+    case ClientStateGone:
+    case ClientStateRetained:
+	rc = dixLookupResource((pointer *)&pAuth, state->authId,
+			       SecurityAuthorizationResType, serverClient,
+			       DixGetAttrAccess);
+	if (rc == Success) {
+	    /* it is a generated authorization */
+	    pAuth->refcnt--;
+	    if (pAuth->refcnt == 0)
+		SecurityStartAuthorizationTimer(pAuth);
 	}
-	else break;
-    }
-    return ( ( (*ws == '\0') || ((*ws == '*') && *(ws+1) == '\0') )
-	     && (*cs == '\0') );
-} /* SecurityMatchString */
-
-
-static void
-SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
-			    pointer calldata)
-{    
-    XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
-    ClientPtr client = rec->client;
-    WindowPtr pWin = rec->pWin;
-    ATOM propertyName = rec->pProp->propertyName;
-    Mask access_mode = rec->access_mode;
-    PropertyAccessPtr pacl;
-    int action = SecurityDefaultAction;
-
-    /* if client trusted or window untrusted, allow operation */
-
-    if ((TRUSTLEVEL(client) == XSecurityClientTrusted) ||
-	 (TRUSTLEVEL(wClient(pWin)) != XSecurityClientTrusted) )
-	return;
-
-    /* If the property atom is bigger than any atoms on the list, 
-     * we know we won't find it, so don't even bother looking.
-     */
-    if (propertyName <= SecurityMaxPropertyName)
-    {
-	/* untrusted client operating on trusted window; see if it's allowed */
-
-	for (pacl = PropertyAccessList; pacl; pacl = pacl->next)
-	{
-	    if (pacl->name < propertyName)
-		continue;
-	    if (pacl->name > propertyName)
-		break;
-
-	    /* pacl->name == propertyName, so see if it applies to this window */
+	break;
 
-	    switch (pacl->windowRestriction)
-	    {
-		case SecurityAnyWindow: /* always applies */
-		    break;
-
-		case SecurityRootWindow:
-		{
-		    /* if not a root window, this rule doesn't apply */
-		    if (pWin->parent)
-			continue;
-		}
-		break;
-
-		case SecurityWindowWithProperty:
-		{
-		    PropertyPtr pProp = wUserProps (pWin);
-		    Bool match = FALSE;
-		    char *p;
-		    char *pEndData;
-
-		    while (pProp)
-		    {
-			if (pProp->propertyName == pacl->mustHaveProperty)
-			    break;
-			pProp = pProp->next;
-		    }
-		    if (!pProp)
-			continue;
-		    if (!pacl->mustHaveValue)
-			break;
-		    if (pProp->type != XA_STRING || pProp->format != 8)
-			continue;
-
-		    p = pProp->data;
-		    pEndData = ((char *)pProp->data) + pProp->size;
-		    while (!match && p < pEndData)
-		    {
-			 if (SecurityMatchString(pacl->mustHaveValue, p))
-			     match = TRUE;
-			 else
-			 { /* skip to the next string */
-			     while (*p++ && p < pEndData)
-				 ;
-			 }
-		    }
-		    if (!match)
-			continue;
-		}
-		break; /* end case SecurityWindowWithProperty */
-	    } /* end switch on windowRestriction */
-
-	    /* If we get here, the property access rule pacl applies.
-	     * If pacl doesn't apply, something above should have
-	     * executed a continue, which will skip the follwing code.
-	     */
-	    action = Success;
-	    if (access_mode & DixReadAccess)
-		action = max(action, pacl->readAction);
-	    if (access_mode & DixWriteAccess)
-		action = max(action, pacl->writeAction);
-	    if (access_mode & DixDestroyAccess)
-		action = max(action, pacl->destroyAction);
-	    break;
-	} /* end for each pacl */
-    } /* end if propertyName <= SecurityMaxPropertyName */
-
-    if (action != Success)
-    { /* audit the access violation */
-	int cid = CLIENT_ID(pWin->drawable.id);
-	int reqtype = ((xReq *)client->requestBuffer)->reqType;
-	char *actionstr = (XaceIgnoreError == action) ? "ignored" : "error";
-	SecurityAudit("client %d attempted request %d with window 0x%x property %s (atom 0x%x) of client %d, %s\n",
-		client->index, reqtype, pWin->drawable.id,
-		      NameForAtom(propertyName), propertyName, cid, actionstr);
+    default:
+	break; 
     }
-    /* return codes increase with strictness */
-    if (action != Success)
-        rec->status = action;
-} /* SecurityCheckPropertyAccess */
-
+}
 
 /* SecurityResetProc
  *
@@ -1764,25 +1038,19 @@ static void
 SecurityResetProc(
     ExtensionEntry *extEntry)
 {
-    SecurityFreePropertyAccessList();
-    SecurityFreeTrustedExtensionStrings();
-} /* SecurityResetProc */
-
-
-int
-XSecurityOptions(argc, argv, i)
-    int argc;
-    char **argv;
-    int i;
-{
-    if (strcmp(argv[i], "-sp") == 0)
-    {
-	if (i < argc)
-	    SecurityPolicyFile = argv[++i];
-	return (i + 1);
-    }
-    return (i);
-} /* XSecurityOptions */
+    /* Unregister callbacks */
+    DeleteCallback(&ClientStateCallback, SecurityClientState, NULL);
+
+    XaceDeleteCallback(XACE_EXT_DISPATCH, SecurityExtension, NULL);
+    XaceDeleteCallback(XACE_RESOURCE_ACCESS, SecurityResource, NULL);
+    XaceDeleteCallback(XACE_DEVICE_ACCESS, SecurityDevice, NULL);
+    XaceDeleteCallback(XACE_PROPERTY_ACCESS, SecurityProperty, NULL);
+    XaceDeleteCallback(XACE_SEND_ACCESS, SecuritySend, NULL);
+    XaceDeleteCallback(XACE_RECEIVE_ACCESS, SecurityReceive, NULL);
+    XaceDeleteCallback(XACE_CLIENT_ACCESS, SecurityClient, NULL);
+    XaceDeleteCallback(XACE_EXT_ACCESS, SecurityExtension, NULL);
+    XaceDeleteCallback(XACE_SERVER_ACCESS, SecurityServer, NULL);
+}
 
 
 /* SecurityExtensionInit
@@ -1799,6 +1067,7 @@ void
 SecurityExtensionInit(INITARGS)
 {
     ExtensionEntry	*extEntry;
+    int ret = TRUE;
 
     SecurityAuthorizationResType =
 	CreateNewResourceType(SecurityDeleteAuthorization);
@@ -1812,12 +1081,26 @@ SecurityExtensionInit(INITARGS)
     RTEventClient |= RC_NEVERRETAIN;
 
     /* Allocate the private storage */
-    if (!dixRequestPrivate(stateKey, sizeof(SecurityClientStateRec)))
+    if (!dixRequestPrivate(stateKey, sizeof(SecurityStateRec)))
 	FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
 
-    if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL))
-	return;
+    /* Register callbacks */
+    ret &= AddCallback(&ClientStateCallback, SecurityClientState, NULL);
+
+    ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SecurityExtension, NULL);
+    ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SecurityResource, NULL);
+    ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SecurityDevice, NULL);
+    ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SecurityProperty, NULL);
+    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SecuritySend, NULL);
+    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SecurityReceive, NULL);
+    ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SecurityClient, NULL);
+    ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SecurityExtension, NULL);
+    ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SecurityServer, NULL);
 
+    if (!ret)
+	FatalError("SecurityExtensionSetup: Failed to register callbacks\n");
+
+    /* Add extension to server */
     extEntry = AddExtension(SECURITY_EXTENSION_NAME,
 			    XSecurityNumberEvents, XSecurityNumberErrors,
 			    ProcSecurityDispatch, SProcSecurityDispatch,
@@ -1829,15 +1112,6 @@ SecurityExtensionInit(INITARGS)
     EventSwapVector[SecurityEventBase + XSecurityAuthorizationRevoked] =
 	(EventSwapPtr)SwapSecurityAuthorizationRevokedEvent;
 
-    SecurityLoadPropertyAccessList();
-
-    /* register callbacks */
-#define XaceRC XaceRegisterCallback
-    XaceRC(XACE_RESOURCE_ACCESS, SecurityCheckResourceIDAccess, NULL);
-    XaceRC(XACE_DEVICE_ACCESS, SecurityCheckDeviceAccess, NULL);
-    XaceRC(XACE_PROPERTY_ACCESS, SecurityCheckPropertyAccess, NULL);
-    XaceRC(XACE_MAP_ACCESS, SecurityCheckMapAccess, NULL);
-    XaceRC(XACE_EXT_DISPATCH, SecurityCheckExtAccess, NULL);
-    XaceRC(XACE_EXT_ACCESS, SecurityCheckExtAccess, NULL);
-    XaceRC(XACE_SERVER_ACCESS, SecurityCheckServerAccess, NULL);
-} /* SecurityExtensionInit */
+    /* Label objects that were created before we could register ourself */
+    SecurityLabelInitial();
+}
diff --git a/Xext/securitysrv.h b/Xext/securitysrv.h
index 7320ab7..f4f3e32 100644
--- a/Xext/securitysrv.h
+++ b/Xext/securitysrv.h
@@ -77,11 +77,7 @@ typedef struct {
     Bool valid; /* did anyone recognize it? if so, set to TRUE */
 } SecurityValidateGroupInfoRec;
 
-extern int XSecurityOptions(int argc, char **argv, int i);
-
 /* Give this value or higher to the -audit option to get security messages */
 #define SECURITY_AUDIT_LEVEL 4
 
-#define SECURITY_POLICY_FILE_VERSION "version-1"
-
 #endif /* _SECURITY_SRV_H */
diff --git a/os/utils.c b/os/utils.c
index 3228146..d69936d 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -123,9 +123,6 @@ OR PERFORMANCE OF THIS SOFTWARE.
 #ifdef XKB
 #include <xkbsrv.h>
 #endif
-#ifdef XCSECURITY
-#include "securitysrv.h"
-#endif
 
 #ifdef RENDER
 #include "picture.h"
@@ -621,9 +618,6 @@ void UseMsg(void)
     ErrorF("-render [default|mono|gray|color] set render color alloc policy\n");
 #endif
     ErrorF("-s #                   screen-saver timeout (minutes)\n");
-#ifdef XCSECURITY
-    ErrorF("-sp file               security policy file\n");
-#endif
 #ifdef XPRINT
     PrinterUseMsg();
 #endif
@@ -1040,12 +1034,6 @@ ProcessCommandLine(int argc, char *argv[])
 	    i = skip - 1;
 	}
 #endif
-#ifdef XCSECURITY
-	else if ((skip = XSecurityOptions(argc, argv, i)) != i)
-	{
-	    i = skip - 1;
-	}
-#endif
 #ifdef AIXV3
         else if ( strcmp( argv[i], "-timeout") == 0)
         {
commit a52c9b2a59f27266557ff9d5d2c08492e04135a6
Merge: c7e18be... 5833289...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 5 19:08:36 2007 -0500

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	dix/dispatch.c
    	dix/property.c
    	hw/xfree86/common/xf86VidMode.c
    	include/xkbsrv.h
    	render/glyph.c
    	xkb/xkbActions.c

diff --cc dix/dispatch.c
index 814c2a8,5c4f8e4..19d02fd
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@@ -2638,19 -2612,14 +2638,19 @@@ ProcListInstalledColormaps(ClientPtr cl
      int nummaps, rc;
      WindowPtr pWin;
      REQUEST(xResourceReq);
 -
      REQUEST_SIZE_MATCH(xResourceReq);
 -    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
 +
 +    rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess);
      if (rc != Success)
 -        return rc;
 +	goto out;
 +
 +    rc = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen,
 +		  DixGetAttrAccess);
 +    if (rc != Success)
 +	goto out;
  
      preply = (xListInstalledColormapsReply *) 
- 		ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) +
+ 		xalloc(sizeof(xListInstalledColormapsReply) +
  		     pWin->drawable.pScreen->maxInstalledCmaps *
  		     sizeof(Colormap));
      if(!preply)
@@@ -2665,10 -2634,8 +2665,10 @@@
      WriteReplyToClient(client, sizeof (xListInstalledColormapsReply), preply);
      client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
      WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]);
-     DEALLOCATE_LOCAL(preply);
+     xfree(preply);
 -    return(client->noClientException);
 +    rc = client->noClientException;
 +out:
 +    return (rc == BadValue) ? BadColor : rc;
  }
  
  int
@@@ -2799,10 -2766,10 +2799,10 @@@ ProcAllocColorCells (ClientPtr client
              return(BadAlloc);
  	pmasks = ppixels + npixels;
  
 -	if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, 
 +	if( (rc = AllocColorCells(client->index, pcmp, npixels, nmasks, 
  				    (Bool)stuff->contiguous, ppixels, pmasks)) )
  	{
- 	    DEALLOCATE_LOCAL(ppixels);
+ 	    xfree(ppixels);
              if (client->noClientException != Success)
                  return(client->noClientException);
  	    else
@@@ -2863,10 -2829,10 +2863,10 @@@ ProcAllocColorPlanes(ClientPtr client
  	acpr.sequenceNumber = client->sequence;
  	acpr.nPixels = npixels;
  	length = (long)npixels * sizeof(Pixel);
- 	ppixels = (Pixel *)ALLOCATE_LOCAL(length);
+ 	ppixels = (Pixel *)xalloc(length);
  	if(!ppixels)
              return(BadAlloc);
 -	if( (retval = AllocColorPlanes(client->index, pcmp, npixels,
 +	if( (rc = AllocColorPlanes(client->index, pcmp, npixels,
  	    (int)stuff->red, (int)stuff->green, (int)stuff->blue,
  	    (Bool)stuff->contiguous, ppixels,
  	    &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) )
@@@ -3016,12 -2981,12 +3016,12 @@@ ProcQueryColors(ClientPtr client
  	xQueryColorsReply	qcr;
  
  	count = ((client->req_len << 2) - sizeof(xQueryColorsReq)) >> 2;
- 	prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb));
+ 	prgbs = (xrgb *)xalloc(count * sizeof(xrgb));
  	if(!prgbs && count)
              return(BadAlloc);
 -	if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
 +	if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
  	{
-    	    if (prgbs) DEALLOCATE_LOCAL(prgbs);
+    	    if (prgbs) xfree(prgbs);
  	    if (client->noClientException != Success)
                  return(client->noClientException);
  	    else
diff --cc dix/property.c
index 713507a,994d3a7..3c0eaf1
--- a/dix/property.c
+++ b/dix/property.c
@@@ -140,29 -127,35 +140,29 @@@ ProcRotateProperties(ClientPtr client
  	return(BadAlloc);
      for (i = 0; i < stuff->nAtoms; i++)
      {
 -	char action = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, atoms[i],
 -				DixReadAccess|DixWriteAccess);
 -
 -        if (!ValidAtom(atoms[i]) || (XaceErrorOperation == action)) {
 +        if (!ValidAtom(atoms[i])) {
-             DEALLOCATE_LOCAL(props);
+             xfree(props);
  	    client->errorValue = atoms[i];
              return BadAtom;
          }
 -	if (XaceIgnoreOperation == action) {
 -            xfree(props);
 -	    return Success;
 -	}
 -
          for (j = i + 1; j < stuff->nAtoms; j++)
              if (atoms[j] == atoms[i])
              {
-                 DEALLOCATE_LOCAL(props);
+                 xfree(props);
                  return BadMatch;
              }
 -        pProp = wUserProps (pWin);
 -        while (pProp)
 -        {
 -            if (pProp->propertyName == atoms[i])
 -                goto found;
 -	    pProp = pProp->next;
 -        }
 -        xfree(props);
 -        return BadMatch;
 -found: 
 +	pProp = FindProperty(pWin, atoms[i]);
 +	if (!pProp) {
- 	    DEALLOCATE_LOCAL(props);
++	    xfree(props);
 +	    return BadMatch;
 +	}
 +	rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
 +		      DixReadAccess|DixWriteAccess);
 +	if (rc != Success) {
-             DEALLOCATE_LOCAL(props);
++	    xfree(props);
 +	    client->errorValue = atoms[i];
 +            return rc;
 +	}
          props[i] = pProp;
      }
      delta = stuff->nPositions;
diff --cc hw/darwin/quartz/quartz.c
index 2899bc2,25061a8..61a7520
--- a/hw/darwin/quartz/quartz.c
+++ b/hw/darwin/quartz/quartz.c
@@@ -62,9 -60,9 +60,9 @@@ int                     quartzUseAGL = 
  int                     quartzEnableKeyEquivalents = 1;
  int                     quartzServerVisible = TRUE;
  int                     quartzServerQuitting = FALSE;
 -int                     quartzScreenIndex = 0;
 +DevPrivateKey           quartzScreenKey = &quartzScreenKey;
  int                     aquaMenuBarHeight = 0;
- int                     noPseudoramiXExtension = TRUE;
+ int                     noPseudoramiXExtension = FALSE;
  QuartzModeProcsPtr      quartzProcs = NULL;
  const char             *quartzOpenGLBundle = NULL;
  
diff --cc hw/xfree86/common/xf86VidMode.c
index 763e5c5,16a4d82..38d605c
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@@ -125,10 -128,8 +121,8 @@@ VidModeAvailable(int scrnIndex
      ScrnInfoPtr pScrn;
      VidModePtr pVidMode;
  
-     DEBUG_P("VidModeAvailable");
- 
 -    if (VidModeIndex < 0) {
 -	DEBUG_P("VidModeIndex < 0");
 +    if (VidModeKey == NULL) {
 +	DEBUG_P("VidModeKey == NULL");
  	return FALSE;
      }
   
diff --cc hw/xnest/Pixmap.c
index c9c662a,1f42001..57bebc6
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@@ -33,10 -32,11 +33,11 @@@ is" without express or implied warranty
  #include "Screen.h"
  #include "XNPixmap.h"
  
 -int xnestPixmapPrivateIndex;	    
 +DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKey;
  
  PixmapPtr
- xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth)
+ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
+ 		  unsigned usage_hint)
  {
    PixmapPtr pPixmap;
  
diff --cc include/xkbsrv.h
index e4a1db3,167dbec..6425e37
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@@ -246,8 -268,11 +268,11 @@@ typedef struc
  	device->public.realInputProc = oldprocs->realInputProc; \
  	device->unwrapProc = oldprocs->unwrapProc;
  
 -extern int xkbDevicePrivateIndex;
 -#define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr) (dev)->devPrivates[xkbDevicePrivateIndex].ptr)
++extern DevPrivateKey xkbDevicePrivateKey;
 +#define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr)dixLookupPrivate(&(dev)->devPrivates, xkbDevicePrivateKey))
  
+ extern void xkbUnwrapProc(DeviceIntPtr, DeviceHandleProc, pointer);
+ 
  /***====================================================================***/
  
  
diff --cc mi/mibank.c
index 05813e5,859770c..ea79e9d
--- a/mi/mibank.c
+++ b/mi/mibank.c
@@@ -172,14 -172,14 +172,14 @@@ typedef struct _miBankQueu
          (*pScreenPriv->BankInfo.SetDestinationBank)(pScreen, (_no)) - \
          (pScreenPriv->BankInfo.BankSize * (_no)))
  
- #define ALLOCATE_LOCAL_ARRAY(atype, ntype) \
-     (atype *)ALLOCATE_LOCAL((ntype) * sizeof(atype))
+ #define xalloc_ARRAY(atype, ntype) \
+     (atype *)xalloc((ntype) * sizeof(atype))
  
 -static int           miBankScreenIndex;
 -static int           miBankGCIndex;
 +static DevPrivateKey miBankScreenKey = &miBankScreenKey;
 +static DevPrivateKey miBankGCKey = &miBankGCKey;
  static unsigned long miBankGeneration = 0;
  
 -#define BANK_SCRPRIVLVAL pScreen->devPrivates[miBankScreenIndex].ptr
 +#define BANK_SCRPRIVLVAL dixLookupPrivate(&pScreen->devPrivates, miBankScreenKey)
  
  #define BANK_SCRPRIVATE ((miBankScreenPtr)(BANK_SCRPRIVLVAL))
  
diff --cc xkb/xkbAccessX.c
index fbd2815,4c6e3d4..50a611e
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@@ -689,9 -689,11 +689,11 @@@ ProcessPointerEvent(	register xEvent  
  			register DeviceIntPtr	mouse, 
  			int		        count)
  {
 -DeviceIntPtr	dev = (DeviceIntPtr)LookupKeyboardDevice();
 +DeviceIntPtr	dev = inputInfo.keyboard;
  XkbSrvInfoPtr	xkbi = dev->key->xkbInfo;
  unsigned 	changed = 0;
+ ProcessInputProc backupproc;
+ xkbDeviceInfoPtr xkbPrivPtr = XKBDEVICEINFO(mouse);
  
      xkbi->shiftKeyCount = 0;
      xkbi->lastPtrEventTime= xE->u.keyButtonPointer.time;
diff --cc xkb/xkbActions.c
index 822afff,8ddbdba..380a232
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@@ -39,10 -40,12 +40,11 @@@ THE USE OR PERFORMANCE OF THIS SOFTWARE
  #include <xkbsrv.h>
  #include "xkb.h"
  #include <ctype.h>
+ #define EXTENSION_EVENT_BASE 64
  
- static DevPrivateKey xkbDevicePrivateKey = &xkbDevicePrivateKey;
 -static unsigned int _xkbServerGeneration;
 -int xkbDevicePrivateIndex = -1;
++DevPrivateKey xkbDevicePrivateKey = &xkbDevicePrivateKey;
  
- static void
+ void
  xkbUnwrapProc(DeviceIntPtr device, DeviceHandleProc proc,
                     pointer data)
  {
@@@ -63,17 -67,23 +66,15 @@@ XkbSetExtension(DeviceIntPtr device, Pr
  {
      xkbDeviceInfoPtr xkbPrivPtr;
  
-     xkbPrivPtr = (xkbDeviceInfoPtr) xalloc(sizeof(xkbDeviceInfoRec));
 -    if (serverGeneration != _xkbServerGeneration) {
 -	if ((xkbDevicePrivateIndex = AllocateDevicePrivateIndex()) == -1)
 -	    return;
 -	_xkbServerGeneration = serverGeneration;
 -    }
 -    if (!AllocateDevicePrivate(device, xkbDevicePrivateIndex))
 -	return;
 -
+     xkbPrivPtr = (xkbDeviceInfoPtr) xcalloc(1, sizeof(xkbDeviceInfoRec));
      if (!xkbPrivPtr)
  	return;
      xkbPrivPtr->unwrapProc = NULL;
  
 -    device->devPrivates[xkbDevicePrivateIndex].ptr = xkbPrivPtr;
 +    dixSetPrivate(&device->devPrivates, xkbDevicePrivateKey, xkbPrivPtr);
-     WRAP_PROCESS_INPUT_PROC(device,xkbPrivPtr,
- 			    proc,xkbUnwrapProc);
+     WRAP_PROCESS_INPUT_PROC(device, xkbPrivPtr, proc, xkbUnwrapProc);
  }
  
- #ifdef XINPUT
  extern	void	ProcessOtherEvent(
      xEvent *		/* xE */,
      DeviceIntPtr 	/* dev */,
commit c7e18beb3c87eb1ada9b21c4ffacd11c1939c087
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Nov 5 15:01:13 2007 -0500

    xselinux: Register SELinux extension protocol names.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 946e5b9..f6d1dcd 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1395,4 +1395,28 @@ XSELinuxExtensionInit(INITARGS)
 
     /* Label objects that were created before we could register ourself */
     SELinuxLabelInitial();
+
+    /* Add names to registry */
+    RegisterRequestName(X_SELinuxQueryVersion, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxQueryVersion");
+    RegisterRequestName(X_SELinuxSetSelectionManager, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxSetSelectionManager");
+    RegisterRequestName(X_SELinuxGetSelectionManager, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxGetSelectionManager");
+    RegisterRequestName(X_SELinuxSetDeviceContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxSetDeviceContext");
+    RegisterRequestName(X_SELinuxGetDeviceContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxGetDeviceContext");
+    RegisterRequestName(X_SELinuxSetPropertyCreateContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxSetPropertyCreateContext");
+    RegisterRequestName(X_SELinuxGetPropertyCreateContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxGetPropertyCreateContext");
+    RegisterRequestName(X_SELinuxGetPropertyContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxGetPropertyContext");
+    RegisterRequestName(X_SELinuxSetWindowCreateContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxSetWindowCreateContext");
+    RegisterRequestName(X_SELinuxGetWindowCreateContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxGetWindowCreateContext");
+    RegisterRequestName(X_SELinuxGetWindowContext, 0,
+			XSELINUX_EXTENSION_NAME ":SELinuxGetWindowContext");
 }
commit 3b7af72fe315c7c26c89838c0c5dacbe58765d0f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Oct 26 20:32:10 2007 -0400

    xselinux: Add a SetDeviceContext request and stubs for more requests.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index bacbe6e..946e5b9 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -985,10 +985,6 @@ static int
 ProcSELinuxQueryVersion(ClientPtr client)
 {
     SELinuxQueryVersionReply rep;
-    /*
-      REQUEST(SELinuxQueryVersionReq);
-      REQUEST_SIZE_MATCH (SELinuxQueryVersionReq);
-    */
 
     rep.type = X_Reply;
     rep.length = 0;
@@ -1009,10 +1005,10 @@ ProcSELinuxQueryVersion(ClientPtr client)
 static int
 ProcSELinuxSetSelectionManager(ClientPtr client)
 {
-    REQUEST(SELinuxSetSelectionManagerReq);
     WindowPtr pWin;
     int rc;
 
+    REQUEST(SELinuxSetSelectionManagerReq);
     REQUEST_SIZE_MATCH(SELinuxSetSelectionManagerReq);
 
     if (stuff->window == None) {
@@ -1032,6 +1028,98 @@ ProcSELinuxSetSelectionManager(ClientPtr client)
 }
 
 static int
+ProcSELinuxGetSelectionManager(ClientPtr client)
+{
+    SELinuxGetSelectionManagerReply rep;
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.window = selectionWindow;
+    if (client->swapped) {
+	int n;
+	swaps(&rep.sequenceNumber, n);
+	swapl(&rep.length, n);
+	swapl(&rep.window, n);
+    }
+    WriteToClient(client, sizeof(rep), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcSELinuxSetDeviceContext(ClientPtr client)
+{
+    char *ctx;
+    security_id_t sid;
+    DeviceIntPtr dev;
+    SELinuxStateRec *state;
+    int rc;
+
+    REQUEST(SELinuxSetContextReq);
+    REQUEST_FIXED_SIZE(SELinuxSetContextReq, stuff->context_len);
+
+    ctx = (char *)(stuff + 1);
+    if (ctx[stuff->context_len - 1])
+	return BadLength;
+
+    rc = dixLookupDevice(&dev, stuff->id, client, DixManageAccess);
+    if (rc != Success)
+	return rc;
+
+    rc = avc_context_to_sid(ctx, &sid);
+    if (rc != Success)
+	return BadValue;
+
+    state = dixLookupPrivate(&dev->devPrivates, stateKey);
+    sidput(state->sid);
+    state->sid = sid;
+    ErrorF("I really, actually did relabel a device to %s\n", ctx);
+    return Success;
+}
+
+static int
+ProcSELinuxGetDeviceContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxSetPropertyCreateContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxGetPropertyCreateContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxGetPropertyContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxSetWindowCreateContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxGetWindowCreateContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
+ProcSELinuxGetWindowContext(ClientPtr client)
+{
+    return Success;
+}
+
+static int
 ProcSELinuxDispatch(ClientPtr client)
 {
     REQUEST(xReq);
@@ -1040,6 +1128,24 @@ ProcSELinuxDispatch(ClientPtr client)
         return ProcSELinuxQueryVersion(client);
     case X_SELinuxSetSelectionManager:
 	return ProcSELinuxSetSelectionManager(client);
+    case X_SELinuxGetSelectionManager:
+    	return ProcSELinuxGetSelectionManager(client);
+    case X_SELinuxSetDeviceContext:
+    	return ProcSELinuxSetDeviceContext(client);
+    case X_SELinuxGetDeviceContext:
+    	return ProcSELinuxGetDeviceContext(client);
+    case X_SELinuxSetPropertyCreateContext:
+    	return ProcSELinuxSetPropertyCreateContext(client);
+    case X_SELinuxGetPropertyCreateContext:
+    	return ProcSELinuxGetPropertyCreateContext(client);
+    case X_SELinuxGetPropertyContext:
+    	return ProcSELinuxGetPropertyContext(client);
+    case X_SELinuxSetWindowCreateContext:
+    	return ProcSELinuxSetWindowCreateContext(client);
+    case X_SELinuxGetWindowCreateContext:
+    	return ProcSELinuxGetWindowCreateContext(client);
+    case X_SELinuxGetWindowContext:
+    	return ProcSELinuxGetWindowContext(client);
     default:
 	return BadRequest;
     }
@@ -1069,6 +1175,60 @@ SProcSELinuxSetSelectionManager(ClientPtr client)
 }
 
 static int
+SProcSELinuxGetSelectionManager(ClientPtr client)
+{
+    return ProcSELinuxGetSelectionManager(client);
+}
+
+static int
+SProcSELinuxSetDeviceContext(ClientPtr client)
+{
+    return ProcSELinuxSetDeviceContext(client);
+}
+
+static int
+SProcSELinuxGetDeviceContext(ClientPtr client)
+{
+    return ProcSELinuxGetDeviceContext(client);
+}
+
+static int
+SProcSELinuxSetPropertyCreateContext(ClientPtr client)
+{
+    return ProcSELinuxSetPropertyCreateContext(client);
+}
+
+static int
+SProcSELinuxGetPropertyCreateContext(ClientPtr client)
+{
+    return ProcSELinuxGetPropertyCreateContext(client);
+}
+
+static int
+SProcSELinuxGetPropertyContext(ClientPtr client)
+{
+    return ProcSELinuxGetPropertyContext(client);
+}
+
+static int
+SProcSELinuxSetWindowCreateContext(ClientPtr client)
+{
+    return ProcSELinuxSetWindowCreateContext(client);
+}
+
+static int
+SProcSELinuxGetWindowCreateContext(ClientPtr client)
+{
+    return ProcSELinuxGetWindowCreateContext(client);
+}
+
+static int
+SProcSELinuxGetWindowContext(ClientPtr client)
+{
+    return ProcSELinuxGetWindowContext(client);
+}
+
+static int
 SProcSELinuxDispatch(ClientPtr client)
 {
     REQUEST(xReq);
@@ -1080,7 +1240,25 @@ SProcSELinuxDispatch(ClientPtr client)
     case X_SELinuxQueryVersion:
         return SProcSELinuxQueryVersion(client);
     case X_SELinuxSetSelectionManager:
-        return SProcSELinuxSetSelectionManager(client);
+	return SProcSELinuxSetSelectionManager(client);
+    case X_SELinuxGetSelectionManager:
+    	return SProcSELinuxGetSelectionManager(client);
+    case X_SELinuxSetDeviceContext:
+    	return SProcSELinuxSetDeviceContext(client);
+    case X_SELinuxGetDeviceContext:
+    	return SProcSELinuxGetDeviceContext(client);
+    case X_SELinuxSetPropertyCreateContext:
+    	return SProcSELinuxSetPropertyCreateContext(client);
+    case X_SELinuxGetPropertyCreateContext:
+    	return SProcSELinuxGetPropertyCreateContext(client);
+    case X_SELinuxGetPropertyContext:
+    	return SProcSELinuxGetPropertyContext(client);
+    case X_SELinuxSetWindowCreateContext:
+    	return SProcSELinuxSetWindowCreateContext(client);
+    case X_SELinuxGetWindowCreateContext:
+    	return SProcSELinuxGetWindowCreateContext(client);
+    case X_SELinuxGetWindowContext:
+    	return SProcSELinuxGetWindowContext(client);
     default:
 	return BadRequest;
     }
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index 691154d..50838d7 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -30,10 +30,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XSELinuxNumberErrors		0
 
 /* Extension protocol */
-#define X_SELinuxQueryVersion		0
-#define X_SELinuxSetSelectionManager	1
+#define X_SELinuxQueryVersion			0
+#define X_SELinuxSetSelectionManager		1
+#define X_SELinuxGetSelectionManager		2
+#define X_SELinuxSetDeviceContext		3
+#define X_SELinuxGetDeviceContext		4
+#define X_SELinuxSetPropertyCreateContext	5
+#define X_SELinuxGetPropertyCreateContext	6
+#define X_SELinuxGetPropertyContext		7
+#define X_SELinuxSetWindowCreateContext		8
+#define X_SELinuxGetWindowCreateContext		9
+#define X_SELinuxGetWindowContext		10
 
-typedef struct _SELinuxQueryVersion {
+typedef struct {
     CARD8   reqType;
     CARD8   SELinuxReqType;
     CARD16  length;
@@ -41,7 +50,6 @@ typedef struct _SELinuxQueryVersion {
     CARD8   client_minor;
     CARD16  unused;
 } SELinuxQueryVersionReq;
-#define sz_SELinuxQueryVersionReq 8
 
 typedef struct {
     CARD8   type;
@@ -56,15 +64,114 @@ typedef struct {
     CARD32  pad5;
     CARD32  pad6; 
 } SELinuxQueryVersionReply;
-#define sz_SELinuxQueryVersionReply  32
 
-typedef struct _SELinuxSetSelectionManager {
+typedef struct {
     CARD8   reqType;
     CARD8   SELinuxReqType;
     CARD16  length;
     CARD32  window;
 } SELinuxSetSelectionManagerReq;
-#define sz_SELinuxSetSelectionManagerReq 8
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+} SELinuxGetSelectionManagerReq;
+
+typedef struct {
+    CARD8   type;
+    CARD8   pad1;
+    CARD16  sequenceNumber;
+    CARD32  length;
+    CARD32  window;
+    CARD32  pad2;
+    CARD32  pad3;
+    CARD32  pad4;
+    CARD32  pad5;
+    CARD32  pad6;
+} SELinuxGetSelectionManagerReply;
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+    CARD8   permanent;
+    CARD8   unused;
+    CARD16  context_len;
+} SELinuxSetCreateContextReq;
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+} SELinuxGetCreateContextReq;
+
+typedef struct {
+    CARD8   type;
+    CARD8   permanent;
+    CARD16  sequenceNumber;
+    CARD32  length;
+    CARD16  context_len;
+    CARD16  pad1;
+    CARD32  pad2;
+    CARD32  pad3;
+    CARD32  pad4;
+    CARD32  pad5;
+    CARD32  pad6;
+} SELinuxGetCreateContextReply;
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+    CARD32  id;
+    CARD16  unused;
+    CARD16  context_len;
+} SELinuxSetContextReq;
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+    CARD32  id;
+} SELinuxGetContextReq;
+
+typedef struct {
+    CARD8   type;
+    CARD8   pad1;
+    CARD16  sequenceNumber;
+    CARD32  length;
+    CARD16  context_len;
+    CARD16  pad2;
+    CARD32  pad3;
+    CARD32  pad4;
+    CARD32  pad5;
+    CARD32  pad6;
+    CARD32  pad7;
+} SELinuxGetContextReply;
+
+typedef struct {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+    CARD32  window;
+    CARD32  property;
+} SELinuxGetPropertyContextReq;
+
+typedef struct {
+    CARD8   type;
+    CARD8   pad1;
+    CARD16  sequenceNumber;
+    CARD32  length;
+    CARD16  context_len;
+    CARD16  pad2;
+    CARD32  pad3;
+    CARD32  pad4;
+    CARD32  pad5;
+    CARD32  pad6;
+    CARD32  pad7;
+} SELinuxGetPropertyContextReply;
+
 
 /* Private Flask definitions */
 #define SECCLASS_X_DRAWABLE		1
commit 5f9095f0d29bac0190d82c87a09cf32d6a34c17c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 25 19:02:03 2007 -0400

    registry: Remove synthetic bit from event types in lookup function.

diff --git a/dix/registry.c b/dix/registry.c
index 48e1b5d..1cf7fa5 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -134,6 +134,7 @@ LookupRequestName(int major, int minor)
 const char *
 LookupEventName(int event)
 {
+    event &= 127;
     if (event >= nevent)
 	return XREGISTRY_UNKNOWN;
 
@@ -153,7 +154,6 @@ const char *
 LookupResourceName(RESTYPE resource)
 {
     resource &= TypeMask;
-
     if (resource >= nresource)
 	return XREGISTRY_UNKNOWN;
 
commit 8c6923018c7d71cd15d9cf4ef9e8528ef5ec7c2e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 25 19:01:29 2007 -0400

    xace: Add a "manage" access check when setting the Redirect event bits.

diff --git a/dix/events.c b/dix/events.c
index 24de947..e13e290 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -3330,6 +3330,8 @@ ProcessPointerEvent (xEvent *xE, DeviceIntPtr mouse, int count)
 
 #define AtMostOneClient \
 	(SubstructureRedirectMask | ResizeRedirectMask | ButtonPressMask)
+#define ManagerMask \
+	(SubstructureRedirectMask | ResizeRedirectMask)
 
 /**
  * Recalculate which events may be deliverable for the given window.
@@ -3418,12 +3420,20 @@ EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
 {
     Mask check;
     OtherClients * others;
+    int rc;
 
     if (mask & ~AllEventMasks)
     {
 	client->errorValue = mask;
 	return BadValue;
     }
+    check = (mask & ManagerMask);
+    if (check) {
+	rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id,
+		      RT_WINDOW, pWin, RT_NONE, NULL, DixManageAccess);
+	if (rc != Success)
+	    return rc;
+    }
     check = (mask & AtMostOneClient);
     if (check & (pWin->eventMask|wOtherEventMasks(pWin)))
     {				       /* It is illegal for two different
commit 7d14ca59c5b942c09feaa2429c394cde9d8d3fd1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 25 19:00:50 2007 -0400

    xselinux: Don't include the client in the receive hook audit messages.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index b780170..bacbe6e 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -545,7 +545,7 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceReceiveAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { .client = rec->client };
+    SELinuxAuditRec auditdata = { .client = NULL };
     int rc, i;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
commit 40de9fcf18930811dd5ae355c83275af887a9f83
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 25 12:35:01 2007 -0400

    xselinux: Label the default device directly with the process context.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index cb62cb9..b780170 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -486,13 +486,9 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     if (rec->access_mode & DixCreateAccess) {
 	sidput(obj->sid);
 
-	/* Perform a transition to obtain the final SID */
-	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_DEVICE,
-			       &obj->sid) < 0) {
-	    ErrorF("XSELinux: a compute_create call failed!\n");
-	    rec->status = BadValue;
-	    return;
-	}
+	/* Label the device directly with the process SID */
+	sidget(subj->sid);
+	obj->sid = subj->sid;
     }
 
     rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_DEVICE,
commit b633d54b94d746d26e13014634d9f63bbb7e8f7d
Merge: 4b05f19... 48ca596...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 25 12:19:30 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	GL/glx/glxscreens.c
    	hw/xnest/Screen.c
    	render/glyph.c
    	render/glyphstr.h
    	render/render.c

diff --cc GL/glx/glxscreens.c
index 6e4d497,2c8f810..2dc9d2f
--- a/GL/glx/glxscreens.c
+++ b/GL/glx/glxscreens.c
@@@ -40,13 -40,14 +40,15 @@@
  #include <string.h>
  #include <windowstr.h>
  #include <os.h>
+ #include <colormapst.h>
  
 +#include "privates.h"
  #include "glxserver.h"
  #include "glxutil.h"
  #include "glxext.h"
+ #include "glcontextmodes.h"
  
 -static int glxScreenPrivateIndex;
 +static DevPrivateKey glxScreenPrivateKey = &glxScreenPrivateKey;
  
  const char GLServerVersion[] = "1.4";
  static const char GLServerExtensions[] = 
@@@ -279,28 -280,267 +281,257 @@@ glxCloseScreen (int index, ScreenPtr pS
  __GLXscreen *
  glxGetScreen(ScreenPtr pScreen)
  {
 -    return (__GLXscreen *) pScreen->devPrivates[glxScreenPrivateIndex].ptr;
 +    return dixLookupPrivate(&pScreen->devPrivates, glxScreenPrivateKey);
  }
  
- void __glXScreenInit(__GLXscreen *glxScreen, ScreenPtr pScreen)
+ void GlxSetVisualConfigs(int nconfigs, 
+                          __GLXvisualConfig *configs, void **privates)
  {
-     glxScreen->pScreen       = pScreen;
-     glxScreen->GLextensions  = xstrdup(GLServerExtensions);
-     glxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
-     glxScreen->GLXversion    = xstrdup(GLXServerVersion);
-     glxScreen->GLXextensions = xstrdup(GLXServerExtensions);
+     /* We keep this stub around for the DDX drivers that still
+      * call it. */
+ }
+ 
+ static XID
+ findVisualForConfig(ScreenPtr pScreen, __GLcontextModes *m)
+ {
+     int i;
+ 
+     for (i = 0; i < pScreen->numVisuals; i++) {
+ 	if (_gl_convert_to_x_visual_type(m->visualType) == pScreen->visuals[i].class)
+ 	    return pScreen->visuals[i].vid;
+     }
+ 
+     return 0;
+ }
+ 
+ /* This code inspired by composite/compinit.c.  We could move this to
+  * mi/ and share it with composite.*/
+ 
+ static VisualPtr
+ AddScreenVisuals(ScreenPtr pScreen, int count, int d)
+ {
+     XID		*installedCmaps, *vids, vid;
+     int		 numInstalledCmaps, numVisuals, i, j;
+     VisualPtr	 visuals;
+     ColormapPtr	 installedCmap;
+     DepthPtr	 depth;
+ 
+     depth = NULL;
+     for (i = 0; i < pScreen->numDepths; i++) {
+ 	if (pScreen->allowedDepths[i].depth == d) {
+ 	    depth = &pScreen->allowedDepths[i];
+ 	    break;
+ 	}
+     }
+     if (depth == NULL)
+ 	return NULL;
+ 
+     /* Find the installed colormaps */
+     installedCmaps = xalloc (pScreen->maxInstalledCmaps * sizeof (XID));
+     if (!installedCmaps)
+ 	return NULL;
+ 
+     numInstalledCmaps = pScreen->ListInstalledColormaps(pScreen, installedCmaps);
+ 
+     /* realloc the visual array to fit the new one in place */
+     numVisuals = pScreen->numVisuals;
+     visuals = xrealloc(pScreen->visuals, (numVisuals + count) * sizeof(VisualRec));
+     if (!visuals) {
+ 	xfree(installedCmaps);
+ 	return NULL;
+     }
+ 
+     vids = xrealloc(depth->vids, (depth->numVids + count) * sizeof(XID));
+     if (vids == NULL) {
+ 	xfree(installedCmaps);
+ 	xfree(visuals);
+ 	return NULL;
+     }
  
-     glxScreen->PositionWindow = pScreen->PositionWindow;
+     /*
+      * Fix up any existing installed colormaps -- we'll assume that
+      * the only ones created so far have been installed.  If this
+      * isn't true, we'll have to walk the resource database looking
+      * for all colormaps.
+      */
+     for (i = 0; i < numInstalledCmaps; i++) {
+ 	installedCmap = LookupIDByType (installedCmaps[i], RT_COLORMAP);
+ 	if (!installedCmap)
+ 	    continue;
+ 	j = installedCmap->pVisual - pScreen->visuals;
+ 	installedCmap->pVisual = &visuals[j];
+     }
+ 
+     xfree(installedCmaps);
+ 
+     for (i = 0; i < count; i++) {
+ 	vid = FakeClientID(0);
+ 	visuals[pScreen->numVisuals + i].vid = vid;
+ 	vids[depth->numVids + i] = vid;
+     }
+ 
+     pScreen->visuals = visuals;
+     pScreen->numVisuals += count;
+     depth->vids = vids;
+     depth->numVids += count;
+ 
+     /* Return a pointer to the first of the added visuals. */ 
+     return pScreen->visuals + pScreen->numVisuals - count;
+ }
+ 
+ static int
+ findFirstSet(unsigned int v)
+ {
+     int i;
+ 
+     for (i = 0; i < 32; i++)
+ 	if (v & (1 << i))
+ 	    return i;
+ 
+     return -1;
+ }
+ 
+ static void
+ initGlxVisual(VisualPtr visual, __GLcontextModes *config)
+ {
+     config->visualID = visual->vid;
+     visual->class = _gl_convert_to_x_visual_type(config->visualType);
+     visual->bitsPerRGBValue = config->redBits;
+     visual->ColormapEntries = 1 << config->redBits;
+     visual->nplanes = config->redBits + config->greenBits + config->blueBits;
+ 
+     visual->redMask = config->redMask;
+     visual->greenMask = config->greenMask;
+     visual->blueMask = config->blueMask;
+     visual->offsetRed = findFirstSet(config->redMask);
+     visual->offsetGreen = findFirstSet(config->greenMask);
+     visual->offsetBlue = findFirstSet(config->blueMask);
+ }
+ 
+ static void
+ addMinimalSet(__GLXscreen *pGlxScreen)
+ {
+     __GLcontextModes *config;
+     VisualPtr visuals;
+     int depth;
+ 
+     for (config = pGlxScreen->fbconfigs; config != NULL; config = config->next) {
+ 	if (config->visualRating != GLX_NONE)
+ 	    continue;
+ 	if (config->doubleBufferMode && config->depthBits > 0)
+ 	    break;
+     }
+     if (config == NULL)
+ 	config = pGlxScreen->fbconfigs;
+ 
+     pGlxScreen->visuals = xcalloc(1, sizeof (__GLcontextModes *));
+     if (pGlxScreen->visuals == NULL) {
+ 	ErrorF("Failed to allocate for minimal set of GLX visuals\n");
+ 	return;
+     }
+ 
+     depth = config->redBits + config->greenBits + config->blueBits;
+     visuals = AddScreenVisuals(pGlxScreen->pScreen, 1, depth);
+     if (visuals == NULL) {
+ 	xfree(pGlxScreen->visuals);
+ 	return;
+     }
+ 
+     pGlxScreen->numVisuals = 1;
+     pGlxScreen->visuals[0] = config;
+     initGlxVisual(&visuals[0], config);
+ }
+ 
+ static void
+ addTypicalSet(__GLXscreen *pGlxScreen)
+ {
+     addMinimalSet(pGlxScreen);
+ }
+ 
+ static void
+ addFullSet(__GLXscreen *pGlxScreen)
+ {
+     __GLcontextModes *config;
+     VisualPtr visuals;
+     int i, depth;
+ 
+     pGlxScreen->visuals =
+ 	xcalloc(pGlxScreen->numFBConfigs, sizeof (__GLcontextModes *));
+     if (pGlxScreen->visuals == NULL) {
+ 	ErrorF("Failed to allocate for full set of GLX visuals\n");
+ 	return;
+     }
+ 
+     config = pGlxScreen->fbconfigs;
+     depth = config->redBits + config->greenBits + config->blueBits;
+     visuals = AddScreenVisuals(pGlxScreen->pScreen, pGlxScreen->numFBConfigs, depth);
+     if (visuals == NULL) {
+ 	xfree(pGlxScreen->visuals);
+ 	return;
+     }
+ 
+     pGlxScreen->numVisuals = pGlxScreen->numFBConfigs;
+     for (i = 0, config = pGlxScreen->fbconfigs; config; config = config->next, i++) {
+ 	pGlxScreen->visuals[i] = config;
+ 	initGlxVisual(&visuals[i], config);
+     }
+ }
+ 
+ static int glxVisualConfig = GLX_ALL_VISUALS;
+ 
+ void GlxSetVisualConfig(int config)
+ {
+     glxVisualConfig = config;
+ }
+ 
+ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
+ {
 -    static int glxGeneration;
+     __GLcontextModes *m;
+     int i;
+ 
 -    if (glxGeneration != serverGeneration)
 -    {
 -	glxScreenPrivateIndex = AllocateScreenPrivateIndex ();
 -	if (glxScreenPrivateIndex == -1)
 -	    return;
 -
 -	glxGeneration = serverGeneration;
 -    }
 -
+     pGlxScreen->pScreen       = pScreen;
+     pGlxScreen->GLextensions  = xstrdup(GLServerExtensions);
+     pGlxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
+     pGlxScreen->GLXversion    = xstrdup(GLXServerVersion);
+     pGlxScreen->GLXextensions = xstrdup(GLXServerExtensions);
+ 
+     pGlxScreen->PositionWindow = pScreen->PositionWindow;
      pScreen->PositionWindow = glxPositionWindow;
   
-     glxScreen->CloseScreen = pScreen->CloseScreen;
+     pGlxScreen->CloseScreen = pScreen->CloseScreen;
      pScreen->CloseScreen = glxCloseScreen;
  
-     __glXScreenInitVisuals(glxScreen);
+     i = 0;
+     for (m = pGlxScreen->fbconfigs; m != NULL; m = m->next) {
+ 	m->fbconfigID = FakeClientID(0);
+ 	m->visualID = findVisualForConfig(pScreen, m);
+ 	ErrorF("mapping fbconfig id 0x%02lx to visual id 0x%02lx\n",
+ 	       m->fbconfigID, m->visualID);
+ 	i++;
+     }
+     pGlxScreen->numFBConfigs = i;
+ 
+     /* Select a subset of fbconfigs that we send to the client when it
+      * asks for the glx visuals.  All the fbconfigs here have a valid
+      * value for visual ID and each visual ID is only present once.
+      * This runs before composite adds its extra visual so we have to
+      * remember the number of visuals here.*/
+ 
+     switch (glxVisualConfig) {
+     case GLX_MINIMAL_VISUALS:
+ 	addMinimalSet(pGlxScreen);
+ 	break;
+     case GLX_TYPICAL_VISUALS:
+ 	addTypicalSet(pGlxScreen);
+ 	break;
+     case GLX_ALL_VISUALS:
+ 	addFullSet(pGlxScreen);
+ 	break;
+     }
  
-     dixSetPrivate(&pScreen->devPrivates, glxScreenPrivateKey, glxScreen);
 -    pScreen->devPrivates[glxScreenPrivateIndex].ptr = (pointer) pGlxScreen;
++    dixSetPrivate(&pScreen->devPrivates, glxScreenPrivateKey, pGlxScreen);
  }
 - 
 +
  void __glXScreenDestroy(__GLXscreen *screen)
  {
      xfree(screen->GLXvendor);
diff --cc hw/xfree86/loader/misym.c
index e87d354,025983b..aa712c0
--- a/hw/xfree86/loader/misym.c
+++ b/hw/xfree86/loader/misym.c
@@@ -200,14 -200,11 +200,11 @@@ _X_HIDDEN void *miLookupTab[] = 
      SYMFUNC(miOverlaySetRootClip)
      SYMVAR(miEmptyBox)
      SYMVAR(miEmptyData)
 -    SYMVAR(miZeroLineScreenIndex)
 +    SYMVAR(miZeroLineScreenKey)
      SYMVAR(miSpritePointerFuncs)
 -    SYMVAR(miPointerScreenIndex)
 +    SYMVAR(miPointerScreenKey)
      SYMVAR(miInstalledMaps)
      SYMVAR(miInitVisualsProc)
- #ifdef RENDER
-     SYMFUNC(miGlyphExtents)
- #endif
  #ifdef DAMAGE
      SYMFUNC(DamageDamageRegion)
  #endif
diff --cc hw/xnest/Screen.c
index 83590bc,02e82d1..61a325f
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@@ -45,10 -45,8 +45,6 @@@ is" without express or implied warranty
  Window xnestDefaultWindows[MAXSCREENS];
  Window xnestScreenSaverWindows[MAXSCREENS];
  
- #ifdef GLXEXT
- extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
- #endif
- 
 -static int xnestScreenGeneration = -1;
 -
  ScreenPtr
  xnestScreen(Window window)
  {
diff --cc render/glyph.c
index cb1534d,5cd7992..bb7c880
--- a/render/glyph.c
+++ b/render/glyph.c
@@@ -26,6 -26,8 +26,9 @@@
  #include <dix-config.h>
  #endif
  
++#include <stddef.h>
+ #include <openssl/sha.h>
+ 
  #include "misc.h"
  #include "scrnintstr.h"
  #include "os.h"
@@@ -81,18 -84,220 +85,19 @@@ static const CARD8	glyphDepths[GlyphFor
  
  static GlyphHashRec	globalGlyphs[GlyphFormatNum];
  
 -static int	globalTotalGlyphPrivateSize = 0;
 -
 -static int	glyphPrivateCount = 0;
 -
 -void
 -ResetGlyphPrivates (void)
 -{
 -    glyphPrivateCount = 0;
 -}
 -
 -int
 -AllocateGlyphPrivateIndex (void)
 -{
 -    return glyphPrivateCount++;
 -}
 -
 -Bool
 -AllocateGlyphPrivate (ScreenPtr pScreen,
 -		      int	index2,
 -		      unsigned	amount)
 -{
 -    PictureScreenPtr ps;
 -    unsigned	     oldamount;
 -
 -    ps = GetPictureScreenIfSet (pScreen);
 -    if (!ps)
 -	return FALSE;
 -
 -    /* Round up sizes for proper alignment */
 -    amount = ((amount + (sizeof (DevUnion) - 1)) / sizeof (DevUnion)) *
 -	sizeof (DevUnion);
 -
 -    if (index2 >= ps->glyphPrivateLen)
 -    {
 -	unsigned *nsizes;
 -	nsizes = (unsigned *) xrealloc (ps->glyphPrivateSizes,
 -					(index2 + 1) * sizeof (unsigned));
 -	if (!nsizes)
 -	    return FALSE;
 -	
 -	while (ps->glyphPrivateLen <= index2)
 -	{
 -	    nsizes[ps->glyphPrivateLen++] = 0;
 -	    ps->totalGlyphPrivateSize += sizeof (DevUnion);
 -	}
 -	ps->glyphPrivateSizes = nsizes;
 -    }
 -    oldamount = ps->glyphPrivateSizes[index2];
 -    if (amount > oldamount)
 -    {
 -	ps->glyphPrivateSizes[index2] = amount;
 -	ps->totalGlyphPrivateSize += (amount - oldamount);
 -    }
 -    ps->totalGlyphPrivateSize = BitmapBytePad (ps->totalGlyphPrivateSize * 8);
 -    
 -    return TRUE;
 -}
 -
  static void
 -SetGlyphScreenPrivateOffsets (void)
 +FreeGlyphPrivates (GlyphPtr glyph)
  {
 -    PictureScreenPtr ps;
 -    int		     offset = 0;
 -    int		     i;
 +    ScreenPtr pScreen;
 +    int i;
  
 -    for (i = 0; i < screenInfo.numScreens; i++)
 -    {
 -	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
 -	if (ps && ps->totalGlyphPrivateSize)
 -	{
 -	    ps->glyphPrivateOffset = offset;
 -	    offset += ps->totalGlyphPrivateSize / sizeof (DevUnion);
 -	}
 +    for (i = 0; i < screenInfo.numScreens; i++) {
 +	pScreen = screenInfo.screens[i];
 +	dixFreePrivates(*GetGlyphPrivatesForScreen(glyph, pScreen));
      }
 -}
  
 -static void
 -SetGlyphPrivatePointers (GlyphPtr glyph)
 -{
 -    PictureScreenPtr ps;
 -    int		     i;
 -    char	     *ptr;
 -    DevUnion         *ppriv;
 -    unsigned         *sizes;
 -    unsigned         size;
 -    int		     len;
 -
 -    for (i = 0; i < screenInfo.numScreens; i++)
 -    {
 -	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
 -	if (ps && ps->totalGlyphPrivateSize)
 -	{
 -	    ppriv = glyph->devPrivates + ps->glyphPrivateOffset;
 -	    sizes = ps->glyphPrivateSizes;
 -	    ptr = (char *) (ppriv + ps->glyphPrivateLen);
 -	    for (len = ps->glyphPrivateLen; --len >= 0; ppriv++, sizes++)
 -	    {
 -		if ((size = *sizes) != 0)
 -		{
 -		    ppriv->ptr = (pointer) ptr;
 -		    ptr += size;
 -		}
 -		else
 -		    ppriv->ptr = (pointer) 0;
 -	    }
 -	}
 -    }
 -}
 -
 -static Bool
 -ReallocGlobalGlyphPrivate (GlyphPtr glyph)
 -{
 -    PictureScreenPtr ps;
 -    DevUnion         *devPrivates;
 -    char	     *ptr;
 -    int		     i;
 -
 -    devPrivates = xalloc (globalTotalGlyphPrivateSize);
 -    if (!devPrivates)
 -	return FALSE;
 -
 -    ptr = (char *) devPrivates;
 -    for (i = 0; i < screenInfo.numScreens; i++)
 -    {
 -	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
 -	if (ps && ps->totalGlyphPrivateSize)
 -	{
 -	    if (ps->glyphPrivateOffset != -1)
 -	    {
 -		memcpy (ptr, glyph->devPrivates + ps->glyphPrivateOffset,
 -			ps->totalGlyphPrivateSize);
 -	    }
 -	    else if (ps->totalGlyphPrivateSize)
 -	    {
 -		memset (ptr, 0, ps->totalGlyphPrivateSize);
 -	    }
 -	    
 -	    ptr += ps->totalGlyphPrivateSize;
 -	}
 -    }
 -
 -    if (glyph->devPrivates)
 -	xfree (glyph->devPrivates);
 -    
 -    glyph->devPrivates = devPrivates;
 -
 -    return TRUE;
 -}
 -
 -Bool
 -GlyphInit (ScreenPtr pScreen)
 -{
 -    PictureScreenPtr ps = GetPictureScreen (pScreen);
 -    
 -    ps->totalGlyphPrivateSize = 0;
 -    ps->glyphPrivateSizes = 0;
 -    ps->glyphPrivateLen = 0;
 -    ps->glyphPrivateOffset = -1;
 -    
 -    return TRUE;
 -}
 -
 -Bool
 -GlyphFinishInit (ScreenPtr pScreen)
 -{
 -    PictureScreenPtr ps = GetPictureScreen (pScreen);
 -
 -    if (ps->totalGlyphPrivateSize)
 -    {
 -	GlyphPtr glyph;
 -	int	 fdepth, i;
 -	
 -	globalTotalGlyphPrivateSize += ps->totalGlyphPrivateSize;
 -	
 -	for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
 -	{
 -	    if (!globalGlyphs[fdepth].hashSet)
 -		continue;
 -		
 -	    for (i = 0; i < globalGlyphs[fdepth].hashSet->size; i++)
 -	    {
 -		glyph = globalGlyphs[fdepth].table[i].glyph;
 -		if (glyph && glyph != DeletedGlyph)
 -		{
 -		    if (!ReallocGlobalGlyphPrivate (glyph))
 -			return FALSE;
 -		}
 -	    }
 -	}
 -
 -	SetGlyphScreenPrivateOffsets ();
 -
 -	for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
 -	{
 -	    if (!globalGlyphs[fdepth].hashSet)
 -		continue;
 -		
 -	    for (i = 0; i < globalGlyphs[fdepth].hashSet->size; i++)
 -	    {
 -		glyph = globalGlyphs[fdepth].table[i].glyph;
 -		if (glyph && glyph != DeletedGlyph)
 -		{
 -		    SetGlyphPrivatePointers (glyph);
 -			
 -		    if (!(*ps->RealizeGlyph) (pScreen, glyph))
 -			return FALSE;
 -		}
 -	    }
 -	}
 -    }
 -    else
 -	ps->glyphPrivateOffset = 0;
 -    
 -    return TRUE;
 +    dixFreePrivates(glyph->devPrivates);
++    glyph->devPrivates = NULL;
  }
  
  void
@@@ -113,8 -320,18 +118,7 @@@ GlyphUninit (ScreenPtr pScreen
  	    if (glyph && glyph != DeletedGlyph)
  	    {
  		(*ps->UnrealizeGlyph) (pScreen, glyph);
 -		
 -		if (globalTotalGlyphPrivateSize)
 -		{
 -		    if (!ReallocGlobalGlyphPrivate (glyph))
 -			return;
 -		}
 -		else
 -		{
 -		    if (glyph->devPrivates)
 -			xfree (glyph->devPrivates);
 -		    glyph->devPrivates = NULL;
 -		}
 +		FreeGlyphPrivates(glyph);
- 		glyph->devPrivates = NULL;
  	    }
  	}
      }
@@@ -140,8 -370,55 +144,11 @@@ FindGlyphHashSet (CARD32 filled
      return 0;
  }
  
 -static int _GlyphSetPrivateAllocateIndex = 0;
 -
 -int
 -AllocateGlyphSetPrivateIndex (void)
 -{
 -    return _GlyphSetPrivateAllocateIndex++;
 -}
 -
 -void
 -ResetGlyphSetPrivateIndex (void)
 -{
 -    _GlyphSetPrivateAllocateIndex = 0;
 -}
 -
 -Bool
 -_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr)
 -{
 -    pointer *new;
 -
 -    if (n > glyphSet->maxPrivate) {
 -	if (glyphSet->devPrivates &&
 -	    glyphSet->devPrivates != (pointer)(&glyphSet[1])) {
 -	    new = (pointer *) xrealloc (glyphSet->devPrivates,
 -					(n + 1) * sizeof (pointer));
 -	    if (!new)
 -		return FALSE;
 -	} else {
 -	    new = (pointer *) xalloc ((n + 1) * sizeof (pointer));
 -	    if (!new)
 -		return FALSE;
 -	    if (glyphSet->devPrivates)
 -		memcpy (new,
 -			glyphSet->devPrivates,
 -			(glyphSet->maxPrivate + 1) * sizeof (pointer));
 -	}
 -	glyphSet->devPrivates = new;
 -	/* Zero out new, uninitialize privates */
 -	while (++glyphSet->maxPrivate < n)
 -	    glyphSet->devPrivates[glyphSet->maxPrivate] = (pointer)0;
 -    }
 -    glyphSet->devPrivates[n] = ptr;
 -    return TRUE;
 -}
 -
  GlyphRefPtr
- FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare)
+ FindGlyphRef (GlyphHashPtr	hash,
+ 	      CARD32		signature,
+ 	      Bool		match,
+ 	      unsigned char	sha1[20])
  {
      CARD32	elt, step, s;
      GlyphPtr	glyph;
@@@ -263,12 -572,17 +302,16 @@@ FreeGlyph (GlyphPtr glyph, int format
  
  	for (i = 0; i < screenInfo.numScreens; i++)
  	{
- 	    ps = GetPictureScreenIfSet (screenInfo.screens[i]);
+ 	    ScreenPtr pScreen = screenInfo.screens[i];
+ 
+ 	    FreePicture ((pointer) GlyphPicture (glyph)[i], 0);
+ 
+ 	    ps = GetPictureScreenIfSet (pScreen);
  	    if (ps)
- 		(*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
+ 		(*ps->UnrealizeGlyph) (pScreen, glyph);
  	}
  	
 -	if (glyph->devPrivates)
 -	    xfree (glyph->devPrivates);
 +	FreeGlyphPrivates(glyph);
  	xfree (glyph);
      }
  }
@@@ -385,6 -700,19 +419,18 @@@ AllocateGlyph (xGlyphInfo *gi, int fdep
      }
      
      return glyph;
+ 
+ bail:
+     while (i--)
+     {
+ 	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
+ 	if (ps)
+ 	    (*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
+     }
 -		
 -    if (glyph->devPrivates)
 -	xfree (glyph->devPrivates);
++
++    FreeGlyphPrivates(glyph);
+     xfree (glyph);
+     return 0;
  }
      
  Bool
diff --cc render/glyphstr.h
index e89f34e,c6ab5aa..67b21fe
--- a/render/glyphstr.h
+++ b/render/glyphstr.h
@@@ -40,13 -39,16 +40,16 @@@
  #define GlyphFormatNum	5
  
  typedef struct _Glyph {
-     CARD32	refcnt;
+     CARD32	    refcnt;
 -    DevUnion	    *devPrivates;
 +    PrivateRec	*devPrivates;
-     CARD32	size;	/* info + bitmap */
-     xGlyphInfo	info;
-     /* bits follow */
+     unsigned char   sha1[20];
+     CARD32	    size; /* info + bitmap */
+     xGlyphInfo	    info;
+     /* per-screen pixmaps follow */
  } GlyphRec, *GlyphPtr;
  
+ #define GlyphPicture(glyph) ((PicturePtr *) ((glyph) + 1))
+ 
  typedef struct _GlyphRef {
      CARD32	signature;
      GlyphPtr	glyph;
diff --cc render/render.c
index fe50dd2,1a1cd7a..b9ac45e
--- a/render/render.c
+++ b/render/render.c
@@@ -1187,18 -1100,23 +1190,22 @@@ ProcRenderAddGlyphs (ClientPtr client
      xGlyphInfo	    *gi;
      CARD8	    *bits;
      int		    size;
 -    int		    err = BadAlloc;
 +    int		    err;
+     int		    i, screen;
+     PicturePtr	    pSrc = NULL, pDst = NULL;
+     PixmapPtr	    pSrcPix = NULL, pDstPix = NULL;
+     CARD32	    component_alpha;
  
      REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq);
 -    glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
 -						     stuff->glyphset,
 -						     GlyphSetType,
 -						     DixWriteAccess);
 -    if (!glyphSet)
 +    err = dixLookupResource((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
 +			    client, DixAddAccess);
 +    if (err != Success)
      {
  	client->errorValue = stuff->glyphset;
 -	return RenderErrBase + BadGlyphSet;
 +	return (err == BadValue) ? RenderErrBase + BadGlyphSet : err;
      }
  
 +    err = BadAlloc;
      nglyphs = stuff->nglyphs;
      if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec))
  	    return BadAlloc;
commit 4b05f19cb9e42d8c8eff5ca4e463f5bc2a05433d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 24 19:59:58 2007 -0400

    xselinux: Introduce a type transition when labeling events.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 8361011..cb62cb9 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -194,7 +194,8 @@ SELinuxSelectionToSID(Atom selection, SELinuxStateRec *sid_return)
  * Looks up the SID corresponding to the given event type
  */
 static int
-SELinuxEventToSID(unsigned type, SELinuxStateRec *sid_return)
+SELinuxEventToSID(unsigned type, security_id_t sid_of_window,
+		  SELinuxStateRec *sid_return)
 {
     const char *name = LookupEventName(type);
     security_context_t con;
@@ -212,7 +213,7 @@ SELinuxEventToSID(unsigned type, SELinuxStateRec *sid_return)
     }
 
     if (!knownEvents[type]) {
-	/* Look in the mappings of property names to contexts */
+	/* Look in the mappings of event names to contexts */
 	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EVENT) < 0) {
 	    ErrorF("XSELinux: an event label lookup failed!\n");
 	    return BadValue;
@@ -225,7 +226,13 @@ SELinuxEventToSID(unsigned type, SELinuxStateRec *sid_return)
 	freecon(con);
     }
 
-    sid_return->sid = knownEvents[type];
+    /* Perform a transition to obtain the final SID */
+    if (avc_compute_create(sid_of_window, knownEvents[type], SECCLASS_X_EVENT,
+			   &sid_return->sid) < 0) {
+	ErrorF("XSELinux: a compute_create call failed!\n");
+	return BadValue;
+    }
+
     return Success;
 }
 
@@ -522,7 +529,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     for (i = 0; i < rec->count; i++) {
 	SELinuxStateRec ev_sid;
 
-	rc = SELinuxEventToSID(rec->events[i].u.u.type, &ev_sid);
+	rc = SELinuxEventToSID(rec->events[i].u.u.type, obj->sid, &ev_sid);
 	if (rc != Success)
 	    goto err;
 
@@ -558,7 +565,7 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     for (i = 0; i < rec->count; i++) {
 	SELinuxStateRec ev_sid;
 
-	rc = SELinuxEventToSID(rec->events[i].u.u.type, &ev_sid);
+	rc = SELinuxEventToSID(rec->events[i].u.u.type, obj->sid, &ev_sid);
 	if (rc != Success)
 	    goto err;
 
commit 0d2ef187e77b12713d2a9661932fa01dba58a945
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 24 18:23:31 2007 -0400

    xselinux: Add audit message fields for selection and event names.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index f11bc1a..8361011 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -83,7 +83,9 @@ typedef struct {
     char *command;	/* client's executable path */
     unsigned id;	/* resource id, if any */
     int restype;	/* resource type, if any */
+    int event;		/* event type, if any */
     Atom property;	/* property name, if any */
+    Atom selection;	/* selection name, if any */
     char *extension;	/* extension name, if any */
 } SELinuxAuditRec;
 
@@ -413,7 +415,7 @@ SELinuxAudit(void *auditdata,
 {
     SELinuxAuditRec *audit = auditdata;
     ClientPtr client = audit->client;
-    char idNum[16], *propertyName;
+    char idNum[16], *propertyName, *selectionName;
     int major = -1, minor = -1;
 
     if (client) {
@@ -427,8 +429,9 @@ SELinuxAudit(void *auditdata,
 	snprintf(idNum, 16, "%x", audit->id);
 
     propertyName = audit->property ? NameForAtom(audit->property) : NULL;
+    selectionName = audit->selection ? NameForAtom(audit->selection) : NULL;
 
-    return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s",
+    return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
 		    (major >= 0) ? "request=" : "",
 		    (major >= 0) ? LookupRequestName(major, minor) : "",
 		    audit->command ? " comm=" : "",
@@ -437,8 +440,12 @@ SELinuxAudit(void *auditdata,
 		    audit->id ? idNum : "",
 		    audit->restype ? " restype=" : "",
 		    audit->restype ? LookupResourceName(audit->restype) : "",
+		    audit->event ? " event=" : "",
+		    audit->event ? LookupEventName(audit->event & 127) : "",
 		    audit->property ? " property=" : "",
 		    audit->property ? propertyName : "",
+		    audit->selection ? " selection=" : "",
+		    audit->selection ? selectionName : "",
 		    audit->extension ? " extension=" : "",
 		    audit->extension ? audit->extension : "");
 }
@@ -462,7 +469,7 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceDeviceAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -492,7 +499,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceSendAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc, i, clientIndex;
 
     if (rec->dev) {
@@ -519,6 +526,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (rc != Success)
 	    goto err;
 
+	auditdata.event = rec->events[i].u.u.type;
 	rc = SELinuxDoCheck(clientIndex, subj, &ev_sid, SECCLASS_X_EVENT,
 			    DixSendAccess, &auditdata);
 	if (rc != Success)
@@ -534,7 +542,7 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceReceiveAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc, i;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -554,6 +562,7 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (rc != Success)
 	    goto err;
 
+	auditdata.event = rec->events[i].u.u.type;
 	rc = SELinuxDoCheck(rec->client->index, subj, &ev_sid, SECCLASS_X_EVENT,
 			    DixReceiveAccess, &auditdata);
 	if (rc != Success)
@@ -569,7 +578,7 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceExtAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj, *serv;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -623,7 +632,7 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XacePropertyAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -675,7 +684,7 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceResourceAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj, *pobj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     PrivateRec **privatePtr;
     security_class_t class;
     int rc, offset;
@@ -731,7 +740,7 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
 {
     XaceScreenAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     Mask access_mode = rec->access_mode;
     int rc;
 
@@ -765,7 +774,7 @@ SELinuxClient(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceClientAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -782,7 +791,7 @@ SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceServerAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -799,7 +808,7 @@ SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceSelectionAccessRec *rec = (XaceSelectionAccessRec *)calldata;
     SELinuxStateRec *subj, sel_sid;
-    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { .client = rec->client };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -810,6 +819,7 @@ SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	return;
     }
 
+    auditdata.selection = rec->name;
     rc = SELinuxDoCheck(rec->client->index, subj, &sel_sid,
 			SECCLASS_X_SELECTION, rec->access_mode, &auditdata);
     if (rc != Success)
commit 0388a59a6ef212c497cc3f64d677b1ca5b410982
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 23 20:59:21 2007 -0400

    Revert "registry: special case minor number when looking up core requests."
    
    This reverts commit 31110d6837ee52fd654729d9e5c4b0c5395abab0.
    
    This is handled properly by StandardMinorOpcode().

diff --git a/dix/registry.c b/dix/registry.c
index 0181858..48e1b5d 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -123,8 +123,6 @@ RegisterResourceName(RESTYPE resource, const char *name)
 const char *
 LookupRequestName(int major, int minor)
 {
-    if (major < 128)
-	minor = 0;
     if (major >= nmajor)
 	return XREGISTRY_UNKNOWN;
     if (minor >= nminor[major])
commit 46521f529841e032e198e5df87974088548a68de
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 23 20:58:48 2007 -0400

    xselinux: Add basic support for selection access control and redirection.
    
    Probably not fully baked yet.  It's difficult to test since so few apps
    actually follow the ICCCM with respect to cut & paste.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index ef5be57..f11bc1a 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -65,6 +65,15 @@ typedef struct {
     char *command;
 } SELinuxStateRec;
 
+/* selection manager */
+typedef struct {
+    Atom selection;
+    security_id_t sid;
+} SELinuxSelectionRec;
+
+static ClientPtr selectionManager;
+static Window selectionWindow;
+
 /* audit file descriptor */
 static int audit_fd;
 
@@ -99,6 +108,10 @@ static unsigned numKnownTypes;
 static security_id_t *knownEvents;
 static unsigned numKnownEvents;
 
+/* Array of selection SID structures */
+static SELinuxSelectionRec *knownSelections;
+static unsigned numKnownSelections;
+
 /* dynamically allocated security classes and permissions */
 static struct security_class_mapping map[] = {
     { "x_drawable", { "read", "write", "destroy", "create", "getattr", "setattr", "list_property", "get_property", "set_property", "", "", "list_child", "add_child", "remove_child", "hide", "show", "blend", "override", "", "", "", "", "send", "receive", "", "manage", NULL }},
@@ -130,6 +143,52 @@ static pointer truep = (pointer)1;
  */
 
 /*
+ * Looks up the SID corresponding to the given selection atom
+ */
+static int
+SELinuxSelectionToSID(Atom selection, SELinuxStateRec *sid_return)
+{
+    const char *name;
+    unsigned i, size;
+
+    for (i = 0; i < numKnownSelections; i++)
+	if (knownSelections[i].selection == selection) {
+	    sid_return->sid = knownSelections[i].sid;
+	    return Success;
+	}
+
+    /* Need to increase size of array */
+    i = numKnownSelections;
+    size = (i + 1) * sizeof(SELinuxSelectionRec);
+    knownSelections = xrealloc(knownSelections, size);
+    if (!knownSelections)
+	return BadAlloc;
+    knownSelections[i].selection = selection;
+
+    /* Look in the mappings of selection names to contexts */
+    name = NameForAtom(selection);
+    if (name) {
+	security_context_t con;
+	security_id_t sid;
+
+	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_SELN) < 0) {
+	    ErrorF("XSELinux: a selection label lookup failed!\n");
+	    return BadValue;
+	}
+	/* Get a SID for context */
+	if (avc_context_to_sid(con, &sid) < 0) {
+	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    return BadAlloc;
+	}
+	freecon(con);
+	knownSelections[i].sid = sid_return->sid = sid;
+    } else
+	knownSelections[i].sid = sid_return->sid = unlabeled_sid;
+
+    return Success;
+}
+
+/*
  * Looks up the SID corresponding to the given event type
  */
 static int
@@ -240,10 +299,71 @@ SELinuxDoCheck(int clientIndex, SELinuxStateRec *subj, SELinuxStateRec *obj,
 }
 
 /*
+ * Labels a newly connected client.
+ */
+static void
+SELinuxLabelClient(ClientPtr client)
+{
+    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+    SELinuxStateRec *state;
+    security_context_t ctx;
+
+    state = dixLookupPrivate(&client->devPrivates, stateKey);
+    sidput(state->sid);
+
+    if (_XSERVTransIsLocal(ci)) {
+	int fd = _XSERVTransGetConnectionNumber(ci);
+	struct ucred creds;
+	socklen_t len = sizeof(creds);
+	char path[PATH_MAX + 1];
+	size_t bytes;
+
+	/* For local clients, can get context from the socket */
+	if (getpeercon(fd, &ctx) < 0)
+	    FatalError("Client %d: couldn't get context from socket\n",
+		       client->index);
+
+	/* Try and determine the client's executable name */
+	memset(&creds, 0, sizeof(creds));
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &len) < 0)
+	    goto finish;
+
+	snprintf(path, PATH_MAX + 1, "/proc/%d/cmdline", creds.pid);
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+	    goto finish;
+
+	bytes = read(fd, path, PATH_MAX + 1);
+	close(fd);
+	if (bytes <= 0)
+	    goto finish;
+
+	state->command = xalloc(bytes);
+	if (!state->command)
+	    goto finish;
+
+	memcpy(state->command, path, bytes);
+	state->command[bytes - 1] = 0;
+    } else
+	/* For remote clients, need to use a default context */
+	if (selabel_lookup(label_hnd, &ctx, NULL, SELABEL_X_CLIENT) < 0)
+	    FatalError("Client %d: couldn't get default remote context\n",
+		       client->index);
+
+finish:
+    /* Get a SID from the context */
+    if (avc_context_to_sid(ctx, &state->sid) < 0)
+	FatalError("Client %d: context_to_sid(%s) failed\n",
+		   client->index, ctx);
+
+    freecon(ctx);
+}
+
+/*
  * Labels initial server objects.
  */
 static void
-SELinuxFixupLabels(void)
+SELinuxLabelInitial(void)
 {
     int i;
     XaceScreenAccessRec srec;
@@ -674,6 +794,28 @@ SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	rec->status = rc;
 }
 
+static void
+SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceSelectionAccessRec *rec = (XaceSelectionAccessRec *)calldata;
+    SELinuxStateRec *subj, sel_sid;
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    int rc;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+
+    rc = SELinuxSelectionToSID(rec->name, &sel_sid);
+    if (rc != Success) {
+	rec->status = rc;
+	return;
+    }
+
+    rc = SELinuxDoCheck(rec->client->index, subj, &sel_sid,
+			SECCLASS_X_SELECTION, rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
+}
+
 
 /*
  * DIX Callbacks
@@ -683,63 +825,23 @@ static void
 SELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     NewClientInfoRec *pci = calldata;
-    ClientPtr client = pci->client;
-    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
-    SELinuxStateRec *state;
-    security_context_t ctx;
-
-    if (client->clientState != ClientStateInitial)
-	return;
-
-    state = dixLookupPrivate(&client->devPrivates, stateKey);
-    sidput(state->sid);
-
-    if (_XSERVTransIsLocal(ci)) {
-	int fd = _XSERVTransGetConnectionNumber(ci);
-	struct ucred creds;
-	socklen_t len = sizeof(creds);
-	char path[PATH_MAX + 1];
-	size_t bytes;
-
-	/* For local clients, can get context from the socket */
-	if (getpeercon(fd, &ctx) < 0)
-	    FatalError("Client %d: couldn't get context from socket\n",
-		       client->index);
-
-	/* Try and determine the client's executable name */
-	memset(&creds, 0, sizeof(creds));
-	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &len) < 0)
-	    goto finish;
-
-	snprintf(path, PATH_MAX + 1, "/proc/%d/cmdline", creds.pid);
-	fd = open(path, O_RDONLY);
-	if (fd < 0)
-	    goto finish;
-
-	bytes = read(fd, path, PATH_MAX + 1);
-	close(fd);
-	if (bytes <= 0)
-	    goto finish;
 
-	state->command = xalloc(bytes);
-	if (!state->command)
-	    goto finish;
-
-	memcpy(state->command, path, bytes);
-	state->command[bytes - 1] = 0;
-    } else
-	/* For remote clients, need to use a default context */
-	if (selabel_lookup(label_hnd, &ctx, NULL, SELABEL_X_CLIENT) < 0)
-	    FatalError("Client %d: couldn't get default remote context\n",
-		       client->index);
+    switch (pci->client->clientState) {
+    case ClientStateInitial:
+	SELinuxLabelClient(pci->client);
+	break;
 
-finish:
-    /* Get a SID from the context */
-    if (avc_context_to_sid(ctx, &state->sid) < 0)
-	FatalError("Client %d: context_to_sid(%s) failed\n",
-		   client->index, ctx);
+    case ClientStateRetained:
+    case ClientStateGone:
+	if (pci->client == selectionManager) {
+	    selectionManager = NULL;
+	    selectionWindow = 0;
+	}
+	break;
 
-    freecon(ctx);
+    default:
+	break;
+    }
 }
 
 static void
@@ -788,6 +890,50 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	FatalError("XSELinux: Unexpected unlabeled window found\n");
 }
 
+static void
+SELinuxSelectionState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    SelectionInfoRec *rec = calldata;
+    SELinuxStateRec *subj, *obj;
+
+    switch (rec->kind) {
+    case SelectionSetOwner:
+	/* save off the "real" owner of the selection */
+	rec->selection->alt_client = rec->selection->client;
+	rec->selection->alt_window = rec->selection->window;
+
+	/* figure out the new label for the content */
+	subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+	obj = dixLookupPrivate(&rec->selection->devPrivates, stateKey);
+	sidput(obj->sid);
+
+	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SELECTION,
+			       &obj->sid) < 0) {
+	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    obj->sid = unlabeled_sid;
+	}
+	break;
+
+    case SelectionGetOwner:
+	/* restore the real owner */
+	rec->selection->window = rec->selection->alt_window;
+	break;
+
+    case SelectionConvertSelection:
+	/* redirect the convert request if necessary */
+	if (selectionManager && selectionManager != rec->client) {
+	    rec->selection->client = selectionManager;
+	    rec->selection->window = selectionWindow;
+	} else {
+	    rec->selection->client = rec->selection->alt_client;
+	    rec->selection->window = rec->selection->alt_window;
+	}
+	break;
+    default:
+	break;
+    }
+}
+
 
 /*
  * DevPrivates Callbacks
@@ -823,9 +969,108 @@ SELinuxStateFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
  */
 
 static int
+ProcSELinuxQueryVersion(ClientPtr client)
+{
+    SELinuxQueryVersionReply rep;
+    /*
+      REQUEST(SELinuxQueryVersionReq);
+      REQUEST_SIZE_MATCH (SELinuxQueryVersionReq);
+    */
+
+    rep.type = X_Reply;
+    rep.length = 0;
+    rep.sequenceNumber = client->sequence;
+    rep.server_major = XSELINUX_MAJOR_VERSION;
+    rep.server_minor = XSELINUX_MINOR_VERSION;
+    if (client->swapped) {
+	int n;
+	swaps(&rep.sequenceNumber, n);
+	swapl(&rep.length, n);
+	swaps(&rep.server_major, n);
+	swaps(&rep.server_minor, n);
+    }
+    WriteToClient(client, sizeof(rep), (char *)&rep);
+    return (client->noClientException);
+}
+
+static int
+ProcSELinuxSetSelectionManager(ClientPtr client)
+{
+    REQUEST(SELinuxSetSelectionManagerReq);
+    WindowPtr pWin;
+    int rc;
+
+    REQUEST_SIZE_MATCH(SELinuxSetSelectionManagerReq);
+
+    if (stuff->window == None) {
+	selectionManager = NULL;
+	selectionWindow = None;
+    } else {
+	rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
+			       client, DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
+
+	selectionManager = client;
+	selectionWindow = stuff->window;
+    }
+
+    return Success;
+}
+
+static int
 ProcSELinuxDispatch(ClientPtr client)
 {
-    return BadRequest;
+    REQUEST(xReq);
+    switch (stuff->data) {
+    case X_SELinuxQueryVersion:
+        return ProcSELinuxQueryVersion(client);
+    case X_SELinuxSetSelectionManager:
+	return ProcSELinuxSetSelectionManager(client);
+    default:
+	return BadRequest;
+    }
+}
+
+static int
+SProcSELinuxQueryVersion(ClientPtr client)
+{
+    REQUEST(SELinuxQueryVersionReq);
+    int n;
+
+    REQUEST_SIZE_MATCH (SELinuxQueryVersionReq);
+    swaps(&stuff->client_major,n);
+    swaps(&stuff->client_minor,n);
+    return ProcSELinuxQueryVersion(client);
+}
+
+static int
+SProcSELinuxSetSelectionManager(ClientPtr client)
+{
+    REQUEST(SELinuxSetSelectionManagerReq);
+    int n;
+
+    REQUEST_SIZE_MATCH (SELinuxSetSelectionManagerReq);
+    swapl(&stuff->window,n);
+    return ProcSELinuxSetSelectionManager(client);
+}
+
+static int
+SProcSELinuxDispatch(ClientPtr client)
+{
+    REQUEST(xReq);
+    int n;
+
+    swaps(&stuff->length, n);
+
+    switch (stuff->data) {
+    case X_SELinuxQueryVersion:
+        return SProcSELinuxQueryVersion(client);
+    case X_SELinuxSetSelectionManager:
+        return SProcSELinuxSetSelectionManager(client);
+    default:
+	return BadRequest;
+    }
 }
 
 
@@ -839,6 +1084,7 @@ SELinuxResetProc(ExtensionEntry *extEntry)
     /* Unregister callbacks */
     DeleteCallback(&ClientStateCallback, SELinuxClientState, NULL);
     DeleteCallback(&ResourceStateCallback, SELinuxResourceState, NULL);
+    DeleteCallback(&SelectionCallback, SELinuxSelectionState, NULL);
 
     XaceDeleteCallback(XACE_EXT_DISPATCH, SELinuxExtension, NULL);
     XaceDeleteCallback(XACE_RESOURCE_ACCESS, SELinuxResource, NULL);
@@ -849,7 +1095,7 @@ SELinuxResetProc(ExtensionEntry *extEntry)
     XaceDeleteCallback(XACE_CLIENT_ACCESS, SELinuxClient, NULL);
     XaceDeleteCallback(XACE_EXT_ACCESS, SELinuxExtension, NULL);
     XaceDeleteCallback(XACE_SERVER_ACCESS, SELinuxServer, NULL);
-//    XaceDeleteCallback(XACE_SELECTION_ACCESS, SELinuxSelection, NULL);
+    XaceDeleteCallback(XACE_SELECTION_ACCESS, SELinuxSelection, NULL);
     XaceDeleteCallback(XACE_SCREEN_ACCESS, SELinuxScreen, NULL);
     XaceDeleteCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, truep);
 
@@ -863,6 +1109,10 @@ SELinuxResetProc(ExtensionEntry *extEntry)
     avc_active = 0;
 
     /* Free local state */
+    xfree(knownSelections);
+    knownSelections = NULL;
+    numKnownSelections = 0;
+
     xfree(knownEvents);
     knownEvents = NULL;
     numKnownEvents = 0;
@@ -929,6 +1179,7 @@ XSELinuxExtensionInit(INITARGS)
 
     ret &= AddCallback(&ClientStateCallback, SELinuxClientState, NULL);
     ret &= AddCallback(&ResourceStateCallback, SELinuxResourceState, NULL);
+    ret &= AddCallback(&SelectionCallback, SELinuxSelectionState, NULL);
 
     ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SELinuxExtension, NULL);
     ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SELinuxResource, NULL);
@@ -939,7 +1190,7 @@ XSELinuxExtensionInit(INITARGS)
     ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SELinuxClient, NULL);
     ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SELinuxExtension, NULL);
     ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SELinuxServer, NULL);
-//    ret &= XaceRegisterCallback(XACE_SELECTION_ACCESS, SELinuxSelection, NULL);
+    ret &= XaceRegisterCallback(XACE_SELECTION_ACCESS, SELinuxSelection, NULL);
     ret &= XaceRegisterCallback(XACE_SCREEN_ACCESS, SELinuxScreen, NULL);
     ret &= XaceRegisterCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, truep);
     if (!ret)
@@ -948,9 +1199,9 @@ XSELinuxExtensionInit(INITARGS)
     /* Add extension to server */
     extEntry = AddExtension(XSELINUX_EXTENSION_NAME,
 			    XSELinuxNumberEvents, XSELinuxNumberErrors,
-			    ProcSELinuxDispatch, ProcSELinuxDispatch,
+			    ProcSELinuxDispatch, SProcSELinuxDispatch,
 			    SELinuxResetProc, StandardMinorOpcode);
 
     /* Label objects that were created before we could register ourself */
-    SELinuxFixupLabels();
+    SELinuxLabelInitial();
 }
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index 407b81f..691154d 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -29,6 +29,43 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XSELinuxNumberEvents		0
 #define XSELinuxNumberErrors		0
 
+/* Extension protocol */
+#define X_SELinuxQueryVersion		0
+#define X_SELinuxSetSelectionManager	1
+
+typedef struct _SELinuxQueryVersion {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+    CARD8   client_major;
+    CARD8   client_minor;
+    CARD16  unused;
+} SELinuxQueryVersionReq;
+#define sz_SELinuxQueryVersionReq 8
+
+typedef struct {
+    CARD8   type;
+    CARD8   pad1;
+    CARD16  sequenceNumber;
+    CARD32  length;
+    CARD16  server_major;
+    CARD16  server_minor;
+    CARD32  pad2;
+    CARD32  pad3;
+    CARD32  pad4;
+    CARD32  pad5;
+    CARD32  pad6; 
+} SELinuxQueryVersionReply;
+#define sz_SELinuxQueryVersionReply  32
+
+typedef struct _SELinuxSetSelectionManager {
+    CARD8   reqType;
+    CARD8   SELinuxReqType;
+    CARD16  length;
+    CARD32  window;
+} SELinuxSetSelectionManagerReq;
+#define sz_SELinuxSetSelectionManagerReq 8
+
 /* Private Flask definitions */
 #define SECCLASS_X_DRAWABLE		1
 #define SECCLASS_X_SCREEN		2
commit 825f09dffd94cfcd0562a01c5181998503851461
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 23 17:12:57 2007 -0400

    xace: Still more changes to selection code.  Removed the SelectionPtr from
    the hook - the hook only needs the Atom to control access to the selection
    object.  Upgraded the SelectionCallback to take a client argument and
    additional type codes so that it can be used for redirection.

diff --git a/Xext/xace.c b/Xext/xace.c
index b126661..7b27ecd 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -177,7 +177,6 @@ int XaceHook(int hook, ...)
 	    XaceSelectionAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, Atom),
-		va_arg(ap, Selection*),
 		va_arg(ap, Mask),
 		Success /* default allow */
 	    };
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 1c61543..045f836 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -112,7 +112,6 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     Atom name;
-    Selection *selection;
     Mask access_mode;
     int status;
 } XaceSelectionAccessRec;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 2cfeb2d..814c2a8 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1005,6 +1005,11 @@ ProcSetSelectionOwner(ClientPtr client)
     {
 	int i = 0;
 
+	rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
+		      DixSetAttrAccess);
+	if (rc != Success)
+	    return rc;
+
 	/*
 	 * First, see if the selection is already set... 
 	 */
@@ -1022,12 +1027,6 @@ ProcSetSelectionOwner(ClientPtr client)
             if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
 		== EARLIER)
 		return Success;
-
-	    rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
-			  CurrentSelections + i, DixSetAttrAccess);
-	    if (rc != Success)
-		return rc;
-
 	    if (CurrentSelections[i].client &&
 		(!pWin || (CurrentSelections[i].client != client)))
 	    {
@@ -1058,10 +1057,6 @@ ProcSetSelectionOwner(ClientPtr client)
 	    CurrentSelections = newsels;
 	    CurrentSelections[i].selection = stuff->selection;
 	    CurrentSelections[i].devPrivates = NULL;
-	    rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
-			  CurrentSelections + i, DixSetAttrAccess);
-	    if (rc != Success)
-		return rc;
 	}
         CurrentSelections[i].lastTimeChanged = time;
 	CurrentSelections[i].window = stuff->window;
@@ -1072,6 +1067,7 @@ ProcSetSelectionOwner(ClientPtr client)
 	    SelectionInfoRec	info;
 
 	    info.selection = &CurrentSelections[i];
+	    info.client = client;
 	    info.kind= SelectionSetOwner;
 	    CallCallbacks(&SelectionCallback, &info);
 	}
@@ -1095,23 +1091,29 @@ ProcGetSelectionOwner(ClientPtr client)
 	int rc, i;
         xGetSelectionOwnerReply reply;
 
-	i = 0;
-        while ((i < NumCurrentSelections) && 
-	       CurrentSelections[i].selection != stuff->id) i++;
-
 	rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->id,
-		      CurrentSelections + i, DixGetAttrAccess);
+		      DixGetAttrAccess);
 	if (rc != Success)
 	    return rc;
 
+	i = 0;
+        while ((i < NumCurrentSelections) && 
+	       CurrentSelections[i].selection != stuff->id) i++;
         reply.type = X_Reply;
 	reply.length = 0;
 	reply.sequenceNumber = client->sequence;
-        if (i < NumCurrentSelections)
+	if (i < NumCurrentSelections) {
+	    if (SelectionCallback) {
+		SelectionInfoRec info;
+
+		info.selection = &CurrentSelections[i];
+		info.client = client;
+		info.kind= SelectionGetOwner;
+		CallCallbacks(&SelectionCallback, &info);
+	    }
             reply.owner = CurrentSelections[i].window;
-        else
+	} else
             reply.owner = None;
-
         WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
         return(client->noClientException);
     }
@@ -1135,6 +1137,10 @@ ProcConvertSelection(ClientPtr client)
     rc = dixLookupWindow(&pWin, stuff->requestor, client, DixSetAttrAccess);
     if (rc != Success)
         return rc;
+    rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
+		  DixReadAccess);
+    if (rc != Success)
+	return rc;
 
     paramsOkay = (ValidAtom(stuff->selection) && ValidAtom(stuff->target));
     if (stuff->property != None)
@@ -1146,11 +1152,15 @@ ProcConvertSelection(ClientPtr client)
 	i = 0;
 	while ((i < NumCurrentSelections) && 
 	       CurrentSelections[i].selection != stuff->selection) i++;
-	if ((i < NumCurrentSelections) &&
-	    (CurrentSelections[i].window != None) &&
-	    XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
-		     CurrentSelections + i, DixReadAccess) == Success)
-	{        
+	if (i < NumCurrentSelections && CurrentSelections[i].window != None) {
+	    if (SelectionCallback) {
+		SelectionInfoRec info;
+
+		info.selection = &CurrentSelections[i];
+		info.client = client;
+		info.kind= SelectionConvertSelection;
+		CallCallbacks(&SelectionCallback, &info);
+	    }
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
 	    event.u.selectionRequest.owner = CurrentSelections[i].window;
diff --git a/include/dix.h b/include/dix.h
index 09ed6d9..30fdc45 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -594,12 +594,15 @@ extern CallbackListPtr SelectionCallback;
 
 typedef enum {
     SelectionSetOwner,
+    SelectionGetOwner,
+    SelectionConvertSelection,
     SelectionWindowDestroy,
     SelectionClientClose
 } SelectionCallbackKind;
 
 typedef struct {
     struct _Selection	    *selection;
+    ClientPtr		    client;
     SelectionCallbackKind   kind;
 } SelectionInfoRec;
 
commit 660557593ea961948722298ea8ffba83891c9914
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 23 14:46:37 2007 -0400

    xselinux: Remove synthetic bit when looking up event type.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 183a047..ef5be57 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -133,10 +133,11 @@ static pointer truep = (pointer)1;
  * Looks up the SID corresponding to the given event type
  */
 static int
-SELinuxEventToSID(int type, SELinuxStateRec *sid_return)
+SELinuxEventToSID(unsigned type, SELinuxStateRec *sid_return)
 {
     const char *name = LookupEventName(type);
     security_context_t con;
+    type &= 127;
 
     if (type >= numKnownEvents) {
 	/* Need to increase size of classes array */
commit d7db549db41a27aef28cff9bfb7973bc741f88b2
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 23 14:08:54 2007 -0400

    xselinux: Unregister callbacks on server reset.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 14a2270..183a047 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -121,6 +121,9 @@ static struct security_class_mapping map[] = {
 /* forward declarations */
 static void SELinuxScreen(CallbackListPtr *, pointer, pointer);
 
+/* "true" pointer value for use as callback data */
+static pointer truep = (pointer)1;
+
 
 /*
  * Support Routines
@@ -832,8 +835,24 @@ ProcSELinuxDispatch(ClientPtr client)
 static void
 SELinuxResetProc(ExtensionEntry *extEntry)
 {
-    /* XXX unregister all callbacks here */
-
+    /* Unregister callbacks */
+    DeleteCallback(&ClientStateCallback, SELinuxClientState, NULL);
+    DeleteCallback(&ResourceStateCallback, SELinuxResourceState, NULL);
+
+    XaceDeleteCallback(XACE_EXT_DISPATCH, SELinuxExtension, NULL);
+    XaceDeleteCallback(XACE_RESOURCE_ACCESS, SELinuxResource, NULL);
+    XaceDeleteCallback(XACE_DEVICE_ACCESS, SELinuxDevice, NULL);
+    XaceDeleteCallback(XACE_PROPERTY_ACCESS, SELinuxProperty, NULL);
+    XaceDeleteCallback(XACE_SEND_ACCESS, SELinuxSend, NULL);
+    XaceDeleteCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, NULL);
+    XaceDeleteCallback(XACE_CLIENT_ACCESS, SELinuxClient, NULL);
+    XaceDeleteCallback(XACE_EXT_ACCESS, SELinuxExtension, NULL);
+    XaceDeleteCallback(XACE_SERVER_ACCESS, SELinuxServer, NULL);
+//    XaceDeleteCallback(XACE_SELECTION_ACCESS, SELinuxSelection, NULL);
+    XaceDeleteCallback(XACE_SCREEN_ACCESS, SELinuxScreen, NULL);
+    XaceDeleteCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, truep);
+
+    /* Tear down SELinux stuff */
     selabel_close(label_hnd);
     label_hnd = NULL;
 
@@ -842,6 +861,7 @@ SELinuxResetProc(ExtensionEntry *extEntry)
     avc_destroy();
     avc_active = 0;
 
+    /* Free local state */
     xfree(knownEvents);
     knownEvents = NULL;
     numKnownEvents = 0;
@@ -906,21 +926,21 @@ XSELinuxExtensionInit(INITARGS)
     ret &= dixRegisterPrivateInitFunc(stateKey, SELinuxStateInit, NULL);
     ret &= dixRegisterPrivateDeleteFunc(stateKey, SELinuxStateFree, NULL);
 
-    ret &= AddCallback(&ClientStateCallback, SELinuxClientState, 0);
-    ret &= AddCallback(&ResourceStateCallback, SELinuxResourceState, 0);
-
-    ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SELinuxExtension, 0);
-    ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SELinuxResource, 0);
-    ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SELinuxDevice, 0);
-    ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SELinuxProperty, 0);
-    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SELinuxSend, 0);
-    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, 0);
-    ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SELinuxClient, 0);
-    ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SELinuxExtension, 0);
-    ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SELinuxServer, 0);
-//    ret &= XaceRegisterCallback(XACE_SELECTION_ACCESS, SELinuxSelection, 0);
-    ret &= XaceRegisterCallback(XACE_SCREEN_ACCESS, SELinuxScreen, 0);
-    ret &= XaceRegisterCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, &ret);
+    ret &= AddCallback(&ClientStateCallback, SELinuxClientState, NULL);
+    ret &= AddCallback(&ResourceStateCallback, SELinuxResourceState, NULL);
+
+    ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SELinuxExtension, NULL);
+    ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SELinuxResource, NULL);
+    ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SELinuxDevice, NULL);
+    ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SELinuxProperty, NULL);
+    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SELinuxSend, NULL);
+    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, NULL);
+    ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SELinuxClient, NULL);
+    ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SELinuxExtension, NULL);
+    ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SELinuxServer, NULL);
+//    ret &= XaceRegisterCallback(XACE_SELECTION_ACCESS, SELinuxSelection, NULL);
+    ret &= XaceRegisterCallback(XACE_SCREEN_ACCESS, SELinuxScreen, NULL);
+    ret &= XaceRegisterCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, truep);
     if (!ret)
 	FatalError("XSELinux: Failed to register one or more callbacks\n");
 
commit 9e0a468af19d8e46330bcff37c9adc5e11d3aee7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 23 13:35:30 2007 -0400

    xace: try to pretend events were sent when a denial occurs.
    
    Probably need to redo the error return paths in these functions
    at some point.

diff --git a/dix/events.c b/dix/events.c
index 246220f..24de947 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1754,7 +1754,7 @@ DeliverEventsToWindow(WindowPtr pWin, xEvent *pEvents, int count,
 	    !((wOtherEventMasks(pWin)|pWin->eventMask) & filter))
 	    return 0;
 	if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count))
-	    nondeliveries--;
+	    /* do nothing */;
 	else if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count,
 					     pWin->eventMask, filter, grab)) )
 	{
@@ -1785,7 +1785,7 @@ DeliverEventsToWindow(WindowPtr pWin, xEvent *pEvents, int count,
 	{
 	    if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin, pEvents,
 			 count))
-		nondeliveries--;
+		/* do nothing */;
 	    else if ( (attempt = TryClientEvents(rClient(other), pEvents, count,
 					  other->mask[mskidx], filter, grab)) )
 	    {
@@ -1884,7 +1884,7 @@ MaybeDeliverEventsToClient(WindowPtr pWin, xEvent *pEvents,
 			wClient(pWin), NullGrab, pWin->eventMask, filter);
 #endif
 	if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count))
-	    return 0;
+	    return 1; /* don't send, but pretend we did */
 	return TryClientEvents(wClient(pWin), pEvents, count,
 			       pWin->eventMask, filter, NullGrab);
     }
@@ -1901,7 +1901,7 @@ MaybeDeliverEventsToClient(WindowPtr pWin, xEvent *pEvents,
 #endif
 	    if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin, pEvents,
 			 count))
-		return 0;
+		return 1; /* don't send, but pretend we did */
 	    return TryClientEvents(rClient(other), pEvents, count,
 				   other->mask, filter, NullGrab);
 	}
@@ -2896,9 +2896,9 @@ DeliverFocusedEvent(DeviceIntPtr keybd, xEvent *xE, WindowPtr window, int count)
 	if (DeliverDeviceEvents(window, xE, NullGrab, focus, keybd, count))
 	    return;
     }
-    /* just deliver it to the focus window */
     if (XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, xE, count))
 	return;
+    /* just deliver it to the focus window */
     FixUpEventFromWindow(xE, focus, None, FALSE);
     if (xE->u.u.type & EXTENSION_EVENT_BASE)
 	mskidx = keybd->id;
@@ -2947,9 +2947,11 @@ DeliverGrabbedEvent(xEvent *xE, DeviceIntPtr thisDev,
     if (!deliveries)
     {
 	FixUpEventFromWindow(xE, grab->window, None, TRUE);
-	if (!XaceHook(XACE_SEND_ACCESS, 0, thisDev, grab->window, xE, count) &&
-	    !XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), grab->window, xE,
-		      count))
+	if (XaceHook(XACE_SEND_ACCESS, 0, thisDev, grab->window, xE, count) ||
+	    XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), grab->window, xE,
+		     count))
+	    deliveries = 1; /* don't send, but pretend we did */
+	else
 	    deliveries = TryClientEvents(rClient(grab), xE, count,
 					 (Mask)grab->eventMask,
 					 filters[xE->u.u.type], grab);
commit ce7f6fe1268fef4f89aa21c7b44d73ecd98efe24
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Oct 19 19:40:04 2007 -0400

    xselinux: properly update sizes when dynamic arrays are resized...

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 8b1898d..14a2270 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -143,6 +143,7 @@ SELinuxEventToSID(int type, SELinuxStateRec *sid_return)
 	    return BadAlloc;
 	memset(knownEvents + numKnownEvents, 0,
 	       (type - numKnownEvents + 1) * size);
+	numKnownEvents = type + 1;
     }
 
     if (!knownEvents[type]) {
@@ -180,6 +181,7 @@ SELinuxTypeToClass(RESTYPE type)
 	    return 0;
 	memset(knownTypes + numKnownTypes, 0,
 	       (type - numKnownTypes + 1) * size);
+	numKnownTypes = type + 1;
     }
 
     if (!knownTypes[type]) {
commit 12e889d202ac9849f534c51167cbfed91c32027a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Oct 19 18:43:38 2007 -0400

    xace: Bug fixes, name changes to selection access hooks and fields.

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 50384db..2cfeb2d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1024,7 +1024,7 @@ ProcSetSelectionOwner(ClientPtr client)
 		return Success;
 
 	    rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
-			  CurrentSelections[i], DixSetAttrAccess);
+			  CurrentSelections + i, DixSetAttrAccess);
 	    if (rc != Success)
 		return rc;
 
@@ -1058,17 +1058,15 @@ ProcSetSelectionOwner(ClientPtr client)
 	    CurrentSelections = newsels;
 	    CurrentSelections[i].selection = stuff->selection;
 	    CurrentSelections[i].devPrivates = NULL;
-	    rc = XaceHook(XACE_SELECTION_ACCESS, stuff->selection,
-			  CurrentSelections[i], DixSetAttrAccess);
+	    rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
+			  CurrentSelections + i, DixSetAttrAccess);
 	    if (rc != Success)
 		return rc;
 	}
         CurrentSelections[i].lastTimeChanged = time;
 	CurrentSelections[i].window = stuff->window;
-	CurrentSelections[i].destwindow = stuff->window;
 	CurrentSelections[i].pWin = pWin;
 	CurrentSelections[i].client = (pWin ? client : NullClient);
-	CurrentSelections[i].destclient = (pWin ? client : NullClient);
 	if (SelectionCallback)
 	{
 	    SelectionInfoRec	info;
@@ -1100,19 +1098,20 @@ ProcGetSelectionOwner(ClientPtr client)
 	i = 0;
         while ((i < NumCurrentSelections) && 
 	       CurrentSelections[i].selection != stuff->id) i++;
+
+	rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->id,
+		      CurrentSelections + i, DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
+
         reply.type = X_Reply;
 	reply.length = 0;
 	reply.sequenceNumber = client->sequence;
         if (i < NumCurrentSelections)
-            reply.owner = CurrentSelections[i].destwindow;
+            reply.owner = CurrentSelections[i].window;
         else
             reply.owner = None;
 
-	rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->id, NULL,
-		      DixGetAttrAccess);
-	if (rc != Success)
-	    return rc;
-
         WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
         return(client->noClientException);
     }
@@ -1150,7 +1149,7 @@ ProcConvertSelection(ClientPtr client)
 	if ((i < NumCurrentSelections) &&
 	    (CurrentSelections[i].window != None) &&
 	    XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
-		     &CurrentSelections[i], DixReadAccess) == Success)
+		     CurrentSelections + i, DixReadAccess) == Success)
 	{        
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
@@ -1160,7 +1159,7 @@ ProcConvertSelection(ClientPtr client)
 	    event.u.selectionRequest.target = stuff->target;
 	    event.u.selectionRequest.property = stuff->property;
 	    if (TryClientEvents(
-		CurrentSelections[i].destclient, &event, 1, NoEventMask,
+		CurrentSelections[i].client, &event, 1, NoEventMask,
 		NoEventMask /* CantBeFiltered */, NullGrab))
 		return (client->noClientException);
 	}
diff --git a/include/selection.h b/include/selection.h
index 9347376..859b6a3 100644
--- a/include/selection.h
+++ b/include/selection.h
@@ -62,8 +62,8 @@ typedef struct _Selection {
     Window window;
     WindowPtr pWin;
     ClientPtr client;
-    ClientPtr destclient; /* support for redirection */
-    Window destwindow;    /* support for redirection */
+    ClientPtr alt_client; /* support for redirection */
+    Window alt_window;    /* support for redirection */
     PrivateRec *devPrivates;
 } Selection;
 
commit 55a96aa6b0995fda6660b7e78c85b955a62b9735
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 18 14:11:11 2007 -0400

    xselinux: add basic event labeling.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 2e36622..8b1898d 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -95,6 +95,10 @@ static security_id_t unlabeled_sid;
 static security_class_t *knownTypes;
 static unsigned numKnownTypes;
 
+/* Array of event SIDs indexed by event type */
+static security_id_t *knownEvents;
+static unsigned numKnownEvents;
+
 /* dynamically allocated security classes and permissions */
 static struct security_class_mapping map[] = {
     { "x_drawable", { "read", "write", "destroy", "create", "getattr", "setattr", "list_property", "get_property", "set_property", "", "", "list_child", "add_child", "remove_child", "hide", "show", "blend", "override", "", "", "", "", "send", "receive", "", "manage", NULL }},
@@ -109,6 +113,7 @@ static struct security_class_mapping map[] = {
     { "x_device", { "read", "write", "", "", "getattr", "setattr", "", "", "", "getfocus", "setfocus", "", "", "", "", "", "", "grab", "freeze", "force_cursor", "", "", "", "", "", "manage", "", "bell", NULL }},
     { "x_server", { "record", "", "", "", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "grab", "", "", "", "", "", "", "", "manage", "debug", NULL }},
     { "x_extension", { "", "", "", "", "query", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
+    { "x_event", { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "send", "receive", NULL }},
     { "x_resource", { "read", "write", "write", "write", "read", "write", "read", "read", "write", "read", "write", "read", "write", "write", "write", "read", "read", "write", "write", "write", "write", "write", "write", "read", "read", "write", "read", "write", NULL }},
     { NULL }
 };
@@ -122,6 +127,43 @@ static void SELinuxScreen(CallbackListPtr *, pointer, pointer);
  */
 
 /*
+ * Looks up the SID corresponding to the given event type
+ */
+static int
+SELinuxEventToSID(int type, SELinuxStateRec *sid_return)
+{
+    const char *name = LookupEventName(type);
+    security_context_t con;
+
+    if (type >= numKnownEvents) {
+	/* Need to increase size of classes array */
+	unsigned size = sizeof(security_id_t);
+	knownEvents = xrealloc(knownEvents, (type + 1) * size);
+	if (!knownEvents)
+	    return BadAlloc;
+	memset(knownEvents + numKnownEvents, 0,
+	       (type - numKnownEvents + 1) * size);
+    }
+
+    if (!knownEvents[type]) {
+	/* Look in the mappings of property names to contexts */
+	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EVENT) < 0) {
+	    ErrorF("XSELinux: an event label lookup failed!\n");
+	    return BadValue;
+	}
+	/* Get a SID for context */
+	if (avc_context_to_sid(con, knownEvents + type) < 0) {
+	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    return BadAlloc;
+	}
+	freecon(con);
+    }
+
+    sid_return->sid = knownEvents[type];
+    return Success;
+}
+
+/*
  * Returns the object class corresponding to the given resource type.
  */
 static security_class_t
@@ -325,7 +367,7 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     XaceSendAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
     SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
-    int clientIndex, rc;
+    int rc, i, clientIndex;
 
     if (rec->dev) {
 	subj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
@@ -337,10 +379,28 @@ SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
 
+    /* Check send permission on window */
     rc = SELinuxDoCheck(clientIndex, subj, obj, SECCLASS_X_DRAWABLE,
 			DixSendAccess, &auditdata);
     if (rc != Success)
-	rec->status = rc;
+	goto err;
+
+    /* Check send permission on specific event types */
+    for (i = 0; i < rec->count; i++) {
+	SELinuxStateRec ev_sid;
+
+	rc = SELinuxEventToSID(rec->events[i].u.u.type, &ev_sid);
+	if (rc != Success)
+	    goto err;
+
+	rc = SELinuxDoCheck(clientIndex, subj, &ev_sid, SECCLASS_X_EVENT,
+			    DixSendAccess, &auditdata);
+	if (rc != Success)
+	    goto err;
+    }
+    return;
+err:
+    rec->status = rc;
 }
 
 static void
@@ -349,15 +409,33 @@ SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     XaceReceiveAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
     SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
-    int rc;
+    int rc, i;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
     obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
 
+    /* Check receive permission on window */
     rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_DRAWABLE,
 			DixReceiveAccess, &auditdata);
     if (rc != Success)
-	rec->status = rc;
+	goto err;
+
+    /* Check receive permission on specific event types */
+    for (i = 0; i < rec->count; i++) {
+	SELinuxStateRec ev_sid;
+
+	rc = SELinuxEventToSID(rec->events[i].u.u.type, &ev_sid);
+	if (rc != Success)
+	    goto err;
+
+	rc = SELinuxDoCheck(rec->client->index, subj, &ev_sid, SECCLASS_X_EVENT,
+			    DixReceiveAccess, &auditdata);
+	if (rc != Success)
+	    goto err;
+    }
+    return;
+err:
+    rec->status = rc;
 }
 
 static void
@@ -762,6 +840,10 @@ SELinuxResetProc(ExtensionEntry *extEntry)
     avc_destroy();
     avc_active = 0;
 
+    xfree(knownEvents);
+    knownEvents = NULL;
+    numKnownEvents = 0;
+
     xfree(knownTypes);
     knownTypes = NULL;
     numKnownTypes = 0;
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index 02ec86b..407b81f 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -42,6 +42,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define SECCLASS_X_DEVICE		10
 #define SECCLASS_X_SERVER		11
 #define SECCLASS_X_EXTENSION		12
-#define SECCLASS_X_RESOURCE		13
+#define SECCLASS_X_EVENT		13
+#define SECCLASS_X_RESOURCE		14
 
 #endif /* _XSELINUX_H */
commit e974bc1233608ec09fbd40b12217925e4d2205aa
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 18 12:33:39 2007 -0400

    xselinux: add hooks for send and receive access.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 8bafa1f..2e36622 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -62,7 +62,7 @@ static DevPrivateKey stateKey = &stateKey;
 typedef struct {
     security_id_t sid;
     struct avc_entry_ref aeref;
-    char *client_path;
+    char *command;
 } SELinuxStateRec;
 
 /* audit file descriptor */
@@ -71,7 +71,7 @@ static int audit_fd;
 /* structure passed to auditing callback */
 typedef struct {
     ClientPtr client;	/* client */
-    char *client_path;	/* client's executable path */
+    char *command;	/* client's executable path */
     unsigned id;	/* resource id, if any */
     int restype;	/* resource type, if any */
     Atom property;	/* property name, if any */
@@ -170,21 +170,17 @@ SELinuxTypeToClass(RESTYPE type)
  * Performs an SELinux permission check.
  */
 static int
-SELinuxDoCheck(ClientPtr client, SELinuxStateRec *obj, security_class_t class,
-	       Mask access_mode, SELinuxAuditRec *auditdata)
+SELinuxDoCheck(int clientIndex, SELinuxStateRec *subj, SELinuxStateRec *obj,
+	       security_class_t class, Mask mode, SELinuxAuditRec *auditdata)
 {
-    SELinuxStateRec *subj;
-
     /* serverClient requests OK */
-    if (client->index == 0)
+    if (clientIndex == 0)
 	return Success;
 
-    subj = dixLookupPrivate(&client->devPrivates, stateKey);
-    auditdata->client = client;
-    auditdata->client_path = subj->client_path;
+    auditdata->command = subj->command;
     errno = 0;
 
-    if (avc_has_perm(subj->sid, obj->sid, class, access_mode, &subj->aeref,
+    if (avc_has_perm(subj->sid, obj->sid, class, mode, &subj->aeref,
 		     auditdata) < 0) {
 	if (errno == EACCES)
 	    return BadAccess;
@@ -250,23 +246,25 @@ SELinuxAudit(void *auditdata,
     SELinuxAuditRec *audit = auditdata;
     ClientPtr client = audit->client;
     char idNum[16], *propertyName;
-    int major = 0, minor = 0;
-    REQUEST(xReq);
+    int major = -1, minor = -1;
 
+    if (client) {
+	REQUEST(xReq);
+	if (stuff) {
+	    major = stuff->reqType;
+	    minor = MinorOpcodeOfRequest(client);
+	}
+    }
     if (audit->id)
 	snprintf(idNum, 16, "%x", audit->id);
-    if (stuff) {
-	major = stuff->reqType;
-	minor = (major < 128) ? 0 : MinorOpcodeOfRequest(client);
-    }
 
     propertyName = audit->property ? NameForAtom(audit->property) : NULL;
 
     return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s",
-		    stuff ? "request=" : "",
-		    stuff ? LookupRequestName(major, minor) : "",
-		    audit->client_path ? " comm=" : "",
-		    audit->client_path ? audit->client_path : "",
+		    (major >= 0) ? "request=" : "",
+		    (major >= 0) ? LookupRequestName(major, minor) : "",
+		    audit->command ? " comm=" : "",
+		    audit->command ? audit->command : "",
 		    audit->id ? " resid=" : "",
 		    audit->id ? idNum : "",
 		    audit->restype ? " restype=" : "",
@@ -296,7 +294,7 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceDeviceAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -315,18 +313,59 @@ SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	}
     }
 
-    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_DEVICE,
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_DEVICE,
 			rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
 
 static void
+SELinuxSend(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceSendAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    int clientIndex, rc;
+
+    if (rec->dev) {
+	subj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
+	clientIndex = -1; /* some nonzero value */
+    } else {
+	subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+	clientIndex = rec->client->index;
+    }
+
+    obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
+
+    rc = SELinuxDoCheck(clientIndex, subj, obj, SECCLASS_X_DRAWABLE,
+			DixSendAccess, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
+}
+
+static void
+SELinuxReceive(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceReceiveAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
+    int rc;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->pWin->devPrivates, stateKey);
+
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_DRAWABLE,
+			DixReceiveAccess, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
+}
+
+static void
 SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceExtAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj, *serv;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -369,7 +408,7 @@ SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     /* Perform the security check */
     auditdata.extension = rec->ext->name;
-    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_EXTENSION,
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_EXTENSION,
 			rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
@@ -380,7 +419,7 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XacePropertyAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     int rc;
 
     subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
@@ -421,7 +460,7 @@ SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
     /* Perform the security check */
     auditdata.property = rec->pProp->propertyName;
-    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_PROPERTY,
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_PROPERTY,
 			rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
@@ -432,7 +471,7 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceResourceAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj, *pobj;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     PrivateRec **privatePtr;
     security_class_t class;
     int rc, offset;
@@ -477,7 +516,8 @@ SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     /* Perform the security check */
     auditdata.restype = rec->rtype;
     auditdata.id = rec->id;
-    rc = SELinuxDoCheck(rec->client, obj, class, rec->access_mode, &auditdata);
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, class,
+			rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
 }
@@ -487,7 +527,7 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
 {
     XaceScreenAccessRec *rec = calldata;
     SELinuxStateRec *subj, *obj;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     Mask access_mode = rec->access_mode;
     int rc;
 
@@ -510,7 +550,7 @@ SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
     if (is_saver)
 	access_mode <<= 2;
 
-    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_SCREEN,
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_SCREEN,
 			access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
@@ -520,13 +560,14 @@ static void
 SELinuxClient(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceClientAccessRec *rec = calldata;
-    SELinuxStateRec *obj;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     int rc;
 
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
     obj = dixLookupPrivate(&rec->target->devPrivates, stateKey);
 
-    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_CLIENT,
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_CLIENT,
 			rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
@@ -536,13 +577,14 @@ static void
 SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceServerAccessRec *rec = calldata;
-    SELinuxStateRec *obj;
-    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { rec->client, NULL, 0, 0, 0, NULL };
     int rc;
 
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
     obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
 
-    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_SERVER,
+    rc = SELinuxDoCheck(rec->client->index, subj, obj, SECCLASS_X_SERVER,
 			rec->access_mode, &auditdata);
     if (rc != Success)
 	rec->status = rc;
@@ -595,12 +637,12 @@ SELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (bytes <= 0)
 	    goto finish;
 
-	state->client_path = xalloc(bytes);
-	if (!state->client_path)
+	state->command = xalloc(bytes);
+	if (!state->command)
 	    goto finish;
 
-	memcpy(state->client_path, path, bytes);
-	state->client_path[bytes - 1] = 0;
+	memcpy(state->command, path, bytes);
+	state->command[bytes - 1] = 0;
     } else
 	/* For remote clients, need to use a default context */
 	if (selabel_lookup(label_hnd, &ctx, NULL, SELABEL_X_CLIENT) < 0)
@@ -685,7 +727,7 @@ SELinuxStateFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     PrivateCallbackRec *rec = calldata;
     SELinuxStateRec *state = *rec->value;
 
-    xfree(state->client_path);
+    xfree(state->command);
 
     if (avc_active)
 	sidput(state->sid);
@@ -787,8 +829,8 @@ XSELinuxExtensionInit(INITARGS)
     ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SELinuxResource, 0);
     ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SELinuxDevice, 0);
     ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SELinuxProperty, 0);
-//    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SELinuxSend, 0);
-//    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, 0);
+    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SELinuxSend, 0);
+    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, 0);
     ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SELinuxClient, 0);
     ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SELinuxExtension, 0);
     ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SELinuxServer, 0);
commit 06eb830169afd0631a31e8846c7d2533c49ea378
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 18 12:31:14 2007 -0400

    xace: Fix bug in AddPassiveGrabToList(), was using wrong GrabPtr.

diff --git a/dix/grabs.c b/dix/grabs.c
index 2293296..a42a46f 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -325,9 +325,9 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab)
 	}
     }
 
-    if (grab->keyboardMode == GrabModeSync || grab->pointerMode == GrabModeSync)
+    if (pGrab->keyboardMode == GrabModeSync||pGrab->pointerMode == GrabModeSync)
 	access_mode |= DixFreezeAccess;
-    rc = XaceHook(XACE_DEVICE_ACCESS, client, grab->device, access_mode);
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, pGrab->device, access_mode);
     if (rc != Success)
 	return rc;
 
commit 6107a245035366fe762756b6aa05ac0e3a5482bb
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 18 12:24:55 2007 -0400

    dix: Add client parameter to AddPassiveGrabsToList().

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 9a17950..7a54c08 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -566,7 +566,7 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
 		      DeviceButtonPress, button, confineTo, cursor);
     if (!grab)
 	return BadAlloc;
-    return AddPassiveGrabToList(grab);
+    return AddPassiveGrabToList(client, grab);
 }
 
 int
@@ -621,7 +621,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
 		      NullWindow, NullCursor);
     if (!grab)
 	return BadAlloc;
-    return AddPassiveGrabToList(grab);
+    return AddPassiveGrabToList(client, grab);
 }
 
 int
diff --git a/dix/events.c b/dix/events.c
index bb5b950..246220f 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4727,7 +4727,7 @@ ProcGrabKey(ClientPtr client)
 	NullWindow, NullCursor);
     if (!grab)
 	return BadAlloc;
-    return AddPassiveGrabToList(grab);
+    return AddPassiveGrabToList(client, grab);
 }
 
 
@@ -4815,7 +4815,7 @@ ProcGrabButton(ClientPtr client)
         stuff->button, confineTo, cursor);
     if (!grab)
 	return BadAlloc;
-    return AddPassiveGrabToList(grab);
+    return AddPassiveGrabToList(client, grab);
 }
 
 /**
diff --git a/dix/grabs.c b/dix/grabs.c
index b8d0df8..2293296 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -307,7 +307,7 @@ GrabsAreIdentical(GrabPtr pFirstGrab, GrabPtr pSecondGrab)
  * @return Success or X error code on failure.
  */
 int
-AddPassiveGrabToList(GrabPtr pGrab)
+AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab)
 {
     GrabPtr grab;
     Mask access_mode = DixGrabAccess;
@@ -327,8 +327,7 @@ AddPassiveGrabToList(GrabPtr pGrab)
 
     if (grab->keyboardMode == GrabModeSync || grab->pointerMode == GrabModeSync)
 	access_mode |= DixFreezeAccess;
-    rc = XaceHook(XACE_DEVICE_ACCESS, clients[CLIENT_ID(grab->resource)],
-		  grab->device, access_mode);
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, grab->device, access_mode);
     if (rc != Success)
 	return rc;
 
diff --git a/include/dixgrabs.h b/include/dixgrabs.h
index 2d66d6b..f93e999 100644
--- a/include/dixgrabs.h
+++ b/include/dixgrabs.h
@@ -50,6 +50,7 @@ extern Bool GrabMatchesSecond(
 	GrabPtr /* pSecondGrab */);
 
 extern int AddPassiveGrabToList(
+	ClientPtr /* client */,
 	GrabPtr /* pGrab */);
 
 extern Bool DeletePassiveGrabFromList(
commit 31110d6837ee52fd654729d9e5c4b0c5395abab0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 18 10:30:44 2007 -0400

    registry: special case minor number when looking up core requests.

diff --git a/dix/registry.c b/dix/registry.c
index 48e1b5d..0181858 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -123,6 +123,8 @@ RegisterResourceName(RESTYPE resource, const char *name)
 const char *
 LookupRequestName(int major, int minor)
 {
+    if (major < 128)
+	minor = 0;
     if (major >= nmajor)
 	return XREGISTRY_UNKNOWN;
     if (minor >= nminor[major])
commit e3fd90ae9c3ddfc5d78e62614e311b73505d7ead
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 18 10:29:10 2007 -0400

    registry: Add "X11:" prefix to core protocol names.

diff --git a/dix/registry.c b/dix/registry.c
index 7b521b5..48e1b5d 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "registry.h"
 
 #define BASE_SIZE 16
+#define CORE "X11:"
 
 static const char ***requests, **events, **errors, **resources;
 static unsigned nmajor, *nminor, nevent, nerror, nresource;
@@ -195,181 +196,181 @@ dixResetRegistry(void)
     RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
 
     /* Add the core protocol */
-    RegisterRequestName(X_CreateWindow, 0, "CreateWindow");
-    RegisterRequestName(X_ChangeWindowAttributes, 0, "ChangeWindowAttributes");
-    RegisterRequestName(X_GetWindowAttributes, 0, "GetWindowAttributes");
-    RegisterRequestName(X_DestroyWindow, 0, "DestroyWindow");
-    RegisterRequestName(X_DestroySubwindows, 0, "DestroySubwindows");
-    RegisterRequestName(X_ChangeSaveSet, 0, "ChangeSaveSet");
-    RegisterRequestName(X_ReparentWindow, 0, "ReparentWindow");
-    RegisterRequestName(X_MapWindow, 0, "MapWindow");
-    RegisterRequestName(X_MapSubwindows, 0, "MapSubwindows");
-    RegisterRequestName(X_UnmapWindow, 0, "UnmapWindow");
-    RegisterRequestName(X_UnmapSubwindows, 0, "UnmapSubwindows");
-    RegisterRequestName(X_ConfigureWindow, 0, "ConfigureWindow");
-    RegisterRequestName(X_CirculateWindow, 0, "CirculateWindow");
-    RegisterRequestName(X_GetGeometry, 0, "GetGeometry");
-    RegisterRequestName(X_QueryTree, 0, "QueryTree");
-    RegisterRequestName(X_InternAtom, 0, "InternAtom");
-    RegisterRequestName(X_GetAtomName, 0, "GetAtomName");
-    RegisterRequestName(X_ChangeProperty, 0, "ChangeProperty");
-    RegisterRequestName(X_DeleteProperty, 0, "DeleteProperty");
-    RegisterRequestName(X_GetProperty, 0, "GetProperty");
-    RegisterRequestName(X_ListProperties, 0, "ListProperties");
-    RegisterRequestName(X_SetSelectionOwner, 0, "SetSelectionOwner");
-    RegisterRequestName(X_GetSelectionOwner, 0, "GetSelectionOwner");
-    RegisterRequestName(X_ConvertSelection, 0, "ConvertSelection");
-    RegisterRequestName(X_SendEvent, 0, "SendEvent");
-    RegisterRequestName(X_GrabPointer, 0, "GrabPointer");
-    RegisterRequestName(X_UngrabPointer, 0, "UngrabPointer");
-    RegisterRequestName(X_GrabButton, 0, "GrabButton");
-    RegisterRequestName(X_UngrabButton, 0, "UngrabButton");
-    RegisterRequestName(X_ChangeActivePointerGrab, 0, "ChangeActivePointerGrab");
-    RegisterRequestName(X_GrabKeyboard, 0, "GrabKeyboard");
-    RegisterRequestName(X_UngrabKeyboard, 0, "UngrabKeyboard");
-    RegisterRequestName(X_GrabKey, 0, "GrabKey");
-    RegisterRequestName(X_UngrabKey, 0, "UngrabKey");
-    RegisterRequestName(X_AllowEvents, 0, "AllowEvents");
-    RegisterRequestName(X_GrabServer, 0, "GrabServer");
-    RegisterRequestName(X_UngrabServer, 0, "UngrabServer");
-    RegisterRequestName(X_QueryPointer, 0, "QueryPointer");
-    RegisterRequestName(X_GetMotionEvents, 0, "GetMotionEvents");
-    RegisterRequestName(X_TranslateCoords, 0, "TranslateCoords");
-    RegisterRequestName(X_WarpPointer, 0, "WarpPointer");
-    RegisterRequestName(X_SetInputFocus, 0, "SetInputFocus");
-    RegisterRequestName(X_GetInputFocus, 0, "GetInputFocus");
-    RegisterRequestName(X_QueryKeymap, 0, "QueryKeymap");
-    RegisterRequestName(X_OpenFont, 0, "OpenFont");
-    RegisterRequestName(X_CloseFont, 0, "CloseFont");
-    RegisterRequestName(X_QueryFont, 0, "QueryFont");
-    RegisterRequestName(X_QueryTextExtents, 0, "QueryTextExtents");
-    RegisterRequestName(X_ListFonts, 0, "ListFonts");
-    RegisterRequestName(X_ListFontsWithInfo, 0, "ListFontsWithInfo");
-    RegisterRequestName(X_SetFontPath, 0, "SetFontPath");
-    RegisterRequestName(X_GetFontPath, 0, "GetFontPath");
-    RegisterRequestName(X_CreatePixmap, 0, "CreatePixmap");
-    RegisterRequestName(X_FreePixmap, 0, "FreePixmap");
-    RegisterRequestName(X_CreateGC, 0, "CreateGC");
-    RegisterRequestName(X_ChangeGC, 0, "ChangeGC");
-    RegisterRequestName(X_CopyGC, 0, "CopyGC");
-    RegisterRequestName(X_SetDashes, 0, "SetDashes");
-    RegisterRequestName(X_SetClipRectangles, 0, "SetClipRectangles");
-    RegisterRequestName(X_FreeGC, 0, "FreeGC");
-    RegisterRequestName(X_ClearArea, 0, "ClearArea");
-    RegisterRequestName(X_CopyArea, 0, "CopyArea");
-    RegisterRequestName(X_CopyPlane, 0, "CopyPlane");
-    RegisterRequestName(X_PolyPoint, 0, "PolyPoint");
-    RegisterRequestName(X_PolyLine, 0, "PolyLine");
-    RegisterRequestName(X_PolySegment, 0, "PolySegment");
-    RegisterRequestName(X_PolyRectangle, 0, "PolyRectangle");
-    RegisterRequestName(X_PolyArc, 0, "PolyArc");
-    RegisterRequestName(X_FillPoly, 0, "FillPoly");
-    RegisterRequestName(X_PolyFillRectangle, 0, "PolyFillRectangle");
-    RegisterRequestName(X_PolyFillArc, 0, "PolyFillArc");
-    RegisterRequestName(X_PutImage, 0, "PutImage");
-    RegisterRequestName(X_GetImage, 0, "GetImage");
-    RegisterRequestName(X_PolyText8, 0, "PolyText8");
-    RegisterRequestName(X_PolyText16, 0, "PolyText16");
-    RegisterRequestName(X_ImageText8, 0, "ImageText8");
-    RegisterRequestName(X_ImageText16, 0, "ImageText16");
-    RegisterRequestName(X_CreateColormap, 0, "CreateColormap");
-    RegisterRequestName(X_FreeColormap, 0, "FreeColormap");
-    RegisterRequestName(X_CopyColormapAndFree, 0, "CopyColormapAndFree");
-    RegisterRequestName(X_InstallColormap, 0, "InstallColormap");
-    RegisterRequestName(X_UninstallColormap, 0, "UninstallColormap");
-    RegisterRequestName(X_ListInstalledColormaps, 0, "ListInstalledColormaps");
-    RegisterRequestName(X_AllocColor, 0, "AllocColor");
-    RegisterRequestName(X_AllocNamedColor, 0, "AllocNamedColor");
-    RegisterRequestName(X_AllocColorCells, 0, "AllocColorCells");
-    RegisterRequestName(X_AllocColorPlanes, 0, "AllocColorPlanes");
-    RegisterRequestName(X_FreeColors, 0, "FreeColors");
-    RegisterRequestName(X_StoreColors, 0, "StoreColors");
-    RegisterRequestName(X_StoreNamedColor, 0, "StoreNamedColor");
-    RegisterRequestName(X_QueryColors, 0, "QueryColors");
-    RegisterRequestName(X_LookupColor, 0, "LookupColor");
-    RegisterRequestName(X_CreateCursor, 0, "CreateCursor");
-    RegisterRequestName(X_CreateGlyphCursor, 0, "CreateGlyphCursor");
-    RegisterRequestName(X_FreeCursor, 0, "FreeCursor");
-    RegisterRequestName(X_RecolorCursor, 0, "RecolorCursor");
-    RegisterRequestName(X_QueryBestSize, 0, "QueryBestSize");
-    RegisterRequestName(X_QueryExtension, 0, "QueryExtension");
-    RegisterRequestName(X_ListExtensions, 0, "ListExtensions");
-    RegisterRequestName(X_ChangeKeyboardMapping, 0, "ChangeKeyboardMapping");
-    RegisterRequestName(X_GetKeyboardMapping, 0, "GetKeyboardMapping");
-    RegisterRequestName(X_ChangeKeyboardControl, 0, "ChangeKeyboardControl");
-    RegisterRequestName(X_GetKeyboardControl, 0, "GetKeyboardControl");
-    RegisterRequestName(X_Bell, 0, "Bell");
-    RegisterRequestName(X_ChangePointerControl, 0, "ChangePointerControl");
-    RegisterRequestName(X_GetPointerControl, 0, "GetPointerControl");
-    RegisterRequestName(X_SetScreenSaver, 0, "SetScreenSaver");
-    RegisterRequestName(X_GetScreenSaver, 0, "GetScreenSaver");
-    RegisterRequestName(X_ChangeHosts, 0, "ChangeHosts");
-    RegisterRequestName(X_ListHosts, 0, "ListHosts");
-    RegisterRequestName(X_SetAccessControl, 0, "SetAccessControl");
-    RegisterRequestName(X_SetCloseDownMode, 0, "SetCloseDownMode");
-    RegisterRequestName(X_KillClient, 0, "KillClient");
-    RegisterRequestName(X_RotateProperties, 0, "RotateProperties");
-    RegisterRequestName(X_ForceScreenSaver, 0, "ForceScreenSaver");
-    RegisterRequestName(X_SetPointerMapping, 0, "SetPointerMapping");
-    RegisterRequestName(X_GetPointerMapping, 0, "GetPointerMapping");
-    RegisterRequestName(X_SetModifierMapping, 0, "SetModifierMapping");
-    RegisterRequestName(X_GetModifierMapping, 0, "GetModifierMapping");
-    RegisterRequestName(X_NoOperation, 0, "NoOperation");
-
-    RegisterErrorName(Success, "Success");
-    RegisterErrorName(BadRequest, "BadRequest");
-    RegisterErrorName(BadValue, "BadValue");
-    RegisterErrorName(BadWindow, "BadWindow");
-    RegisterErrorName(BadPixmap, "BadPixmap");
-    RegisterErrorName(BadAtom, "BadAtom");
-    RegisterErrorName(BadCursor, "BadCursor");
-    RegisterErrorName(BadFont, "BadFont");
-    RegisterErrorName(BadMatch, "BadMatch");
-    RegisterErrorName(BadDrawable, "BadDrawable");
-    RegisterErrorName(BadAccess, "BadAccess");
-    RegisterErrorName(BadAlloc, "BadAlloc");
-    RegisterErrorName(BadColor, "BadColor");
-    RegisterErrorName(BadGC, "BadGC");
-    RegisterErrorName(BadIDChoice, "BadIDChoice");
-    RegisterErrorName(BadName, "BadName");
-    RegisterErrorName(BadLength, "BadLength");
-    RegisterErrorName(BadImplementation, "BadImplementation");
-
-    RegisterEventName(X_Error, "Error");
-    RegisterEventName(X_Reply, "Reply");
-    RegisterEventName(KeyPress, "KeyPress");
-    RegisterEventName(KeyRelease, "KeyRelease");
-    RegisterEventName(ButtonPress, "ButtonPress");
-    RegisterEventName(ButtonRelease, "ButtonRelease");
-    RegisterEventName(MotionNotify, "MotionNotify");
-    RegisterEventName(EnterNotify, "EnterNotify");
-    RegisterEventName(LeaveNotify, "LeaveNotify");
-    RegisterEventName(FocusIn, "FocusIn");
-    RegisterEventName(FocusOut, "FocusOut");
-    RegisterEventName(KeymapNotify, "KeymapNotify");
-    RegisterEventName(Expose, "Expose");
-    RegisterEventName(GraphicsExpose, "GraphicsExpose");
-    RegisterEventName(NoExpose, "NoExpose");
-    RegisterEventName(VisibilityNotify, "VisibilityNotify");
-    RegisterEventName(CreateNotify, "CreateNotify");
-    RegisterEventName(DestroyNotify, "DestroyNotify");
-    RegisterEventName(UnmapNotify, "UnmapNotify");
-    RegisterEventName(MapNotify, "MapNotify");
-    RegisterEventName(MapRequest, "MapRequest");
-    RegisterEventName(ReparentNotify, "ReparentNotify");
-    RegisterEventName(ConfigureNotify, "ConfigureNotify");
-    RegisterEventName(ConfigureRequest, "ConfigureRequest");
-    RegisterEventName(GravityNotify, "GravityNotify");
-    RegisterEventName(ResizeRequest, "ResizeRequest");
-    RegisterEventName(CirculateNotify, "CirculateNotify");
-    RegisterEventName(CirculateRequest, "CirculateRequest");
-    RegisterEventName(PropertyNotify, "PropertyNotify");
-    RegisterEventName(SelectionClear, "SelectionClear");
-    RegisterEventName(SelectionRequest, "SelectionRequest");
-    RegisterEventName(SelectionNotify, "SelectionNotify");
-    RegisterEventName(ColormapNotify, "ColormapNotify");
-    RegisterEventName(ClientMessage, "ClientMessage");
-    RegisterEventName(MappingNotify, "MappingNotify");
+    RegisterRequestName(X_CreateWindow, 0, CORE "CreateWindow");
+    RegisterRequestName(X_ChangeWindowAttributes, 0, CORE "ChangeWindowAttributes");
+    RegisterRequestName(X_GetWindowAttributes, 0, CORE "GetWindowAttributes");
+    RegisterRequestName(X_DestroyWindow, 0, CORE "DestroyWindow");
+    RegisterRequestName(X_DestroySubwindows, 0, CORE "DestroySubwindows");
+    RegisterRequestName(X_ChangeSaveSet, 0, CORE "ChangeSaveSet");
+    RegisterRequestName(X_ReparentWindow, 0, CORE "ReparentWindow");
+    RegisterRequestName(X_MapWindow, 0, CORE "MapWindow");
+    RegisterRequestName(X_MapSubwindows, 0, CORE "MapSubwindows");
+    RegisterRequestName(X_UnmapWindow, 0, CORE "UnmapWindow");
+    RegisterRequestName(X_UnmapSubwindows, 0, CORE "UnmapSubwindows");
+    RegisterRequestName(X_ConfigureWindow, 0, CORE "ConfigureWindow");
+    RegisterRequestName(X_CirculateWindow, 0, CORE "CirculateWindow");
+    RegisterRequestName(X_GetGeometry, 0, CORE "GetGeometry");
+    RegisterRequestName(X_QueryTree, 0, CORE "QueryTree");
+    RegisterRequestName(X_InternAtom, 0, CORE "InternAtom");
+    RegisterRequestName(X_GetAtomName, 0, CORE "GetAtomName");
+    RegisterRequestName(X_ChangeProperty, 0, CORE "ChangeProperty");
+    RegisterRequestName(X_DeleteProperty, 0, CORE "DeleteProperty");
+    RegisterRequestName(X_GetProperty, 0, CORE "GetProperty");
+    RegisterRequestName(X_ListProperties, 0, CORE "ListProperties");
+    RegisterRequestName(X_SetSelectionOwner, 0, CORE "SetSelectionOwner");
+    RegisterRequestName(X_GetSelectionOwner, 0, CORE "GetSelectionOwner");
+    RegisterRequestName(X_ConvertSelection, 0, CORE "ConvertSelection");
+    RegisterRequestName(X_SendEvent, 0, CORE "SendEvent");
+    RegisterRequestName(X_GrabPointer, 0, CORE "GrabPointer");
+    RegisterRequestName(X_UngrabPointer, 0, CORE "UngrabPointer");
+    RegisterRequestName(X_GrabButton, 0, CORE "GrabButton");
+    RegisterRequestName(X_UngrabButton, 0, CORE "UngrabButton");
+    RegisterRequestName(X_ChangeActivePointerGrab, 0, CORE "ChangeActivePointerGrab");
+    RegisterRequestName(X_GrabKeyboard, 0, CORE "GrabKeyboard");
+    RegisterRequestName(X_UngrabKeyboard, 0, CORE "UngrabKeyboard");
+    RegisterRequestName(X_GrabKey, 0, CORE "GrabKey");
+    RegisterRequestName(X_UngrabKey, 0, CORE "UngrabKey");
+    RegisterRequestName(X_AllowEvents, 0, CORE "AllowEvents");
+    RegisterRequestName(X_GrabServer, 0, CORE "GrabServer");
+    RegisterRequestName(X_UngrabServer, 0, CORE "UngrabServer");
+    RegisterRequestName(X_QueryPointer, 0, CORE "QueryPointer");
+    RegisterRequestName(X_GetMotionEvents, 0, CORE "GetMotionEvents");
+    RegisterRequestName(X_TranslateCoords, 0, CORE "TranslateCoords");
+    RegisterRequestName(X_WarpPointer, 0, CORE "WarpPointer");
+    RegisterRequestName(X_SetInputFocus, 0, CORE "SetInputFocus");
+    RegisterRequestName(X_GetInputFocus, 0, CORE "GetInputFocus");
+    RegisterRequestName(X_QueryKeymap, 0, CORE "QueryKeymap");
+    RegisterRequestName(X_OpenFont, 0, CORE "OpenFont");
+    RegisterRequestName(X_CloseFont, 0, CORE "CloseFont");
+    RegisterRequestName(X_QueryFont, 0, CORE "QueryFont");
+    RegisterRequestName(X_QueryTextExtents, 0, CORE "QueryTextExtents");
+    RegisterRequestName(X_ListFonts, 0, CORE "ListFonts");
+    RegisterRequestName(X_ListFontsWithInfo, 0, CORE "ListFontsWithInfo");
+    RegisterRequestName(X_SetFontPath, 0, CORE "SetFontPath");
+    RegisterRequestName(X_GetFontPath, 0, CORE "GetFontPath");
+    RegisterRequestName(X_CreatePixmap, 0, CORE "CreatePixmap");
+    RegisterRequestName(X_FreePixmap, 0, CORE "FreePixmap");
+    RegisterRequestName(X_CreateGC, 0, CORE "CreateGC");
+    RegisterRequestName(X_ChangeGC, 0, CORE "ChangeGC");
+    RegisterRequestName(X_CopyGC, 0, CORE "CopyGC");
+    RegisterRequestName(X_SetDashes, 0, CORE "SetDashes");
+    RegisterRequestName(X_SetClipRectangles, 0, CORE "SetClipRectangles");
+    RegisterRequestName(X_FreeGC, 0, CORE "FreeGC");
+    RegisterRequestName(X_ClearArea, 0, CORE "ClearArea");
+    RegisterRequestName(X_CopyArea, 0, CORE "CopyArea");
+    RegisterRequestName(X_CopyPlane, 0, CORE "CopyPlane");
+    RegisterRequestName(X_PolyPoint, 0, CORE "PolyPoint");
+    RegisterRequestName(X_PolyLine, 0, CORE "PolyLine");
+    RegisterRequestName(X_PolySegment, 0, CORE "PolySegment");
+    RegisterRequestName(X_PolyRectangle, 0, CORE "PolyRectangle");
+    RegisterRequestName(X_PolyArc, 0, CORE "PolyArc");
+    RegisterRequestName(X_FillPoly, 0, CORE "FillPoly");
+    RegisterRequestName(X_PolyFillRectangle, 0, CORE "PolyFillRectangle");
+    RegisterRequestName(X_PolyFillArc, 0, CORE "PolyFillArc");
+    RegisterRequestName(X_PutImage, 0, CORE "PutImage");
+    RegisterRequestName(X_GetImage, 0, CORE "GetImage");
+    RegisterRequestName(X_PolyText8, 0, CORE "PolyText8");
+    RegisterRequestName(X_PolyText16, 0, CORE "PolyText16");
+    RegisterRequestName(X_ImageText8, 0, CORE "ImageText8");
+    RegisterRequestName(X_ImageText16, 0, CORE "ImageText16");
+    RegisterRequestName(X_CreateColormap, 0, CORE "CreateColormap");
+    RegisterRequestName(X_FreeColormap, 0, CORE "FreeColormap");
+    RegisterRequestName(X_CopyColormapAndFree, 0, CORE "CopyColormapAndFree");
+    RegisterRequestName(X_InstallColormap, 0, CORE "InstallColormap");
+    RegisterRequestName(X_UninstallColormap, 0, CORE "UninstallColormap");
+    RegisterRequestName(X_ListInstalledColormaps, 0, CORE "ListInstalledColormaps");
+    RegisterRequestName(X_AllocColor, 0, CORE "AllocColor");
+    RegisterRequestName(X_AllocNamedColor, 0, CORE "AllocNamedColor");
+    RegisterRequestName(X_AllocColorCells, 0, CORE "AllocColorCells");
+    RegisterRequestName(X_AllocColorPlanes, 0, CORE "AllocColorPlanes");
+    RegisterRequestName(X_FreeColors, 0, CORE "FreeColors");
+    RegisterRequestName(X_StoreColors, 0, CORE "StoreColors");
+    RegisterRequestName(X_StoreNamedColor, 0, CORE "StoreNamedColor");
+    RegisterRequestName(X_QueryColors, 0, CORE "QueryColors");
+    RegisterRequestName(X_LookupColor, 0, CORE "LookupColor");
+    RegisterRequestName(X_CreateCursor, 0, CORE "CreateCursor");
+    RegisterRequestName(X_CreateGlyphCursor, 0, CORE "CreateGlyphCursor");
+    RegisterRequestName(X_FreeCursor, 0, CORE "FreeCursor");
+    RegisterRequestName(X_RecolorCursor, 0, CORE "RecolorCursor");
+    RegisterRequestName(X_QueryBestSize, 0, CORE "QueryBestSize");
+    RegisterRequestName(X_QueryExtension, 0, CORE "QueryExtension");
+    RegisterRequestName(X_ListExtensions, 0, CORE "ListExtensions");
+    RegisterRequestName(X_ChangeKeyboardMapping, 0, CORE "ChangeKeyboardMapping");
+    RegisterRequestName(X_GetKeyboardMapping, 0, CORE "GetKeyboardMapping");
+    RegisterRequestName(X_ChangeKeyboardControl, 0, CORE "ChangeKeyboardControl");
+    RegisterRequestName(X_GetKeyboardControl, 0, CORE "GetKeyboardControl");
+    RegisterRequestName(X_Bell, 0, CORE "Bell");
+    RegisterRequestName(X_ChangePointerControl, 0, CORE "ChangePointerControl");
+    RegisterRequestName(X_GetPointerControl, 0, CORE "GetPointerControl");
+    RegisterRequestName(X_SetScreenSaver, 0, CORE "SetScreenSaver");
+    RegisterRequestName(X_GetScreenSaver, 0, CORE "GetScreenSaver");
+    RegisterRequestName(X_ChangeHosts, 0, CORE "ChangeHosts");
+    RegisterRequestName(X_ListHosts, 0, CORE "ListHosts");
+    RegisterRequestName(X_SetAccessControl, 0, CORE "SetAccessControl");
+    RegisterRequestName(X_SetCloseDownMode, 0, CORE "SetCloseDownMode");
+    RegisterRequestName(X_KillClient, 0, CORE "KillClient");
+    RegisterRequestName(X_RotateProperties, 0, CORE "RotateProperties");
+    RegisterRequestName(X_ForceScreenSaver, 0, CORE "ForceScreenSaver");
+    RegisterRequestName(X_SetPointerMapping, 0, CORE "SetPointerMapping");
+    RegisterRequestName(X_GetPointerMapping, 0, CORE "GetPointerMapping");
+    RegisterRequestName(X_SetModifierMapping, 0, CORE "SetModifierMapping");
+    RegisterRequestName(X_GetModifierMapping, 0, CORE "GetModifierMapping");
+    RegisterRequestName(X_NoOperation, 0, CORE "NoOperation");
+
+    RegisterErrorName(Success, CORE "Success");
+    RegisterErrorName(BadRequest, CORE "BadRequest");
+    RegisterErrorName(BadValue, CORE "BadValue");
+    RegisterErrorName(BadWindow, CORE "BadWindow");
+    RegisterErrorName(BadPixmap, CORE "BadPixmap");
+    RegisterErrorName(BadAtom, CORE "BadAtom");
+    RegisterErrorName(BadCursor, CORE "BadCursor");
+    RegisterErrorName(BadFont, CORE "BadFont");
+    RegisterErrorName(BadMatch, CORE "BadMatch");
+    RegisterErrorName(BadDrawable, CORE "BadDrawable");
+    RegisterErrorName(BadAccess, CORE "BadAccess");
+    RegisterErrorName(BadAlloc, CORE "BadAlloc");
+    RegisterErrorName(BadColor, CORE "BadColor");
+    RegisterErrorName(BadGC, CORE "BadGC");
+    RegisterErrorName(BadIDChoice, CORE "BadIDChoice");
+    RegisterErrorName(BadName, CORE "BadName");
+    RegisterErrorName(BadLength, CORE "BadLength");
+    RegisterErrorName(BadImplementation, CORE "BadImplementation");
+
+    RegisterEventName(X_Error, CORE "Error");
+    RegisterEventName(X_Reply, CORE "Reply");
+    RegisterEventName(KeyPress, CORE "KeyPress");
+    RegisterEventName(KeyRelease, CORE "KeyRelease");
+    RegisterEventName(ButtonPress, CORE "ButtonPress");
+    RegisterEventName(ButtonRelease, CORE "ButtonRelease");
+    RegisterEventName(MotionNotify, CORE "MotionNotify");
+    RegisterEventName(EnterNotify, CORE "EnterNotify");
+    RegisterEventName(LeaveNotify, CORE "LeaveNotify");
+    RegisterEventName(FocusIn, CORE "FocusIn");
+    RegisterEventName(FocusOut, CORE "FocusOut");
+    RegisterEventName(KeymapNotify, CORE "KeymapNotify");
+    RegisterEventName(Expose, CORE "Expose");
+    RegisterEventName(GraphicsExpose, CORE "GraphicsExpose");
+    RegisterEventName(NoExpose, CORE "NoExpose");
+    RegisterEventName(VisibilityNotify, CORE "VisibilityNotify");
+    RegisterEventName(CreateNotify, CORE "CreateNotify");
+    RegisterEventName(DestroyNotify, CORE "DestroyNotify");
+    RegisterEventName(UnmapNotify, CORE "UnmapNotify");
+    RegisterEventName(MapNotify, CORE "MapNotify");
+    RegisterEventName(MapRequest, CORE "MapRequest");
+    RegisterEventName(ReparentNotify, CORE "ReparentNotify");
+    RegisterEventName(ConfigureNotify, CORE "ConfigureNotify");
+    RegisterEventName(ConfigureRequest, CORE "ConfigureRequest");
+    RegisterEventName(GravityNotify, CORE "GravityNotify");
+    RegisterEventName(ResizeRequest, CORE "ResizeRequest");
+    RegisterEventName(CirculateNotify, CORE "CirculateNotify");
+    RegisterEventName(CirculateRequest, CORE "CirculateRequest");
+    RegisterEventName(PropertyNotify, CORE "PropertyNotify");
+    RegisterEventName(SelectionClear, CORE "SelectionClear");
+    RegisterEventName(SelectionRequest, CORE "SelectionRequest");
+    RegisterEventName(SelectionNotify, CORE "SelectionNotify");
+    RegisterEventName(ColormapNotify, CORE "ColormapNotify");
+    RegisterEventName(ClientMessage, CORE "ClientMessage");
+    RegisterEventName(MappingNotify, CORE "MappingNotify");
 }
 
 #endif /* XREGISTRY */
commit aa340b2c7cbe9ddab53cff08c8ba165558209187
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 19:27:16 2007 -0400

    xselinux: add hook for device acceses.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index fc91ae3..8bafa1f 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -292,6 +292,36 @@ SELinuxLog(int type, const char *fmt, ...)
  */
 
 static void
+SELinuxDevice(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+{
+    XaceDeviceAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    int rc;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->dev->devPrivates, stateKey);
+
+    /* If this is a new object that needs labeling, do it now */
+    if (rec->access_mode & DixCreateAccess) {
+	sidput(obj->sid);
+
+	/* Perform a transition to obtain the final SID */
+	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_DEVICE,
+			       &obj->sid) < 0) {
+	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    rec->status = BadValue;
+	    return;
+	}
+    }
+
+    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_DEVICE,
+			rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
+}
+
+static void
 SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceExtAccessRec *rec = calldata;
@@ -755,7 +785,7 @@ XSELinuxExtensionInit(INITARGS)
 
     ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SELinuxExtension, 0);
     ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SELinuxResource, 0);
-//    ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SELinuxDevice, 0);
+    ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SELinuxDevice, 0);
     ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SELinuxProperty, 0);
 //    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SELinuxSend, 0);
 //    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, 0);
commit 503f918f55d0cb29585d83b022bbb8dc29f446c5
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 19:14:15 2007 -0400

    xselinux: Move functions around; add some more comments.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 9ff0554..fc91ae3 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -50,6 +50,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <stdarg.h>
 #include "modinit.h"
 
+
+/*
+ * Globals
+ */
+
 /* private state record */
 static DevPrivateKey stateKey = &stateKey;
 
@@ -108,6 +113,14 @@ static struct security_class_mapping map[] = {
     { NULL }
 };
 
+/* forward declarations */
+static void SELinuxScreen(CallbackListPtr *, pointer, pointer);
+
+
+/*
+ * Support Routines
+ */
+
 /*
  * Returns the object class corresponding to the given resource type.
  */
@@ -150,7 +163,6 @@ SELinuxTypeToClass(RESTYPE type)
 	    knownTypes[type] = SECCLASS_X_FONT;
     }
 
-//    ErrorF("Returning a class of %d for a type of %d\n", knownTypes[type], type);
     return knownTypes[type];
 }
 
@@ -163,8 +175,6 @@ SELinuxDoCheck(ClientPtr client, SELinuxStateRec *obj, security_class_t class,
 {
     SELinuxStateRec *subj;
 
-//    ErrorF("SuperCheck: client=%d, class=%d, access_mode=%x\n", client->index, class, access_mode);
-
     /* serverClient requests OK */
     if (client->index == 0)
 	return Success;
@@ -185,11 +195,101 @@ SELinuxDoCheck(ClientPtr client, SELinuxStateRec *obj, security_class_t class,
     return Success;
 }
 
-//static void
-//SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-//{
-//    XaceSelectionAccessRec *rec = calldata;
-//}
+/*
+ * Labels initial server objects.
+ */
+static void
+SELinuxFixupLabels(void)
+{
+    int i;
+    XaceScreenAccessRec srec;
+    SELinuxStateRec *state;
+    security_context_t ctx;
+    pointer unused;
+
+    /* Do the serverClient */
+    state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+    sidput(state->sid);
+
+    /* Use the context of the X server process for the serverClient */
+    if (getcon(&ctx) < 0)
+	FatalError("Couldn't get context of X server process\n");
+
+    /* Get a SID from the context */
+    if (avc_context_to_sid(ctx, &state->sid) < 0)
+	FatalError("serverClient: context_to_sid(%s) failed\n", ctx);
+
+    freecon(ctx);
+
+    srec.client = serverClient;
+    srec.access_mode = DixCreateAccess;
+    srec.status = Success;
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	/* Do the screen object */
+	srec.screen = screenInfo.screens[i];
+	SELinuxScreen(NULL, NULL, &srec);
+
+	/* Do the default colormap */
+	dixLookupResource(&unused, screenInfo.screens[i]->defColormap,
+			  RT_COLORMAP, serverClient, DixCreateAccess);
+    }
+}
+
+
+/*
+ * Libselinux Callbacks
+ */
+
+static int
+SELinuxAudit(void *auditdata,
+	     security_class_t class,
+	     char *msgbuf,
+	     size_t msgbufsize)
+{
+    SELinuxAuditRec *audit = auditdata;
+    ClientPtr client = audit->client;
+    char idNum[16], *propertyName;
+    int major = 0, minor = 0;
+    REQUEST(xReq);
+
+    if (audit->id)
+	snprintf(idNum, 16, "%x", audit->id);
+    if (stuff) {
+	major = stuff->reqType;
+	minor = (major < 128) ? 0 : MinorOpcodeOfRequest(client);
+    }
+
+    propertyName = audit->property ? NameForAtom(audit->property) : NULL;
+
+    return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s",
+		    stuff ? "request=" : "",
+		    stuff ? LookupRequestName(major, minor) : "",
+		    audit->client_path ? " comm=" : "",
+		    audit->client_path ? audit->client_path : "",
+		    audit->id ? " resid=" : "",
+		    audit->id ? idNum : "",
+		    audit->restype ? " restype=" : "",
+		    audit->restype ? LookupResourceName(audit->restype) : "",
+		    audit->property ? " property=" : "",
+		    audit->property ? propertyName : "",
+		    audit->extension ? " extension=" : "",
+		    audit->extension ? audit->extension : "");
+}
+
+static int
+SELinuxLog(int type, const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    VErrorF(fmt, ap);
+    va_end(ap);
+    return 0;
+}
+
+/*
+ * XACE Callbacks
+ */
 
 static void
 SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
@@ -418,30 +518,10 @@ SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	rec->status = rc;
 }
 
-/* Extension callbacks */
-static void
-SELinuxStateInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    PrivateCallbackRec *rec = calldata;
-    SELinuxStateRec *state = *rec->value;
-
-    sidget(unlabeled_sid);
-    state->sid = unlabeled_sid;
-
-    avc_entry_ref_init(&state->aeref);
-}
-
-static void
-SELinuxStateFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    PrivateCallbackRec *rec = calldata;
-    SELinuxStateRec *state = *rec->value;
 
-    xfree(state->client_path);
-
-    if (avc_active)
-	sidput(state->sid);
-}
+/*
+ * DIX Callbacks
+ */
 
 static void
 SELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
@@ -506,7 +586,6 @@ finish:
     freecon(ctx);
 }
 
-/* Labeling callbacks */
 static void
 SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
@@ -553,113 +632,67 @@ SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	FatalError("XSELinux: Unexpected unlabeled window found\n");
 }
 
-/* Extension dispatch functions */
-static int
-ProcSELinuxDispatch(ClientPtr client)
-{
-    return BadRequest;
-}
+
+/*
+ * DevPrivates Callbacks
+ */
 
 static void
-SELinuxResetProc(ExtensionEntry *extEntry)
+SELinuxStateInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    /* XXX unregister all callbacks here */
-
-    selabel_close(label_hnd);
-    label_hnd = NULL;
-
-    audit_close(audit_fd);
+    PrivateCallbackRec *rec = calldata;
+    SELinuxStateRec *state = *rec->value;
 
-    avc_destroy();
-    avc_active = 0;
+    sidget(unlabeled_sid);
+    state->sid = unlabeled_sid;
 
-    xfree(knownTypes);
-    knownTypes = NULL;
-    numKnownTypes = 0;
+    avc_entry_ref_init(&state->aeref);
 }
 
-static int
-SELinuxAudit(void *auditdata,
-	     security_class_t class,
-	     char *msgbuf,
-	     size_t msgbufsize)
+static void
+SELinuxStateFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    SELinuxAuditRec *audit = auditdata;
-    ClientPtr client = audit->client;
-    char idNum[16], *propertyName;
-    int major = 0, minor = 0;
-    REQUEST(xReq);
-
-    if (audit->id)
-	snprintf(idNum, 16, "%x", audit->id);
-    if (stuff) {
-	major = stuff->reqType;
-	minor = (major < 128) ? 0 : MinorOpcodeOfRequest(client);
-    }
+    PrivateCallbackRec *rec = calldata;
+    SELinuxStateRec *state = *rec->value;
 
-    propertyName = audit->property ? NameForAtom(audit->property) : NULL;
+    xfree(state->client_path);
 
-    return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s",
-		    stuff ? "request=" : "",
-		    stuff ? LookupRequestName(major, minor) : "",
-		    audit->client_path ? " client=" : "",
-		    audit->client_path ? audit->client_path : "",
-		    audit->id ? " resid=" : "",
-		    audit->id ? idNum : "",
-		    audit->restype ? " restype=" : "",
-		    audit->restype ? LookupResourceName(audit->restype) : "",
-		    audit->property ? " property=" : "",
-		    audit->property ? propertyName : "",
-		    audit->extension ? " extension=" : "",
-		    audit->extension ? audit->extension : "");
+    if (avc_active)
+	sidput(state->sid);
 }
 
+
+/*
+ * Extension Dispatch
+ */
+
 static int
-SELinuxLog(int type, const char *fmt, ...)
+ProcSELinuxDispatch(ClientPtr client)
 {
-    va_list ap;
-    va_start(ap, fmt);
-    VErrorF(fmt, ap);
-    va_end(ap);
-    return 0;
+    return BadRequest;
 }
 
-static void
-SELinuxFixupLabels(void)
-{
-    int i;
-    XaceScreenAccessRec srec;
-    SELinuxStateRec *state;
-    security_context_t ctx;
-    pointer unused;
 
-    /* Do the serverClient */
-    state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
-    sidput(state->sid);
-
-    /* Use the context of the X server process for the serverClient */
-    if (getcon(&ctx) < 0)
-	FatalError("Couldn't get context of X server process\n");
+/*
+ * Extension Setup / Teardown
+ */
 
-    /* Get a SID from the context */
-    if (avc_context_to_sid(ctx, &state->sid) < 0)
-	FatalError("serverClient: context_to_sid(%s) failed\n", ctx);
+static void
+SELinuxResetProc(ExtensionEntry *extEntry)
+{
+    /* XXX unregister all callbacks here */
 
-    freecon(ctx);
+    selabel_close(label_hnd);
+    label_hnd = NULL;
 
-    srec.client = serverClient;
-    srec.access_mode = DixCreateAccess;
-    srec.status = Success;
+    audit_close(audit_fd);
 
-    for (i = 0; i < screenInfo.numScreens; i++) {
-	/* Do the screen object */
-	srec.screen = screenInfo.screens[i];
-	SELinuxScreen(NULL, NULL, &srec);
+    avc_destroy();
+    avc_active = 0;
 
-	/* Do the default colormap */
-	dixLookupResource(&unused, screenInfo.screens[i]->defColormap,
-			  RT_COLORMAP, serverClient, DixCreateAccess);
-    }
+    xfree(knownTypes);
+    knownTypes = NULL;
+    numKnownTypes = 0;
 }
 
 void
commit 50b27e1ad2a98d36728dc8157492ef5c59c132cd
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 16:09:40 2007 -0400

    devPrivates rework: update new GL/glxext code.
    
    Need to merge so this type of thing stops happening.

diff --git a/GL/glx/glxext.c b/GL/glx/glxext.c
index 4d6bfd7..55463c7 100644
--- a/GL/glx/glxext.c
+++ b/GL/glx/glxext.c
@@ -27,6 +27,7 @@
 #include "glxserver.h"
 #include <windowstr.h>
 #include <propertyst.h>
+#include "privates.h"
 #include <os.h>
 #include "g_disptab.h"
 #include "unpack.h"
@@ -53,7 +54,7 @@ RESTYPE __glXSwapBarrierRes;
 */
 xGLXSingleReply __glXReply;
 
-static int glxClientPrivateIndex;
+static DevPrivateKey glxClientPrivateKey = &glxClientPrivateKey;
 
 /*
 ** Client that called into GLX dispatch.
@@ -218,7 +219,7 @@ int __glXError(int error)
 __GLXclientState *
 glxGetClient(ClientPtr pClient)
 {
-    return (__GLXclientState *) pClient->devPrivates[glxClientPrivateIndex].ptr;
+    return dixLookupPrivate(&pClient->devPrivates, glxClientPrivateKey);
 }
 
 static void
@@ -288,9 +289,7 @@ void GlxExtensionInit(void)
     __glXDrawableRes = CreateNewResourceType((DeleteType)DrawableGone);
     __glXSwapBarrierRes = CreateNewResourceType((DeleteType)SwapBarrierGone);
 
-    glxClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (glxClientPrivateIndex,
-				sizeof (__GLXclientState)))
+    if (!dixRequestPrivate(glxClientPrivateKey, sizeof (__GLXclientState)))
 	return;
     if (!AddCallback (&ClientStateCallback, glxClientCallback, 0))
 	return;
diff --git a/GL/glx/glxscreens.c b/GL/glx/glxscreens.c
index c6f060b..6e4d497 100644
--- a/GL/glx/glxscreens.c
+++ b/GL/glx/glxscreens.c
@@ -41,11 +41,12 @@
 #include <windowstr.h>
 #include <os.h>
 
+#include "privates.h"
 #include "glxserver.h"
 #include "glxutil.h"
 #include "glxext.h"
 
-static int glxScreenPrivateIndex;
+static DevPrivateKey glxScreenPrivateKey = &glxScreenPrivateKey;
 
 const char GLServerVersion[] = "1.4";
 static const char GLServerExtensions[] = 
@@ -278,22 +279,11 @@ glxCloseScreen (int index, ScreenPtr pScreen)
 __GLXscreen *
 glxGetScreen(ScreenPtr pScreen)
 {
-    return (__GLXscreen *) pScreen->devPrivates[glxScreenPrivateIndex].ptr;
+    return dixLookupPrivate(&pScreen->devPrivates, glxScreenPrivateKey);
 }
 
 void __glXScreenInit(__GLXscreen *glxScreen, ScreenPtr pScreen)
 {
-    static int glxGeneration;
-
-    if (glxGeneration != serverGeneration)
-    {
-	glxScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (glxScreenPrivateIndex == -1)
-	    return;
-
-	glxGeneration = serverGeneration;
-    }
-
     glxScreen->pScreen       = pScreen;
     glxScreen->GLextensions  = xstrdup(GLServerExtensions);
     glxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
@@ -308,9 +298,9 @@ void __glXScreenInit(__GLXscreen *glxScreen, ScreenPtr pScreen)
 
     __glXScreenInitVisuals(glxScreen);
 
-    pScreen->devPrivates[glxScreenPrivateIndex].ptr = (pointer) glxScreen;
+    dixSetPrivate(&pScreen->devPrivates, glxScreenPrivateKey, glxScreen);
 }
- 
+
 void __glXScreenDestroy(__GLXscreen *screen)
 {
     xfree(screen->GLXvendor);
commit c3f7b862550fa8f46633162f83db8c27e46fc672
Merge: af4dde0... feac075...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 15:00:54 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	os/access.c

diff --cc exa/exa.c
index 56996c4,7ad226f..3f724e6
--- a/exa/exa.c
+++ b/exa/exa.c
@@@ -829,10 -883,10 +876,9 @@@ exaDriverInit (ScreenPtr		pScreen
      /*
       * Hookup offscreen pixmaps
       */
-     if ((pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) &&
- 	pExaScr->info->offScreenBase < pExaScr->info->memorySize)
+     if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS)
      {
 -	if (!AllocatePixmapPrivate(pScreen, exaPixmapPrivateIndex,
 -				   sizeof (ExaPixmapPrivRec))) {
 +	if (!dixRequestPrivate(exaPixmapPrivateKey, sizeof(ExaPixmapPrivRec))) {
              LogMessage(X_WARNING,
  		       "EXA(%d): Failed to allocate pixmap private\n",
  		       pScreen->myNum);
@@@ -846,21 -900,33 +892,29 @@@
  
  	pExaScr->SavedModifyPixmapHeader = pScreen->ModifyPixmapHeader;
  	pScreen->ModifyPixmapHeader = exaModifyPixmapHeader;
- 	LogMessage(X_INFO, "EXA(%d): Offscreen pixmap area of %d bytes\n",
- 		   pScreen->myNum,
- 		   pExaScr->info->memorySize - pExaScr->info->offScreenBase);
+ 	if (!pExaScr->info->CreatePixmap) {
+ 	    LogMessage(X_INFO, "EXA(%d): Offscreen pixmap area of %lu bytes\n",
+ 		       pScreen->myNum,
+ 		       pExaScr->info->memorySize - pExaScr->info->offScreenBase);
+ 	} else {
+ 	    LogMessage(X_INFO, "EXA(%d): Driver allocated offscreen pixmaps\n",
+ 		       pScreen->myNum);
+ 
+ 	}
      }
      else
 -    {
          LogMessage(X_INFO, "EXA(%d): No offscreen pixmaps\n", pScreen->myNum);
 -	if (!AllocatePixmapPrivate(pScreen, exaPixmapPrivateIndex, 0))
 -	    return FALSE;
 -    }
  
-     DBG_PIXMAP(("============== %ld < %ld\n", pExaScr->info->offScreenBase,
-                 pExaScr->info->memorySize));
-     if (pExaScr->info->offScreenBase < pExaScr->info->memorySize) {
- 	if (!exaOffscreenInit (pScreen)) {
-             LogMessage(X_WARNING, "EXA(%d): Offscreen pixmap setup failed\n",
-                        pScreen->myNum);
-             return FALSE;
-         }
+     if (!pExaScr->info->CreatePixmap) {
+ 	DBG_PIXMAP(("============== %ld < %ld\n", pExaScr->info->offScreenBase,
+ 		    pExaScr->info->memorySize));
+ 	if (pExaScr->info->offScreenBase < pExaScr->info->memorySize) {
+ 	    if (!exaOffscreenInit (pScreen)) {
+ 		LogMessage(X_WARNING, "EXA(%d): Offscreen pixmap setup failed\n",
+ 			   pScreen->myNum);
+ 		return FALSE;
+ 	    }
+ 	}
      }
  
      LogMessage(X_INFO, "EXA(%d): Driver registered support for the following"
diff --cc os/access.c
index 33b2eb6,b0f63ed..e91dd37
--- a/os/access.c
+++ b/os/access.c
@@@ -1493,20 -1510,28 +1510,31 @@@ GetLocalClientCreds(ClientPtr client, L
  #endif
  }
  
+ void
+ FreeLocalClientCreds(LocalClientCredRec *lcc)
+ {
+     if (lcc != NULL) {
+ 	if (lcc->nSuppGids > 0) {
+ 	    Xfree(lcc->pSuppGids);
+ 	}
+ 	Xfree(lcc);
+     }
+ }
+ 
 -static Bool
 +static int
  AuthorizedClient(ClientPtr client)
  {
 +    int rc;
 +
      if (!client || defeatAccessControl)
 -	return TRUE;
 +	return Success;
  
      /* untrusted clients can't change host access */
 -    if (!XaceHook(XACE_HOSTLIST_ACCESS, client, DixWriteAccess))
 -	return FALSE;
 +    rc = XaceHook(XACE_SERVER_ACCESS, client, DixManageAccess);
 +    if (rc != Success)
 +	return rc;
  
 -    return LocalClient(client);
 +    return LocalClient(client) ? Success : BadAccess;
  }
  
  /* Add a host to the access control list.  This is the external interface
commit af4dde0ac19ecec1d0ad988eb25b15401e7c6b36
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 14:13:02 2007 -0400

    xselinux: Remove config file, this has been moved to the policy.

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 2423c83..6fe1c34 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -80,9 +80,6 @@ endif
 XSELINUX_SRCS = xselinux.c xselinux.h
 if XSELINUX
 BUILTIN_SRCS += $(XSELINUX_SRCS)
-
-SERVERCONFIG_DATA += XSELinuxConfig
-AM_CFLAGS += -DXSELINUXCONFIGFILE=\"$(SERVERCONFIGdir)/XSELinuxConfig\"
 endif
 
 # Security extension: multi-level security to protect clients from each other
diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
deleted file mode 100644
index 66f93c5..0000000
--- a/Xext/XSELinuxConfig
+++ /dev/null
@@ -1,133 +0,0 @@
-#
-# Config file for XSELinux extension
-#
-
-#
-# The default client rule defines a context to be used for all clients
-# connecting to the server from a remote host.
-#
-client	*				system_u:object_r:remote_xclient_t:s0
-
-#
-# Property rules map a property name to a context.  A default property
-# rule indicated by an asterisk should follow all other property rules.
-#
-# Properties set by typical clients: WM, _NET_WM, etc.
-property WM_NAME			system_u:object_r:client_xproperty_t:s0
-property WM_CLASS			system_u:object_r:client_xproperty_t:s0
-property WM_ICON_NAME			system_u:object_r:client_xproperty_t:s0
-property WM_HINTS			system_u:object_r:client_xproperty_t:s0
-property WM_NORMAL_HINTS		system_u:object_r:client_xproperty_t:s0
-property WM_COMMAND			system_u:object_r:client_xproperty_t:s0
-property WM_CLIENT_MACHINE		system_u:object_r:client_xproperty_t:s0
-property WM_LOCALE_NAME			system_u:object_r:client_xproperty_t:s0
-property WM_CLIENT_LEADER		system_u:object_r:client_xproperty_t:s0
-property WM_STATE			system_u:object_r:client_xproperty_t:s0
-property WM_PROTOCOLS			system_u:object_r:client_xproperty_t:s0
-property WM_WINDOW_ROLE			system_u:object_r:client_xproperty_t:s0
-property WM_TRANSIENT_FOR		system_u:object_r:client_xproperty_t:s0
-property _NET_WM_NAME			system_u:object_r:client_xproperty_t:s0
-property _NET_WM_ICON			system_u:object_r:client_xproperty_t:s0
-property _NET_WM_ICON_NAME		system_u:object_r:client_xproperty_t:s0
-property _NET_WM_PID			system_u:object_r:client_xproperty_t:s0
-property _NET_WM_STATE			system_u:object_r:client_xproperty_t:s0
-property _NET_WM_DESKTOP		system_u:object_r:client_xproperty_t:s0
-property _NET_WM_SYNC_REQUEST_COUNTER	system_u:object_r:client_xproperty_t:s0
-property _NET_WM_WINDOW_TYPE		system_u:object_r:client_xproperty_t:s0
-property _NET_WM_USER_TIME		system_u:object_r:client_xproperty_t:s0
-property _MOTIF_DRAG_RECEIVER_INFO	system_u:object_r:client_xproperty_t:s0
-property XdndAware			system_u:object_r:client_xproperty_t:s0
-
-# Properties written by xrdb
-property RESOURCE_MANAGER		system_u:object_r:rm_xproperty_t:s0
-property SCREEN_RESOURCES		system_u:object_r:rm_xproperty_t:s0
-
-# Properties written by window managers
-property _MIT_PRIORITY_COLORS		system_u:object_r:wm_xproperty_t:s0
-
-# Properties used for security labeling
-property _SELINUX_CLIENT_CONTEXT	system_u:object_r:seclabel_xproperty_t:s0
-
-# Properties used to communicate screen information
-property XFree86_VT			system_u:object_r:info_xproperty_t:s0
-property XFree86_DDC_EDID1_RAWDATA	system_u:object_r:info_xproperty_t:s0
-
-# Clipboard and selection properties
-property CUT_BUFFER0			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER1			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER2			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER3			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER4			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER5			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER6			system_u:object_r:clipboard_xproperty_t:s0
-property CUT_BUFFER7			system_u:object_r:clipboard_xproperty_t:s0
-property _XT_SELECTION_0		system_u:object_r:clipboard_xproperty_t:s0
-
-# Default fallback type
-property *	   			system_u:object_r:unknown_xproperty_t:s0
-
-#
-# Extension rules map an extension name to a context.  A default extension
-# rule indicated by an asterisk should follow all other extension rules.
-#
-# Standard extensions
-extension BIG-REQUESTS			system_u:object_r:std_xext_t:s0
-extension DOUBLE-BUFFER			system_u:object_r:std_xext_t:s0
-extension Extended-Visual-Information	system_u:object_r:std_xext_t:s0
-extension MIT-SUNDRY-NONSTANDARD	system_u:object_r:std_xext_t:s0
-extension SHAPE				system_u:object_r:std_xext_t:s0
-extension SYNC				system_u:object_r:std_xext_t:s0
-extension XC-MISC			system_u:object_r:std_xext_t:s0
-extension XFIXES			system_u:object_r:std_xext_t:s0
-extension XFree86-Misc			system_u:object_r:std_xext_t:s0
-extension XpExtension                   system_u:object_r:std_xext_t:s0
-
-# Screen management and multihead extensions
-extension RANDR				system_u:object_r:output_xext_t:s0
-extension XINERAMA			system_u:object_r:std_xext_t:s0
-
-# Input extensions
-extension XInputExtension		system_u:object_r:input_xext_t:s0
-extension XKEYBOARD			system_u:object_r:input_xext_t:s0
-
-# Screensaver, power management extensions
-extension DPMS				system_u:object_r:screensaver_xext_t:s0
-extension MIT-SCREEN-SAVER		system_u:object_r:screensaver_xext_t:s0
-
-# Fonting extensions
-extension FontCache			system_u:object_r:font_xext_t:s0
-extension XFree86-Bigfont		system_u:object_r:font_xext_t:s0
-
-# Shared memory extensions
-extension MIT-SHM			system_u:object_r:shmem_xext_t:s0
-
-# Accelerated graphics, OpenGL, direct rendering extensions
-extension DAMAGE			system_u:object_r:accelgraphics_xext_t:s0
-extension GLX				system_u:object_r:accelgraphics_xext_t:s0
-extension NV-CONTROL			system_u:object_r:accelgraphics_xext_t:s0
-extension NV-GLX			system_u:object_r:accelgraphics_xext_t:s0
-extension NVIDIA-GLX			system_u:object_r:accelgraphics_xext_t:s0
-extension RENDER			system_u:object_r:std_xext_t:s0
-extension XFree86-DGA			system_u:object_r:accelgraphics_xext_t:s0
-
-# Debugging, testing, and recording extensions
-extension RECORD			system_u:object_r:debug_xext_t:s0
-extension X-Resource			system_u:object_r:debug_xext_t:s0
-extension XTEST				system_u:object_r:debug_xext_t:s0
-
-# Extensions just for window managers
-extension TOG-CUP			system_u:object_r:windowmgr_xext_t:s0
-
-# Security-related extensions
-extension SECURITY			system_u:object_r:security_xext_t:s0
-extension SELinux			system_u:object_r:security_xext_t:s0
-extension XAccessControlExtension	system_u:object_r:security_xext_t:s0
-extension XC-APPGROUP			system_u:object_r:security_xext_t:s0
-
-# Video extensions
-extension XFree86-VidModeExtension	system_u:object_r:video_xext_t:s0
-extension XVideo			system_u:object_r:video_xext_t:s0
-extension XVideo-MotionCompensation	system_u:object_r:video_xext_t:s0
-
-# Default fallback type
-extension *	   			system_u:object_r:unknown_xext_t:s0
commit baabae623b3658196b67a710dc72663c2105bf31
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 13:54:56 2007 -0400

    xselinux: Started reworking extension using new XACE hooks.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index bc86a32..9ff0554 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -32,13 +32,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <dix-config.h>
 #endif
 
-#include <X11/X.h>
 #include <X11/Xatom.h>
-#include <X11/Xproto.h>
-#include <X11/Xfuncproto.h>
+#include "resource.h"
+#include "privates.h"
+#include "registry.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
-#include "resource.h"
+#include "scrnintstr.h"
 #include "selection.h"
 #include "xacestr.h"
 #include "xselinux.h"
@@ -50,14 +50,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <stdarg.h>
 #include "modinit.h"
 
-#ifndef XSELINUXCONFIGFILE
-#warning "XSELinux Policy file is not defined"
-#define XSELINUXCONFIGFILE  NULL
-#endif
+/* private state record */
+static DevPrivateKey stateKey = &stateKey;
 
-/* devPrivates in client and extension */
-static int clientPrivateIndex;
-static int extnsnPrivateIndex;
+/* This is what we store for security state */
+typedef struct {
+    security_id_t sid;
+    struct avc_entry_ref aeref;
+    char *client_path;
+} SELinuxStateRec;
 
 /* audit file descriptor */
 static int audit_fd;
@@ -65,1337 +66,681 @@ static int audit_fd;
 /* structure passed to auditing callback */
 typedef struct {
     ClientPtr client;	/* client */
-    char *property;	/* property name, if any */
+    char *client_path;	/* client's executable path */
+    unsigned id;	/* resource id, if any */
+    int restype;	/* resource type, if any */
+    Atom property;	/* property name, if any */
     char *extension;	/* extension name, if any */
-} XSELinuxAuditRec;
+} SELinuxAuditRec;
 
 /* labeling handle */
 static struct selabel_handle *label_hnd;
 
-/* Atoms for SELinux window labeling properties */
-Atom atom_ctx;
-Atom atom_client_ctx;
+/* whether AVC is active */
+static int avc_active;
+
+/* atoms for window label properties */
+static Atom atom_ctx;
+static Atom atom_client_ctx;
 
-/* Selection stuff from dix */
-extern Selection *CurrentSelections;
-extern int NumCurrentSelections;
+/* The unlabeled SID */
+static security_id_t unlabeled_sid;
 
-/* Dynamically allocated security classes and permissions */
+/* Array of object classes indexed by resource type */
+static security_class_t *knownTypes;
+static unsigned numKnownTypes;
+
+/* dynamically allocated security classes and permissions */
 static struct security_class_mapping map[] = {
-    { "drawable",
-      { "create", "destroy", "draw", "copy", "getattr", NULL }},
-    { "window",
-      { "addchild", "create", "destroy", "map", "unmap", "chstack",
-	"chproplist", "chprop", "listprop", "getattr", "setattr", "setfocus",
-	"move", "chselection", "chparent", "ctrllife", "enumerate",
-	"transparent", "mousemotion", "clientcomevent", "inputevent",
-	"drawevent", "windowchangeevent", "windowchangerequest",
-	"serverchangeevent", "extensionevent", NULL }},
-    { "gc",
-      { "create", "free", "getattr", "setattr", NULL }},
-    { "font",
-      { "load", "free", "getattr", "use", NULL }},
-    { "colormap",
-      { "create", "free", "install", "uninstall", "list", "read", "store",
-	"getattr", "setattr", NULL }},
-    { "property",
-      { "create", "free", "read", "write", NULL }},
-    { "cursor",
-      { "create", "createglyph", "free", "assign", "setattr", NULL }},
-    { "xclient",
-      { "kill", NULL }},
-    { "xinput",
-      { "lookup", "getattr", "setattr", "setfocus", "warppointer",
-	"activegrab", "passivegrab", "ungrab", "bell", "mousemotion",
-	"relabelinput", NULL }},
-    { "xserver",
-      { "screensaver", "gethostlist", "sethostlist", "getfontpath",
-	"setfontpath", "getattr", "grab", "ungrab", NULL }},
-    { "xextension",
-      { "query", "use", NULL }},
+    { "x_drawable", { "read", "write", "destroy", "create", "getattr", "setattr", "list_property", "get_property", "set_property", "", "", "list_child", "add_child", "remove_child", "hide", "show", "blend", "override", "", "", "", "", "send", "receive", "", "manage", NULL }},
+    { "x_screen", { "", "", "", "", "getattr", "setattr", "saver_getattr", "saver_setattr", "", "", "", "", "", "", "hide_cursor", "show_cursor", "saver_hide", "saver_show", NULL }},
+    { "x_gc", { "", "", "destroy", "create", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
+    { "x_font", { "", "", "destroy", "create", "getattr", "", "", "", "", "", "", "", "add_glyph", "remove_glyph", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
+    { "x_colormap", { "read", "write", "destroy", "create", "getattr", "", "", "", "", "", "", "", "add_color", "remove_color", "", "", "", "", "", "", "install", "uninstall", "", "", "use", NULL }},
+    { "x_property", { "read", "write", "destroy", "create", NULL }},
+    { "x_selection", { "read", "", "", "", "getattr", "setattr", NULL }},
+    { "x_cursor", { "read", "write", "destroy", "create", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
+    { "x_client", { "", "", "destroy", "", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "manage", NULL }},
+    { "x_device", { "read", "write", "", "", "getattr", "setattr", "", "", "", "getfocus", "setfocus", "", "", "", "", "", "", "grab", "freeze", "force_cursor", "", "", "", "", "", "manage", "", "bell", NULL }},
+    { "x_server", { "record", "", "", "", "getattr", "setattr", "", "", "", "", "", "", "", "", "", "", "", "grab", "", "", "", "", "", "", "", "manage", "debug", NULL }},
+    { "x_extension", { "", "", "", "", "query", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "use", NULL }},
+    { "x_resource", { "read", "write", "write", "write", "read", "write", "read", "read", "write", "read", "write", "read", "write", "write", "write", "read", "read", "write", "write", "write", "write", "write", "write", "read", "read", "write", "read", "write", NULL }},
     { NULL }
 };
 
 /*
- * list of classes corresponding to SIDs in the
- * rsid array of the security state structure (below).
- *
- * XXX SIDs should be stored in their native objects, not all
- * bunched together in the client structure.  However, this will
- * require modification to the resource manager.
+ * Returns the object class corresponding to the given resource type.
  */
-static security_class_t sClasses[] = {
-    SECCLASS_WINDOW,
-    SECCLASS_DRAWABLE,
-    SECCLASS_GC,
-    SECCLASS_CURSOR,
-    SECCLASS_FONT,
-    SECCLASS_COLORMAP,
-    SECCLASS_PROPERTY,
-    SECCLASS_XCLIENT,
-    SECCLASS_XINPUT,
-    SECCLASS_XSERVER
-};
-#define NRES (sizeof(sClasses)/sizeof(sClasses[0]))
-
-/* This is what we store for client security state */
-typedef struct {
-    int haveState;
-    security_id_t sid;
-    security_id_t rsid[NRES];
-    struct avc_entry_ref aeref;
-} XSELinuxClientStateRec;
-
-/* Convenience macros for accessing security state fields */
-#define STATEPTR(client) \
-    ((client)->devPrivates[clientPrivateIndex].ptr)
-#define HAVESTATE(client) \
-    (((XSELinuxClientStateRec*)STATEPTR(client))->haveState)
-#define SID(client) \
-    (((XSELinuxClientStateRec*)STATEPTR(client))->sid)
-#define RSID(client,n) \
-    (((XSELinuxClientStateRec*)STATEPTR(client))->rsid[n])
-#define AEREF(client) \
-    (((XSELinuxClientStateRec*)STATEPTR(client))->aeref)
-#define EXTENSIONSID(ext) \
-    ((ext)->devPrivates[extnsnPrivateIndex].ptr)
-
-/*
- * Returns the index into the rsid array where the SID for the
- * given class is stored.
- */
-static int
-IndexByClass(security_class_t class)
+static security_class_t
+SELinuxTypeToClass(RESTYPE type)
 {
-    int i;
-    for (i=0; i<NRES; i++)
-	if (class == sClasses[i])
-	    return i;
-    return 0;
-}
-
-/*
- * Does sanity checking on a resource ID.  This can be removed after
- * testing.
- */
-static void
-CheckXID(XID id)
-{
-    /*
-    XID c = CLIENT_ID(id);
-
-    if (c > 10)
-	ErrorF("Warning: possibly mangled ID %x\n", id);
-
-    c = id & RESOURCE_ID_MASK;
-    if (c > 100)
-	ErrorF("Warning: possibly mangled ID %x\n", id);
-        */
-}
-
-/*
- * Byte-swap a CARD32 id if necessary.
- */
-static XID
-SwapXID(ClientPtr client, XID id)
-{
-    register char n;
-    if (client->swapped)
-	swapl(&id, n);
-    return id;
-}
-
-/*
- * ServerPerm - check access permissions on a server-owned object.
- *
- * Arguments:
- * client: Client doing the request.
- * class: Security class of the server object being accessed.
- * perm: Permissions required on the object.
- *
- * Returns: X status code.
- */
-static int
-ServerPerm(ClientPtr client,
-	   security_class_t class,
-	   access_vector_t perm)
-{
-    int idx = IndexByClass(class);
-    if (HAVESTATE(client))
-    {
-	XSELinuxAuditRec auditdata;
-	auditdata.client = client;
-	auditdata.property = NULL;
-	auditdata.extension = NULL;
-	errno = 0;
-        if (avc_has_perm(SID(client), RSID(serverClient,idx), class,
-                         perm, &AEREF(client), &auditdata) < 0)
-        {
-            if (errno == EACCES)
-		return BadAccess;
-	    ErrorF("ServerPerm: unexpected error %d\n", errno);
-	    return BadValue;
-        }
+    RESTYPE fulltype = type;
+    type &= TypeMask;
+
+    if (type >= numKnownTypes) {
+	/* Need to increase size of classes array */
+	unsigned size = sizeof(security_class_t);
+	knownTypes = xrealloc(knownTypes, (type + 1) * size);
+	if (!knownTypes)
+	    return 0;
+	memset(knownTypes + numKnownTypes, 0,
+	       (type - numKnownTypes + 1) * size);
     }
-    else
-    {
-	ErrorF("No client state in server-perm check!\n");
-        return Success;
+
+    if (!knownTypes[type]) {
+	const char *str;
+	knownTypes[type] = SECCLASS_X_RESOURCE;
+
+	if (fulltype & RC_DRAWABLE)
+	    knownTypes[type] = SECCLASS_X_DRAWABLE;
+	if (fulltype == RT_GC)
+	    knownTypes[type] = SECCLASS_X_GC;
+	if (fulltype == RT_FONT)
+	    knownTypes[type] = SECCLASS_X_FONT;
+	if (fulltype == RT_CURSOR)
+	    knownTypes[type] = SECCLASS_X_CURSOR;
+	if (fulltype == RT_COLORMAP)
+	    knownTypes[type] = SECCLASS_X_COLORMAP;
+	
+	/* Need to do a string lookup */
+	str = LookupResourceName(fulltype);
+	if (!strcmp(str, "PICTURE"))
+	    knownTypes[type] = SECCLASS_X_DRAWABLE;
+	if (!strcmp(str, "GLYPHSET"))
+	    knownTypes[type] = SECCLASS_X_FONT;
     }
 
-    return Success;
+//    ErrorF("Returning a class of %d for a type of %d\n", knownTypes[type], type);
+    return knownTypes[type];
 }
 
 /*
- * IDPerm - check access permissions on a resource.
- *
- * Arguments:
- * client: Client doing the request.
- * id: resource id of the resource being accessed.
- * class: Security class of the resource being accessed.
- * perm: Permissions required on the resource.
- *
- * Returns: X status code.
+ * Performs an SELinux permission check.
  */
 static int
-IDPerm(ClientPtr sclient,
-	 XID id,
-	 security_class_t class,
-	 access_vector_t perm)
+SELinuxDoCheck(ClientPtr client, SELinuxStateRec *obj, security_class_t class,
+	       Mask access_mode, SELinuxAuditRec *auditdata)
 {
-    ClientPtr tclient;
-    int idx = IndexByClass(class);
-    XSELinuxAuditRec auditdata;
+    SELinuxStateRec *subj;
 
-    if (id == None)
-	return Success;
-
-    CheckXID(id);
-    tclient = clients[CLIENT_ID(id)];
+//    ErrorF("SuperCheck: client=%d, class=%d, access_mode=%x\n", client->index, class, access_mode);
 
-    /*
-     * This happens in the case where a client has
-     * disconnected.  XXX might want to make the server
-     * own orphaned resources...
-     */
-    if (!tclient || !HAVESTATE(tclient) || !HAVESTATE(sclient))
-    {
+    /* serverClient requests OK */
+    if (client->index == 0)
 	return Success;
-    }
 
-    auditdata.client = sclient;
-    auditdata.property = NULL;
-    auditdata.extension = NULL;
+    subj = dixLookupPrivate(&client->devPrivates, stateKey);
+    auditdata->client = client;
+    auditdata->client_path = subj->client_path;
     errno = 0;
-    if (avc_has_perm(SID(sclient), RSID(tclient,idx), class,
-		     perm, &AEREF(sclient), &auditdata) < 0)
-    {
+
+    if (avc_has_perm(subj->sid, obj->sid, class, access_mode, &subj->aeref,
+		     auditdata) < 0) {
 	if (errno == EACCES)
 	    return BadAccess;
-	ErrorF("IDPerm: unexpected error %d\n", errno);
+	ErrorF("ServerPerm: unexpected error %d\n", errno);
 	return BadValue;
     }
 
     return Success;
 }
 
-/*
- * GetPropertySID - compute SID for a property object.
- *
- * Arguments:
- * basecontext: context of client owning the property.
- * name: name of the property.
- *
- * Returns: proper SID for the object or NULL on error.
- */
-static security_id_t
-GetPropertySID(security_context_t base, const char *name)
-{
-    security_context_t con, result;
-    security_id_t sid = NULL;
-
-    /* look in the mappings of names to types */
-    if (selabel_lookup(label_hnd, &con, name, SELABEL_X_PROP) < 0)
-	goto out;
-
-    /* perform a transition to obtain the final context */
-    if (security_compute_create(base, con, SECCLASS_PROPERTY, &result) < 0)
-	goto out2;
-
-    /* get a SID for the context */
-    avc_context_to_sid(result, &sid);
-    freecon(result);
-  out2:
-    freecon(con);
-  out:
-    return sid;
-}
-
-/*
- * GetExtensionSID - compute SID for an extension object.
- *
- * Arguments:
- * name: name of the extension.
- *
- * Returns: proper SID for the object or NULL on error.
- */
-static security_id_t
-GetExtensionSID(const char *name)
-{
-    security_context_t base, con, result;
-    security_id_t sid = NULL;
-
-    /* get server context */
-    if (getcon(&base) < 0)
-	goto out;
-
-    /* look in the mappings of names to types */
-    if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EXT) < 0)
-	goto out2;
-
-    /* perform a transition to obtain the final context */
-    if (security_compute_create(base, con, SECCLASS_XEXTENSION, &result) < 0)
-	goto out3;
-
-    /* get a SID for the context */
-    avc_context_to_sid(result, &sid);
-    freecon(result);
-  out3:
-    freecon(con);
-  out2:
-    freecon(base);
-  out:
-    return sid;
-}
+//static void
+//SELinuxSelection(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+//{
+//    XaceSelectionAccessRec *rec = calldata;
+//}
 
-/*
- * AssignServerState - set up server security state.
- *
- * Arguments:
- */
 static void
-AssignServerState(void)
+SELinuxExtension(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    int i;
-    security_context_t basectx, objctx;
-    XSELinuxClientStateRec *state;
+    XaceExtAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj, *serv;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    int rc;
 
-    state = (XSELinuxClientStateRec*)STATEPTR(serverClient);
-    avc_entry_ref_init(&state->aeref);
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->ext->devPrivates, stateKey);
 
-    /* use the context of the X server process for the serverClient */
-    if (getcon(&basectx) < 0)
-	FatalError("Couldn't get context of X server process\n");
+    /* If this is a new object that needs labeling, do it now */
+    /* XXX there should be a separate callback for this */
+    if (obj->sid == unlabeled_sid) {
+	const char *name = rec->ext->name;
+	security_context_t con;
+	security_id_t sid;
 
-    /* get a SID from the context */
-    if (avc_context_to_sid(basectx, &state->sid) < 0)
-	FatalError("Client %d: context_to_sid(%s) failed\n", 0, basectx);
+	serv = dixLookupPrivate(&serverClient->devPrivates, stateKey);
 
-    /* get contexts and then SIDs for each resource type */
-    for (i=0; i<NRES; i++) {
-	if (security_compute_create(basectx, basectx, sClasses[i],
-				    &objctx) < 0)
-	    FatalError("Client %d: compute_create(base=%s, cls=%d) failed\n",
-		       0, basectx, sClasses[i]);
+	/* Look in the mappings of property names to contexts */
+	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EXT) < 0) {
+	    ErrorF("XSELinux: a property label lookup failed!\n");
+	    rec->status = BadValue;
+	    return;
+	}
+	/* Get a SID for context */
+	if (avc_context_to_sid(con, &sid) < 0) {
+	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    rec->status = BadAlloc;
+	    return;
+	}
 
-	if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
-	    FatalError("Client %d: context_to_sid(%s) failed\n",
-		       0, objctx);
+	sidput(obj->sid);
 
-	freecon(objctx);
+	/* Perform a transition to obtain the final SID */
+	if (avc_compute_create(serv->sid, sid, SECCLASS_X_EXTENSION,
+			       &obj->sid) < 0) {
+	    ErrorF("XSELinux: a SID transition call failed!\n");
+	    freecon(con);
+	    rec->status = BadValue;
+	    return;
+	}
+	freecon(con);
     }
 
-    /* mark as set up, free base context, and return */
-    state->haveState = TRUE;
-    freecon(basectx);
+    /* Perform the security check */
+    auditdata.extension = rec->ext->name;
+    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_EXTENSION,
+			rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
 }
 
-/*
- * AssignClientState - set up client security state.
- *
- * Arguments:
- * client: client to set up (can be serverClient).
- */
 static void
-AssignClientState(ClientPtr client)
+SELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    int i;
-    security_context_t basectx, objctx;
-    XSELinuxClientStateRec *state;
-
-    state = (XSELinuxClientStateRec*)STATEPTR(client);
-    avc_entry_ref_init(&state->aeref);
+    XacePropertyAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    int rc;
 
-    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
-    if (_XSERVTransIsLocal(ci)) {
-	/* for local clients, can get context from the socket */
-	int fd = _XSERVTransGetConnectionNumber(ci);
-	if (getpeercon(fd, &basectx) < 0)
-	    FatalError("Client %d: couldn't get context from socket\n",
-		       client->index);
-    }
-    else
-	/* for remote clients, need to use a default context */
-	if (selabel_lookup(label_hnd, &basectx, NULL, SELABEL_X_CLIENT) < 0)
-	    FatalError("Client %d: couldn't get default remote connection context\n",
-		       client->index);
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->pProp->devPrivates, stateKey);
 
-    /* get a SID from the context */
-    if (avc_context_to_sid(basectx, &state->sid) < 0)
-	FatalError("Client %d: context_to_sid(%s) failed\n",
-		   client->index, basectx);
+    /* If this is a new object that needs labeling, do it now */
+    if (rec->access_mode & DixCreateAccess) {
+	const char *name = NameForAtom(rec->pProp->propertyName);
+	security_context_t con;
+	security_id_t sid;
 
-    /* get contexts and then SIDs for each resource type */
-    for (i=0; i<NRES; i++) {
-	if (security_compute_create(basectx, basectx, sClasses[i],
-				    &objctx) < 0)
-	    FatalError("Client %d: compute_create(base=%s, cls=%d) failed\n",
-		       client->index, basectx, sClasses[i]);
+	/* Look in the mappings of property names to contexts */
+	if (selabel_lookup(label_hnd, &con, name, SELABEL_X_PROP) < 0) {
+	    ErrorF("XSELinux: a property label lookup failed!\n");
+	    rec->status = BadValue;
+	    return;
+	}
+	/* Get a SID for context */
+	if (avc_context_to_sid(con, &sid) < 0) {
+	    ErrorF("XSELinux: a context_to_SID call failed!\n");
+	    rec->status = BadAlloc;
+	    return;
+	}
 
-	if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
-	    FatalError("Client %d: context_to_sid(%s) failed\n",
-		       client->index, objctx);
+	sidput(obj->sid);
 
-	freecon(objctx);
+	/* Perform a transition to obtain the final SID */
+	if (avc_compute_create(subj->sid, sid, SECCLASS_X_PROPERTY,
+			       &obj->sid) < 0) {
+	    ErrorF("XSELinux: a SID transition call failed!\n");
+	    freecon(con);
+	    rec->status = BadValue;
+	    return;
+	}
+	freecon(con);
+	avc_entry_ref_init(&obj->aeref);
     }
 
-    /* mark as set up, free base context, and return */
-    state->haveState = TRUE;
-    freecon(basectx);
+    /* Perform the security check */
+    auditdata.property = rec->pProp->propertyName;
+    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_PROPERTY,
+			rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
 }
 
-/*
- * FreeClientState - tear down client security state.
- *
- * Arguments:
- * client: client to release (can be serverClient).
- */
 static void
-FreeClientState(ClientPtr client)
+SELinuxResource(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    int i;
-    XSELinuxClientStateRec *state = (XSELinuxClientStateRec*)STATEPTR(client);
-
-    /* client state may not be set up if its auth was rejected */
-    if (state->haveState) {
-	state = (XSELinuxClientStateRec*)STATEPTR(client);
-	sidput(state->sid);
-	for (i=0; i<NRES; i++)
-	    sidput(state->rsid[i]);
-	state->haveState = FALSE;
+    XaceResourceAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj, *pobj;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    PrivateRec **privatePtr;
+    security_class_t class;
+    int rc, offset;
+
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+
+    /* Determine if the resource object has a devPrivates field */
+    offset = dixLookupPrivateOffset(rec->rtype);
+    if (offset < 0) {
+	/* No: use the SID of the owning client */
+	class = SECCLASS_X_RESOURCE;
+	privatePtr = &clients[CLIENT_ID(rec->id)]->devPrivates;
+	obj = dixLookupPrivate(privatePtr, stateKey);
+    } else {
+	/* Yes: use the SID from the resource object itself */
+	class = SELinuxTypeToClass(rec->rtype);
+	privatePtr = DEVPRIV_AT(rec->res, offset);
+	obj = dixLookupPrivate(privatePtr, stateKey);
     }
-}
 
-#define REQUEST_SIZE_CHECK(client, req) \
-    (client->req_len >= (sizeof(req) >> 2))
-#define IDPERM(client, req, field, class, perm) \
-    (REQUEST_SIZE_CHECK(client,req) ? \
-     IDPerm(client, SwapXID(client,((req*)stuff)->field), class, perm) : \
-     BadLength)
-
-static int
-CheckSendEventPerms(ClientPtr client)
-{
-    register char n;
-    access_vector_t perm = 0;
-    REQUEST(xSendEventReq);
-
-    /* might need type bounds checking here */
-    if (!REQUEST_SIZE_CHECK(client, xSendEventReq))
-	return BadLength;
-
-    switch (stuff->event.u.u.type) {
-	case SelectionClear:
-	case SelectionNotify:
-	case SelectionRequest:
-	case ClientMessage:
-	case PropertyNotify:
-	    perm = WINDOW__CLIENTCOMEVENT;
-	    break;
-	case ButtonPress:
-	case ButtonRelease:
-	case KeyPress:
-	case KeyRelease:
-	case KeymapNotify:
-	case MotionNotify:
-	case EnterNotify:
-	case LeaveNotify:
-	case FocusIn:
-	case FocusOut:
-	    perm = WINDOW__INPUTEVENT;
-	    break;
-	case Expose:
-	case GraphicsExpose:
-	case NoExpose:
-	case VisibilityNotify:
-	    perm = WINDOW__DRAWEVENT;
-	    break;
-	case CirculateNotify:
-	case ConfigureNotify:
-	case CreateNotify:
-	case DestroyNotify:
-	case MapNotify:
-	case UnmapNotify:
-	case GravityNotify:
-	case ReparentNotify:
-	    perm = WINDOW__WINDOWCHANGEEVENT;
-	    break;
-	case CirculateRequest:
-	case ConfigureRequest:
-	case MapRequest:
-	case ResizeRequest:
-	    perm = WINDOW__WINDOWCHANGEREQUEST;
-	    break;
-	case ColormapNotify:
-	case MappingNotify:
-	    perm = WINDOW__SERVERCHANGEEVENT;
-	    break;
-	default:
-	    perm = WINDOW__EXTENSIONEVENT;
-	    break;
+    /* If this is a new object that needs labeling, do it now */
+    if (rec->access_mode & DixCreateAccess && offset >= 0) {
+	if (rec->parent)
+	    offset = dixLookupPrivateOffset(rec->ptype);
+	if (rec->parent && offset >= 0)
+	    /* Use the SID of the parent object in the labeling operation */
+	    pobj = dixLookupPrivate(DEVPRIV_AT(rec->parent, offset), stateKey);
+	else
+	    /* Use the SID of the subject */
+	    pobj = subj;
+
+	sidput(obj->sid);
+
+	/* Perform a transition to obtain the final SID */
+	if (avc_compute_create(subj->sid, pobj->sid, class, &obj->sid) < 0) {
+	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    rec->status = BadValue;
+	    return;
+	}
     }
-    if (client->swapped)
-	swapl(&stuff->destination, n);
-    return IDPerm(client, stuff->destination, SECCLASS_WINDOW, perm);
+
+    /* Perform the security check */
+    auditdata.restype = rec->rtype;
+    auditdata.id = rec->id;
+    rc = SELinuxDoCheck(rec->client, obj, class, rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
 }
 
-static int
-CheckConvertSelectionPerms(ClientPtr client)
+static void
+SELinuxScreen(CallbackListPtr *pcbl, pointer is_saver, pointer calldata)
 {
-    register char n;
-    int rval = Success;
-    REQUEST(xConvertSelectionReq);
+    XaceScreenAccessRec *rec = calldata;
+    SELinuxStateRec *subj, *obj;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    Mask access_mode = rec->access_mode;
+    int rc;
 
-    if (!REQUEST_SIZE_CHECK(client, xConvertSelectionReq))
-	return BadLength;
+    subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
+    obj = dixLookupPrivate(&rec->screen->devPrivates, stateKey);
 
-    if (client->swapped)
-    {
-	swapl(&stuff->selection, n);
-	swapl(&stuff->requestor, n);
-    }
+    /* If this is a new object that needs labeling, do it now */
+    if (access_mode & DixCreateAccess) {
+	sidput(obj->sid);
 
-    if (ValidAtom(stuff->selection))
-    {
-	int i = 0;
-	while ((i < NumCurrentSelections) &&
-	       CurrentSelections[i].selection != stuff->selection) i++;
-	if (i < NumCurrentSelections) {
-	    rval = IDPerm(client, CurrentSelections[i].window,
-			  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
-	    if (rval != Success)
-		return rval;
+	/* Perform a transition to obtain the final SID */
+	if (avc_compute_create(subj->sid, subj->sid, SECCLASS_X_SCREEN,
+			       &obj->sid) < 0) {
+	    ErrorF("XSELinux: a compute_create call failed!\n");
+	    rec->status = BadValue;
+	    return;
 	}
     }
-    return IDPerm(client, stuff->requestor,
-		  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
+
+    if (is_saver)
+	access_mode <<= 2;
+
+    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_SCREEN,
+			access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
 }
 
-static int
-CheckSetSelectionOwnerPerms(ClientPtr client)
+static void
+SELinuxClient(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    register char n;
-    int rval = Success;
-    REQUEST(xSetSelectionOwnerReq);
-
-    if (!REQUEST_SIZE_CHECK(client, xSetSelectionOwnerReq))
-	return BadLength;
+    XaceClientAccessRec *rec = calldata;
+    SELinuxStateRec *obj;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    int rc;
 
-    if (client->swapped)
-    {
-	swapl(&stuff->selection, n);
-	swapl(&stuff->window, n);
-    }
+    obj = dixLookupPrivate(&rec->target->devPrivates, stateKey);
 
-    if (ValidAtom(stuff->selection))
-    {
-	int i = 0;
-	while ((i < NumCurrentSelections) &&
-	       CurrentSelections[i].selection != stuff->selection) i++;
-	if (i < NumCurrentSelections) {
-	    rval = IDPerm(client, CurrentSelections[i].window,
-			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
-	    if (rval != Success)
-		return rval;
-	}
-    }
-    return IDPerm(client, stuff->window,
-			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_CLIENT,
+			rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
 }
 
 static void
-XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceCoreDispatchRec *rec = (XaceCoreDispatchRec*)calldata;
-    ClientPtr client = rec->client;
-    REQUEST(xReq);
-    int rval = Success, rval2 = Success, rval3 = Success;
-
-    switch(stuff->reqType) {
-    /* Drawable class control requirements */
-    case X_ClearArea:
-	rval = IDPERM(client, xClearAreaReq, window,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_PolySegment:
-    case X_PolyRectangle:
-    case X_PolyArc:
-    case X_PolyFillRectangle:
-    case X_PolyFillArc:
-	rval = IDPERM(client, xPolySegmentReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_PolyPoint:
-    case X_PolyLine:
-	rval = IDPERM(client, xPolyPointReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_FillPoly:
-	rval = IDPERM(client, xFillPolyReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_PutImage:
-	rval = IDPERM(client, xPutImageReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_CopyArea:
-    case X_CopyPlane:
-	rval = IDPERM(client, xCopyAreaReq, srcDrawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
-	rval2 = IDPERM(client, xCopyAreaReq, dstDrawable,
-		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_GetImage:
-	rval = IDPERM(client, xGetImageReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
-	break;
-    case X_GetGeometry:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_DRAWABLE, DRAWABLE__GETATTR);
-	break;
-
-    /* Window class control requirements */
-    case X_ChangeProperty:
-	rval = IDPERM(client, xChangePropertyReq, window,
-		      SECCLASS_WINDOW,
-		      WINDOW__CHPROPLIST | WINDOW__CHPROP |
-		      WINDOW__LISTPROP);
-	break;
-    case X_ChangeSaveSet:
-	rval = IDPERM(client, xChangeSaveSetReq, window,
-		      SECCLASS_WINDOW,
-		      WINDOW__CTRLLIFE | WINDOW__CHPARENT);
-	break;
-    case X_ChangeWindowAttributes:
-	rval = IDPERM(client, xChangeWindowAttributesReq, window,
-		      SECCLASS_WINDOW, WINDOW__SETATTR);
-	break;
-    case X_CirculateWindow:
-	rval = IDPERM(client, xCirculateWindowReq, window,
-		      SECCLASS_WINDOW, WINDOW__CHSTACK);
-	break;
-    case X_ConfigureWindow:
-	rval = IDPERM(client, xConfigureWindowReq, window,
-		      SECCLASS_WINDOW,
-		      WINDOW__SETATTR | WINDOW__MOVE | WINDOW__CHSTACK);
-	break;
-    case X_ConvertSelection:
-	rval = CheckConvertSelectionPerms(client);
-	break;
-    case X_CreateWindow:
-	rval = IDPERM(client, xCreateWindowReq, wid,
-		      SECCLASS_WINDOW,
-		      WINDOW__CREATE | WINDOW__SETATTR | WINDOW__MOVE);
-	rval2 = IDPERM(client, xCreateWindowReq, parent,
-		       SECCLASS_WINDOW,
-		       WINDOW__CHSTACK | WINDOW__ADDCHILD);
-	rval3 = IDPERM(client, xCreateWindowReq, wid,
-		       SECCLASS_DRAWABLE, DRAWABLE__CREATE);
-	break;
-    case X_DeleteProperty:
-	rval = IDPERM(client, xDeletePropertyReq, window,
-		      SECCLASS_WINDOW,
-		      WINDOW__CHPROP | WINDOW__CHPROPLIST);
-	break;
-    case X_DestroyWindow:
-    case X_DestroySubwindows:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_WINDOW,
-		      WINDOW__ENUMERATE | WINDOW__UNMAP | WINDOW__DESTROY);
-	rval2 = IDPERM(client, xResourceReq, id,
-		       SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
-	break;
-    case X_GetMotionEvents:
-	rval = IDPERM(client, xGetMotionEventsReq, window,
-		      SECCLASS_WINDOW, WINDOW__MOUSEMOTION);
-	break;
-    case X_GetProperty:
-	rval = IDPERM(client, xGetPropertyReq, window,
-		      SECCLASS_WINDOW, WINDOW__LISTPROP);
-	break;
-    case X_GetWindowAttributes:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_WINDOW, WINDOW__GETATTR);
-	break;
-    case X_KillClient:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_XCLIENT, XCLIENT__KILL);
-	break;
-    case X_ListProperties:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_WINDOW, WINDOW__LISTPROP);
-	break;
-    case X_MapWindow:
-    case X_MapSubwindows:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_WINDOW,
-		      WINDOW__ENUMERATE | WINDOW__GETATTR | WINDOW__MAP);
-	break;
-    case X_QueryTree:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_WINDOW, WINDOW__ENUMERATE | WINDOW__GETATTR);
-	break;
-    case X_RotateProperties:
-	rval = IDPERM(client, xRotatePropertiesReq, window,
-		      SECCLASS_WINDOW, WINDOW__CHPROP | WINDOW__CHPROPLIST);
-	break;
-    case X_ReparentWindow:
-	rval = IDPERM(client, xReparentWindowReq, window,
-		      SECCLASS_WINDOW, WINDOW__CHPARENT | WINDOW__MOVE);
-	rval2 = IDPERM(client, xReparentWindowReq, parent,
-		       SECCLASS_WINDOW, WINDOW__CHSTACK | WINDOW__ADDCHILD);
-	break;
-    case X_SendEvent:
-	rval = CheckSendEventPerms(client);
-	break;
-    case X_SetInputFocus:
-	rval = IDPERM(client, xSetInputFocusReq, focus,
-		      SECCLASS_WINDOW, WINDOW__SETFOCUS);
-	rval2 = ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETFOCUS);
-	break;
-    case X_SetSelectionOwner:
-	rval = CheckSetSelectionOwnerPerms(client);
-	break;
-    case X_TranslateCoords:
-	rval = IDPERM(client, xTranslateCoordsReq, srcWid,
-		      SECCLASS_WINDOW, WINDOW__GETATTR);
-	rval2 = IDPERM(client, xTranslateCoordsReq, dstWid,
-		       SECCLASS_WINDOW, WINDOW__GETATTR);
-	break;
-    case X_UnmapWindow:
-    case X_UnmapSubwindows:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_WINDOW,
-		      WINDOW__ENUMERATE | WINDOW__GETATTR |
-		      WINDOW__UNMAP);
-	break;
-    case X_WarpPointer:
-	rval = IDPERM(client, xWarpPointerReq, srcWid,
-		      SECCLASS_WINDOW, WINDOW__GETATTR);
-	rval2 = IDPERM(client, xWarpPointerReq, dstWid,
-		       SECCLASS_WINDOW, WINDOW__GETATTR);
-	rval3 = ServerPerm(client, SECCLASS_XINPUT, XINPUT__WARPPOINTER);
-	break;
-
-    /* Input class control requirements */
-    case X_GrabButton:
-    case X_GrabKey:
-	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__PASSIVEGRAB);
-	break;
-    case X_GrabKeyboard:
-    case X_GrabPointer:
-    case X_ChangeActivePointerGrab:
-	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__ACTIVEGRAB);
-	break;
-    case X_AllowEvents:
-    case X_UngrabButton:
-    case X_UngrabKey:
-    case X_UngrabKeyboard:
-    case X_UngrabPointer:
-	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__UNGRAB);
-	break;
-    case X_GetKeyboardControl:
-    case X_GetKeyboardMapping:
-    case X_GetPointerControl:
-    case X_GetPointerMapping:
-    case X_GetModifierMapping:
-    case X_QueryKeymap:
-    case X_QueryPointer:
-	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__GETATTR);
-	break;
-    case X_ChangeKeyboardControl:
-    case X_ChangePointerControl:
-    case X_ChangeKeyboardMapping:
-    case X_SetModifierMapping:
-    case X_SetPointerMapping:
-	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETATTR);
-	break;
-    case X_Bell:
-	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__BELL);
-	break;
-
-    /* Colormap class control requirements */
-    case X_AllocColor:
-    case X_AllocColorCells:
-    case X_AllocColorPlanes:
-    case X_AllocNamedColor:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP,
-		      COLORMAP__READ | COLORMAP__STORE);
-	break;
-    case X_CopyColormapAndFree:
-	rval = IDPERM(client, xCopyColormapAndFreeReq, mid,
-		      SECCLASS_COLORMAP, COLORMAP__CREATE);
-	rval2 = IDPERM(client, xCopyColormapAndFreeReq, srcCmap,
-		       SECCLASS_COLORMAP,
-		       COLORMAP__READ | COLORMAP__FREE);
-	break;
-    case X_CreateColormap:
-	rval = IDPERM(client, xCreateColormapReq, mid,
-		      SECCLASS_COLORMAP, COLORMAP__CREATE);
-	rval2 = IDPERM(client, xCreateColormapReq, window,
-		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_FreeColormap:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__FREE);
-	break;
-    case X_FreeColors:
-	rval = IDPERM(client, xFreeColorsReq, cmap,
-		      SECCLASS_COLORMAP, COLORMAP__STORE);
-	break;
-    case X_InstallColormap:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__INSTALL);
-	rval2 = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__INSTALL);
-	break;
-    case X_ListInstalledColormaps:
-	rval = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__LIST);
-	break;
-    case X_LookupColor:
-    case X_QueryColors:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__READ);
-	break;
-    case X_StoreColors:
-    case X_StoreNamedColor:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__STORE);
-	break;
-    case X_UninstallColormap:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
-	rval2 = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
-	break;
-
-    /* Font class control requirements */
-    case X_CloseFont:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_FONT, FONT__FREE);
-	break;
-    case X_ImageText8:
-    case X_ImageText16:
-	/* Font accesses checked through the resource manager */
-	rval = IDPERM(client, xImageTextReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-    case X_OpenFont:
-	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD);
-	rval2 = IDPERM(client, xOpenFontReq, fid,
-		       SECCLASS_FONT, FONT__USE);
-	break;
-    case X_PolyText8:
-    case X_PolyText16:
-	/* Font accesses checked through the resource manager */
-	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD);
-	rval2 = IDPERM(client, xPolyTextReq, gc,
-		       SECCLASS_GC, GC__SETATTR);
-	rval3 = IDPERM(client, xPolyTextReq, drawable,
-		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	break;
-
-    /* Pixmap class control requirements */
-    case X_CreatePixmap:
-	rval = IDPERM(client, xCreatePixmapReq, pid,
-		      SECCLASS_DRAWABLE, DRAWABLE__CREATE);
-	break;
-    case X_FreePixmap:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
-	break;
-
-    /* Cursor class control requirements */
-    case X_CreateCursor:
-	rval = IDPERM(client, xCreateCursorReq, cid,
-		      SECCLASS_CURSOR, CURSOR__CREATE);
-	rval2 = IDPERM(client, xCreateCursorReq, source,
-		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
-	rval3 = IDPERM(client, xCreateCursorReq, mask,
-		       SECCLASS_DRAWABLE, DRAWABLE__COPY);
-	break;
-    case X_CreateGlyphCursor:
-	rval = IDPERM(client, xCreateGlyphCursorReq, cid,
-		      SECCLASS_CURSOR, CURSOR__CREATEGLYPH);
-	rval2 = IDPERM(client, xCreateGlyphCursorReq, source,
-		       SECCLASS_FONT, FONT__USE);
-	rval3 = IDPERM(client, xCreateGlyphCursorReq, mask,
-		       SECCLASS_FONT, FONT__USE);
-	break;
-    case X_RecolorCursor:
-	rval = IDPERM(client, xRecolorCursorReq, cursor,
-		      SECCLASS_CURSOR, CURSOR__SETATTR);
-	break;
-    case X_FreeCursor:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_CURSOR, CURSOR__FREE);
-	break;
-
-    /* GC class control requirements */
-    case X_CreateGC:
-	rval = IDPERM(client, xCreateGCReq, gc,
-		      SECCLASS_GC, GC__CREATE | GC__SETATTR);
-	break;
-    case X_ChangeGC:
-    case X_SetDashes:
-    case X_SetClipRectangles:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_GC, GC__SETATTR);
-	break;
-    case X_CopyGC:
-	rval = IDPERM(client, xCopyGCReq, srcGC,
-		      SECCLASS_GC, GC__GETATTR);
-	rval2 = IDPERM(client, xCopyGCReq, dstGC,
-		       SECCLASS_GC, GC__SETATTR);
-	break;
-    case X_FreeGC:
-	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_GC, GC__FREE);
-	break;
-
-    /* Server class control requirements */
-    case X_GrabServer:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GRAB);
-	break;
-    case X_UngrabServer:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__UNGRAB);
-	break;
-    case X_ForceScreenSaver:
-    case X_GetScreenSaver:
-    case X_SetScreenSaver:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SCREENSAVER);
-	break;
-    case X_ListHosts:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETHOSTLIST);
-	break;
-    case X_ChangeHosts:
-    case X_SetAccessControl:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SETHOSTLIST);
-	break;
-    case X_GetFontPath:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETFONTPATH);
-	break;
-    case X_SetFontPath:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SETFONTPATH);
-	break;
-    case X_QueryBestSize:
-	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETATTR);
-	break;
-
-    default:
-	break;
-    }
-    if (rval != Success)
-	rec->status = rval;
-    if (rval2 != Success)
-	rec->status = rval2;
-    if (rval != Success)
-	rec->status = rval3;
+    XaceServerAccessRec *rec = calldata;
+    SELinuxStateRec *obj;
+    SELinuxAuditRec auditdata = { NULL, NULL, 0, 0, 0, NULL };
+    int rc;
+
+    obj = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+
+    rc = SELinuxDoCheck(rec->client, obj, SECCLASS_X_SERVER,
+			rec->access_mode, &auditdata);
+    if (rc != Success)
+	rec->status = rc;
 }
 
+/* Extension callbacks */
 static void
-XSELinuxExtDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxStateInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
-    ClientPtr client = rec->client;
-    ExtensionEntry *ext = rec->ext;
-    security_id_t extsid;
-    access_vector_t perm;
-    REQUEST(xReq);
+    PrivateCallbackRec *rec = calldata;
+    SELinuxStateRec *state = *rec->value;
 
-    /* XXX there should be a separate callback for this */
-    if (!EXTENSIONSID(ext))
-    {
-	extsid = GetExtensionSID(ext->name);
-	if (!extsid)
-	    return;
-	EXTENSIONSID(ext) = extsid;
-    }
+    sidget(unlabeled_sid);
+    state->sid = unlabeled_sid;
 
-    extsid = (security_id_t)EXTENSIONSID(ext);
-    perm = ((stuff->reqType == X_QueryExtension) ||
-	    (stuff->reqType == X_ListExtensions)) ?
-	XEXTENSION__QUERY : XEXTENSION__USE;
-
-    if (HAVESTATE(client))
-    {
-	XSELinuxAuditRec auditdata;
-	auditdata.client = client;
-	auditdata.property = NULL;
-	auditdata.extension = ext->name;
-	errno = 0;
-	if (avc_has_perm(SID(client), extsid, SECCLASS_XEXTENSION,
-			 perm, &AEREF(client), &auditdata) < 0)
-	{
-	    if (errno == EACCES)
-		rec->status = BadAccess;
-	    ErrorF("ExtDispatch: unexpected error %d\n", errno);
-	    rec->status = BadValue;
-	}
-    } else
-	ErrorF("No client state in extension dispatcher!\n");
-} /* XSELinuxExtDispatch */
+    avc_entry_ref_init(&state->aeref);
+}
 
 static void
-XSELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxStateFree(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
-    WindowPtr pWin = rec->pWin;
-    ClientPtr client = rec->client;
-    ClientPtr tclient;
-    access_vector_t perm = 0;
-    security_id_t propsid;
-    char *propname = NameForAtom(rec->pProp->propertyName);
-
-    tclient = wClient(pWin);
-    if (!tclient || !HAVESTATE(tclient))
-        return;
+    PrivateCallbackRec *rec = calldata;
+    SELinuxStateRec *state = *rec->value;
 
-    propsid = GetPropertySID(SID(tclient)->ctx, propname);
-    if (!propsid)
-	return;
-
-    if (rec->access_mode & DixReadAccess)
-	perm |= PROPERTY__READ;
-    if (rec->access_mode & DixWriteAccess)
-	perm |= PROPERTY__WRITE;
-    if (rec->access_mode & DixDestroyAccess)
-	perm |= PROPERTY__FREE;
-    if (!rec->access_mode)
-	perm = PROPERTY__READ | PROPERTY__WRITE | PROPERTY__FREE;
-
-    if (HAVESTATE(client))
-    {
-	XSELinuxAuditRec auditdata;
-	auditdata.client = client;
-	auditdata.property = propname;
-	auditdata.extension = NULL;
-	errno = 0;
-	if (avc_has_perm(SID(client), propsid, SECCLASS_PROPERTY,
-			 perm, &AEREF(client), &auditdata) < 0)
-	{
-	    if (errno == EACCES)
-		rec->status = BadAccess;
-	    ErrorF("Property: unexpected error %d\n", errno);
-	    rec->status = BadValue;
-	}
-    } else
-	ErrorF("No client state in property callback!\n");
+    xfree(state->client_path);
 
-    /* XXX this should be saved in the property structure */
-    sidput(propsid);
-} /* XSELinuxProperty */
+    if (avc_active)
+	sidput(state->sid);
+}
 
 static void
-XSELinuxResLookup(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceResourceAccessRec *rec = (XaceResourceAccessRec*)calldata;
-    ClientPtr client = rec->client;
-    REQUEST(xReq);
-    access_vector_t perm = 0;
-    int rval = Success;
+    NewClientInfoRec *pci = calldata;
+    ClientPtr client = pci->client;
+    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+    SELinuxStateRec *state;
+    security_context_t ctx;
 
-    /* serverClient requests OK */
-    if (client->index == 0)
+    if (client->clientState != ClientStateInitial)
 	return;
 
-    switch(rec->rtype) {
-	case RT_FONT: {
-	    switch(stuff->reqType) {
-		case X_ImageText8:
-		case X_ImageText16:
-		case X_PolyText8:
-		case X_PolyText16:
-		    perm = FONT__USE;
-		    break;
-		case X_ListFonts:
-		case X_ListFontsWithInfo:
-		case X_QueryFont:
-		case X_QueryTextExtents:
-		    perm = FONT__GETATTR;
-		    break;
-		default:
-		    break;
-	    }
-	    if (perm)
-		rval = IDPerm(client, rec->id, SECCLASS_FONT, perm);
-	    break;
-	}
-	default:
-	    break;
-    }
-    if (rval != Success)
-	rec->status = rval;
-} /* XSELinuxResLookup */
+    state = dixLookupPrivate(&client->devPrivates, stateKey);
+    sidput(state->sid);
 
-static void
-XSELinuxMap(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
-    if (IDPerm(rec->client, rec->pWin->drawable.id,
-               SECCLASS_WINDOW, WINDOW__MAP) != Success)
-	rec->status = BadAccess;
-} /* XSELinuxMap */
+    if (_XSERVTransIsLocal(ci)) {
+	int fd = _XSERVTransGetConnectionNumber(ci);
+	struct ucred creds;
+	socklen_t len = sizeof(creds);
+	char path[PATH_MAX + 1];
+	size_t bytes;
 
-static void
-XSELinuxDrawable(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
-    if (IDPerm(rec->client, rec->pDraw->id,
-               SECCLASS_DRAWABLE, DRAWABLE__COPY) != Success)
-	rec->status = BadAccess;
-} /* XSELinuxDrawable */
+	/* For local clients, can get context from the socket */
+	if (getpeercon(fd, &ctx) < 0)
+	    FatalError("Client %d: couldn't get context from socket\n",
+		       client->index);
 
-static void
-XSELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    XaceServerAccessRec *rec = (XaceServerAccessRec*)calldata;
-    access_vector_t perm = (rec->access_mode == DixReadAccess) ?
-	XSERVER__GETHOSTLIST : XSERVER__SETHOSTLIST;
+	/* Try and determine the client's executable name */
+	memset(&creds, 0, sizeof(creds));
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &len) < 0)
+	    goto finish;
 
-    if (ServerPerm(rec->client, SECCLASS_XSERVER, perm) != Success)
-	rec->status = BadAccess;
-} /* XSELinuxServer */
+	snprintf(path, PATH_MAX + 1, "/proc/%d/cmdline", creds.pid);
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+	    goto finish;
 
-/* Extension callbacks */
-static void
-XSELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
-    ClientPtr client = pci->client;
+	bytes = read(fd, path, PATH_MAX + 1);
+	close(fd);
+	if (bytes <= 0)
+	    goto finish;
 
-    switch(client->clientState)
-    {
-    case ClientStateInitial:
-	AssignServerState();
-	break;
+	state->client_path = xalloc(bytes);
+	if (!state->client_path)
+	    goto finish;
 
-	case ClientStateRunning:
-	{
-	    AssignClientState(client);
-	    break;
-	}
-	case ClientStateGone:
-	case ClientStateRetained:
-	{
-	    FreeClientState(client);
-	    break;
-	}
-	default: break;
-    }
-} /* XSELinuxClientState */
+	memcpy(state->client_path, path, bytes);
+	state->client_path[bytes - 1] = 0;
+    } else
+	/* For remote clients, need to use a default context */
+	if (selabel_lookup(label_hnd, &ctx, NULL, SELABEL_X_CLIENT) < 0)
+	    FatalError("Client %d: couldn't get default remote context\n",
+		       client->index);
+
+finish:
+    /* Get a SID from the context */
+    if (avc_context_to_sid(ctx, &state->sid) < 0)
+	FatalError("Client %d: context_to_sid(%s) failed\n",
+		   client->index, ctx);
+
+    freecon(ctx);
+}
 
 /* Labeling callbacks */
 static void
-XSELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+SELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    ResourceStateInfoRec *rec = (ResourceStateInfoRec *)calldata;
+    ResourceStateInfoRec *rec = calldata;
+    SELinuxStateRec *state;
     WindowPtr pWin;
-    ClientPtr client;
-    security_context_t ctx;
-    int rc;
 
     if (rec->type != RT_WINDOW)
 	return;
 
     pWin = (WindowPtr)rec->value;
-    client = wClient(pWin);
+    state = dixLookupPrivate(&wClient(pWin)->devPrivates, stateKey);
 
-    if (HAVESTATE(client)) {
-	rc = avc_sid_to_context(SID(client), &ctx);
+    if (state->sid) {
+	security_context_t ctx;
+	int rc = avc_sid_to_context(state->sid, &ctx);
 	if (rc < 0)
 	    FatalError("XSELinux: Failed to get security context!\n");
 	rc = dixChangeWindowProperty(serverClient,
 				     pWin, atom_client_ctx, XA_STRING, 8,
 				     PropModeReplace, strlen(ctx), ctx, FALSE);
+	if (rc != Success)
+	    FatalError("XSELinux: Failed to set label property on window!\n");
 	freecon(ctx);
     }
     else
-	rc = dixChangeWindowProperty(serverClient,
-				     pWin, atom_client_ctx, XA_STRING, 8,
-				     PropModeReplace, 10, "UNLABELED!", FALSE);
-    if (rc != Success)
-	FatalError("XSELinux: Failed to set context property on window!\n");
-} /* XSELinuxResourceState */
-
-static Bool
-XSELinuxLoadConfigFile(void)
-{
-    struct selinux_opt options[] = {
-	{ SELABEL_OPT_PATH, XSELINUXCONFIGFILE },
-	{ SELABEL_OPT_VALIDATE, (char *)1 },
-    };
-
-    if (!XSELINUXCONFIGFILE)
-        return FALSE;
+	FatalError("XSELinux: Unexpected unlabeled client found\n");
 
-    label_hnd = selabel_open(SELABEL_CTX_X, options, 2);
-    return !!label_hnd;
-} /* XSELinuxLoadConfigFile */
+    state = dixLookupPrivate(&pWin->devPrivates, stateKey);
 
-static void
-XSELinuxFreeConfigData(void)
-{
-    selabel_close(label_hnd);
-    label_hnd = NULL;
-} /* XSELinuxFreeConfigData */
+    if (state->sid) {
+	security_context_t ctx;
+	int rc = avc_sid_to_context(state->sid, &ctx);
+	if (rc < 0)
+	    FatalError("XSELinux: Failed to get security context!\n");
+	rc = dixChangeWindowProperty(serverClient,
+				     pWin, atom_ctx, XA_STRING, 8,
+				     PropModeReplace, strlen(ctx), ctx, FALSE);
+	if (rc != Success)
+	    FatalError("XSELinux: Failed to set label property on window!\n");
+	freecon(ctx);
+    }
+    else
+	FatalError("XSELinux: Unexpected unlabeled window found\n");
+}
 
 /* Extension dispatch functions */
 static int
-ProcXSELinuxDispatch(ClientPtr client)
+ProcSELinuxDispatch(ClientPtr client)
 {
     return BadRequest;
-} /* ProcXSELinuxDispatch */
+}
 
 static void
-XSELinuxResetProc(ExtensionEntry *extEntry)
+SELinuxResetProc(ExtensionEntry *extEntry)
 {
-    FreeClientState(serverClient);
+    /* XXX unregister all callbacks here */
 
-    XSELinuxFreeConfigData();
+    selabel_close(label_hnd);
+    label_hnd = NULL;
 
     audit_close(audit_fd);
 
     avc_destroy();
-} /* XSELinuxResetProc */
+    avc_active = 0;
 
-static void
-XSELinuxAVCAudit(void *auditdata,
-		 security_class_t class,
-		 char *msgbuf,
-		 size_t msgbufsize)
+    xfree(knownTypes);
+    knownTypes = NULL;
+    numKnownTypes = 0;
+}
+
+static int
+SELinuxAudit(void *auditdata,
+	     security_class_t class,
+	     char *msgbuf,
+	     size_t msgbufsize)
 {
-    XSELinuxAuditRec *audit = (XSELinuxAuditRec*)auditdata;
+    SELinuxAuditRec *audit = auditdata;
     ClientPtr client = audit->client;
-    char requestNum[8];
+    char idNum[16], *propertyName;
+    int major = 0, minor = 0;
     REQUEST(xReq);
 
-    if (stuff)
-	snprintf(requestNum, 8, "%d", stuff->reqType);
+    if (audit->id)
+	snprintf(idNum, 16, "%x", audit->id);
+    if (stuff) {
+	major = stuff->reqType;
+	minor = (major < 128) ? 0 : MinorOpcodeOfRequest(client);
+    }
 
-    snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s",
-	     stuff ? "request=" : "",
-	     stuff ? requestNum : "",
-	     audit->property ? " property=" : "",
-	     audit->property ? audit->property : "",
-	     audit->extension ? " extension=" : "",
-	     audit->extension ? audit->extension : "");
+    propertyName = audit->property ? NameForAtom(audit->property) : NULL;
+
+    return snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s%s%s%s%s%s%s",
+		    stuff ? "request=" : "",
+		    stuff ? LookupRequestName(major, minor) : "",
+		    audit->client_path ? " client=" : "",
+		    audit->client_path ? audit->client_path : "",
+		    audit->id ? " resid=" : "",
+		    audit->id ? idNum : "",
+		    audit->restype ? " restype=" : "",
+		    audit->restype ? LookupResourceName(audit->restype) : "",
+		    audit->property ? " property=" : "",
+		    audit->property ? propertyName : "",
+		    audit->extension ? " extension=" : "",
+		    audit->extension ? audit->extension : "");
 }
 
-static void
-XSELinuxAVCLog(const char *fmt, ...)
+static int
+SELinuxLog(int type, const char *fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
     VErrorF(fmt, ap);
     va_end(ap);
+    return 0;
 }
 
-/* XSELinuxExtensionSetup
- *
- * Set up the XSELinux Extension (pre-init)
- */
-void
-XSELinuxExtensionSetup(INITARGS)
+static void
+SELinuxFixupLabels(void)
 {
-    /* Allocate the client private index */
-    clientPrivateIndex = AllocateClientPrivateIndex();
-    if (!AllocateClientPrivate(clientPrivateIndex,
-			       sizeof (XSELinuxClientStateRec)))
-	FatalError("XSELinux: Failed to allocate client private.\n");
-
-    /* Allocate the extension private index */
-    extnsnPrivateIndex = AllocateExtensionPrivateIndex();
-    if (!AllocateExtensionPrivate(extnsnPrivateIndex, 0))
-	FatalError("XSELinux: Failed to allocate extension private.\n");
+    int i;
+    XaceScreenAccessRec srec;
+    SELinuxStateRec *state;
+    security_context_t ctx;
+    pointer unused;
+
+    /* Do the serverClient */
+    state = dixLookupPrivate(&serverClient->devPrivates, stateKey);
+    sidput(state->sid);
+
+    /* Use the context of the X server process for the serverClient */
+    if (getcon(&ctx) < 0)
+	FatalError("Couldn't get context of X server process\n");
+
+    /* Get a SID from the context */
+    if (avc_context_to_sid(ctx, &state->sid) < 0)
+	FatalError("serverClient: context_to_sid(%s) failed\n", ctx);
+
+    freecon(ctx);
+
+    srec.client = serverClient;
+    srec.access_mode = DixCreateAccess;
+    srec.status = Success;
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	/* Do the screen object */
+	srec.screen = screenInfo.screens[i];
+	SELinuxScreen(NULL, NULL, &srec);
+
+	/* Do the default colormap */
+	dixLookupResource(&unused, screenInfo.screens[i]->defColormap,
+			  RT_COLORMAP, serverClient, DixCreateAccess);
+    }
 }
 
-/* XSELinuxExtensionInit
- *
- * Initialize the XSELinux Extension
- */
 void
 XSELinuxExtensionInit(INITARGS)
 {
-    ExtensionEntry	*extEntry;
-    struct avc_log_callback alc = {XSELinuxAVCLog, XSELinuxAVCAudit};
+    ExtensionEntry *extEntry;
+    struct selinux_opt options[] = { { SELABEL_OPT_VALIDATE, (char *)1 } };
+    security_context_t con;
+    int ret = TRUE;
 
-    if (!is_selinux_enabled())
-    {
+    /* Setup SELinux stuff */
+    if (!is_selinux_enabled()) {
         ErrorF("XSELinux: Extension failed to load: SELinux not enabled\n");
         return;
     }
 
-    if (selinux_set_mapping(map) < 0) {
+    selinux_set_callback(SELINUX_CB_LOG, (union selinux_callback)SELinuxLog);
+    selinux_set_callback(SELINUX_CB_AUDIT, (union selinux_callback)SELinuxAudit);
+
+    if (selinux_set_mapping(map) < 0)
 	FatalError("XSELinux: Failed to set up security class mapping\n");
-    }
 
-    if (avc_init("xserver", NULL, &alc, NULL, NULL) < 0)
-    {
+    if (avc_open(NULL, 0) < 0)
 	FatalError("XSELinux: Couldn't initialize SELinux userspace AVC\n");
-    }
+    avc_active = 1;
 
-    if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
-	return;
-    if (!AddCallback(&ResourceStateCallback, XSELinuxResourceState, NULL))
-	return;
+    label_hnd = selabel_open(SELABEL_CTX_X, options, 1);
+    if (!label_hnd)
+	FatalError("XSELinux: Failed to open x_contexts mapping in policy\n");
+
+    if (security_get_initial_context("unlabeled", &con) < 0)
+	FatalError("XSELinux: Failed to look up unlabeled context\n");
+    if (avc_context_to_sid(con, &unlabeled_sid) < 0)
+	FatalError("XSELinux: a context_to_SID call failed!\n");
+    freecon(con);
+
+    /* Prepare for auditing */
+    audit_fd = audit_open();
+    if (audit_fd < 0)
+        FatalError("XSELinux: Failed to open the system audit log\n");
+
+    /* Allocate private storage */
+    if (!dixRequestPrivate(stateKey, sizeof(SELinuxStateRec)))
+	FatalError("XSELinux: Failed to allocate private storage.\n");
 
     /* Create atoms for doing window labeling */
-    atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1);
+    atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, TRUE);
     if (atom_ctx == BAD_RESOURCE)
 	FatalError("XSELinux: Failed to create atom\n");
-    atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, 1);
+    atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, TRUE);
     if (atom_client_ctx == BAD_RESOURCE)
 	FatalError("XSELinux: Failed to create atom\n");
 
-    /* Load the config file.  If this fails, shut down the server,
-     * since an unknown security status is worse than no security.
-     */
-    if (XSELinuxLoadConfigFile() != TRUE)
-    {
-	FatalError("XSELinux: Failed to load security policy\n");
-    }
-
-    /* prepare for auditing */
-    audit_fd = audit_open();
-    if (audit_fd < 0)
-    {
-        FatalError("XSELinux: Failed to open the system audit log\n");
-    }
-
-    /* register security callbacks */
-    XaceRegisterCallback(XACE_CORE_DISPATCH, XSELinuxCoreDispatch, NULL);
-    XaceRegisterCallback(XACE_EXT_ACCESS, XSELinuxExtDispatch, NULL);
-    XaceRegisterCallback(XACE_EXT_DISPATCH, XSELinuxExtDispatch, NULL);
-    XaceRegisterCallback(XACE_RESOURCE_ACCESS, XSELinuxResLookup, NULL);
-    XaceRegisterCallback(XACE_MAP_ACCESS, XSELinuxMap, NULL);
-    XaceRegisterCallback(XACE_SERVER_ACCESS, XSELinuxServer, NULL);
-    XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
-    /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
-    XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
-
-    /* register extension with server */
+    /* Register callbacks */
+    ret &= dixRegisterPrivateInitFunc(stateKey, SELinuxStateInit, NULL);
+    ret &= dixRegisterPrivateDeleteFunc(stateKey, SELinuxStateFree, NULL);
+
+    ret &= AddCallback(&ClientStateCallback, SELinuxClientState, 0);
+    ret &= AddCallback(&ResourceStateCallback, SELinuxResourceState, 0);
+
+    ret &= XaceRegisterCallback(XACE_EXT_DISPATCH, SELinuxExtension, 0);
+    ret &= XaceRegisterCallback(XACE_RESOURCE_ACCESS, SELinuxResource, 0);
+//    ret &= XaceRegisterCallback(XACE_DEVICE_ACCESS, SELinuxDevice, 0);
+    ret &= XaceRegisterCallback(XACE_PROPERTY_ACCESS, SELinuxProperty, 0);
+//    ret &= XaceRegisterCallback(XACE_SEND_ACCESS, SELinuxSend, 0);
+//    ret &= XaceRegisterCallback(XACE_RECEIVE_ACCESS, SELinuxReceive, 0);
+    ret &= XaceRegisterCallback(XACE_CLIENT_ACCESS, SELinuxClient, 0);
+    ret &= XaceRegisterCallback(XACE_EXT_ACCESS, SELinuxExtension, 0);
+    ret &= XaceRegisterCallback(XACE_SERVER_ACCESS, SELinuxServer, 0);
+//    ret &= XaceRegisterCallback(XACE_SELECTION_ACCESS, SELinuxSelection, 0);
+    ret &= XaceRegisterCallback(XACE_SCREEN_ACCESS, SELinuxScreen, 0);
+    ret &= XaceRegisterCallback(XACE_SCREENSAVER_ACCESS, SELinuxScreen, &ret);
+    if (!ret)
+	FatalError("XSELinux: Failed to register one or more callbacks\n");
+
+    /* Add extension to server */
     extEntry = AddExtension(XSELINUX_EXTENSION_NAME,
 			    XSELinuxNumberEvents, XSELinuxNumberErrors,
-			    ProcXSELinuxDispatch, ProcXSELinuxDispatch,
-			    XSELinuxResetProc, StandardMinorOpcode);
+			    ProcSELinuxDispatch, ProcSELinuxDispatch,
+			    SELinuxResetProc, StandardMinorOpcode);
+
+    /* Label objects that were created before we could register ourself */
+    SELinuxFixupLabels();
 }
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index 57fcbb2..02ec86b 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -20,6 +20,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _XSELINUX_H
 #define _XSELINUX_H
 
+#include "dixaccess.h"
+
 /* Extension info */
 #define XSELINUX_EXTENSION_NAME		"SELinux"
 #define XSELINUX_MAJOR_VERSION		1
@@ -28,95 +30,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XSELinuxNumberErrors		0
 
 /* Private Flask definitions */
-#define SECCLASS_DRAWABLE		1
-#define DRAWABLE__CREATE		0x00000001UL
-#define DRAWABLE__DESTROY		0x00000002UL
-#define DRAWABLE__DRAW			0x00000004UL
-#define DRAWABLE__COPY			0x00000008UL
-#define DRAWABLE__GETATTR		0x00000010UL
-#define SECCLASS_WINDOW			2
-#define WINDOW__ADDCHILD		0x00000001UL
-#define WINDOW__CREATE			0x00000002UL
-#define WINDOW__DESTROY			0x00000004UL
-#define WINDOW__MAP			0x00000008UL
-#define WINDOW__UNMAP			0x00000010UL
-#define WINDOW__CHSTACK			0x00000020UL
-#define WINDOW__CHPROPLIST		0x00000040UL
-#define WINDOW__CHPROP			0x00000080UL
-#define WINDOW__LISTPROP		0x00000100UL
-#define WINDOW__GETATTR			0x00000200UL
-#define WINDOW__SETATTR			0x00000400UL
-#define WINDOW__SETFOCUS		0x00000800UL
-#define WINDOW__MOVE			0x00001000UL
-#define WINDOW__CHSELECTION		0x00002000UL
-#define WINDOW__CHPARENT		0x00004000UL
-#define WINDOW__CTRLLIFE		0x00008000UL
-#define WINDOW__ENUMERATE		0x00010000UL
-#define WINDOW__TRANSPARENT		0x00020000UL
-#define WINDOW__MOUSEMOTION		0x00040000UL
-#define WINDOW__CLIENTCOMEVENT		0x00080000UL
-#define WINDOW__INPUTEVENT		0x00100000UL
-#define WINDOW__DRAWEVENT		0x00200000UL
-#define WINDOW__WINDOWCHANGEEVENT	0x00400000UL
-#define WINDOW__WINDOWCHANGEREQUEST	0x00800000UL
-#define WINDOW__SERVERCHANGEEVENT	0x01000000UL
-#define WINDOW__EXTENSIONEVENT		0x02000000UL
-#define SECCLASS_GC			3
-#define GC__CREATE			0x00000001UL
-#define GC__FREE			0x00000002UL
-#define GC__GETATTR			0x00000004UL
-#define GC__SETATTR			0x00000008UL
-#define SECCLASS_FONT			4
-#define FONT__LOAD			0x00000001UL
-#define FONT__FREE			0x00000002UL
-#define FONT__GETATTR			0x00000004UL
-#define FONT__USE			0x00000008UL
-#define SECCLASS_COLORMAP		5
-#define COLORMAP__CREATE		0x00000001UL
-#define COLORMAP__FREE			0x00000002UL
-#define COLORMAP__INSTALL		0x00000004UL
-#define COLORMAP__UNINSTALL		0x00000008UL
-#define COLORMAP__LIST			0x00000010UL
-#define COLORMAP__READ			0x00000020UL
-#define COLORMAP__STORE			0x00000040UL
-#define COLORMAP__GETATTR		0x00000080UL
-#define COLORMAP__SETATTR		0x00000100UL
-#define SECCLASS_PROPERTY		6
-#define PROPERTY__CREATE		0x00000001UL
-#define PROPERTY__FREE			0x00000002UL
-#define PROPERTY__READ			0x00000004UL
-#define PROPERTY__WRITE			0x00000008UL
-#define SECCLASS_CURSOR			7
-#define CURSOR__CREATE			0x00000001UL
-#define CURSOR__CREATEGLYPH		0x00000002UL
-#define CURSOR__FREE			0x00000004UL
-#define CURSOR__ASSIGN			0x00000008UL
-#define CURSOR__SETATTR			0x00000010UL
-#define SECCLASS_XCLIENT		8
-#define XCLIENT__KILL			0x00000001UL
-#define SECCLASS_XINPUT			9
-#define XINPUT__LOOKUP			0x00000001UL
-#define XINPUT__GETATTR			0x00000002UL
-#define XINPUT__SETATTR			0x00000004UL
-#define XINPUT__SETFOCUS		0x00000008UL
-#define XINPUT__WARPPOINTER		0x00000010UL
-#define XINPUT__ACTIVEGRAB		0x00000020UL
-#define XINPUT__PASSIVEGRAB		0x00000040UL
-#define XINPUT__UNGRAB			0x00000080UL
-#define XINPUT__BELL			0x00000100UL
-#define XINPUT__MOUSEMOTION		0x00000200UL
-#define XINPUT__RELABELINPUT		0x00000400UL
-#define SECCLASS_XSERVER		10
-#define XSERVER__SCREENSAVER		0x00000001UL
-#define XSERVER__GETHOSTLIST		0x00000002UL
-#define XSERVER__SETHOSTLIST		0x00000004UL
-#define XSERVER__GETFONTPATH		0x00000008UL
-#define XSERVER__SETFONTPATH		0x00000010UL
-#define XSERVER__GETATTR		0x00000020UL
-#define XSERVER__GRAB			0x00000040UL
-#define XSERVER__UNGRAB			0x00000080UL
-#define SECCLASS_XEXTENSION		11
-#define XEXTENSION__QUERY		0x00000001UL
-#define XEXTENSION__USE			0x00000002UL
+#define SECCLASS_X_DRAWABLE		1
+#define SECCLASS_X_SCREEN		2
+#define SECCLASS_X_GC			3
+#define SECCLASS_X_FONT			4
+#define SECCLASS_X_COLORMAP		5
+#define SECCLASS_X_PROPERTY		6
+#define SECCLASS_X_SELECTION		7
+#define SECCLASS_X_CURSOR		8
+#define SECCLASS_X_CLIENT		9
+#define SECCLASS_X_DEVICE		10
+#define SECCLASS_X_SERVER		11
+#define SECCLASS_X_EXTENSION		12
+#define SECCLASS_X_RESOURCE		13
 
 #endif /* _XSELINUX_H */
diff --git a/configure.ac b/configure.ac
index e73e250..8901fae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -511,7 +511,7 @@ AC_ARG_ENABLE(xinerama,	      AS_HELP_STRING([--disable-xinerama], [Build Xinera
 AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: auto)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=auto])
 AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: auto)]), [XF86MISC=$enableval], [XF86MISC=auto])
 AC_ARG_ENABLE(xace,           AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
-AC_ARG_ENABLE(xselinux,       AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (TEMPORARILY DISABLED)]), [XSELINUX=no], [XSELINUX=no])
+AC_ARG_ENABLE(xselinux,       AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: disabled)]), [XSELINUX=$enableval], [XSELINUX=no])
 AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (TEMPORARILY DISABLED)]), [XCSECURITY=no], [XCSECURITY=no])
 AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
 AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index fb75092..191b3ef 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -130,7 +130,6 @@ extern void XaceExtensionInit(INITARGS);
 #endif
 
 #ifdef XSELINUX
-extern void XSELinuxExtensionSetup(INITARGS);
 extern void XSELinuxExtensionInit(INITARGS);
 #endif
 
diff --git a/mi/miinitext.c b/mi/miinitext.c
index 964ef3e..2540975 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -324,7 +324,6 @@ extern void XaceExtensionInit(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
 #endif
 #ifdef XSELINUX
-extern void XSELinuxExtensionSetup(INITARGS);
 extern void XSELinuxExtensionInit(INITARGS);
 #endif
 #ifdef XPRINT
@@ -537,9 +536,6 @@ InitExtensions(argc, argv)
     int		argc;
     char	*argv[];
 {
-#ifdef XSELINUX
-    XSELinuxExtensionSetup();
-#endif
 #ifdef PANORAMIX
 # if !defined(PRINT_ONLY_SERVER) && !defined(NO_PANORAMIX)
   if (!noPanoramiXExtension) PanoramiXExtensionInit();
@@ -718,7 +714,7 @@ static ExtensionModule staticExtensions[] = {
     { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL, NULL },
 #endif
 #ifdef XSELINUX
-    { XSELinuxExtensionInit, XSELINUX_EXTENSION_NAME, NULL, XSELinuxExtensionSetup, NULL },
+    { XSELinuxExtensionInit, XSELINUX_EXTENSION_NAME, NULL, NULL, NULL },
 #endif
 #ifdef XPRINT
     { XpExtensionInit, XP_PRINTNAME, NULL, NULL, NULL },
commit db66e66dbf26b91c655f1659859c022cc31f0db6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 13:51:11 2007 -0400

    xace: Add an access_mode field to the extension structure.
    This allows the same callback to be used for both extension hooks.

diff --git a/Xext/xace.c b/Xext/xace.c
index 3de259f..b126661 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -67,6 +67,17 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
+	case XACE_EXT_DISPATCH: {
+	    XaceExtAccessRec rec = {
+		va_arg(ap, ClientPtr),
+		va_arg(ap, ExtensionEntry*),
+		DixUseAccess,
+		Success /* default allow */
+	    };
+	    calldata = &rec;
+	    prv = &rec.status;
+	    break;
+	}
 	case XACE_RESOURCE_ACCESS: {
 	    XaceResourceAccessRec rec = {
 		va_arg(ap, ClientPtr),
@@ -141,11 +152,11 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_EXT_DISPATCH:
 	case XACE_EXT_ACCESS: {
 	    XaceExtAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, ExtensionEntry*),
+		DixGetAttrAccess,
 		Success /* default allow */
 	    };
 	    calldata = &rec;
@@ -228,7 +239,7 @@ int XaceHook(int hook, ...)
  
     /* call callbacks and return result, if any. */
     CallCallbacks(&XaceHooks[hook], calldata);
-    return prv ? *prv : 0;
+    return prv ? *prv : Success;
 }
 
 static int
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 1dae4d6..1c61543 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -97,6 +97,7 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     ExtensionEntry *ext;
+    Mask access_mode;
     int status;
 } XaceExtAccessRec;
 
commit e3a8cbe523bae8b771ad3c8ad497f4444f6d05d5
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 17 13:48:44 2007 -0400

    xace: add creation/labeling hook to CreateRootWindow().

diff --git a/dix/window.c b/dix/window.c
index 597ad2e..17ab2a7 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -434,6 +434,12 @@ CreateRootWindow(ScreenPtr pScreen)
     pWin->border.pixel = pScreen->blackPixel;
     pWin->borderWidth = 0;
 
+    /*  security creation/labeling check
+     */
+    if (XaceHook(XACE_RESOURCE_ACCESS, serverClient, pWin->drawable.id,
+		 RT_WINDOW, pWin, RT_NONE, NULL, DixCreateAccess))
+	return FALSE;
+
     if (!AddResource(pWin->drawable.id, RT_WINDOW, (pointer)pWin))
 	return FALSE;
 
commit 773f6491c1cc8819038e753d08c32ba213f80f8f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 16 19:11:36 2007 -0400

    xace: update the DeleteProperty prototype to include the client argument.
    This should have been part of 8f23d40068151ad85cde239d07031284f0b2c4dc.

diff --git a/include/property.h b/include/property.h
index 77536aa..ba7d226 100644
--- a/include/property.h
+++ b/include/property.h
@@ -74,6 +74,7 @@ extern int ChangeWindowProperty(
     Bool /*sendevent*/);
 
 extern int DeleteProperty(
+    ClientPtr /*client*/,
     WindowPtr /*pWin*/,
     Atom /*propName*/);
 
commit fe97f7c54a1b42acd542696b6cdc9e83e89548f3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 22:46:08 2007 -0400

    registry: Add some missing #include's.

diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 6384857..43486cd 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -22,6 +22,7 @@
 
 #include "randrstr.h"
 #include "swaprep.h"
+#include "registry.h"
 
 RESTYPE	RRCrtcType;
 
diff --git a/randr/rrmode.c b/randr/rrmode.c
index d7cc916..63a67da 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -21,6 +21,7 @@
  */
 
 #include "randrstr.h"
+#include "registry.h"
 
 RESTYPE	RRModeType;
 
diff --git a/randr/rroutput.c b/randr/rroutput.c
index fea8797..1ecde31 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -21,6 +21,7 @@
  */
 
 #include "randrstr.h"
+#include "registry.h"
 
 RESTYPE	RROutputType;
 
diff --git a/render/picture.c b/render/picture.c
index dd4221f..049274e 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -41,6 +41,7 @@
 #include "servermd.h"
 #include "picturestr.h"
 #include "xace.h"
+#include "registry.h"
 
 _X_EXPORT DevPrivateKey PictureScreenPrivateKey = &PictureScreenPrivateKey;
 DevPrivateKey	PictureWindowPrivateKey = &PictureWindowPrivateKey;
commit 853ea337bdad17f8f6ec7d940de14ce2cbbbf93e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 22:13:02 2007 -0400

    registry: Register XvMC extension protocol names.

diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 7ae8cc0..a1e0ed1 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -16,6 +16,7 @@
 #include "scrnintstr.h"
 #include "extnsionst.h"
 #include "servermd.h"
+#include "registry.h"
 #include <X11/Xfuncproto.h>
 #include "xvdix.h"
 #include <X11/extensions/XvMC.h>
@@ -700,6 +701,34 @@ XvMCExtensionInit(void)
    XvMCReqCode = extEntry->base;
    XvMCEventBase = extEntry->eventBase;
    XvMCErrorBase = extEntry->errorBase;
+
+    RegisterRequestName(XvMCReqCode, xvmc_QueryVersion,
+			XvMCName ":QueryVersion");
+    RegisterRequestName(XvMCReqCode, xvmc_ListSurfaceTypes,
+			XvMCName ":ListSurfaceTypes");
+    RegisterRequestName(XvMCReqCode, xvmc_CreateContext,
+			XvMCName ":CreateContext");
+    RegisterRequestName(XvMCReqCode, xvmc_DestroyContext,
+			XvMCName ":DestroyContext");
+    RegisterRequestName(XvMCReqCode, xvmc_CreateSurface,
+			XvMCName ":CreateSurface");
+    RegisterRequestName(XvMCReqCode, xvmc_DestroySurface,
+			XvMCName ":DestroySurface");
+    RegisterRequestName(XvMCReqCode, xvmc_CreateSubpicture,
+			XvMCName ":CreateSubpicture");
+    RegisterRequestName(XvMCReqCode, xvmc_DestroySubpicture,
+			XvMCName ":DestroySubpicture");
+    RegisterRequestName(XvMCReqCode, xvmc_ListSubpictureTypes,
+			XvMCName ":ListSubpictureTypes");
+    RegisterRequestName(XvMCReqCode, xvmc_GetDRInfo,
+			XvMCName ":GetDRInfo");
+
+    RegisterErrorName(XvMCErrorBase + XvMCBadContext,
+		      XvMCName ":BadContext");
+    RegisterErrorName(XvMCErrorBase + XvMCBadSurface,
+		      XvMCName ":BadSurface");
+    RegisterErrorName(XvMCErrorBase + XvMCBadSubpicture,
+		      XvMCName ":BadSubpicture");
 }
 
 static Bool
commit 58c3240fcbec23aad122e1c340f6bb6d3b18f779
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 22:09:47 2007 -0400

    registry: Register MIT-SCREEN-SAVER extension protocol names.

diff --git a/Xext/saver.c b/Xext/saver.c
index d282173..eff9325 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -49,6 +49,7 @@ in this Software without prior written authorization from the X Consortium.
 #include "cursorstr.h"
 #include "colormapst.h"
 #include "xace.h"
+#include "registry.h"
 #ifdef PANORAMIX
 #include "panoramiX.h"
 #include "panoramiXsrv.h"
@@ -62,9 +63,6 @@ in this Software without prior written authorization from the X Consortium.
 
 #include "modinit.h"
 
-#if 0
-static unsigned char ScreenSaverReqCode = 0;
-#endif
 static int ScreenSaverEventBase = 0;
 
 static DISPATCH_PROC(ProcScreenSaverQueryInfo);
@@ -274,12 +272,26 @@ ScreenSaverExtensionInit(INITARGS)
 				 ProcScreenSaverDispatch, SProcScreenSaverDispatch,
 				 ScreenSaverResetProc, StandardMinorOpcode)))
     {
-#if 0
-	ScreenSaverReqCode = (unsigned char)extEntry->base;
-#endif
 	ScreenSaverEventBase = extEntry->eventBase;
 	EventSwapVector[ScreenSaverEventBase] = (EventSwapPtr) SScreenSaverNotifyEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_ScreenSaverQueryVersion,
+			ScreenSaverName ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_ScreenSaverQueryInfo,
+			ScreenSaverName ":QueryInfo");
+    RegisterRequestName(extEntry->base, X_ScreenSaverSelectInput,
+			ScreenSaverName ":SelectInput");
+    RegisterRequestName(extEntry->base, X_ScreenSaverSetAttributes,
+			ScreenSaverName ":SetAttributes");
+    RegisterRequestName(extEntry->base, X_ScreenSaverUnsetAttributes,
+			ScreenSaverName ":UnsetAttributes");
+    RegisterRequestName(extEntry->base, X_ScreenSaverSuspend,
+			ScreenSaverName ":Suspend");
+
+    RegisterEventName(ScreenSaverEventBase + ScreenSaverNotify,
+		      ScreenSaverName ":Notify");
 }
 
 /*ARGSUSED*/
commit 4e274e90e16b1d954391e1af3e2074fb10f70ee7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 22:04:20 2007 -0400

    registry: Register SHAPE extension protocol names.

diff --git a/Xext/shape.c b/Xext/shape.c
index 0f49f73..12ab53a 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -43,6 +43,7 @@ in this Software without prior written authorization from The Open Group.
 #include "dixstruct.h"
 #include "resource.h"
 #include "opaque.h"
+#include "registry.h"
 #define _SHAPE_SERVER_	/* don't want Xlib structures */
 #include <X11/extensions/shapestr.h>
 #include "regionstr.h"
@@ -111,9 +112,6 @@ static DISPATCH_PROC(SProcShapeSelectInput);
 #include "panoramiXsrv.h"
 #endif
 
-#if 0
-static unsigned char ShapeReqCode = 0;
-#endif
 static int ShapeEventBase = 0;
 static RESTYPE ClientType, EventType; /* resource types for event masks */
 
@@ -154,12 +152,32 @@ ShapeExtensionInit(void)
 				 ProcShapeDispatch, SProcShapeDispatch,
 				 ShapeResetProc, StandardMinorOpcode)))
     {
-#if 0
-	ShapeReqCode = (unsigned char)extEntry->base;
-#endif
 	ShapeEventBase = extEntry->eventBase;
 	EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_ShapeQueryVersion,
+			SHAPENAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_ShapeRectangles,
+			SHAPENAME ":Rectangles");
+    RegisterRequestName(extEntry->base, X_ShapeMask,
+			SHAPENAME ":Mask");
+    RegisterRequestName(extEntry->base, X_ShapeCombine,
+			SHAPENAME ":Combine");
+    RegisterRequestName(extEntry->base, X_ShapeOffset,
+			SHAPENAME ":Offset");
+    RegisterRequestName(extEntry->base, X_ShapeQueryExtents,
+			SHAPENAME ":QueryExtents");
+    RegisterRequestName(extEntry->base, X_ShapeSelectInput,
+			SHAPENAME ":SelectInput");
+    RegisterRequestName(extEntry->base, X_ShapeInputSelected,
+			SHAPENAME ":InputSelected");
+    RegisterRequestName(extEntry->base, X_ShapeGetRectangles,
+			SHAPENAME ":GetRectangles");
+
+    RegisterEventName(ShapeEventBase + ShapeNotify,
+		      SHAPENAME ":Notify");
 }
 
 /*ARGSUSED*/
commit 9f597f6c87e0b14cc382d8e5929e42f822db4329
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 22:01:20 2007 -0400

    registry: Register SYNC extension protocol names.

diff --git a/Xext/sync.c b/Xext/sync.c
index 81b0cc4..750e0db 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -67,6 +67,7 @@ PERFORMANCE OF THIS SOFTWARE.
 #include "dixstruct.h"
 #include "resource.h"
 #include "opaque.h"
+#include "registry.h"
 #define _SYNC_SERVER
 #include <X11/extensions/sync.h>
 #include <X11/extensions/syncstr.h>
@@ -2411,6 +2412,45 @@ SyncExtensionInit(INITARGS)
     fprintf(stderr, "Sync Extension %d.%d\n",
 	    SYNC_MAJOR_VERSION, SYNC_MINOR_VERSION);
 #endif
+
+    RegisterRequestName(extEntry->base, X_SyncInitialize,
+			SYNC_NAME ":Initialize");
+    RegisterRequestName(extEntry->base, X_SyncListSystemCounters,
+			SYNC_NAME ":ListSystemCounters");
+    RegisterRequestName(extEntry->base, X_SyncCreateCounter,
+			SYNC_NAME ":CreateCounter");
+    RegisterRequestName(extEntry->base, X_SyncSetCounter,
+			SYNC_NAME ":SetCounter");
+    RegisterRequestName(extEntry->base, X_SyncChangeCounter,
+			SYNC_NAME ":ChangeCounter");
+    RegisterRequestName(extEntry->base, X_SyncQueryCounter,
+			SYNC_NAME ":QueryCounter");
+    RegisterRequestName(extEntry->base, X_SyncDestroyCounter,
+			SYNC_NAME ":DestroyCounter");
+    RegisterRequestName(extEntry->base, X_SyncAwait,
+			SYNC_NAME ":Await");
+    RegisterRequestName(extEntry->base, X_SyncCreateAlarm,
+			SYNC_NAME ":CreateAlarm");
+    RegisterRequestName(extEntry->base, X_SyncChangeAlarm,
+			SYNC_NAME ":ChangeAlarm");
+    RegisterRequestName(extEntry->base, X_SyncQueryAlarm,
+			SYNC_NAME ":QueryAlarm");
+    RegisterRequestName(extEntry->base, X_SyncDestroyAlarm,
+			SYNC_NAME ":DestroyAlarm");
+    RegisterRequestName(extEntry->base, X_SyncSetPriority,
+			SYNC_NAME ":SetPriority");
+    RegisterRequestName(extEntry->base, X_SyncGetPriority,
+			SYNC_NAME ":GetPriority");
+
+    RegisterEventName(SyncEventBase + XSyncCounterNotify,
+		      SYNC_NAME ":CounterNotify");
+    RegisterEventName(SyncEventBase + XSyncAlarmNotify,
+		      SYNC_NAME ":AlarmNotify");
+
+    RegisterErrorName(SyncErrorBase + XSyncBadCounter,
+		      SYNC_NAME ":BadCounter");
+    RegisterErrorName(SyncErrorBase + XSyncBadAlarm,
+		      SYNC_NAME ":BadAlarm");
 }
 
 
commit b504678ba5407a6fd8d47d051305f7c3d5606dfe
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:54:25 2007 -0400

    registry: Register APPGROUP extension protocol names.

diff --git a/Xext/appgroup.c b/Xext/appgroup.c
index c40782d..4fb4020 100644
--- a/Xext/appgroup.c
+++ b/Xext/appgroup.c
@@ -39,6 +39,7 @@ from The Open Group.
 #include "windowstr.h"
 #include "colormapst.h"
 #include "servermd.h"
+#include "registry.h"
 #define _XAG_SERVER_
 #include <X11/extensions/Xagstr.h>
 #include "xacestr.h"
@@ -762,14 +763,35 @@ static void XagCallClientStateChange(
 void
 XagExtensionInit(INITARGS)
 {
-    if (AddExtension (XAGNAME,
-		      0,
-		      XagNumberErrors,
-		      ProcXagDispatch,
-		      SProcXagDispatch,
-		      XagResetProc,
-		      StandardMinorOpcode)) {
+    ExtensionEntry *extEntry;
+
+    if ((extEntry = AddExtension (XAGNAME,
+				  0,
+				  XagNumberErrors,
+				  ProcXagDispatch,
+				  SProcXagDispatch,
+				  XagResetProc,
+				  StandardMinorOpcode))) {
 	RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);
 	XaceRegisterCallback(XACE_AUTH_AVAIL, XagCallClientStateChange, NULL);
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_XagQueryVersion,
+			XAGNAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_XagCreate,
+			XAGNAME ":Create");
+    RegisterRequestName(extEntry->base, X_XagDestroy,
+			XAGNAME ":Destroy");
+    RegisterRequestName(extEntry->base, X_XagGetAttr,
+			XAGNAME ":GetAttr");
+    RegisterRequestName(extEntry->base, X_XagQuery,
+			XAGNAME ":Query");
+    RegisterRequestName(extEntry->base, X_XagCreateAssoc,
+			XAGNAME ":CreateAssoc");
+    RegisterRequestName(extEntry->base, X_XagDestroyAssoc,
+			XAGNAME ":DestroyAssoc");
+
+    RegisterErrorName(extEntry->errorBase + XagBadAppGroup,
+			XAGNAME ":BadAppGroup");
 }
commit 6ec35a8cf539c900b334dd6df146b394f54e3706
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:46:56 2007 -0400

    registry: Register BigRequests extension protocol names.

diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index d388790..6303f38 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -37,14 +37,11 @@ from The Open Group.
 #include "os.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "registry.h"
 #include <X11/extensions/bigreqstr.h>
 #include "opaque.h"
 #include "modinit.h"
 
-#if 0
-static unsigned char XBigReqCode;
-#endif
-
 static void BigReqResetProc(
     ExtensionEntry * /* extEntry */
 );
@@ -54,18 +51,15 @@ static DISPATCH_PROC(ProcBigReqDispatch);
 void
 BigReqExtensionInit(INITARGS)
 {
-#if 0
     ExtensionEntry *extEntry;
 
-    if ((extEntry = AddExtension(XBigReqExtensionName, 0, 0,
-				 ProcBigReqDispatch, ProcBigReqDispatch,
-				 BigReqResetProc, StandardMinorOpcode)) != 0)
-	XBigReqCode = (unsigned char)extEntry->base;
-#else
-    (void) AddExtension(XBigReqExtensionName, 0, 0,
-			ProcBigReqDispatch, ProcBigReqDispatch,
-			BigReqResetProc, StandardMinorOpcode);
-#endif
+    if (!(extEntry = AddExtension(XBigReqExtensionName, 0, 0,
+				  ProcBigReqDispatch, ProcBigReqDispatch,
+				  BigReqResetProc, StandardMinorOpcode)))
+	return;
+
+    RegisterRequestName(extEntry->base, X_BigReqEnable,
+			XBigReqExtensionName ":Enable");
 }
 
 /*ARGSUSED*/
commit 1254cc399c53eadcc32eeabf69990ed2526c7ae0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:43:06 2007 -0400

    registry: Register Fontcache extension protocol names.

diff --git a/Xext/fontcache.c b/Xext/fontcache.c
index c54340b..9fae2d7 100644
--- a/Xext/fontcache.c
+++ b/Xext/fontcache.c
@@ -42,6 +42,7 @@
 #include "scrnintstr.h"
 #include "inputstr.h"
 #include "servermd.h"
+#include "registry.h"
 #define _FONTCACHE_SERVER_
 #include <X11/extensions/fontcacheP.h>
 #include <X11/extensions/fontcachstr.h>
@@ -67,28 +68,34 @@ static DISPATCH_PROC(SProcFontCacheGetCacheStatistics);
 static DISPATCH_PROC(SProcFontCacheQueryVersion);
 static DISPATCH_PROC(SProcFontCacheChangeCacheSettings);
 
-#if 0
-static unsigned char FontCacheReqCode = 0;
-#endif
-
 void
 FontCacheExtensionInit(INITARGS)
 {
     ExtensionEntry* extEntry;
 
-    if (
+    if (!
 	(extEntry = AddExtension(FONTCACHENAME,
 				FontCacheNumberEvents,
 				FontCacheNumberErrors,
 				ProcFontCacheDispatch,
 				SProcFontCacheDispatch,
 				FontCacheResetProc,
-				StandardMinorOpcode))) {
-#if 0
-	FontCacheReqCode = (unsigned char)extEntry->base;
-#endif
-	miscErrorBase = extEntry->errorBase;
-    }
+				StandardMinorOpcode)))
+	return;
+
+    RegisterRequestName(extEntry->base, X_FontCacheQueryVersion,
+			FONTCACHENAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_FontCacheGetCacheSettings,
+			FONTCACHENAME ":GetCacheSettings");
+    RegisterRequestName(extEntry->base, X_FontCacheChangeCacheSettings,
+			FONTCACHENAME ":ChangeCacheSettings");
+    RegisterRequestName(extEntry->base, X_FontCacheGetCacheStatistics,
+			FONTCACHENAME ":GetCacheStatistics");
+
+    RegisterErrorName(extEntry->errorBase + FontCacheBadProtocol,
+		      FONTCACHENAME ":BadProtocol");
+    RegisterErrorName(extEntry->errorBase + FontCacheCannotAllocMemory,
+		      FONTCACHENAME ":CannotAllocMemory");
 }
 
 /*ARGSUSED*/
commit e987648cf2c21dcbd77dd9a71793090a48e4f521
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:38:56 2007 -0400

    registry: Register EVI extension protocol names.

diff --git a/Xext/EVI.c b/Xext/EVI.c
index 8fe3481..b6752c0 100644
--- a/Xext/EVI.c
+++ b/Xext/EVI.c
@@ -30,14 +30,12 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "dix.h"
+#include "registry.h"
 #define _XEVI_SERVER_
 #include <X11/extensions/XEVIstr.h>
 #include "EVIstruct.h"
 #include "modinit.h"
 
-#if 0
-static unsigned char XEVIReqCode = 0;
-#endif
 static EviPrivPtr eviPriv;
 
 static int
@@ -182,19 +180,18 @@ EVIResetProc(ExtensionEntry *extEntry)
 void
 EVIExtensionInit(INITARGS)
 {
-#if 0
     ExtensionEntry *extEntry;
 
-    if ((extEntry = AddExtension(EVINAME, 0, 0,
-				ProcEVIDispatch,
-				SProcEVIDispatch,
-				EVIResetProc, StandardMinorOpcode))) {
-	XEVIReqCode = (unsigned char)extEntry->base;
-#else
-    if (AddExtension(EVINAME, 0, 0,
-		     ProcEVIDispatch, SProcEVIDispatch,
-		     EVIResetProc, StandardMinorOpcode)) {
-#endif
-	eviPriv = eviDDXInit();
-    }
+    if (!(extEntry = AddExtension(EVINAME, 0, 0,
+				  ProcEVIDispatch,
+				  SProcEVIDispatch,
+				  EVIResetProc, StandardMinorOpcode)))
+	return;
+
+    eviPriv = eviDDXInit();
+
+    RegisterRequestName(extEntry->base, X_EVIQueryVersion,
+			EVINAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_EVIGetVisualInfo,
+			EVINAME ":GetVisualInfo");
 }
commit f6226d3bfe1515058e2092e8662ae87825501209
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:35:12 2007 -0400

    registry: Register TOG-CUP extension protocol names.

diff --git a/Xext/cup.c b/Xext/cup.c
index b544a75..4adfc61 100644
--- a/Xext/cup.c
+++ b/Xext/cup.c
@@ -39,6 +39,7 @@ in this Software without prior written authorization from The Open Group.
 #include "scrnintstr.h"
 #include "servermd.h"
 #include "swapreq.h"
+#include "registry.h"
 #define _XCUP_SERVER_
 #include <X11/extensions/Xcupstr.h>
 #include <X11/Xfuncproto.h>
@@ -51,11 +52,6 @@ static int		ProcDispatch(ClientPtr client);
 static int              SProcDispatch(ClientPtr client);
 static void		ResetProc(ExtensionEntry* extEntry);
 
-#if 0
-static unsigned char	ReqCode = 0;
-static int		ErrorBase;
-#endif
-
 #if defined(WIN32) || defined(TESTWIN32)
 #define HAVE_SPECIAL_DESKTOP_COLORS
 #endif
@@ -128,30 +124,25 @@ static xColorItem citems[] = {
 void
 XcupExtensionInit (INITARGS)
 {
-#if 0
     ExtensionEntry* extEntry;
 
-    if ((extEntry = AddExtension (XCUPNAME,
-				0,
-				XcupNumberErrors,
-				ProcDispatch,
-				SProcDispatch,
-				ResetProc,
-				StandardMinorOpcode))) {
-	ReqCode = (unsigned char)extEntry->base;
-	ErrorBase = extEntry->errorBase;
-    }
-#else
-    (void) AddExtension (XCUPNAME,
-			0,
-			XcupNumberErrors,
-			ProcDispatch,
-			SProcDispatch,
-			ResetProc,
-			StandardMinorOpcode);
-#endif
+    if (!(extEntry = AddExtension (XCUPNAME,
+				   0,
+				   XcupNumberErrors,
+				   ProcDispatch,
+				   SProcDispatch,
+				   ResetProc,
+				   StandardMinorOpcode)))
+	return;
 
     /* PC servers initialize the desktop colors (citems) here! */
+
+    RegisterRequestName(extEntry->base, X_XcupQueryVersion,
+			XCUPNAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_XcupGetReservedColormapEntries,
+			XCUPNAME ":GetReservedColormapEntries");
+    RegisterRequestName(extEntry->base, X_XcupStoreColors,
+			XCUPNAME ":StoreColors");
 }
 
 /*ARGSUSED*/
commit 7e182a5d89d618e20dcc77850131690733322d39
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:13:39 2007 -0400

    registry: Register MIT-MISC extension protocol names.

diff --git a/Xext/mitmisc.c b/Xext/mitmisc.c
index 924b880..0b23152 100644
--- a/Xext/mitmisc.c
+++ b/Xext/mitmisc.c
@@ -38,14 +38,11 @@ in this Software without prior written authorization from The Open Group.
 #include "os.h"
 #include "dixstruct.h"
 #include "extnsionst.h"
+#include "registry.h"
 #define _MITMISC_SERVER_
 #include <X11/extensions/mitmiscstr.h>
 #include "modinit.h"
 
-#if 0
-static unsigned char MITReqCode;
-#endif
-
 static void MITResetProc(
     ExtensionEntry * /* extEntry */
 );
@@ -60,18 +57,17 @@ static DISPATCH_PROC(SProcMITSetBugMode);
 void
 MITMiscExtensionInit(INITARGS)
 {
-#if 0
     ExtensionEntry *extEntry;
 
-    if ((extEntry = AddExtension(MITMISCNAME, 0, 0,
-				 ProcMITDispatch, SProcMITDispatch,
-				 MITResetProc, StandardMinorOpcode)) != 0)
-	MITReqCode = (unsigned char)extEntry->base;
-#else
-    (void) AddExtension(MITMISCNAME, 0, 0,
-			ProcMITDispatch, SProcMITDispatch,
-			MITResetProc, StandardMinorOpcode);
-#endif
+    if (!(extEntry = AddExtension(MITMISCNAME, 0, 0,
+				  ProcMITDispatch, SProcMITDispatch,
+				  MITResetProc, StandardMinorOpcode)))
+	return;
+
+    RegisterRequestName(extEntry->base, X_MITSetBugMode,
+			MITMISCNAME ":SetBugMode");
+    RegisterRequestName(extEntry->base, X_MITGetBugMode,
+			MITMISCNAME ":GetBugMode");
 }
 
 /*ARGSUSED*/
commit 32f6171862461d17ebea58a2fb6ddd16ac71358c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:10:14 2007 -0400

    registry: Register XF86Bigfont extension protocol names.

diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 29f07a6..a8af43d 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -71,6 +71,7 @@
 #include "gcstruct.h"
 #include "dixfontstr.h"
 #include "extnsionst.h"
+#include "registry.h"
 
 #define _XF86BIGFONT_SERVER_
 #include <X11/extensions/xf86bigfstr.h>
@@ -86,10 +87,6 @@ static DISPATCH_PROC(SProcXF86BigfontDispatch);
 static DISPATCH_PROC(SProcXF86BigfontQueryVersion);
 static DISPATCH_PROC(SProcXF86BigfontQueryFont);
 
-#if 0
-static unsigned char XF86BigfontReqCode;
-#endif
-
 #ifdef HAS_SHM
 
 /* A random signature, transmitted to the clients so they can verify that the
@@ -149,7 +146,6 @@ CheckForShmSyscall(void)
 void
 XFree86BigfontExtensionInit()
 {
-#if 0
     ExtensionEntry* extEntry;
 
     if ((extEntry = AddExtension(XF86BIGFONTNAME,
@@ -159,16 +155,6 @@ XFree86BigfontExtensionInit()
 				 SProcXF86BigfontDispatch,
 				 XF86BigfontResetProc,
 				 StandardMinorOpcode))) {
-	XF86BigfontReqCode = (unsigned char) extEntry->base;
-#else
-    if (AddExtension(XF86BIGFONTNAME,
-		     XF86BigfontNumberEvents,
-		     XF86BigfontNumberErrors,
-		     ProcXF86BigfontDispatch,
-		     SProcXF86BigfontDispatch,
-		     XF86BigfontResetProc,
-		     StandardMinorOpcode)) {
-#endif
 #ifdef HAS_SHM
 #ifdef MUST_CHECK_FOR_SHM_SYSCALL
 	/*
@@ -200,7 +186,13 @@ XFree86BigfontExtensionInit()
 # endif
 #endif
 #endif
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_XF86BigfontQueryVersion,
+			XF86BIGFONTNAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_XF86BigfontQueryFont,
+			XF86BIGFONTNAME ":QueryFont");
 }
 
 
commit 12766c5b5ffdab95255a63b2c8421ee773fd43b5
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 21:00:46 2007 -0400

    registry: Register Xv extension protocol names.

diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index a2fc108..b3449b4 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -92,6 +92,7 @@ SOFTWARE.
 #include "resource.h"
 #include "opaque.h"
 #include "input.h"
+#include "registry.h"
 
 #define GLOBAL
 
@@ -195,6 +196,58 @@ XvExtensionInit(void)
 
       (void)MakeAtom(XvName, strlen(XvName), xTrue);
 
+      RegisterRequestName(XvReqCode, xv_QueryExtension,
+			  XvName ":QueryExtension");
+      RegisterRequestName(XvReqCode, xv_QueryAdaptors,
+			  XvName ":QueryAdaptors");
+      RegisterRequestName(XvReqCode, xv_QueryEncodings,
+			  XvName ":QueryEncodings");
+      RegisterRequestName(XvReqCode, xv_GrabPort,
+			  XvName ":GrabPort");
+      RegisterRequestName(XvReqCode, xv_UngrabPort,
+			  XvName ":UngrabPort");
+      RegisterRequestName(XvReqCode, xv_PutVideo,
+			  XvName ":PutVideo");
+      RegisterRequestName(XvReqCode, xv_PutStill,
+			  XvName ":PutStill");
+      RegisterRequestName(XvReqCode, xv_GetVideo,
+			  XvName ":GetVideo");
+      RegisterRequestName(XvReqCode, xv_GetStill,
+			  XvName ":GetStill");
+      RegisterRequestName(XvReqCode, xv_StopVideo,
+			  XvName ":StopVideo");
+      RegisterRequestName(XvReqCode, xv_SelectVideoNotify,
+			  XvName ":SelectVideoNotify");
+      RegisterRequestName(XvReqCode, xv_SelectPortNotify,
+			  XvName ":SelectPortNotify");
+      RegisterRequestName(XvReqCode, xv_QueryBestSize,
+			  XvName ":QueryBestSize");
+      RegisterRequestName(XvReqCode, xv_SetPortAttribute,
+			  XvName ":SetPortAttribute");
+      RegisterRequestName(XvReqCode, xv_GetPortAttribute,
+			  XvName ":GetPortAttribute");
+      RegisterRequestName(XvReqCode, xv_QueryPortAttributes,
+			  XvName ":QueryPortAttributes");
+      RegisterRequestName(XvReqCode, xv_ListImageFormats,
+			  XvName ":ListImageFormats");
+      RegisterRequestName(XvReqCode, xv_QueryImageAttributes,
+			  XvName ":QueryImageAttributes");
+      RegisterRequestName(XvReqCode, xv_PutImage,
+			  XvName ":PutImage");
+      RegisterRequestName(XvReqCode, xv_ShmPutImage,
+			  XvName ":ShmPutImage");
+
+      RegisterEventName(XvEventBase + XvVideoNotify,
+			XvName ":VideoNotify");
+      RegisterEventName(XvEventBase + XvPortNotify,
+			XvName ":PortNotify");
+
+      RegisterErrorName(XvErrorBase + XvBadPort,
+			XvName ":BadPort");
+      RegisterErrorName(XvErrorBase + XvBadEncoding,
+			XvName ":BadEncoding");
+      RegisterErrorName(XvErrorBase + XvBadControl,
+			XvName ":BadControl");
     }
 }
 
commit 35ae03871af88b2f420dd83448011a077852d7a0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 20:50:26 2007 -0400

    registry: Register XC-MISC extension protocol names.

diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index d9a7f10..ba0402c 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -39,6 +39,7 @@ from The Open Group.
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "swaprep.h"
+#include "registry.h"
 #include <X11/extensions/xcmiscstr.h>
 #include "modinit.h"
 
@@ -48,10 +49,6 @@ from The Open Group.
 #define UINT32_MAX 0xffffffffU
 #endif
 
-#if 0
-static unsigned char XCMiscCode;
-#endif
-
 static void XCMiscResetProc(
     ExtensionEntry * /* extEntry */
 );
@@ -68,18 +65,19 @@ static DISPATCH_PROC(SProcXCMiscGetXIDRange);
 void
 XCMiscExtensionInit(INITARGS)
 {
-#if 0
     ExtensionEntry *extEntry;
 
-    if ((extEntry = AddExtension(XCMiscExtensionName, 0, 0,
+    if (!(extEntry = AddExtension(XCMiscExtensionName, 0, 0,
 				ProcXCMiscDispatch, SProcXCMiscDispatch,
-				XCMiscResetProc, StandardMinorOpcode)) != 0)
-	XCMiscCode = (unsigned char)extEntry->base;
-#else
-    (void) AddExtension(XCMiscExtensionName, 0, 0,
-			ProcXCMiscDispatch, SProcXCMiscDispatch,
-			XCMiscResetProc, StandardMinorOpcode);
-#endif
+				XCMiscResetProc, StandardMinorOpcode)))
+	return;
+
+    RegisterRequestName(extEntry->base, X_XCMiscGetVersion,
+			XCMiscExtensionName ":GetVersion");
+    RegisterRequestName(extEntry->base, X_XCMiscGetXIDRange,
+			XCMiscExtensionName ":GetXIDRange");
+    RegisterRequestName(extEntry->base, X_XCMiscGetXIDList,
+			XCMiscExtensionName ":GetXIDList");
 }
 
 /*ARGSUSED*/
commit 32fe282d5b8306514d641e15bc6d9fd4ab360977
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 20:45:18 2007 -0400

    registry: Register XTest extension protocol names.

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 79c53b4..3895a00 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -42,6 +42,7 @@ from The Open Group.
 #include "scrnintstr.h"
 #include "dixevents.h"
 #include "sleepuntil.h"
+#include "registry.h"
 #define _XTEST_SERVER_
 #include <X11/extensions/XTest.h>
 #include <X11/extensions/xteststr.h>
@@ -53,10 +54,6 @@ from The Open Group.
 
 #include "modinit.h"
 
-#if 0
-static unsigned char XTestReqCode;
-#endif
-
 #ifdef XINPUT
 extern int DeviceValuator;
 #endif /* XINPUT */
@@ -88,18 +85,21 @@ static DISPATCH_PROC(SProcXTestGrabControl);
 void
 XTestExtensionInit(INITARGS)
 {
-#if 0
     ExtensionEntry *extEntry;
 
-    if ((extEntry = AddExtension(XTestExtensionName, 0, 0,
-				 ProcXTestDispatch, SProcXTestDispatch,
-				 XTestResetProc, StandardMinorOpcode)) != 0)
-	XTestReqCode = (unsigned char)extEntry->base;
-#else
-    (void) AddExtension(XTestExtensionName, 0, 0,
-			ProcXTestDispatch, SProcXTestDispatch,
-			XTestResetProc, StandardMinorOpcode);
-#endif
+    if (!(extEntry = AddExtension(XTestExtensionName, 0, 0,
+				  ProcXTestDispatch, SProcXTestDispatch,
+				  XTestResetProc, StandardMinorOpcode)))
+	return;
+
+    RegisterRequestName(extEntry->base, X_XTestGetVersion,
+			XTestExtensionName ":GetVersion");
+    RegisterRequestName(extEntry->base, X_XTestCompareCursor,
+			XTestExtensionName ":CompareCursor");
+    RegisterRequestName(extEntry->base, X_XTestFakeInput,
+			XTestExtensionName ":FakeInput");
+    RegisterRequestName(extEntry->base, X_XTestGrabControl,
+			XTestExtensionName ":GrabControl");
 }
 
 /*ARGSUSED*/
commit 3877faf7d9fe00ed634077e38a198ae4b91a2bb4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 20:35:13 2007 -0400

    registry: Register Multibuffer extension protocol names.

diff --git a/Xext/mbuf.c b/Xext/mbuf.c
index ee2ef64..701af66 100644
--- a/Xext/mbuf.c
+++ b/Xext/mbuf.c
@@ -43,6 +43,7 @@ in this Software without prior written authorization from The Open Group.
 #include "resource.h"
 #include "opaque.h"
 #include "sleepuntil.h"
+#include "registry.h"
 #define _MULTIBUF_SERVER_	/* don't want Xlib structures */
 #include <X11/extensions/multibufst.h>
 
@@ -254,7 +255,39 @@ MultibufferExtensionInit()
 	MultibufferErrorBase = extEntry->errorBase;
 	EventSwapVector[MultibufferEventBase + MultibufferClobberNotify] = (EventSwapPtr) SClobberNotifyEvent;
 	EventSwapVector[MultibufferEventBase + MultibufferUpdateNotify] = (EventSwapPtr) SUpdateNotifyEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_MbufGetBufferVersion,
+			MULTIBUFFER_PROTOCOL_NAME ":GetBufferVersion");
+    RegisterRequestName(extEntry->base, X_MbufCreateImageBuffers,
+			MULTIBUFFER_PROTOCOL_NAME ":CreateImageBuffers");
+    RegisterRequestName(extEntry->base, X_MbufDestroyImageBuffers,
+			MULTIBUFFER_PROTOCOL_NAME ":DestroyImageBuffers");
+    RegisterRequestName(extEntry->base, X_MbufDisplayImageBuffers,
+			MULTIBUFFER_PROTOCOL_NAME ":DisplayImageBuffers");
+    RegisterRequestName(extEntry->base, X_MbufSetMBufferAttributes,
+			MULTIBUFFER_PROTOCOL_NAME ":SetMBufferAttributes");
+    RegisterRequestName(extEntry->base, X_MbufGetMBufferAttributes,
+			MULTIBUFFER_PROTOCOL_NAME ":GetMBufferAttributes");
+    RegisterRequestName(extEntry->base, X_MbufSetBufferAttributes,
+			MULTIBUFFER_PROTOCOL_NAME ":SetBufferAttributes");
+    RegisterRequestName(extEntry->base, X_MbufGetBufferAttributes,
+			MULTIBUFFER_PROTOCOL_NAME ":GetBufferAttributes");
+    RegisterRequestName(extEntry->base, X_MbufGetBufferInfo,
+			MULTIBUFFER_PROTOCOL_NAME ":GetBufferInfo");
+    RegisterRequestName(extEntry->base, X_MbufCreateStereoWindow,
+			MULTIBUFFER_PROTOCOL_NAME ":CreateStereoWindow");
+    RegisterRequestName(extEntry->base, X_MbufClearImageBufferArea,
+			MULTIBUFFER_PROTOCOL_NAME ":ClearImageBufferArea");
+
+    RegisterEventName(MultibufferEventBase + MultibufferClobberNotify,
+		      MULTIBUFFER_PROTOCOL_NAME ":ClobberNotify");
+    RegisterEventName(MultibufferEventBase + MultibufferUpdateNotify,
+		      MULTIBUFFER_PROTOCOL_NAME ":UpdateNotify");
+
+    RegisterErrorName(MultibufferErrorBase + BadBuffer,
+		      MULTIBUFFER_PROTOCOL_NAME ":BadBuffer");
 }
 
 /*ARGSUSED*/
commit 16764a2d299c7c0c98002aadd52ab4a1a36758c3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 20:29:23 2007 -0400

    registry: Register DPMS extension protocol names.

diff --git a/Xext/dpms.c b/Xext/dpms.c
index 97622cb..613493a 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -44,15 +44,13 @@ Equipment Corporation.
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "opaque.h"
+#include "registry.h"
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 #include <X11/extensions/dpmsstr.h>
 #include "dpmsproc.h"
 #include "modinit.h"
 
-#if 0
-static unsigned char DPMSCode;
-#endif
 static DISPATCH_PROC(ProcDPMSDispatch);
 static DISPATCH_PROC(SProcDPMSDispatch);
 static DISPATCH_PROC(ProcDPMSGetVersion);
@@ -76,18 +74,29 @@ static void DPMSResetProc(ExtensionEntry* extEntry);
 void
 DPMSExtensionInit(INITARGS)
 {
-#if 0
     ExtensionEntry *extEntry;
     
-    if ((extEntry = AddExtension(DPMSExtensionName, 0, 0,
-				ProcDPMSDispatch, SProcDPMSDispatch,
-				DPMSResetProc, StandardMinorOpcode)))
-	DPMSCode = (unsigned char)extEntry->base;
-#else
-    (void) AddExtension(DPMSExtensionName, 0, 0,
-			ProcDPMSDispatch, SProcDPMSDispatch,
-			DPMSResetProc, StandardMinorOpcode);
-#endif
+    if (!(extEntry = AddExtension(DPMSExtensionName, 0, 0,
+				  ProcDPMSDispatch, SProcDPMSDispatch,
+				  DPMSResetProc, StandardMinorOpcode)))
+	return;
+
+    RegisterRequestName(extEntry->base, X_DPMSGetVersion,
+			DPMSExtensionName ":GetVersion");
+    RegisterRequestName(extEntry->base, X_DPMSCapable,
+			DPMSExtensionName ":Capable");
+    RegisterRequestName(extEntry->base, X_DPMSGetTimeouts,
+			DPMSExtensionName ":GetTimeouts");
+    RegisterRequestName(extEntry->base, X_DPMSSetTimeouts,
+			DPMSExtensionName ":SetTimeouts");
+    RegisterRequestName(extEntry->base, X_DPMSEnable,
+			DPMSExtensionName ":Enable");
+    RegisterRequestName(extEntry->base, X_DPMSDisable,
+			DPMSExtensionName ":Disable");
+    RegisterRequestName(extEntry->base, X_DPMSForceLevel,
+			DPMSExtensionName ":ForceLevel");
+    RegisterRequestName(extEntry->base, X_DPMSInfo,
+			DPMSExtensionName ":Info");
 }
 
 /*ARGSUSED*/
commit f077578e42eee424b0e534774574c84af9d6f85b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 19:43:02 2007 -0400

    registry: Register XPrint extension protocol names.

diff --git a/Xext/xprint.c b/Xext/xprint.c
index ef51118..48559dd 100644
--- a/Xext/xprint.c
+++ b/Xext/xprint.c
@@ -80,6 +80,7 @@ copyright holders.
 #include "pixmapstr.h"
 #include "extnsionst.h"
 #include "dixstruct.h"
+#include "registry.h"
 #include <X11/Xatom.h>
 #include <X11/extensions/Print.h>
 #include <X11/extensions/Printstr.h>
@@ -310,6 +311,69 @@ XpExtensionInit(INITARGS)
 	    screenInfo.screens[i]->CloseScreen = XpCloseScreen;
 	}
     }
+
+    RegisterRequestName(XpReqCode, X_PrintQueryVersion,
+			XP_PRINTNAME ":QueryVersion");
+    RegisterRequestName(XpReqCode, X_PrintGetPrinterList,
+			XP_PRINTNAME ":GetPrinterList");
+    RegisterRequestName(XpReqCode, X_PrintCreateContext,
+			XP_PRINTNAME ":CreateContext");
+    RegisterRequestName(XpReqCode, X_PrintSetContext,
+			XP_PRINTNAME ":SetContext");
+    RegisterRequestName(XpReqCode, X_PrintGetContext,
+			XP_PRINTNAME ":GetContext");
+    RegisterRequestName(XpReqCode, X_PrintDestroyContext,
+			XP_PRINTNAME ":DestroyContext");
+    RegisterRequestName(XpReqCode, X_PrintGetContextScreen,
+			XP_PRINTNAME ":GetContextScreen");
+    RegisterRequestName(XpReqCode, X_PrintStartJob,
+			XP_PRINTNAME ":StartJob");
+    RegisterRequestName(XpReqCode, X_PrintEndJob,
+			XP_PRINTNAME ":EndJob");
+    RegisterRequestName(XpReqCode, X_PrintStartDoc,
+			XP_PRINTNAME ":StartDoc");
+    RegisterRequestName(XpReqCode, X_PrintEndDoc,
+			XP_PRINTNAME ":EndDoc");
+    RegisterRequestName(XpReqCode, X_PrintPutDocumentData,
+			XP_PRINTNAME ":PutDocumentData");
+    RegisterRequestName(XpReqCode, X_PrintGetDocumentData,
+			XP_PRINTNAME ":GetDocumentData");
+    RegisterRequestName(XpReqCode, X_PrintStartPage,
+			XP_PRINTNAME ":StartPage");
+    RegisterRequestName(XpReqCode, X_PrintEndPage,
+			XP_PRINTNAME ":EndPage");
+    RegisterRequestName(XpReqCode, X_PrintSelectInput,
+			XP_PRINTNAME ":SelectInput");
+    RegisterRequestName(XpReqCode, X_PrintInputSelected,
+			XP_PRINTNAME ":InputSelected");
+    RegisterRequestName(XpReqCode, X_PrintGetAttributes,
+			XP_PRINTNAME ":GetAttributes");
+    RegisterRequestName(XpReqCode, X_PrintSetAttributes,
+			XP_PRINTNAME ":SetAttributes");
+    RegisterRequestName(XpReqCode, X_PrintGetOneAttribute,
+			XP_PRINTNAME ":GetOneAttribute");
+    RegisterRequestName(XpReqCode, X_PrintRehashPrinterList,
+			XP_PRINTNAME ":RehashPrinterList");
+    RegisterRequestName(XpReqCode, X_PrintGetPageDimensions,
+			XP_PRINTNAME ":GetPageDimensions");
+    RegisterRequestName(XpReqCode, X_PrintQueryScreens,
+			XP_PRINTNAME ":QueryScreens");
+    RegisterRequestName(XpReqCode, X_PrintSetImageResolution,
+			XP_PRINTNAME ":SetImageResolution");
+    RegisterRequestName(XpReqCode, X_PrintGetImageResolution,
+			XP_PRINTNAME ":GetImageResolution");
+
+    RegisterEventName(XpEventBase + XPPrintNotify,
+		      XP_PRINTNAME ":PrintNotify");
+    RegisterEventName(XpEventBase + XPAttributeNotify,
+		      XP_PRINTNAME ":AttributeNotify");
+
+    RegisterErrorName(XpErrorBase + XPBadContext,
+		      XP_PRINTNAME ":BadContext");
+    RegisterErrorName(XpErrorBase + XPBadSequence,
+		      XP_PRINTNAME ":BadSequence");
+    RegisterErrorName(XpErrorBase + XPBadResourceID,
+		      XP_PRINTNAME ":BadResourceID");
 }
 
 static void
commit 5c8b1a91726817816d20faefad21c7a68ab634cc
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 19:35:04 2007 -0400

    registry: Register Resource extension protocol names.

diff --git a/Xext/xres.c b/Xext/xres.c
index 3660260..e78176e 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -17,6 +17,7 @@
 #include "dixstruct.h"
 #include "extnsionst.h"
 #include "swaprep.h"
+#include "registry.h"
 #include <X11/extensions/XResproto.h>
 #include "pixmapstr.h"
 #include "windowstr.h"
@@ -388,7 +389,18 @@ SProcResDispatch (ClientPtr client)
 void
 ResExtensionInit(INITARGS)
 {
-    (void) AddExtension(XRES_NAME, 0, 0,
+    ExtensionEntry *extEntry;
+
+    extEntry = AddExtension(XRES_NAME, 0, 0,
                             ProcResDispatch, SProcResDispatch,
                             ResResetProc, StandardMinorOpcode);
+
+    RegisterRequestName(extEntry->base, X_XResQueryVersion,
+			XRES_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_XResQueryClients,
+			XRES_NAME ":QueryClients");
+    RegisterRequestName(extEntry->base, X_XResQueryClientResources,
+			XRES_NAME ":QueryClientResources");
+    RegisterRequestName(extEntry->base, X_XResQueryClientPixmapBytes,
+			XRES_NAME ":QueryClientPixmapBytes");
 }
commit 48891d5696f56711f23743cb03be39cf6b26c522
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 19:32:01 2007 -0400

    registry: Register EVIE extension protocol names.

diff --git a/Xext/xevie.c b/Xext/xevie.c
index 7dd67bb..8dc1678 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -45,6 +45,7 @@ of the copyright holder.
 #include "colormapst.h"
 #include "scrnintstr.h"
 #include "servermd.h"
+#include "registry.h"
 #define  _XEVIE_SERVER_
 #include <X11/extensions/Xeviestr.h>
 #include <X11/Xfuncproto.h>
@@ -146,9 +147,21 @@ XevieExtensionInit (void)
 				StandardMinorOpcode))) {
 	ReqCode = (unsigned char)extEntry->base;
 	ErrorBase = extEntry->errorBase;
-    }
+    } else
+	return;
 
     /* PC servers initialize the desktop colors (citems) here! */
+
+    RegisterRequestName(ReqCode, X_XevieQueryVersion,
+			XEVIENAME ":QueryVersion");
+    RegisterRequestName(ReqCode, X_XevieStart,
+			XEVIENAME ":Start");
+    RegisterRequestName(ReqCode, X_XevieEnd,
+			XEVIENAME ":End");
+    RegisterRequestName(ReqCode, X_XevieSend,
+			XEVIENAME ":Send");
+    RegisterRequestName(ReqCode, X_XevieSelectInput,
+			XEVIENAME ":SelectInput");
 }
 
 /*ARGSUSED*/
commit 2c9646ad4e65bb061d910c9e2b1a8a978f21fa17
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 19:18:03 2007 -0400

    registry: Register SHM extension protocol names.

diff --git a/Xext/shm.c b/Xext/shm.c
index ee4c340..56a944b 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -59,6 +59,7 @@ in this Software without prior written authorization from The Open Group.
 #include "servermd.h"
 #include "shmint.h"
 #include "xace.h"
+#include "registry.h"
 #define _XSHM_SERVER_
 #include <X11/extensions/shmstr.h>
 #include <X11/Xfuncproto.h>
@@ -246,7 +247,27 @@ ShmExtensionInit(INITARGS)
 	ShmCompletionCode = extEntry->eventBase;
 	BadShmSegCode = extEntry->errorBase;
 	EventSwapVector[ShmCompletionCode] = (EventSwapPtr) SShmCompletionEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(ShmReqCode, X_ShmQueryVersion,
+			SHMNAME ":QueryVersion");
+    RegisterRequestName(ShmReqCode, X_ShmAttach,
+			SHMNAME ":Attach");
+    RegisterRequestName(ShmReqCode, X_ShmDetach,
+			SHMNAME ":Detach");
+    RegisterRequestName(ShmReqCode, X_ShmPutImage,
+			SHMNAME ":PutImage");
+    RegisterRequestName(ShmReqCode, X_ShmGetImage,
+			SHMNAME ":GetImage");
+    RegisterRequestName(ShmReqCode, X_ShmCreatePixmap,
+			SHMNAME ":CreatePixmap");
+
+    RegisterEventName(extEntry->eventBase + ShmCompletion,
+		      SHMNAME ":Completion");
+
+    RegisterErrorName(extEntry->errorBase + BadShmSeg,
+		      SHMNAME ":BadShmSeg");
 }
 
 /*ARGSUSED*/
commit 8964c6d8e14ae47798762191e359b2bf138ca32e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 19:10:51 2007 -0400

    registry: Register RENDER extension protocol names.

diff --git a/render/render.c b/render/render.c
index 40d5add..fe50dd2 100644
--- a/render/render.c
+++ b/render/render.c
@@ -40,6 +40,7 @@
 #include "colormapst.h"
 #include "extnsionst.h"
 #include "servermd.h"
+#include "registry.h"
 #include <X11/extensions/render.h>
 #include <X11/extensions/renderproto.h>
 #include "picturestr.h"
@@ -262,6 +263,95 @@ RenderExtensionInit (void)
     RenderReqCode = (CARD8) extEntry->base;
 #endif
     RenderErrBase = extEntry->errorBase;
+
+    RegisterRequestName(extEntry->base, X_RenderQueryVersion,
+			RENDER_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_RenderQueryPictFormats,
+			RENDER_NAME ":QueryPictFormats");
+    RegisterRequestName(extEntry->base, X_RenderQueryPictIndexValues,
+			RENDER_NAME ":QueryPictIndexValues");
+    RegisterRequestName(extEntry->base, X_RenderQueryDithers,
+			RENDER_NAME ":QueryDithers");
+    RegisterRequestName(extEntry->base, X_RenderCreatePicture,
+			RENDER_NAME ":CreatePicture");
+    RegisterRequestName(extEntry->base, X_RenderChangePicture,
+			RENDER_NAME ":ChangePicture");
+    RegisterRequestName(extEntry->base, X_RenderSetPictureClipRectangles,
+			RENDER_NAME ":SetPictureClipRectangles");
+    RegisterRequestName(extEntry->base, X_RenderFreePicture,
+			RENDER_NAME ":FreePicture");
+    RegisterRequestName(extEntry->base, X_RenderComposite,
+			RENDER_NAME ":Composite");
+    RegisterRequestName(extEntry->base, X_RenderScale,
+			RENDER_NAME ":Scale");
+    RegisterRequestName(extEntry->base, X_RenderTrapezoids,
+			RENDER_NAME ":Trapezoids");
+    RegisterRequestName(extEntry->base, X_RenderTriangles,
+			RENDER_NAME ":Triangles");
+    RegisterRequestName(extEntry->base, X_RenderTriStrip,
+			RENDER_NAME ":TriStrip");
+    RegisterRequestName(extEntry->base, X_RenderTriFan,
+			RENDER_NAME ":TriFan");
+    RegisterRequestName(extEntry->base, X_RenderColorTrapezoids,
+			RENDER_NAME ":ColorTrapezoids");
+    RegisterRequestName(extEntry->base, X_RenderColorTriangles,
+			RENDER_NAME ":ColorTriangles");
+    RegisterRequestName(extEntry->base, X_RenderCreateGlyphSet,
+			RENDER_NAME ":CreateGlyphSet");
+    RegisterRequestName(extEntry->base, X_RenderReferenceGlyphSet,
+			RENDER_NAME ":ReferenceGlyphSet");
+    RegisterRequestName(extEntry->base, X_RenderFreeGlyphSet,
+			RENDER_NAME ":FreeGlyphSet");
+    RegisterRequestName(extEntry->base, X_RenderAddGlyphs,
+			RENDER_NAME ":AddGlyphs");
+    RegisterRequestName(extEntry->base, X_RenderAddGlyphsFromPicture,
+			RENDER_NAME ":AddGlyphsFromPicture");
+    RegisterRequestName(extEntry->base, X_RenderFreeGlyphs,
+			RENDER_NAME ":FreeGlyphs");
+    RegisterRequestName(extEntry->base, X_RenderCompositeGlyphs8,
+			RENDER_NAME ":CompositeGlyphs8");
+    RegisterRequestName(extEntry->base, X_RenderCompositeGlyphs16,
+			RENDER_NAME ":CompositeGlyphs16");
+    RegisterRequestName(extEntry->base, X_RenderCompositeGlyphs32,
+			RENDER_NAME ":CompositeGlyphs32");
+    RegisterRequestName(extEntry->base, X_RenderFillRectangles,
+			RENDER_NAME ":FillRectangles");
+    /* 0.5 */
+    RegisterRequestName(extEntry->base, X_RenderCreateCursor,
+			RENDER_NAME ":CreateCursor");
+    /* 0.6 */
+    RegisterRequestName(extEntry->base, X_RenderSetPictureTransform,
+			RENDER_NAME ":SetPictureTransform");
+    RegisterRequestName(extEntry->base, X_RenderQueryFilters,
+			RENDER_NAME ":QueryFilters");
+    RegisterRequestName(extEntry->base, X_RenderSetPictureFilter,
+			RENDER_NAME ":SetPictureFilter");
+    /* 0.8 */
+    RegisterRequestName(extEntry->base, X_RenderCreateAnimCursor,
+			RENDER_NAME ":CreateAnimCursor");
+    /* 0.9 */
+    RegisterRequestName(extEntry->base, X_RenderAddTraps,
+			RENDER_NAME ":AddTraps");
+    /* 0.10 */
+    RegisterRequestName(extEntry->base, X_RenderCreateSolidFill,
+			RENDER_NAME ":CreateSolidFill");
+    RegisterRequestName(extEntry->base, X_RenderCreateLinearGradient,
+			RENDER_NAME ":CreateLinearGradient");
+    RegisterRequestName(extEntry->base, X_RenderCreateRadialGradient,
+			RENDER_NAME ":CreateRadialGradient");
+    RegisterRequestName(extEntry->base, X_RenderCreateConicalGradient,
+			RENDER_NAME ":CreateConicalGradient");
+
+    RegisterErrorName(RenderErrBase + BadPictFormat,
+		      RENDER_NAME ":BadPictFormat");
+    RegisterErrorName(RenderErrBase + BadPicture,
+		      RENDER_NAME ":BadPicture");
+    RegisterErrorName(RenderErrBase + BadPictOp,
+		      RENDER_NAME ":BadPictOp");
+    RegisterErrorName(RenderErrBase + BadGlyphSet,
+		      RENDER_NAME ":BadGlyphSet");
+    RegisterErrorName(RenderErrBase + BadGlyph,
+		      RENDER_NAME ":BadGlyph");
 }
 
 static void
commit c827db57e4d9ca14c82b099dcfc9b7a0c0b5ba0a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 19:06:01 2007 -0400

    registry: Register RANDR extension protocol names.

diff --git a/randr/randr.c b/randr/randr.c
index bc2b995..d5b9819 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -32,6 +32,7 @@
 #endif
 
 #include "randrstr.h"
+#include "registry.h"
 
 /* From render.h */
 #ifndef SubPixelUnknown
@@ -351,6 +352,73 @@ RRExtensionInit (void)
 #ifdef PANORAMIX
     RRXineramaExtensionInit();
 #endif
+
+    RegisterRequestName(extEntry->base, X_RRQueryVersion,
+			RANDR_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_RROldGetScreenInfo,
+			RANDR_NAME ":OldGetScreenInfo");
+    RegisterRequestName(extEntry->base, X_RR1_0SetScreenConfig,
+			RANDR_NAME ":1_0SetScreenConfig");
+    RegisterRequestName(extEntry->base, X_RRSetScreenConfig,
+			RANDR_NAME ":SetScreenConfig");
+    RegisterRequestName(extEntry->base, X_RROldScreenChangeSelectInput,
+			RANDR_NAME ":OldScreenChangeSelectInput");
+    RegisterRequestName(extEntry->base, X_RRSelectInput,
+			RANDR_NAME ":SelectInput");
+    RegisterRequestName(extEntry->base, X_RRGetScreenInfo,
+			RANDR_NAME ":GetScreenInfo");
+    /* V1.2 additions */
+    RegisterRequestName(extEntry->base, X_RRGetScreenSizeRange,
+			RANDR_NAME ":GetScreenSizeRange");
+    RegisterRequestName(extEntry->base, X_RRSetScreenSize,
+			RANDR_NAME ":SetScreenSize");
+    RegisterRequestName(extEntry->base, X_RRGetScreenResources,
+			RANDR_NAME ":GetScreenResources");
+    RegisterRequestName(extEntry->base, X_RRGetOutputInfo,
+			RANDR_NAME ":GetOutputInfo");
+    RegisterRequestName(extEntry->base, X_RRListOutputProperties,
+			RANDR_NAME ":ListOutputProperties");
+    RegisterRequestName(extEntry->base, X_RRQueryOutputProperty,
+			RANDR_NAME ":QueryOutputProperty");
+    RegisterRequestName(extEntry->base, X_RRConfigureOutputProperty,
+			RANDR_NAME ":ConfigureOutputProperty");
+    RegisterRequestName(extEntry->base, X_RRChangeOutputProperty,
+			RANDR_NAME ":ChangeOutputProperty");
+    RegisterRequestName(extEntry->base, X_RRDeleteOutputProperty,
+			RANDR_NAME ":DeleteOutputProperty");
+    RegisterRequestName(extEntry->base, X_RRGetOutputProperty,
+			RANDR_NAME ":GetOutputProperty");
+    RegisterRequestName(extEntry->base, X_RRCreateMode,
+			RANDR_NAME ":CreateMode");
+    RegisterRequestName(extEntry->base, X_RRDestroyMode,
+			RANDR_NAME ":DestroyMode");
+    RegisterRequestName(extEntry->base, X_RRAddOutputMode,
+			RANDR_NAME ":AddOutputMode");
+    RegisterRequestName(extEntry->base, X_RRDeleteOutputMode,
+			RANDR_NAME ":DeleteOutputMode");
+    RegisterRequestName(extEntry->base, X_RRGetCrtcInfo,
+			RANDR_NAME ":GetCrtcInfo");
+    RegisterRequestName(extEntry->base, X_RRSetCrtcConfig,
+			RANDR_NAME ":SetCrtcConfig");
+    RegisterRequestName(extEntry->base, X_RRGetCrtcGammaSize,
+			RANDR_NAME ":GetCrtcGammaSize");
+    RegisterRequestName(extEntry->base, X_RRGetCrtcGamma,
+			RANDR_NAME ":GetCrtcGamma");
+    RegisterRequestName(extEntry->base, X_RRSetCrtcGamma,
+			RANDR_NAME ":SetCrtcGamma");
+
+    RegisterEventName(RREventBase + RRScreenChangeNotify,
+		      RANDR_NAME ":ScreenChangeNotify");
+    /* V1.2 additions */
+    RegisterEventName(RREventBase + RRNotify,
+		      RANDR_NAME ":Notify");
+
+    RegisterErrorName(RRErrorBase + BadRROutput,
+		      RANDR_NAME ":BadRROutput");
+    RegisterErrorName(RRErrorBase + BadRRCrtc,
+		      RANDR_NAME ":BadRRCrtc");
+    RegisterErrorName(RRErrorBase + BadRRMode,
+		      RANDR_NAME ":BadRRMode");
 }
 
 static int
commit 20db50b4c44a14f7eeac2b1de17ada68482521da
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 18:56:59 2007 -0400

    registry: Register DAMAGE extension protocol names.

diff --git a/damageext/damageext.c b/damageext/damageext.c
index 517c72d..ac2198b 100755
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -25,6 +25,7 @@
 #endif
 
 #include "damageextint.h"
+#include "registry.h"
 
 static unsigned char	DamageReqCode;
 static int		DamageEventBase;
@@ -526,5 +527,23 @@ DamageExtensionInit(void)
 	DamageErrorBase = extEntry->errorBase;
 	EventSwapVector[DamageEventBase + XDamageNotify] =
 			(EventSwapPtr) SDamageNotifyEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(DamageReqCode, X_DamageQueryVersion,
+			DAMAGE_NAME ":QueryVersion");
+    RegisterRequestName(DamageReqCode, X_DamageCreate,
+			DAMAGE_NAME ":Create");
+    RegisterRequestName(DamageReqCode, X_DamageDestroy,
+			DAMAGE_NAME ":Destroy");
+    RegisterRequestName(DamageReqCode, X_DamageSubtract,
+			DAMAGE_NAME ":Subtract");
+    RegisterRequestName(DamageReqCode, X_DamageAdd,
+			DAMAGE_NAME ":Add");
+
+    RegisterEventName(DamageEventBase + XDamageNotify,
+			DAMAGE_NAME ":Notify");
+
+    RegisterErrorName(extEntry->errorBase + BadDamage,
+			DAMAGE_NAME ":BadDamage");
 }
commit b38a91993364aa80cfd99721e319e1458d9fb760
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 18:50:06 2007 -0400

    registry: Register XTrap extension protocol names.

diff --git a/XTrap/xtrapdi.c b/XTrap/xtrapdi.c
index efad36f..734922c 100644
--- a/XTrap/xtrapdi.c
+++ b/XTrap/xtrapdi.c
@@ -62,6 +62,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "misc.h"               /* Server swapping macros */
 #include "dixstruct.h"          /* Server ClientRec definitions */
 #include "resource.h"           /* Used with the MakeAtom call */
+#include "registry.h"
 #ifdef PC
 # include "scrintst.h"          /* Screen struct */
 # include "extnsist.h"
@@ -463,6 +464,41 @@ void DEC_XTRAPInit()
         XETrap_avail.data.xtrap_revision);
 #endif
 
+    RegisterRequestName(extEntry->base, XETrap_Reset,
+			XTrapExtName ":Reset");
+    RegisterRequestName(extEntry->base, XETrap_GetAvailable,
+			XTrapExtName ":GetAvailable");
+    RegisterRequestName(extEntry->base, XETrap_Config,
+			XTrapExtName ":Config");
+    RegisterRequestName(extEntry->base, XETrap_StartTrap,
+			XTrapExtName ":StartTrap");
+    RegisterRequestName(extEntry->base, XETrap_StopTrap,
+			XTrapExtName ":StopTrap");
+    RegisterRequestName(extEntry->base, XETrap_GetCurrent,
+			XTrapExtName ":GetCurrent");
+    RegisterRequestName(extEntry->base, XETrap_GetStatistics,
+			XTrapExtName ":GetStatistics");
+#ifndef _XINPUT
+    RegisterRequestName(extEntry->base, XETrap_SimulateXEvent,
+			XTrapExtName ":SimulateXEvent");
+#endif
+    RegisterRequestName(extEntry->base, XETrap_GetVersion,
+			XTrapExtName ":GetVersion");
+    RegisterRequestName(extEntry->base, XETrap_GetLastInpTime,
+			XTrapExtName ":GetLastInpTime");
+
+    RegisterEventName(extEntry->eventBase, XTrapExtName ":Event");
+
+    RegisterErrorName(extEntry->errorBase + BadIO,
+			XTrapExtName ":BadIO");
+    RegisterErrorName(extEntry->errorBase + BadStatistics,
+			XTrapExtName ":BadStatistics");
+    RegisterErrorName(extEntry->errorBase + BadDevices,
+			XTrapExtName ":BadDevices");
+    RegisterErrorName(extEntry->errorBase + BadScreen,
+			XTrapExtName ":BadScreen");
+    RegisterErrorName(extEntry->errorBase + BadSwapReq,
+			XTrapExtName ":BadSwapReq");
     return;
 }
 
commit 106758893b68033f14f69c4ee6591fb6a149ba37
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 18:31:40 2007 -0400

    registry: Register XFixes extension protocol names.

diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 0db4989..ccce7b9 100755
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -45,6 +45,7 @@
 #endif
 
 #include "xfixesint.h"
+#include "registry.h"
 
 /*
  * Must use these instead of the constants from xfixeswire.h.  They advertise
@@ -257,5 +258,80 @@ XFixesExtensionInit(void)
 	    (EventSwapPtr) SXFixesSelectionNotifyEvent;
 	EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
 	    (EventSwapPtr) SXFixesCursorNotifyEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(XFixesReqCode, X_XFixesQueryVersion,
+			XFIXES_NAME ":QueryVersion");
+    RegisterRequestName(XFixesReqCode, X_XFixesChangeSaveSet,
+			XFIXES_NAME ":ChangeSaveSet");
+    RegisterRequestName(XFixesReqCode, X_XFixesSelectSelectionInput,
+			XFIXES_NAME ":SelectSelectionInput");
+    RegisterRequestName(XFixesReqCode, X_XFixesSelectCursorInput,
+			XFIXES_NAME ":SelectCursorInput");
+    RegisterRequestName(XFixesReqCode, X_XFixesGetCursorImage,
+			XFIXES_NAME ":GetCursorImage");
+    /*************** Version 2 ******************/
+    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegion,
+			XFIXES_NAME ":CreateRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromBitmap,
+			XFIXES_NAME ":CreateRegionFromBitmap");
+    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromWindow,
+			XFIXES_NAME ":CreateRegionFromWindow");
+    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromGC,
+			XFIXES_NAME ":CreateRegionFromGC");
+    RegisterRequestName(XFixesReqCode, X_XFixesCreateRegionFromPicture,
+			XFIXES_NAME ":CreateRegionFromPicture");
+    RegisterRequestName(XFixesReqCode, X_XFixesDestroyRegion,
+			XFIXES_NAME ":DestroyRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesSetRegion,
+			XFIXES_NAME ":SetRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesCopyRegion,
+			XFIXES_NAME ":CopyRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesUnionRegion,
+			XFIXES_NAME ":UnionRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesIntersectRegion,
+			XFIXES_NAME ":IntersectRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesSubtractRegion,
+			XFIXES_NAME ":SubtractRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesInvertRegion,
+			XFIXES_NAME ":InvertRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesTranslateRegion,
+			XFIXES_NAME ":TranslateRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesRegionExtents,
+			XFIXES_NAME ":RegionExtents");
+    RegisterRequestName(XFixesReqCode, X_XFixesFetchRegion,
+			XFIXES_NAME ":FetchRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesSetGCClipRegion,
+			XFIXES_NAME ":SetGCClipRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesSetWindowShapeRegion,
+			XFIXES_NAME ":SetWindowShapeRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesSetPictureClipRegion,
+			XFIXES_NAME ":SetPictureClipRegion");
+    RegisterRequestName(XFixesReqCode, X_XFixesSetCursorName,
+			XFIXES_NAME ":SetCursorName");
+    RegisterRequestName(XFixesReqCode, X_XFixesGetCursorName,
+			XFIXES_NAME ":GetCursorName");
+    RegisterRequestName(XFixesReqCode, X_XFixesGetCursorImageAndName,
+			XFIXES_NAME ":GetCursorImageAndName");
+    RegisterRequestName(XFixesReqCode, X_XFixesChangeCursor,
+			XFIXES_NAME ":ChangeCursor");
+    RegisterRequestName(XFixesReqCode, X_XFixesChangeCursorByName,
+			XFIXES_NAME ":ChangeCursorByName");
+    /*************** Version 3 ******************/
+    RegisterRequestName(XFixesReqCode, X_XFixesExpandRegion,
+			XFIXES_NAME ":ExpandRegion");
+    /*************** Version 4 ******************/
+    RegisterRequestName(XFixesReqCode, X_XFixesHideCursor,
+			XFIXES_NAME ":HideCursor");
+    RegisterRequestName(XFixesReqCode, X_XFixesShowCursor,
+			XFIXES_NAME ":ShowCursor");
+
+    RegisterEventName(XFixesEventBase + XFixesSelectionNotify,
+			XFIXES_NAME ":SelectionNotify");
+    RegisterEventName(XFixesEventBase + XFixesCursorNotify,
+			XFIXES_NAME ":CursorNotify");
+
+    RegisterErrorName(XFixesErrorBase + BadRegion,
+			XFIXES_NAME ":BadRegion");
 }
commit ea09c9acc8f0d5577f54c864ff88b7f03d93b2f4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 18:25:12 2007 -0400

    registry: Register Record extension protocol names.

diff --git a/record/record.c b/record/record.c
index 2e65e67..5772baf 100644
--- a/record/record.c
+++ b/record/record.c
@@ -43,6 +43,7 @@ and Jim Haggerty of Metheus.
 #include <X11/extensions/recordstr.h>
 #include "set.h"
 #include "swaprep.h"
+#include "registry.h"
 
 #include <stdio.h>
 #include <assert.h>
@@ -2965,5 +2966,24 @@ RecordExtensionInit(void)
     }
     RecordErrorBase = extentry->errorBase;
 
+    RegisterRequestName(extentry->base, X_RecordQueryVersion,
+			RECORD_NAME ":QueryVersion");
+    RegisterRequestName(extentry->base, X_RecordCreateContext,
+			RECORD_NAME ":CreateContext");
+    RegisterRequestName(extentry->base, X_RecordRegisterClients,
+			RECORD_NAME ":RegisterClients");
+    RegisterRequestName(extentry->base, X_RecordUnregisterClients,
+			RECORD_NAME ":UnregisterClients");
+    RegisterRequestName(extentry->base, X_RecordGetContext,
+			RECORD_NAME ":GetContext");
+    RegisterRequestName(extentry->base, X_RecordEnableContext,
+			RECORD_NAME ":EnableContext");
+    RegisterRequestName(extentry->base, X_RecordDisableContext,
+			RECORD_NAME ":DisableContext");
+    RegisterRequestName(extentry->base, X_RecordFreeContext,
+			RECORD_NAME ":FreeContext");
+
+    RegisterErrorName(RecordErrorBase + XRecordBadContext,
+			RECORD_NAME ":BadContext");
 } /* RecordExtensionInit */
 
commit 2e1e5be1d9067816525aa13a1d818e8ca6899599
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 18:18:57 2007 -0400

    registry: Register DBE extension protocol names.

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 8175a35..a872544 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -51,6 +51,7 @@
 #include "extnsionst.h"
 #include "gcstruct.h"
 #include "dixstruct.h"
+#include "registry.h"
 #define NEED_DBE_PROTOCOL
 #include "dbestruct.h"
 #include "midbe.h"
@@ -1747,5 +1748,25 @@ DbeExtensionInit(void)
 
     dbeErrorBase = extEntry->errorBase;
 
+    RegisterRequestName(extEntry->base, X_DbeGetVersion,
+			DBE_PROTOCOL_NAME ":GetVersion");
+    RegisterRequestName(extEntry->base, X_DbeAllocateBackBufferName,
+			DBE_PROTOCOL_NAME ":AllocateBackBufferName");
+    RegisterRequestName(extEntry->base, X_DbeDeallocateBackBufferName,
+			DBE_PROTOCOL_NAME ":DeallocateBackBufferName");
+    RegisterRequestName(extEntry->base, X_DbeSwapBuffers,
+			DBE_PROTOCOL_NAME ":SwapBuffers");
+    RegisterRequestName(extEntry->base, X_DbeBeginIdiom,
+			DBE_PROTOCOL_NAME ":BeginIdiom");
+    RegisterRequestName(extEntry->base, X_DbeEndIdiom,
+			DBE_PROTOCOL_NAME ":EndIdiom");
+    RegisterRequestName(extEntry->base, X_DbeGetVisualInfo,
+			DBE_PROTOCOL_NAME ":GetVisualInfo");
+    RegisterRequestName(extEntry->base, X_DbeGetBackBufferAttributes,
+			DBE_PROTOCOL_NAME ":GetBackBufferAttributes");
+
+    RegisterErrorName(dbeErrorBase + DbeBadBuffer,
+		      DBE_PROTOCOL_NAME ":BadBuffer");
+
 } /* DbeExtensionInit() */
 
commit 4c3285c883cc50a91bc5262bbc9d073d816f860a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 18:04:47 2007 -0400

    registry: Register WINDOWSWM extension protocol names.

diff --git a/hw/xwin/winwindowswm.c b/hw/xwin/winwindowswm.c
index e1994de..1356465 100755
--- a/hw/xwin/winwindowswm.c
+++ b/hw/xwin/winwindowswm.c
@@ -41,6 +41,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "scrnintstr.h"
 #include "servermd.h"
 #include "swaprep.h"
+#include "registry.h"
 #define _WINDOWSWM_SERVER_
 #include "windowswmstr.h"
 
@@ -105,7 +106,35 @@ winWindowsWMExtensionInit ()
       WMErrorBase = extEntry->errorBase;
       WMEventBase = extEntry->eventBase;
       EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
-    }
+    } else
+      return;
+
+  RegisterRequestName(WMReqCode, X_WindowsWMQueryVersion,
+		      WINDOWSWMNAME ":QueryVersion");
+  RegisterRequestName(WMReqCode, X_WindowsWMFrameGetRect,
+		      WINDOWSWMNAME ":FrameGetRect");
+  RegisterRequestName(WMReqCode, X_WindowsWMFrameDraw,
+		      WINDOWSWMNAME ":FrameDraw");
+  RegisterRequestName(WMReqCode, X_WindowsWMFrameSetTitle,
+		      WINDOWSWMNAME ":FrameSetTitle");
+  RegisterRequestName(WMReqCode, X_WindowsWMDisableUpdate,
+		      WINDOWSWMNAME ":DisableUpdate");
+  RegisterRequestName(WMReqCode, X_WindowsWMReenableUpdate,
+		      WINDOWSWMNAME ":ReenableUpdate");
+  RegisterRequestName(WMReqCode, X_WindowsWMSelectInput,
+		      WINDOWSWMNAME ":SelectInput");
+  RegisterRequestName(WMReqCode, X_WindowsWMSetFrontProcess,
+		      WINDOWSWMNAME ":SetFrontProcess");
+
+  RegisterEventName(WMEventBase + WindowsWMControllerNotify,
+		    WINDOWSWMNAME ":ControllerNotify");
+  RegisterEventName(WMEventBase + WindowsWMActivationNotify,
+		    WINDOWSWMNAME ":ActivationNotify");
+
+  RegisterErrorName(WMErrorBase + WindowsWMClientNotLocal,
+		    WINDOWSWMNAME ":ClientNotLocal");
+  RegisterErrorName(WMErrorBase + WindowsWMOperationNotSupported,
+		    WINDOWSWMNAME ":OperationNotSupported");
 }
 
 /*ARGSUSED*/
commit 3815284e899b61731b6a63c4ba14c5d773e24eb6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 17:57:59 2007 -0400

    registry: Register XF86DGA extension protocol names.

diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 295e05e..3b866c7 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -22,6 +22,7 @@
 #include "cursorstr.h"
 #include "scrnintstr.h"
 #include "servermd.h"
+#include "registry.h"
 #define _XF86DGA_SERVER_
 #include <X11/extensions/xf86dga.h>
 #include <X11/extensions/xf86dgastr.h>
@@ -99,7 +100,72 @@ XFree86DGAExtensionInit(INITARGS)
 	DGAEventBase = extEntry->eventBase;
 	for (i = KeyPress; i <= MotionNotify; i++)
 	    SetCriticalEvent (DGAEventBase + i);
-    }
+    } else
+	return;
+
+    RegisterRequestName(DGAReqCode, X_XF86DGAQueryVersion,
+			XF86DGANAME ":QueryVersion");
+    RegisterRequestName(DGAReqCode, X_XF86DGAGetVideoLL,
+			XF86DGANAME ":GetVideoLL");
+    RegisterRequestName(DGAReqCode, X_XF86DGADirectVideo,
+			XF86DGANAME ":DirectVideo");
+    RegisterRequestName(DGAReqCode, X_XF86DGAGetViewPortSize,
+			XF86DGANAME ":GetViewPortSize");
+    RegisterRequestName(DGAReqCode, X_XF86DGASetViewPort,
+			XF86DGANAME ":SetViewPort");
+    RegisterRequestName(DGAReqCode, X_XF86DGAGetVidPage,
+			XF86DGANAME ":GetVidPage");
+    RegisterRequestName(DGAReqCode, X_XF86DGASetVidPage,
+			XF86DGANAME ":SetVidPage");
+    RegisterRequestName(DGAReqCode, X_XF86DGAInstallColormap,
+			XF86DGANAME ":InstallColormap");
+    RegisterRequestName(DGAReqCode, X_XF86DGAQueryDirectVideo,
+			XF86DGANAME ":QueryDirectVideo");
+    RegisterRequestName(DGAReqCode, X_XF86DGAViewPortChanged,
+			XF86DGANAME ":ViewPortChanged");
+    RegisterRequestName(DGAReqCode, X_XDGAQueryModes,
+			XF86DGANAME ":QueryModes");
+    RegisterRequestName(DGAReqCode, X_XDGASetMode,
+			XF86DGANAME ":SetMode");
+    RegisterRequestName(DGAReqCode, X_XDGASetViewport,
+			XF86DGANAME ":SetViewport");
+    RegisterRequestName(DGAReqCode, X_XDGAInstallColormap,
+			XF86DGANAME ":InstallColormap");
+    RegisterRequestName(DGAReqCode, X_XDGASelectInput,
+			XF86DGANAME ":SelectInput");
+    RegisterRequestName(DGAReqCode, X_XDGAFillRectangle,
+			XF86DGANAME ":FillRectangle");
+    RegisterRequestName(DGAReqCode, X_XDGACopyArea,
+			XF86DGANAME ":CopyArea");
+    RegisterRequestName(DGAReqCode, X_XDGACopyTransparentArea,
+			XF86DGANAME ":CopyTransparentArea");
+    RegisterRequestName(DGAReqCode, X_XDGAGetViewportStatus,
+			XF86DGANAME ":GetViewportStatus");
+    RegisterRequestName(DGAReqCode, X_XDGASync,
+			XF86DGANAME ":Sync");
+    RegisterRequestName(DGAReqCode, X_XDGAOpenFramebuffer,
+			XF86DGANAME ":OpenFramebuffer");
+    RegisterRequestName(DGAReqCode, X_XDGACloseFramebuffer,
+			XF86DGANAME ":CloseFramebuffer");
+    RegisterRequestName(DGAReqCode, X_XDGASetClientVersion,
+			XF86DGANAME ":SetClientVersion");
+    RegisterRequestName(DGAReqCode, X_XDGAChangePixmapMode,
+			XF86DGANAME ":ChangePixmapMode");
+    RegisterRequestName(DGAReqCode, X_XDGACreateColormap,
+			XF86DGANAME ":CreateColormap");
+
+    /* 7 Events: Don't know where they are defined. EFW */
+
+    RegisterErrorName(extEntry->errorBase + XF86DGAClientNotLocal,
+		      XF86DGANAME ":ClientNotLocal");
+    RegisterErrorName(extEntry->errorBase + XF86DGANoDirectVideoMode,
+		      XF86DGANAME ":NoDirectVideoMode");
+    RegisterErrorName(extEntry->errorBase + XF86DGAScreenNotActive,
+		      XF86DGANAME ":ScreenNotActive");
+    RegisterErrorName(extEntry->errorBase + XF86DGADirectNotActivated,
+		      XF86DGANAME ":DirectNotActivated");
+    RegisterErrorName(extEntry->errorBase + XF86DGAOperationNotSupported,
+		      XF86DGANAME ":OperationNotSupported");
 }
 
 
commit 2cd1b32b77e0ceeaccb3f01c4ac13a97c557668c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 17:37:58 2007 -0400

    registry: Register XF86Misc extension protocol names.

diff --git a/hw/xfree86/dixmods/extmod/xf86misc.c b/hw/xfree86/dixmods/extmod/xf86misc.c
index 66278a2..274b1d3 100644
--- a/hw/xfree86/dixmods/extmod/xf86misc.c
+++ b/hw/xfree86/dixmods/extmod/xf86misc.c
@@ -19,6 +19,7 @@
 #include "scrnintstr.h"
 #include "inputstr.h"
 #include "servermd.h"
+#include "registry.h"
 #define _XF86MISC_SERVER_
 #undef _XF86MISC_SAVER_COMPAT_
 #include <X11/extensions/xf86mscstr.h>
@@ -137,7 +138,50 @@ XFree86MiscExtensionInit(void)
 	XF86MiscReqCode = (unsigned char)extEntry->base;
 #endif
 	miscErrorBase = extEntry->errorBase;
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_XF86MiscQueryVersion,
+			XF86MISCNAME ":QueryVersion");
+#ifdef _XF86MISC_SAVER_COMPAT_
+    RegisterRequestName(extEntry->base, X_XF86MiscGetSaver,
+			XF86MISCNAME ":GetSaver");
+    RegisterRequestName(extEntry->base, X_XF86MiscSetSaver,
+			XF86MISCNAME ":SetSaver");
+#endif
+    RegisterRequestName(extEntry->base, X_XF86MiscGetMouseSettings,
+			XF86MISCNAME ":GetMouseSettings");
+    RegisterRequestName(extEntry->base, X_XF86MiscGetKbdSettings,
+			XF86MISCNAME ":GetKbdSettings");
+    RegisterRequestName(extEntry->base, X_XF86MiscSetMouseSettings,
+			XF86MISCNAME ":SetMouseSettings");
+    RegisterRequestName(extEntry->base, X_XF86MiscSetKbdSettings,
+			XF86MISCNAME ":SetKbdSettings");
+    RegisterRequestName(extEntry->base, X_XF86MiscSetGrabKeysState,
+			XF86MISCNAME ":SetGrabKeysState");
+    RegisterRequestName(extEntry->base, X_XF86MiscSetClientVersion,
+			XF86MISCNAME ":SetClientVersion");
+    RegisterRequestName(extEntry->base, X_XF86MiscGetFilePaths,
+			XF86MISCNAME ":GetFilePaths");
+    RegisterRequestName(extEntry->base, X_XF86MiscPassMessage,
+			XF86MISCNAME ":PassMessage");
+
+    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseProtocol,
+			XF86MISCNAME ":BadMouseProtocol");
+    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseBaudRate,
+			XF86MISCNAME ":BadMouseBaudRate");
+    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseFlags,
+			XF86MISCNAME ":BadMouseFlags");
+    RegisterErrorName(extEntry->errorBase + XF86MiscBadMouseCombo,
+			XF86MISCNAME ":BadMouseCombo");
+    RegisterErrorName(extEntry->errorBase + XF86MiscBadKbdType,
+			XF86MISCNAME ":BadKbdType");
+    RegisterErrorName(extEntry->errorBase + XF86MiscModInDevDisabled,
+			XF86MISCNAME ":ModInDevDisabled");
+    RegisterErrorName(extEntry->errorBase + XF86MiscModInDevClientNotLocal,
+			XF86MISCNAME ":ModInDevClientNotLocal");
+    RegisterErrorName(extEntry->errorBase + XF86MiscNoModule,
+			XF86MISCNAME ":NoModule");
 }
 
 /*ARGSUSED*/
commit 960677e876c068400fb45e1764bb5470cd8c389f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 17:30:00 2007 -0400

    registry: Register XF86VidMode extension protocol names.

diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index fa32848..2ad681c 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -43,6 +43,7 @@ from Kaleb S. KEITHLEY
 #include "extnsionst.h"
 #include "scrnintstr.h"
 #include "servermd.h"
+#include "registry.h"
 #define _XF86VIDMODE_SERVER_
 #include <X11/extensions/xf86vmstr.h>
 #include "swaprep.h"
@@ -209,7 +210,71 @@ XFree86VidModeExtensionInit(void)
 	XF86VidModeEventBase = extEntry->eventBase;
 	EventSwapVector[XF86VidModeEventBase] = (EventSwapPtr)SXF86VidModeNotifyEvent;
 #endif
-    }
+    } else
+	return;
+
+    RegisterRequestName(extEntry->base, X_XF86VidModeQueryVersion,
+			XF86VIDMODENAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetModeLine,
+			XF86VIDMODENAME ":GetModeLine");
+    RegisterRequestName(extEntry->base, X_XF86VidModeModModeLine,
+			XF86VIDMODENAME ":ModModeLine");
+    RegisterRequestName(extEntry->base, X_XF86VidModeSwitchMode,
+			XF86VIDMODENAME ":SwitchMode");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetMonitor,
+			XF86VIDMODENAME ":GetMonitor");
+    RegisterRequestName(extEntry->base, X_XF86VidModeLockModeSwitch,
+			XF86VIDMODENAME ":LockModeSwitch");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetAllModeLines,
+			XF86VIDMODENAME ":GetAllModeLines");
+    RegisterRequestName(extEntry->base, X_XF86VidModeAddModeLine,
+			XF86VIDMODENAME ":AddModeLine");
+    RegisterRequestName(extEntry->base, X_XF86VidModeDeleteModeLine,
+			XF86VIDMODENAME ":DeleteModeLine");
+    RegisterRequestName(extEntry->base, X_XF86VidModeValidateModeLine,
+			XF86VIDMODENAME ":ValidateModeLine");
+    RegisterRequestName(extEntry->base, X_XF86VidModeSwitchToMode,
+			XF86VIDMODENAME ":SwitchToMode");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetViewPort,
+			XF86VIDMODENAME ":GetViewPort");
+    RegisterRequestName(extEntry->base, X_XF86VidModeSetViewPort,
+			XF86VIDMODENAME ":SetViewPort");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetDotClocks,
+			XF86VIDMODENAME ":GetDotClocks");
+    RegisterRequestName(extEntry->base, X_XF86VidModeSetClientVersion,
+			XF86VIDMODENAME ":SetClientVersion");
+    RegisterRequestName(extEntry->base, X_XF86VidModeSetGamma,
+			XF86VIDMODENAME ":SetGamma");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetGamma,
+			XF86VIDMODENAME ":GetGamma");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetGammaRamp,
+			XF86VIDMODENAME ":GetGammaRamp");
+    RegisterRequestName(extEntry->base, X_XF86VidModeSetGammaRamp,
+			XF86VIDMODENAME ":SetGammaRamp");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetGammaRampSize,
+			XF86VIDMODENAME ":GetGammaRampSize");
+    RegisterRequestName(extEntry->base, X_XF86VidModeGetPermissions,
+			XF86VIDMODENAME ":GetPermissions");
+
+#ifdef XF86VIDMODE_EVENTS
+    RegisterEventName(extEntry->eventBase + XF86VidModeNotify,
+		      XF86VIDMODENAME ":Notify");
+#endif
+
+    RegisterErrorName(extEntry->errorBase + XF86VidModeBadClock,
+		      XF86VIDMODENAME ":BadClock");
+    RegisterErrorName(extEntry->errorBase + XF86VidModeBadHTimings,
+		      XF86VIDMODENAME ":BadHTimings");
+    RegisterErrorName(extEntry->errorBase + XF86VidModeBadVTimings,
+		      XF86VIDMODENAME ":BadVTimings");
+    RegisterErrorName(extEntry->errorBase + XF86VidModeModeUnsuitable,
+		      XF86VIDMODENAME ":ModeUnsuitable");
+    RegisterErrorName(extEntry->errorBase + XF86VidModeExtensionDisabled,
+		      XF86VIDMODENAME ":ExtensionDisabled");
+    RegisterErrorName(extEntry->errorBase + XF86VidModeClientNotLocal,
+		      XF86VIDMODENAME ":ClientNotLocal");
+    RegisterErrorName(extEntry->errorBase + XF86VidModeZoomLocked,
+		      XF86VIDMODENAME ":ZoomLocked");
 }
 
 /*ARGSUSED*/
commit b7786724080fd3928ef7b8c294346661d7ffd90b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 17:15:34 2007 -0400

    registry: Register XF86DRI extension protocol names.

diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
index fdf0e99..c658421 100644
--- a/hw/xfree86/dri/xf86dri.c
+++ b/hw/xfree86/dri/xf86dri.c
@@ -53,6 +53,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "cursorstr.h"
 #include "scrnintstr.h"
 #include "servermd.h"
+#include "registry.h"
 #define _XF86DRI_SERVER_
 #include "xf86dristr.h"
 #include "swaprep.h"
@@ -112,7 +113,42 @@ XFree86DRIExtensionInit(void)
 				 StandardMinorOpcode))) {
 	DRIReqCode = (unsigned char)extEntry->base;
 	DRIErrorBase = extEntry->errorBase;
-    }
+    } else
+	return;
+
+    RegisterRequestName(DRIReqCode, X_XF86DRIQueryVersion,
+			XF86DRINAME ":QueryVersion");
+    RegisterRequestName(DRIReqCode, X_XF86DRIQueryDirectRenderingCapable,
+			XF86DRINAME ":QueryDirectRenderingCapable");
+    RegisterRequestName(DRIReqCode, X_XF86DRIOpenConnection,
+			XF86DRINAME ":OpenConnection");
+    RegisterRequestName(DRIReqCode, X_XF86DRICloseConnection,
+			XF86DRINAME ":CloseConnection");
+    RegisterRequestName(DRIReqCode, X_XF86DRIGetClientDriverName,
+			XF86DRINAME ":GetClientDriverName");
+    RegisterRequestName(DRIReqCode, X_XF86DRICreateContext,
+			XF86DRINAME ":CreateContext");
+    RegisterRequestName(DRIReqCode, X_XF86DRIDestroyContext,
+			XF86DRINAME ":DestroyContext");
+    RegisterRequestName(DRIReqCode, X_XF86DRICreateDrawable,
+			XF86DRINAME ":CreateDrawable");
+    RegisterRequestName(DRIReqCode, X_XF86DRIDestroyDrawable,
+			XF86DRINAME ":DestroyDrawable");
+    RegisterRequestName(DRIReqCode, X_XF86DRIGetDrawableInfo,
+			XF86DRINAME ":GetDrawableInfo");
+    RegisterRequestName(DRIReqCode, X_XF86DRIGetDeviceInfo,
+			XF86DRINAME ":GetDeviceInfo");
+    RegisterRequestName(DRIReqCode, X_XF86DRIAuthConnection,
+			XF86DRINAME ":AuthConnection");
+    RegisterRequestName(DRIReqCode, X_XF86DRIOpenFullScreen,
+			XF86DRINAME ":OpenFullScreen");
+    RegisterRequestName(DRIReqCode, X_XF86DRICloseFullScreen,
+			XF86DRINAME ":CloseFullScreen");
+
+    RegisterErrorName(DRIErrorBase + XF86DRIClientNotLocal,
+		      XF86DRINAME ":ClientNotLocal");
+    RegisterErrorName(DRIErrorBase + XF86DRIOperationNotSupported,
+		      XF86DRINAME ":OperationNotSupported");
 }
 
 /*ARGSUSED*/
commit eee46b4681ec55297604b0425705f2b18381f7ca
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 17:06:22 2007 -0400

    registry: Register APPLEWM extension protocol names.

diff --git a/hw/darwin/quartz/applewm.c b/hw/darwin/quartz/applewm.c
index d3c26ed..8b9f1ee 100644
--- a/hw/darwin/quartz/applewm.c
+++ b/hw/darwin/quartz/applewm.c
@@ -42,6 +42,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "servermd.h"
 #include "swaprep.h"
 #include "propertyst.h"
+#include "registry.h"
 #include <X11/Xatom.h>
 #include "darwin.h"
 #define _APPLEWM_SERVER_
@@ -127,7 +128,45 @@ AppleWMExtensionInit(
         WMEventBase = extEntry->eventBase;
         EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
         appleWMProcs = procsPtr;
-    }
+    } else
+	return;
+
+    RegisterRequestName(WMReqCode, X_AppleWMQueryVersion,
+			APPLEWMNAME ":QueryVersion");
+    RegisterRequestName(WMReqCode, X_AppleWMFrameGetRect,
+			APPLEWMNAME ":FrameGetRect");
+    RegisterRequestName(WMReqCode, X_AppleWMFrameHitTest,
+			APPLEWMNAME ":FrameHitTest");
+    RegisterRequestName(WMReqCode, X_AppleWMFrameDraw,
+			APPLEWMNAME ":FrameDraw");
+    RegisterRequestName(WMReqCode, X_AppleWMDisableUpdate,
+			APPLEWMNAME ":DisableUpdate");
+    RegisterRequestName(WMReqCode, X_AppleWMReenableUpdate,
+			APPLEWMNAME ":ReenableUpdate");
+    RegisterRequestName(WMReqCode, X_AppleWMSelectInput,
+			APPLEWMNAME ":SelectInput");
+    RegisterRequestName(WMReqCode, X_AppleWMSetWindowMenuCheck,
+			APPLEWMNAME ":SetWindowMenuCheck");
+    RegisterRequestName(WMReqCode, X_AppleWMSetFrontProcess,
+			APPLEWMNAME ":SetFrontProcess");
+    RegisterRequestName(WMReqCode, X_AppleWMSetWindowLevel,
+			APPLEWMNAME ":SetWindowLevel");
+    RegisterRequestName(WMReqCode, X_AppleWMSetCanQuit,
+			APPLEWMNAME ":SetCanQuit");
+    RegisterRequestName(WMReqCode, X_AppleWMSetWindowMenu,
+			APPLEWMNAME ":SetWindowMenu");
+
+    RegisterEventName(WMEventBase + AppleWMControllerNotify,
+		      APPLEWMNAME ":ControllerNotify");
+    RegisterEventName(WMEventBase + AppleWMActivationNotify,
+		      APPLEWMNAME ":ActivationNotify");
+    RegisterEventName(WMEventBase + AppleWMPasteboardNotify,
+		      APPLEWMNAME ":PasteboardNotify");
+
+    RegisterErrorName(WMErrorBase + AppleWMClientNotLocal,
+		      APPLEWMNAME ":ClientNotLocal");
+    RegisterErrorName(WMErrorBase + AppleWMOperationNotSupported,
+		      APPLEWMNAME ":OperationNotSupported");
 }
 
 /*ARGSUSED*/
commit b9f5ab98c8dea36dcce1ad15fd2e059a77e77c39
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 16:18:37 2007 -0400

    registry: Register XINERAMA extension protocol names.

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 26c2809..1ba0c4d 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -53,6 +53,7 @@ Equipment Corporation.
 #include "globals.h"
 #include "servermd.h"
 #include "resource.h"
+#include "registry.h"
 #ifdef RENDER
 #include "picturestr.h"
 #endif
@@ -589,6 +590,19 @@ void PanoramiXExtensionInit(int argc, char *argv[])
 #ifdef RENDER
     PanoramiXRenderInit ();
 #endif
+
+    RegisterRequestName(extEntry->base, X_PanoramiXQueryVersion,
+			PANORAMIX_PROTOCOL_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetState,
+			PANORAMIX_PROTOCOL_NAME ":GetState");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenCount,
+			PANORAMIX_PROTOCOL_NAME ":GetScreenCount");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenSize,
+			PANORAMIX_PROTOCOL_NAME ":GetScreenSize");
+    RegisterRequestName(extEntry->base, X_XineramaIsActive,
+			PANORAMIX_PROTOCOL_NAME ":IsActive");
+    RegisterRequestName(extEntry->base, X_XineramaQueryScreens,
+			PANORAMIX_PROTOCOL_NAME ":QueryScreens");
 }
 
 extern Bool CreateConnectionBlock(void);
diff --git a/hw/darwin/quartz/pseudoramiX.c b/hw/darwin/quartz/pseudoramiX.c
index 787601b..cdd4fff 100644
--- a/hw/darwin/quartz/pseudoramiX.c
+++ b/hw/darwin/quartz/pseudoramiX.c
@@ -42,6 +42,7 @@ Equipment Corporation.
 #include "window.h"
 #include <X11/extensions/panoramiXproto.h>
 #include "globals.h"
+#include "registry.h"
 
 extern int noPseudoramiXExtension;
 extern int noPanoramiXExtension;
@@ -147,6 +148,19 @@ void PseudoramiXExtensionInit(int argc, char *argv[])
                PANORAMIX_PROTOCOL_NAME);
         return;
     }
+
+    RegisterRequestName(extEntry->base, X_PanoramiXQueryVersion,
+			PANORAMIX_PROTOCOL_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetState,
+			PANORAMIX_PROTOCOL_NAME ":GetState");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenCount,
+			PANORAMIX_PROTOCOL_NAME ":GetScreenCount");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenSize,
+			PANORAMIX_PROTOCOL_NAME ":GetScreenSize");
+    RegisterRequestName(extEntry->base, X_XineramaIsActive,
+			PANORAMIX_PROTOCOL_NAME ":IsActive");
+    RegisterRequestName(extEntry->base, X_XineramaQueryScreens,
+			PANORAMIX_PROTOCOL_NAME ":QueryScreens");
 }
 
 
diff --git a/randr/rrxinerama.c b/randr/rrxinerama.c
index 896f61f..c499802 100644
--- a/randr/rrxinerama.c
+++ b/randr/rrxinerama.c
@@ -71,6 +71,7 @@
 #include "randrstr.h"
 #include "swaprep.h"
 #include <X11/extensions/panoramiXproto.h>
+#include "registry.h"
 
 #define RR_XINERAMA_MAJOR_VERSION   1
 #define RR_XINERAMA_MINOR_VERSION   1
@@ -423,6 +424,8 @@ RRXineramaResetProc(ExtensionEntry* extEntry)
 void
 RRXineramaExtensionInit(void)
 {
+    ExtensionEntry *extEntry;
+
 #ifdef PANORAMIX
     if(!noPanoramiXExtension)
 	return;
@@ -436,9 +439,22 @@ RRXineramaExtensionInit(void)
     if (screenInfo.numScreens > 1)
 	return;
 
-    (void) AddExtension(PANORAMIX_PROTOCOL_NAME, 0,0,
-			ProcRRXineramaDispatch,
-			SProcRRXineramaDispatch,
-			RRXineramaResetProc,
-			StandardMinorOpcode);
+    extEntry = AddExtension(PANORAMIX_PROTOCOL_NAME, 0, 0,
+			    ProcRRXineramaDispatch,
+			    SProcRRXineramaDispatch,
+			    RRXineramaResetProc,
+			    StandardMinorOpcode);
+
+    RegisterRequestName(extEntry->base, X_PanoramiXQueryVersion,
+			PANORAMIX_PROTOCOL_NAME ":QueryVersion");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetState,
+			PANORAMIX_PROTOCOL_NAME ":GetState");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenCount,
+			PANORAMIX_PROTOCOL_NAME ":GetScreenCount");
+    RegisterRequestName(extEntry->base, X_PanoramiXGetScreenSize,
+			PANORAMIX_PROTOCOL_NAME ":GetScreenSize");
+    RegisterRequestName(extEntry->base, X_XineramaIsActive,
+			PANORAMIX_PROTOCOL_NAME ":IsActive");
+    RegisterRequestName(extEntry->base, X_XineramaQueryScreens,
+			PANORAMIX_PROTOCOL_NAME ":QueryScreens");
 }
commit 3464b419230c6d17e940d967b567c5d2cb22d232
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 15:45:12 2007 -0400

    registry: Register APPLEDRI extension protocol names.

diff --git a/hw/darwin/quartz/xpr/appledri.c b/hw/darwin/quartz/xpr/appledri.c
index 70b7400..d9690fd 100644
--- a/hw/darwin/quartz/xpr/appledri.c
+++ b/hw/darwin/quartz/xpr/appledri.c
@@ -53,6 +53,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "swaprep.h"
 #include "dri.h"
 #include "dristruct.h"
+#include "registry.h"
 
 static int DRIErrorBase = 0;
 
@@ -92,7 +93,33 @@ AppleDRIExtensionInit(void)
         DRIErrorBase = extEntry->errorBase;
         DRIEventBase = extEntry->eventBase;
         EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
-    }
+    } else
+	return;
+
+    RegisterRequestName(DRIReqCode, X_AppleDRIQueryVersion,
+			APPLEDRINAME ":QueryVersion");
+    RegisterRequestName(DRIReqCode, X_AppleDRIQueryDirectRenderingCapable,
+			APPLEDRINAME ":QueryDirectRenderingCapable");
+    RegisterRequestName(DRIReqCode, X_AppleDRICreateSurface,
+			APPLEDRINAME ":CreateSurface");
+    RegisterRequestName(DRIReqCode, X_AppleDRIDestroySurface,
+			APPLEDRINAME ":DestroySurface");
+    RegisterRequestName(DRIReqCode, X_AppleDRIAuthConnection,
+			APPLEDRINAME ":AuthConnection");
+
+    RegisterEventName(DRIEventBase + AppleDRIObsoleteEvent1,
+		      APPLEDRINAME ":ObsoleteEvent1");
+    RegisterEventName(DRIEventBase + AppleDRIObsoleteEvent2,
+		      APPLEDRINAME ":ObsoleteEvent2");
+    RegisterEventName(DRIEventBase + AppleDRIObsoleteEvent3,
+		      APPLEDRINAME ":ObsoleteEvent3");
+    RegisterEventName(DRIEventBase + AppleDRISurfaceNotify,
+		      APPLEDRINAME ":SurfaceNotify");
+
+    RegisterErrorName(DRIEventBase + AppleDRIClientNotLocal,
+		      APPLEDRINAME ":ClientNotLocal");
+    RegisterErrorName(DRIEventBase + AppleDRIOperationNotSupported,
+		      APPLEDRINAME ":OperationNotSupported");
 }
 
 /*ARGSUSED*/
commit 32f3f5a1e7654f8bb43ea16b9227b3994e616739
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 15:32:17 2007 -0400

    registry: Register DMX extension protocol names.

diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c
index 24d1620..a4d6beb 100644
--- a/hw/dmx/dmx.c
+++ b/hw/dmx/dmx.c
@@ -54,6 +54,7 @@
 #define EXTENSION_PROC_ARGS void *
 #include "extnsionst.h"
 #include "opaque.h"
+#include "registry.h"
 
 #include "dmxextension.h"
 #include <X11/extensions/dmxproto.h>
@@ -126,6 +127,45 @@ void DMXExtensionInit(void)
                                  ProcDMXDispatch, SProcDMXDispatch,
                                  DMXResetProc, StandardMinorOpcode)))
 	DMXCode = extEntry->base;
+    else
+	return;
+
+    RegisterRequestName(DMXCode, X_DMXQueryVersion,
+			DMX_EXTENSION_NAME ":DMXQueryVersion");
+    RegisterRequestName(DMXCode, X_DMXGetScreenCount,
+			DMX_EXTENSION_NAME ":DMXGetScreenCount");
+    RegisterRequestName(DMXCode, X_DMXGetScreenInformationDEPRECATED,
+			DMX_EXTENSION_NAME ":DMXGetScreenInfoDEPRECATED");
+    RegisterRequestName(DMXCode, X_DMXGetWindowAttributes,
+			DMX_EXTENSION_NAME ":DMXGetWindowAttributes");
+    RegisterRequestName(DMXCode, X_DMXGetInputCount,
+			DMX_EXTENSION_NAME ":DMXGetInputCount");
+    RegisterRequestName(DMXCode, X_DMXGetInputAttributes,
+			DMX_EXTENSION_NAME ":DMXGetInputAttributes");
+    RegisterRequestName(DMXCode, X_DMXForceWindowCreationDEPRECATED,
+			DMX_EXTENSION_NAME ":DMXForceWindowCreationDEPRECATED");
+    RegisterRequestName(DMXCode, X_DMXReconfigureScreenDEPRECATED,
+			DMX_EXTENSION_NAME ":DMXReconfigureScreenDEPRECATED");
+    RegisterRequestName(DMXCode, X_DMXSync,
+			DMX_EXTENSION_NAME ":DMXSync");
+    RegisterRequestName(DMXCode, X_DMXForceWindowCreation,
+			DMX_EXTENSION_NAME ":DMXForceWindowCreation");
+    RegisterRequestName(DMXCode, X_DMXGetScreenAttributes,
+			DMX_EXTENSION_NAME ":DMXGetScreenAttributes");
+    RegisterRequestName(DMXCode, X_DMXChangeScreensAttributes,
+			DMX_EXTENSION_NAME ":DMXChangeScreensAttributes");
+    RegisterRequestName(DMXCode, X_DMXAddScreen,
+			DMX_EXTENSION_NAME ":DMXAddScreen");
+    RegisterRequestName(DMXCode, X_DMXRemoveScreen,
+			DMX_EXTENSION_NAME ":DMXRemoveScreen");
+    RegisterRequestName(DMXCode, X_DMXGetDesktopAttributes,
+			DMX_EXTENSION_NAME ":DMXGetDesktopAttributes");
+    RegisterRequestName(DMXCode, X_DMXChangeDesktopAttributes,
+			DMX_EXTENSION_NAME ":DMXChangeDesktopAttributes");
+    RegisterRequestName(DMXCode, X_DMXAddInput,
+			DMX_EXTENSION_NAME ":DMXAddInput");
+    RegisterRequestName(DMXCode, X_DMXRemoveInput,
+			DMX_EXTENSION_NAME ":DMXRemoveInput");
 }
 
 static void dmxSetScreenAttribute(int bit, DMXScreenAttributesPtr attr,
commit 166ef972febc00c665e1d5aeb68e75d7bbcf9879
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 15:22:02 2007 -0400

    registry: Register composite extension protocol names.

diff --git a/composite/compext.c b/composite/compext.c
index 2918556..98adabb 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -46,6 +46,7 @@
 
 #include "compint.h"
 #include "xace.h"
+#include "registry.h"
 
 #define SERVER_COMPOSITE_MAJOR	0
 #define SERVER_COMPOSITE_MINOR	4
@@ -754,4 +755,23 @@ CompositeExtensionInit (void)
 
     /* Initialization succeeded */
     noCompositeExtension = FALSE;
+
+    RegisterRequestName(CompositeReqCode, X_CompositeQueryVersion,
+			COMPOSITE_NAME ":CompositeQueryVersion");
+    RegisterRequestName(CompositeReqCode, X_CompositeRedirectWindow,
+			COMPOSITE_NAME ":CompositeRedirectWindow");
+    RegisterRequestName(CompositeReqCode, X_CompositeRedirectSubwindows,
+			COMPOSITE_NAME ":CompositeRedirectSubwindows");
+    RegisterRequestName(CompositeReqCode, X_CompositeUnredirectWindow,
+			COMPOSITE_NAME ":CompositeUnredirectWindow");
+    RegisterRequestName(CompositeReqCode, X_CompositeUnredirectSubwindows,
+			COMPOSITE_NAME ":CompositeUnredirectSubwindows");
+    RegisterRequestName(CompositeReqCode, X_CompositeCreateRegionFromBorderClip,
+			COMPOSITE_NAME ":CompositeCreateRegionFromBorderClip");
+    RegisterRequestName(CompositeReqCode, X_CompositeNameWindowPixmap,
+			COMPOSITE_NAME ":CompositeNameWindowPixmap");
+    RegisterRequestName(CompositeReqCode, X_CompositeGetOverlayWindow,
+			COMPOSITE_NAME ":CompositeGetOverlayWindow");
+    RegisterRequestName(CompositeReqCode, X_CompositeReleaseOverlayWindow,
+			COMPOSITE_NAME ":CompositeReleaseOverlayWindow");
 }
commit a5cf3f21f712e46dbf9bca289e67be75f2b531d3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 14:27:32 2007 -0400

    registry: Register XKB extension protocol names.

diff --git a/xkb/xkb.c b/xkb/xkb.c
index 9efdfb6..63576c2 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -35,6 +35,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xproto.h>
 #include "misc.h"
 #include "inputstr.h"
+#include "registry.h"
 #define	XKBSRV_NEED_FILE_FUNCS
 #include <xkbsrv.h>
 #include "extnsionst.h"
@@ -6226,8 +6227,62 @@ XkbExtensionInit(void)
 	XkbErrorBase = (unsigned char)extEntry->errorBase;
 	XkbKeyboardErrorCode = XkbErrorBase+XkbKeyboard;
 	RT_XKBCLIENT = CreateNewResourceType(XkbClientGone);
-    }
-    return;
+    } else
+	return;
+
+    RegisterRequestName(XkbReqCode, X_kbUseExtension,
+			XkbName ":UseExtension");
+    RegisterRequestName(XkbReqCode, X_kbSelectEvents,
+			XkbName ":SelectEvents");
+    RegisterRequestName(XkbReqCode, X_kbBell,
+			XkbName ":Bell");
+    RegisterRequestName(XkbReqCode, X_kbGetState,
+			XkbName ":GetState");
+    RegisterRequestName(XkbReqCode, X_kbLatchLockState,
+			XkbName ":LatchLockState");
+    RegisterRequestName(XkbReqCode, X_kbGetControls,
+			XkbName ":GetControls");
+    RegisterRequestName(XkbReqCode, X_kbSetControls,
+			XkbName ":SetControls");
+    RegisterRequestName(XkbReqCode, X_kbGetMap,
+			XkbName ":GetMap");
+    RegisterRequestName(XkbReqCode, X_kbSetMap,
+			XkbName ":SetMap");
+    RegisterRequestName(XkbReqCode, X_kbGetCompatMap,
+			XkbName ":GetCompatMap");
+    RegisterRequestName(XkbReqCode, X_kbSetCompatMap,
+			XkbName ":SetCompatMap");
+    RegisterRequestName(XkbReqCode, X_kbGetIndicatorState,
+			XkbName ":GetIndicatorState");
+    RegisterRequestName(XkbReqCode, X_kbGetIndicatorMap,
+			XkbName ":GetIndicatorMap");
+    RegisterRequestName(XkbReqCode, X_kbSetIndicatorMap,
+			XkbName ":SetIndicatorMap");
+    RegisterRequestName(XkbReqCode, X_kbGetNamedIndicator,
+			XkbName ":GetNamedIndicator");
+    RegisterRequestName(XkbReqCode, X_kbSetNamedIndicator,
+			XkbName ":SetNamedIndicator");
+    RegisterRequestName(XkbReqCode, X_kbGetNames,
+			XkbName ":GetNames");
+    RegisterRequestName(XkbReqCode, X_kbSetNames,
+			XkbName ":SetNames");
+    RegisterRequestName(XkbReqCode, X_kbGetGeometry,
+			XkbName ":GetGeometry");
+    RegisterRequestName(XkbReqCode, X_kbSetGeometry,
+			XkbName ":SetGeometry");
+    RegisterRequestName(XkbReqCode, X_kbPerClientFlags,
+			XkbName ":PerClientFlags");
+    RegisterRequestName(XkbReqCode, X_kbListComponents,
+			XkbName ":ListComponents");
+    RegisterRequestName(XkbReqCode, X_kbGetKbdByName,
+			XkbName ":GetKbdByName");
+    RegisterRequestName(XkbReqCode, X_kbGetDeviceInfo,
+			XkbName ":GetDeviceInfo");
+    RegisterRequestName(XkbReqCode, X_kbSetDeviceInfo,
+			XkbName ":SetDeviceInfo");
+    RegisterRequestName(XkbReqCode, X_kbSetDebuggingFlags,
+			XkbName ":SetDebuggingFlags");
+
+    RegisterEventName(extEntry->eventBase, XkbName ":EventCode");
+    RegisterErrorName(extEntry->errorBase, XkbName ":Keyboard");
 }
-
-
commit 5277a6ff589b5ddb475b90e1aaf5dbd9172d9711
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Oct 15 13:38:35 2007 -0400

    registry: Register Input extension protocol names.

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 1a435ed..bf5ebd2 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -69,6 +69,7 @@ SOFTWARE.
 #include "extinit.h"
 #include "exglobals.h"
 #include "swaprep.h"
+#include "registry.h"
 
 /* modules local to Xi */
 #include "allowev.h"
@@ -936,6 +937,7 @@ XInputExtensionInit(void)
 	AllExtensionVersions[IReqCode - 128] = thisversion;
 	MakeDeviceTypeAtoms();
 	RT_INPUTCLIENT = CreateNewResourceType((DeleteType) InputClientGone);
+	RegisterResourceName(RT_INPUTCLIENT, "INPUTCLIENT");
 	FixExtensionEvents(extEntry);
 	ReplySwapVector[IReqCode] = (ReplySwapPtr) SReplyIDispatch;
 	EventSwapVector[DeviceValuator] = SEventIDispatch;
@@ -957,4 +959,119 @@ XInputExtensionInit(void)
     } else {
 	FatalError("IExtensionInit: AddExtensions failed\n");
     }
+
+    RegisterRequestName(IReqCode, X_GetExtensionVersion,
+			INAME ":GetExtensionVersion");
+    RegisterRequestName(IReqCode, X_ListInputDevices,
+			INAME ":ListInputDevices");
+    RegisterRequestName(IReqCode, X_OpenDevice,
+			INAME ":OpenDevice");
+    RegisterRequestName(IReqCode, X_CloseDevice,
+			INAME ":CloseDevice");
+    RegisterRequestName(IReqCode, X_SetDeviceMode,
+			INAME ":SetDeviceMode");
+    RegisterRequestName(IReqCode, X_SelectExtensionEvent,
+			INAME ":SelectExtensionEvent");
+    RegisterRequestName(IReqCode, X_GetSelectedExtensionEvents,
+			INAME ":GetSelectedExtensionEvents");
+    RegisterRequestName(IReqCode, X_ChangeDeviceDontPropagateList,
+			INAME ":ChangeDeviceDontPropagateList");
+    RegisterRequestName(IReqCode, X_GetDeviceDontPropagateList,
+			INAME ":GetDeviceDontPropagageList");
+    RegisterRequestName(IReqCode, X_GetDeviceMotionEvents,
+			INAME ":GetDeviceMotionEvents");
+    RegisterRequestName(IReqCode, X_ChangeKeyboardDevice,
+			INAME ":ChangeKeyboardDevice");
+    RegisterRequestName(IReqCode, X_ChangePointerDevice,
+			INAME ":ChangePointerDevice");
+    RegisterRequestName(IReqCode, X_GrabDevice,
+			INAME ":GrabDevice");
+    RegisterRequestName(IReqCode, X_UngrabDevice,
+			INAME ":UngrabDevice");
+    RegisterRequestName(IReqCode, X_GrabDeviceKey,
+			INAME ":GrabDeviceKey");
+    RegisterRequestName(IReqCode, X_UngrabDeviceKey,
+			INAME ":UngrabDeviceKey");
+    RegisterRequestName(IReqCode, X_GrabDeviceButton,
+			INAME ":GrabDeviceButton");
+    RegisterRequestName(IReqCode, X_UngrabDeviceButton,
+			INAME ":UngrabDeviceButton");
+    RegisterRequestName(IReqCode, X_AllowDeviceEvents,
+			INAME ":AllowDeviceEvents");
+    RegisterRequestName(IReqCode, X_GetDeviceFocus,
+			INAME ":GetDeviceFocus");
+    RegisterRequestName(IReqCode, X_SetDeviceFocus,
+			INAME ":SetDeviceFocus");
+    RegisterRequestName(IReqCode, X_GetFeedbackControl,
+			INAME ":GetFeedbackControl");
+    RegisterRequestName(IReqCode, X_ChangeFeedbackControl,
+			INAME ":ChangeFeedbackControl");
+    RegisterRequestName(IReqCode, X_GetDeviceKeyMapping,
+			INAME ":GetDeviceKeyMapping");
+    RegisterRequestName(IReqCode, X_ChangeDeviceKeyMapping,
+			INAME ":ChangeDeviceKeyMapping");
+    RegisterRequestName(IReqCode, X_GetDeviceModifierMapping,
+			INAME ":GetDeviceModifierMapping");
+    RegisterRequestName(IReqCode, X_SetDeviceModifierMapping,
+			INAME ":SetDeviceModifierMapping");
+    RegisterRequestName(IReqCode, X_GetDeviceButtonMapping,
+			INAME ":GetDeviceButtonMapping");
+    RegisterRequestName(IReqCode, X_SetDeviceButtonMapping,
+			INAME ":SetDeviceButtonMapping");
+    RegisterRequestName(IReqCode, X_QueryDeviceState,
+			INAME ":QueryDeviceState");
+    RegisterRequestName(IReqCode, X_SendExtensionEvent,
+			INAME ":SendExtensionEvent");
+    RegisterRequestName(IReqCode, X_DeviceBell,
+			INAME ":DeviceBell");
+    RegisterRequestName(IReqCode, X_SetDeviceValuators,
+			INAME ":SetDeviceValuators");
+    RegisterRequestName(IReqCode, X_GetDeviceControl,
+			INAME ":GetDeviceControl");
+    RegisterRequestName(IReqCode, X_ChangeDeviceControl,
+			INAME ":ChangeDeviceControl");
+
+    RegisterEventName(extEntry->eventBase + XI_DeviceValuator,
+		      INAME ":DeviceValuator");
+    RegisterEventName(extEntry->eventBase + XI_DeviceKeyPress,
+		      INAME ":DeviceKeyPress");
+    RegisterEventName(extEntry->eventBase + XI_DeviceKeyRelease,
+		      INAME ":DeviceKeyRelease");
+    RegisterEventName(extEntry->eventBase + XI_DeviceButtonPress,
+		      INAME ":DeviceButtonPress");
+    RegisterEventName(extEntry->eventBase + XI_DeviceButtonRelease,
+		      INAME ":DeviceButtonRelease");
+    RegisterEventName(extEntry->eventBase + XI_DeviceMotionNotify,
+		      INAME ":DeviceMotionNotify");
+    RegisterEventName(extEntry->eventBase + XI_DeviceFocusIn,
+		      INAME ":DeviceFocusIn");
+    RegisterEventName(extEntry->eventBase + XI_DeviceFocusOut,
+		      INAME ":DeviceFocusOut");
+    RegisterEventName(extEntry->eventBase + XI_ProximityIn,
+		      INAME ":ProximityIn");
+    RegisterEventName(extEntry->eventBase + XI_ProximityOut,
+		      INAME ":ProximityOut");
+    RegisterEventName(extEntry->eventBase + XI_DeviceStateNotify,
+		      INAME ":DeviceStateNotify");
+    RegisterEventName(extEntry->eventBase + XI_DeviceMappingNotify,
+		      INAME ":DeviceMappingNotify");
+    RegisterEventName(extEntry->eventBase + XI_ChangeDeviceNotify,
+		      INAME ":ChangeDeviceNotify");
+    RegisterEventName(extEntry->eventBase + XI_DeviceKeystateNotify,
+		      INAME ":DeviceKeystateNotify");
+    RegisterEventName(extEntry->eventBase + XI_DeviceButtonstateNotify,
+		      INAME ":DeviceButtonstateNotify");
+    RegisterEventName(extEntry->eventBase + XI_DevicePresenceNotify,
+		      INAME ":DevicePresenceNotify");
+
+    RegisterErrorName(extEntry->errorBase + XI_BadDevice,
+		      INAME ":BadDevice");
+    RegisterErrorName(extEntry->errorBase + XI_BadEvent,
+		      INAME ":BadEvent");
+    RegisterErrorName(extEntry->errorBase + XI_BadMode,
+		      INAME ":BadMode");
+    RegisterErrorName(extEntry->errorBase + XI_DeviceBusy,
+		      INAME ":DeviceBusy");
+    RegisterErrorName(extEntry->errorBase + XI_BadClass,
+		      INAME ":BadClass");
 }
commit 526f40434c86548830c4f72940462b6253fe9790
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Oct 12 18:18:00 2007 -0400

    NULL is not a valid argument to CreatePicture, please use serverClient
    as the client argument if no real client is creating the object.

diff --git a/hw/xgl/xglscreen.c b/hw/xgl/xglscreen.c
index 9b7297b..6bd91b7 100644
--- a/hw/xgl/xglscreen.c
+++ b/hw/xgl/xglscreen.c
@@ -463,7 +463,8 @@ xglCreateSolidAlphaPicture (ScreenPtr pScreen)
 
     tmpval[0] = xTrue;
     pScreenPriv->pSolidAlpha = CreatePicture (0, &pPixmap->drawable, pFormat,
-					      CPRepeat, tmpval, 0, &error);
+					      CPRepeat, tmpval,
+					      serverClient, &error);
     (*pScreen->DestroyPixmap) (pPixmap);
 
     if (pScreenPriv->pSolidAlpha)
diff --git a/render/mirect.c b/render/mirect.c
index 87767a7..fa9dab8 100644
--- a/render/mirect.c
+++ b/render/mirect.c
@@ -158,7 +158,7 @@ miCompositeRects (CARD8		op,
 	
 	tmpval[0] = xTrue;
 	pSrc = CreatePicture (0, &pPixmap->drawable, rgbaFormat,
-			      CPRepeat, tmpval, 0, &error);
+			      CPRepeat, tmpval, serverClient, &error);
 			      
 	if (!pSrc)
 	    goto bail4;
commit 6adeba17301a309be2f34cd51eca84a13d5503fd
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 11 14:17:17 2007 -0400

    dix: Add a new "registry" mechanism for registering string names of things.
    Supports protocol requests, events, and errors, and resource names.
    Modify XRES extension to use it.

diff --git a/Xext/xres.c b/Xext/xres.c
index 1617337..3660260 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -22,6 +22,7 @@
 #include "windowstr.h"
 #include "gcstruct.h"
 #include "modinit.h"
+#include "registry.h"
 
 static int
 ProcXResQueryVersion (ClientPtr client)
@@ -161,17 +162,20 @@ ProcXResQueryClientResources (ClientPtr client)
 
     if(num_types) {
         xXResType scratch;
+	char *name;
 
         for(i = 0; i < lastResourceType; i++) {
             if(!counts[i]) continue;
 
-            if(!ResourceNames[i + 1]) {
+	    name = (char *)LookupResourceName(i + 1);
+            if (strcmp(name, XREGISTRY_UNKNOWN))
+		scratch.resource_type = MakeAtom(name, strlen(name), TRUE);
+	    else {
                 char buf[40];
                 snprintf(buf, sizeof(buf), "Unregistered resource %i", i + 1);
-                RegisterResourceName(i + 1, buf);
+		scratch.resource_type = MakeAtom(buf, strlen(buf), TRUE);
             }
 
-            scratch.resource_type = ResourceNames[i + 1];
             scratch.count = counts[i];
 
             if(client->swapped) {
@@ -387,15 +391,4 @@ ResExtensionInit(INITARGS)
     (void) AddExtension(XRES_NAME, 0, 0,
                             ProcResDispatch, SProcResDispatch,
                             ResResetProc, StandardMinorOpcode);
-
-    RegisterResourceName(RT_NONE, "NONE");
-    RegisterResourceName(RT_WINDOW, "WINDOW");
-    RegisterResourceName(RT_PIXMAP, "PIXMAP");
-    RegisterResourceName(RT_GC, "GC");
-    RegisterResourceName(RT_FONT, "FONT");
-    RegisterResourceName(RT_CURSOR, "CURSOR");
-    RegisterResourceName(RT_COLORMAP, "COLORMAP");
-    RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
-    RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
-    RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
 }
diff --git a/configure.ac b/configure.ac
index ca8fcc2..e73e250 100644
--- a/configure.ac
+++ b/configure.ac
@@ -493,6 +493,7 @@ AC_ARG_ENABLE(glx-tls,        AS_HELP_STRING([--enable-glx-tls], [Build GLX with
                                 [GLX_USE_TLS=no])
 
 dnl Extensions.
+AC_ARG_ENABLE(registry,       AS_HELP_STRING([--disable-registry], [Build string registry module (default: enabled)]), [XREGISTRY=$enableval], [XREGISTRY=yes])
 AC_ARG_ENABLE(composite,      AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=yes])
 AC_ARG_ENABLE(mitshm,         AS_HELP_STRING([--disable-shm], [Build SHM extension (default: enabled)]), [MITSHM=$enableval], [MITSHM=yes])
 AC_ARG_ENABLE(xres,           AS_HELP_STRING([--disable-xres], [Build XRes extension (default: enabled)]), [RES=$enableval], [RES=yes])
@@ -733,6 +734,10 @@ if test "x$XVMC" = xyes; then
 	AC_DEFINE(XvMCExtension, 1, [Build XvMC extension])
 fi
 
+AM_CONDITIONAL(XREGISTRY, [test "x$XREGISTRY" = xyes])
+if test "x$XREGISTRY" = xyes; then
+	AC_DEFINE(XREGISTRY, 1, [Build registry module])
+fi
 
 AM_CONDITIONAL(COMPOSITE, [test "x$COMPOSITE" = xyes])
 if test "x$COMPOSITE" = xyes; then
diff --git a/dix/Makefile.am b/dix/Makefile.am
index 827243a..65c387c 100644
--- a/dix/Makefile.am
+++ b/dix/Makefile.am
@@ -27,6 +27,7 @@ libdix_la_SOURCES = 	\
 	pixmap.c	\
 	privates.c	\
 	property.c	\
+	registry.c	\
 	resource.c	\
 	swaprep.c	\
 	swapreq.c	\
diff --git a/dix/main.c b/dix/main.c
index 119828b..ca0028a 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -102,6 +102,7 @@ Equipment Corporation.
 #include "dixfont.h"
 #include "extnsionst.h"
 #include "privates.h"
+#include "registry.h"
 #ifdef XPRINT
 #include "DiPrint.h"
 #endif
@@ -354,6 +355,7 @@ main(int argc, char *argv[], char *envp[])
 	InitGlyphCaching();
 	if (!dixResetPrivates())
 	    FatalError("couldn't init private data storage");
+	dixResetRegistry();
 	ResetFontPrivateIndex();
 	InitCallbackManager();
 	InitVisualWrap();
diff --git a/dix/registry.c b/dix/registry.c
new file mode 100644
index 0000000..7b521b5
--- /dev/null
+++ b/dix/registry.c
@@ -0,0 +1,375 @@
+/************************************************************
+
+Author: Eamon Walsh <ewalsh at epoch.ncsc.mil>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+this permission notice appear in supporting documentation.  This permission
+notice shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+********************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#ifdef XREGISTRY
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "resource.h"
+#include "registry.h"
+
+#define BASE_SIZE 16
+
+static const char ***requests, **events, **errors, **resources;
+static unsigned nmajor, *nminor, nevent, nerror, nresource;
+
+static int double_size(void *p, unsigned n, unsigned size)
+{
+    char **ptr = (char **)p;
+    unsigned s, f;
+
+    if (n) {
+	s = n * size;
+	n *= 2 * size;
+	f = n;
+    } else {
+	s = 0;
+	n = f = BASE_SIZE * size;
+    }
+
+    *ptr = xrealloc(*ptr, n);
+    if (!*ptr) {
+	dixResetRegistry();
+	return FALSE;
+    }
+    memset(*ptr + s, 0, f - s);
+    return TRUE;
+}       
+
+/*
+ * Registration functions
+ */
+
+void
+RegisterRequestName(unsigned major, unsigned minor, const char *name)
+{
+    while (major >= nmajor) {
+	if (!double_size(&requests, nmajor, sizeof(const char **)))
+	    return;
+	if (!double_size(&nminor, nmajor, sizeof(unsigned)))
+	    return;
+	nmajor = nmajor ? nmajor * 2 : BASE_SIZE;
+    }
+    while (minor >= nminor[major]) {
+	if (!double_size(requests+major, nminor[major], sizeof(const char *)))
+	    return;
+	nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE;
+    }
+
+    requests[major][minor] = name;
+}
+
+void
+RegisterEventName(unsigned event, const char *name) {
+    while (event >= nevent) {
+	if (!double_size(&events, nevent, sizeof(const char *)))
+	    return;
+	nevent = nevent ? nevent * 2 : BASE_SIZE;
+    }
+
+    events[event] = name;
+}
+
+void
+RegisterErrorName(unsigned error, const char *name) {
+    while (error >= nerror) {
+	if (!double_size(&errors, nerror, sizeof(const char *)))
+	    return;
+	nerror = nerror ? nerror * 2 : BASE_SIZE;
+    }
+
+    errors[error] = name;
+}
+
+void
+RegisterResourceName(RESTYPE resource, const char *name)
+{
+    resource &= TypeMask;
+
+    while (resource >= nresource) {
+	if (!double_size(&resources, nresource, sizeof(const char *)))
+	    return;
+	nresource = nresource ? nresource * 2 : BASE_SIZE;
+    }
+
+    resources[resource] = name;
+}
+
+/*
+ * Lookup functions
+ */
+
+const char *
+LookupRequestName(int major, int minor)
+{
+    if (major >= nmajor)
+	return XREGISTRY_UNKNOWN;
+    if (minor >= nminor[major])
+	return XREGISTRY_UNKNOWN;
+
+    return requests[major][minor] ? requests[major][minor] : XREGISTRY_UNKNOWN;
+}
+
+const char *
+LookupEventName(int event)
+{
+    if (event >= nevent)
+	return XREGISTRY_UNKNOWN;
+
+    return events[event] ? events[event] : XREGISTRY_UNKNOWN;
+}
+
+const char *
+LookupErrorName(int error)
+{
+    if (error >= nerror)
+	return XREGISTRY_UNKNOWN;
+
+    return errors[error] ? errors[error] : XREGISTRY_UNKNOWN;
+}
+
+const char *
+LookupResourceName(RESTYPE resource)
+{
+    resource &= TypeMask;
+
+    if (resource >= nresource)
+	return XREGISTRY_UNKNOWN;
+
+    return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN;
+}
+
+/*
+ * Setup and teardown
+ */
+void
+dixResetRegistry(void)
+{
+    /* Free all memory */
+    while (nmajor)
+	xfree(requests[--nmajor]);
+    xfree(requests);
+    xfree(nminor);
+    xfree(events);
+    xfree(errors);
+    xfree(resources);
+
+    requests = NULL;
+    nminor = NULL;
+    events = NULL;
+    errors = NULL;
+    resources = NULL;
+
+    nmajor = nevent = nerror = nresource = 0;
+
+    /* Add built-in resources */
+    RegisterResourceName(RT_NONE, "NONE");
+    RegisterResourceName(RT_WINDOW, "WINDOW");
+    RegisterResourceName(RT_PIXMAP, "PIXMAP");
+    RegisterResourceName(RT_GC, "GC");
+    RegisterResourceName(RT_FONT, "FONT");
+    RegisterResourceName(RT_CURSOR, "CURSOR");
+    RegisterResourceName(RT_COLORMAP, "COLORMAP");
+    RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
+    RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
+    RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
+
+    /* Add the core protocol */
+    RegisterRequestName(X_CreateWindow, 0, "CreateWindow");
+    RegisterRequestName(X_ChangeWindowAttributes, 0, "ChangeWindowAttributes");
+    RegisterRequestName(X_GetWindowAttributes, 0, "GetWindowAttributes");
+    RegisterRequestName(X_DestroyWindow, 0, "DestroyWindow");
+    RegisterRequestName(X_DestroySubwindows, 0, "DestroySubwindows");
+    RegisterRequestName(X_ChangeSaveSet, 0, "ChangeSaveSet");
+    RegisterRequestName(X_ReparentWindow, 0, "ReparentWindow");
+    RegisterRequestName(X_MapWindow, 0, "MapWindow");
+    RegisterRequestName(X_MapSubwindows, 0, "MapSubwindows");
+    RegisterRequestName(X_UnmapWindow, 0, "UnmapWindow");
+    RegisterRequestName(X_UnmapSubwindows, 0, "UnmapSubwindows");
+    RegisterRequestName(X_ConfigureWindow, 0, "ConfigureWindow");
+    RegisterRequestName(X_CirculateWindow, 0, "CirculateWindow");
+    RegisterRequestName(X_GetGeometry, 0, "GetGeometry");
+    RegisterRequestName(X_QueryTree, 0, "QueryTree");
+    RegisterRequestName(X_InternAtom, 0, "InternAtom");
+    RegisterRequestName(X_GetAtomName, 0, "GetAtomName");
+    RegisterRequestName(X_ChangeProperty, 0, "ChangeProperty");
+    RegisterRequestName(X_DeleteProperty, 0, "DeleteProperty");
+    RegisterRequestName(X_GetProperty, 0, "GetProperty");
+    RegisterRequestName(X_ListProperties, 0, "ListProperties");
+    RegisterRequestName(X_SetSelectionOwner, 0, "SetSelectionOwner");
+    RegisterRequestName(X_GetSelectionOwner, 0, "GetSelectionOwner");
+    RegisterRequestName(X_ConvertSelection, 0, "ConvertSelection");
+    RegisterRequestName(X_SendEvent, 0, "SendEvent");
+    RegisterRequestName(X_GrabPointer, 0, "GrabPointer");
+    RegisterRequestName(X_UngrabPointer, 0, "UngrabPointer");
+    RegisterRequestName(X_GrabButton, 0, "GrabButton");
+    RegisterRequestName(X_UngrabButton, 0, "UngrabButton");
+    RegisterRequestName(X_ChangeActivePointerGrab, 0, "ChangeActivePointerGrab");
+    RegisterRequestName(X_GrabKeyboard, 0, "GrabKeyboard");
+    RegisterRequestName(X_UngrabKeyboard, 0, "UngrabKeyboard");
+    RegisterRequestName(X_GrabKey, 0, "GrabKey");
+    RegisterRequestName(X_UngrabKey, 0, "UngrabKey");
+    RegisterRequestName(X_AllowEvents, 0, "AllowEvents");
+    RegisterRequestName(X_GrabServer, 0, "GrabServer");
+    RegisterRequestName(X_UngrabServer, 0, "UngrabServer");
+    RegisterRequestName(X_QueryPointer, 0, "QueryPointer");
+    RegisterRequestName(X_GetMotionEvents, 0, "GetMotionEvents");
+    RegisterRequestName(X_TranslateCoords, 0, "TranslateCoords");
+    RegisterRequestName(X_WarpPointer, 0, "WarpPointer");
+    RegisterRequestName(X_SetInputFocus, 0, "SetInputFocus");
+    RegisterRequestName(X_GetInputFocus, 0, "GetInputFocus");
+    RegisterRequestName(X_QueryKeymap, 0, "QueryKeymap");
+    RegisterRequestName(X_OpenFont, 0, "OpenFont");
+    RegisterRequestName(X_CloseFont, 0, "CloseFont");
+    RegisterRequestName(X_QueryFont, 0, "QueryFont");
+    RegisterRequestName(X_QueryTextExtents, 0, "QueryTextExtents");
+    RegisterRequestName(X_ListFonts, 0, "ListFonts");
+    RegisterRequestName(X_ListFontsWithInfo, 0, "ListFontsWithInfo");
+    RegisterRequestName(X_SetFontPath, 0, "SetFontPath");
+    RegisterRequestName(X_GetFontPath, 0, "GetFontPath");
+    RegisterRequestName(X_CreatePixmap, 0, "CreatePixmap");
+    RegisterRequestName(X_FreePixmap, 0, "FreePixmap");
+    RegisterRequestName(X_CreateGC, 0, "CreateGC");
+    RegisterRequestName(X_ChangeGC, 0, "ChangeGC");
+    RegisterRequestName(X_CopyGC, 0, "CopyGC");
+    RegisterRequestName(X_SetDashes, 0, "SetDashes");
+    RegisterRequestName(X_SetClipRectangles, 0, "SetClipRectangles");
+    RegisterRequestName(X_FreeGC, 0, "FreeGC");
+    RegisterRequestName(X_ClearArea, 0, "ClearArea");
+    RegisterRequestName(X_CopyArea, 0, "CopyArea");
+    RegisterRequestName(X_CopyPlane, 0, "CopyPlane");
+    RegisterRequestName(X_PolyPoint, 0, "PolyPoint");
+    RegisterRequestName(X_PolyLine, 0, "PolyLine");
+    RegisterRequestName(X_PolySegment, 0, "PolySegment");
+    RegisterRequestName(X_PolyRectangle, 0, "PolyRectangle");
+    RegisterRequestName(X_PolyArc, 0, "PolyArc");
+    RegisterRequestName(X_FillPoly, 0, "FillPoly");
+    RegisterRequestName(X_PolyFillRectangle, 0, "PolyFillRectangle");
+    RegisterRequestName(X_PolyFillArc, 0, "PolyFillArc");
+    RegisterRequestName(X_PutImage, 0, "PutImage");
+    RegisterRequestName(X_GetImage, 0, "GetImage");
+    RegisterRequestName(X_PolyText8, 0, "PolyText8");
+    RegisterRequestName(X_PolyText16, 0, "PolyText16");
+    RegisterRequestName(X_ImageText8, 0, "ImageText8");
+    RegisterRequestName(X_ImageText16, 0, "ImageText16");
+    RegisterRequestName(X_CreateColormap, 0, "CreateColormap");
+    RegisterRequestName(X_FreeColormap, 0, "FreeColormap");
+    RegisterRequestName(X_CopyColormapAndFree, 0, "CopyColormapAndFree");
+    RegisterRequestName(X_InstallColormap, 0, "InstallColormap");
+    RegisterRequestName(X_UninstallColormap, 0, "UninstallColormap");
+    RegisterRequestName(X_ListInstalledColormaps, 0, "ListInstalledColormaps");
+    RegisterRequestName(X_AllocColor, 0, "AllocColor");
+    RegisterRequestName(X_AllocNamedColor, 0, "AllocNamedColor");
+    RegisterRequestName(X_AllocColorCells, 0, "AllocColorCells");
+    RegisterRequestName(X_AllocColorPlanes, 0, "AllocColorPlanes");
+    RegisterRequestName(X_FreeColors, 0, "FreeColors");
+    RegisterRequestName(X_StoreColors, 0, "StoreColors");
+    RegisterRequestName(X_StoreNamedColor, 0, "StoreNamedColor");
+    RegisterRequestName(X_QueryColors, 0, "QueryColors");
+    RegisterRequestName(X_LookupColor, 0, "LookupColor");
+    RegisterRequestName(X_CreateCursor, 0, "CreateCursor");
+    RegisterRequestName(X_CreateGlyphCursor, 0, "CreateGlyphCursor");
+    RegisterRequestName(X_FreeCursor, 0, "FreeCursor");
+    RegisterRequestName(X_RecolorCursor, 0, "RecolorCursor");
+    RegisterRequestName(X_QueryBestSize, 0, "QueryBestSize");
+    RegisterRequestName(X_QueryExtension, 0, "QueryExtension");
+    RegisterRequestName(X_ListExtensions, 0, "ListExtensions");
+    RegisterRequestName(X_ChangeKeyboardMapping, 0, "ChangeKeyboardMapping");
+    RegisterRequestName(X_GetKeyboardMapping, 0, "GetKeyboardMapping");
+    RegisterRequestName(X_ChangeKeyboardControl, 0, "ChangeKeyboardControl");
+    RegisterRequestName(X_GetKeyboardControl, 0, "GetKeyboardControl");
+    RegisterRequestName(X_Bell, 0, "Bell");
+    RegisterRequestName(X_ChangePointerControl, 0, "ChangePointerControl");
+    RegisterRequestName(X_GetPointerControl, 0, "GetPointerControl");
+    RegisterRequestName(X_SetScreenSaver, 0, "SetScreenSaver");
+    RegisterRequestName(X_GetScreenSaver, 0, "GetScreenSaver");
+    RegisterRequestName(X_ChangeHosts, 0, "ChangeHosts");
+    RegisterRequestName(X_ListHosts, 0, "ListHosts");
+    RegisterRequestName(X_SetAccessControl, 0, "SetAccessControl");
+    RegisterRequestName(X_SetCloseDownMode, 0, "SetCloseDownMode");
+    RegisterRequestName(X_KillClient, 0, "KillClient");
+    RegisterRequestName(X_RotateProperties, 0, "RotateProperties");
+    RegisterRequestName(X_ForceScreenSaver, 0, "ForceScreenSaver");
+    RegisterRequestName(X_SetPointerMapping, 0, "SetPointerMapping");
+    RegisterRequestName(X_GetPointerMapping, 0, "GetPointerMapping");
+    RegisterRequestName(X_SetModifierMapping, 0, "SetModifierMapping");
+    RegisterRequestName(X_GetModifierMapping, 0, "GetModifierMapping");
+    RegisterRequestName(X_NoOperation, 0, "NoOperation");
+
+    RegisterErrorName(Success, "Success");
+    RegisterErrorName(BadRequest, "BadRequest");
+    RegisterErrorName(BadValue, "BadValue");
+    RegisterErrorName(BadWindow, "BadWindow");
+    RegisterErrorName(BadPixmap, "BadPixmap");
+    RegisterErrorName(BadAtom, "BadAtom");
+    RegisterErrorName(BadCursor, "BadCursor");
+    RegisterErrorName(BadFont, "BadFont");
+    RegisterErrorName(BadMatch, "BadMatch");
+    RegisterErrorName(BadDrawable, "BadDrawable");
+    RegisterErrorName(BadAccess, "BadAccess");
+    RegisterErrorName(BadAlloc, "BadAlloc");
+    RegisterErrorName(BadColor, "BadColor");
+    RegisterErrorName(BadGC, "BadGC");
+    RegisterErrorName(BadIDChoice, "BadIDChoice");
+    RegisterErrorName(BadName, "BadName");
+    RegisterErrorName(BadLength, "BadLength");
+    RegisterErrorName(BadImplementation, "BadImplementation");
+
+    RegisterEventName(X_Error, "Error");
+    RegisterEventName(X_Reply, "Reply");
+    RegisterEventName(KeyPress, "KeyPress");
+    RegisterEventName(KeyRelease, "KeyRelease");
+    RegisterEventName(ButtonPress, "ButtonPress");
+    RegisterEventName(ButtonRelease, "ButtonRelease");
+    RegisterEventName(MotionNotify, "MotionNotify");
+    RegisterEventName(EnterNotify, "EnterNotify");
+    RegisterEventName(LeaveNotify, "LeaveNotify");
+    RegisterEventName(FocusIn, "FocusIn");
+    RegisterEventName(FocusOut, "FocusOut");
+    RegisterEventName(KeymapNotify, "KeymapNotify");
+    RegisterEventName(Expose, "Expose");
+    RegisterEventName(GraphicsExpose, "GraphicsExpose");
+    RegisterEventName(NoExpose, "NoExpose");
+    RegisterEventName(VisibilityNotify, "VisibilityNotify");
+    RegisterEventName(CreateNotify, "CreateNotify");
+    RegisterEventName(DestroyNotify, "DestroyNotify");
+    RegisterEventName(UnmapNotify, "UnmapNotify");
+    RegisterEventName(MapNotify, "MapNotify");
+    RegisterEventName(MapRequest, "MapRequest");
+    RegisterEventName(ReparentNotify, "ReparentNotify");
+    RegisterEventName(ConfigureNotify, "ConfigureNotify");
+    RegisterEventName(ConfigureRequest, "ConfigureRequest");
+    RegisterEventName(GravityNotify, "GravityNotify");
+    RegisterEventName(ResizeRequest, "ResizeRequest");
+    RegisterEventName(CirculateNotify, "CirculateNotify");
+    RegisterEventName(CirculateRequest, "CirculateRequest");
+    RegisterEventName(PropertyNotify, "PropertyNotify");
+    RegisterEventName(SelectionClear, "SelectionClear");
+    RegisterEventName(SelectionRequest, "SelectionRequest");
+    RegisterEventName(SelectionNotify, "SelectionNotify");
+    RegisterEventName(ColormapNotify, "ColormapNotify");
+    RegisterEventName(ClientMessage, "ClientMessage");
+    RegisterEventName(MappingNotify, "MappingNotify");
+}
+
+#endif /* XREGISTRY */
diff --git a/dix/resource.c b/dix/resource.c
index c892cf9..857776d 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -151,10 +151,11 @@ Equipment Corporation.
 
 #ifdef XSERVER_DTRACE
 #include <sys/types.h>
+#include "registry.h"
 typedef const char *string;
 #include "Xserver-dtrace.h"
 
-#define TypeNameString(t) NameForAtom(ResourceNames[t & TypeMask])
+#define TypeNameString(t) LookupResourceName(t)
 #endif
 
 static void RebuildTable(
@@ -202,17 +203,6 @@ CallResourceStateCallback(ResourceState state, ResourceRec *res)
     }
 }
 
-#ifdef XResExtension
-
-_X_EXPORT Atom * ResourceNames = NULL;
-
-_X_EXPORT void RegisterResourceName (RESTYPE type, char *name)
-{
-    ResourceNames[type & TypeMask] =  MakeAtom(name, strlen(name), TRUE);
-}
-
-#endif
-
 _X_EXPORT RESTYPE
 CreateNewResourceType(DeleteType deleteFunc)
 {
@@ -228,17 +218,6 @@ CreateNewResourceType(DeleteType deleteFunc)
     if (!dixRegisterPrivateOffset(next, -1))
 	return 0;
 
-#ifdef XResExtension
-    {
-       Atom *newnames;
-       newnames = xrealloc(ResourceNames, (next + 1) * sizeof(Atom));
-       if(!newnames)
-           return 0;
-       ResourceNames = newnames;
-       ResourceNames[next] = 0;
-    }
-#endif
-
     lastResourceType = next;
     DeleteFuncs = funcs;
     DeleteFuncs[next] = deleteFunc;
@@ -291,14 +270,6 @@ InitClientResources(ClientPtr client)
 	DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels;
 	DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone;
 	DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab;
-
-#ifdef XResExtension
-        if(ResourceNames)
-            xfree(ResourceNames);
-        ResourceNames = xalloc((lastResourceType + 1) * sizeof(Atom));
-        if(!ResourceNames)
-           return FALSE;
-#endif
     }
     clientTable[i = client->index].resources =
 	(ResourcePtr *)xalloc(INITBUCKETS*sizeof(ResourcePtr));
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 0eaa2d3..139e23c 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -65,6 +65,7 @@
 #include "osdep.h"
 #include "privates.h"
 #include "resource.h"
+#include "registry.h"
 #include "servermd.h"
 #include "scrnintstr.h"
 #include "windowstr.h"
@@ -285,9 +286,12 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMVAR(lastResourceType)
     SYMVAR(TypeMask)
     SYMVAR(ResourceStateCallback)
-#ifdef RES
+    /* registry.c */
+#ifdef XREGISTRY
+    SYMFUNC(RegisterRequestName)
+    SYMFUNC(RegisterEventName)
+    SYMFUNC(RegisterErrorName)
     SYMFUNC(RegisterResourceName)
-    SYMVAR(ResourceNames)
 #endif
     /* swaprep.c */
     SYMFUNC(CopySwap32Write)
diff --git a/include/Makefile.am b/include/Makefile.am
index ef39836..0654b57 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -37,6 +37,7 @@ sdk_HEADERS =		\
 	propertyst.h	\
 	region.h	\
 	regionstr.h	\
+	registry.h	\
 	resource.h	\
 	rgb.h		\
 	screenint.h	\
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 8d4d731..a091527 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -329,6 +329,9 @@
 /* unaligned word accesses behave as expected */
 #undef WORKING_UNALIGNED_INT
 
+/* Build X string registry */
+#undef XREGISTRY
+
 /* Build X-ACE extension */
 #undef XACE
 
diff --git a/include/registry.h b/include/registry.h
new file mode 100644
index 0000000..d57f32d
--- /dev/null
+++ b/include/registry.h
@@ -0,0 +1,65 @@
+/***********************************************************
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+
+#ifndef DIX_REGISTRY_H
+#define DIX_REGISTRY_H
+
+#ifdef XREGISTRY
+
+#include "resource.h"
+
+/* Internal string registry - for auditing, debugging, security, etc. */
+
+/*
+ * Registration functions.  The name string is not copied, so it must
+ * not be a stack variable.
+ */
+void RegisterRequestName(unsigned major, unsigned minor, const char *name);
+void RegisterEventName(unsigned event, const char *name);
+void RegisterErrorName(unsigned error, const char *name);
+void RegisterResourceName(RESTYPE type, const char *name);
+
+/*
+ * Lookup functions.  The returned string must not be modified.
+ */
+const char *LookupRequestName(int major, int minor);
+const char *LookupEventName(int event);
+const char *LookupErrorName(int error);
+const char *LookupResourceName(RESTYPE rtype);
+
+/*
+ * Result returned from any unsuccessful lookup
+ */
+#define XREGISTRY_UNKNOWN "<unknown>"
+
+/*
+ * Setup and teardown
+ */
+void dixResetRegistry(void);
+
+#else /* XREGISTRY */
+
+/* Define calls away when the registry is not being built. */
+
+#define RegisterRequestName(a, b, c) { ; }
+#define RegisterEventName(a, b) { ; }
+#define RegisterErrorName(a, b) { ; }
+#define RegisterResourceName(a, b) { ; }
+
+#define LookupRequestName(a, b) XREGISTRY_UNKNOWN
+#define LookupEventName(a) XREGISTRY_UNKNOWN
+#define LookupErrorName(a) XREGISTRY_UNKNOWN
+#define LookupResourceName(a) XREGISTRY_UNKNOWN
+
+#define dixResetRegistry() { ; }
+
+#endif /* XREGISTRY */
+#endif /* DIX_REGISTRY_H */
diff --git a/include/resource.h b/include/resource.h
index 087d62c..4a33804 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -239,11 +239,6 @@ extern unsigned int GetXIDList(
 extern RESTYPE lastResourceType;
 extern RESTYPE TypeMask;
 
-#ifdef XResExtension
-extern Atom *ResourceNames;
-void RegisterResourceName(RESTYPE type, char* name);
-#endif
-
 /*
  * These are deprecated compatibility functions and will be removed soon!
  * Please use the noted replacements instead.
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index db5007e..6384857 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -500,9 +500,7 @@ RRCrtcInit (void)
     RRCrtcType = CreateNewResourceType (RRCrtcDestroyResource);
     if (!RRCrtcType)
 	return FALSE;
-#ifdef XResExtension
-	RegisterResourceName (RRCrtcType, "CRTC");
-#endif
+    RegisterResourceName (RRCrtcType, "CRTC");
     return TRUE;
 }
 
diff --git a/randr/rrmode.c b/randr/rrmode.c
index 1117581..d7cc916 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -266,9 +266,7 @@ RRModeInit (void)
     RRModeType = CreateNewResourceType (RRModeDestroyResource);
     if (!RRModeType)
 	return FALSE;
-#ifdef XResExtension
     RegisterResourceName (RRModeType, "MODE");
-#endif
     return TRUE;
 }
 
diff --git a/randr/rroutput.c b/randr/rroutput.c
index c1e971d..fea8797 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -420,9 +420,7 @@ RROutputInit (void)
     RROutputType = CreateNewResourceType (RROutputDestroyResource);
     if (!RROutputType)
 	return FALSE;
-#ifdef XResExtension
-	RegisterResourceName (RROutputType, "OUTPUT");
-#endif
+    RegisterResourceName (RROutputType, "OUTPUT");
     return TRUE;
 }
 
diff --git a/render/picture.c b/render/picture.c
index 184edb4..dd4221f 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -584,11 +584,9 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 	if (!GlyphSetType)
 	    return FALSE;
 	PictureGeneration = serverGeneration;
-#ifdef XResExtension
 	RegisterResourceName (PictureType, "PICTURE");
 	RegisterResourceName (PictFormatType, "PICTFORMAT");
 	RegisterResourceName (GlyphSetType, "GLYPHSET");
-#endif
     }
     if (!formats)
     {
commit 8f23d40068151ad85cde239d07031284f0b2c4dc
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 10 19:56:03 2007 -0400

    xace: move the property deletion hook inside the DeleteProperty function.

diff --git a/dix/property.c b/dix/property.c
index cff51d8..713507a 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -365,9 +365,10 @@ ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format,
 }
 
 int
-DeleteProperty(WindowPtr pWin, Atom propName)
+DeleteProperty(ClientPtr client, WindowPtr pWin, Atom propName)
 {
     PropertyPtr pProp, prevProp;
+    int rc;
 
     if (!(pProp = wUserProps (pWin)))
 	return(Success);
@@ -381,6 +382,11 @@ DeleteProperty(WindowPtr pWin, Atom propName)
     }
     if (pProp) 
     {		    
+	rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
+		      DixDestroyAccess);
+	if (rc != Success)
+	    return rc;
+
         if (prevProp == (PropertyPtr)NULL)      /* takes care of head */
         {
             if (!(pWin->optional->userProps = pProp->next))
@@ -636,14 +642,7 @@ ProcDeleteProperty(ClientPtr client)
 	return (BadAtom);
     }
 
-    result = XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
-		      FindProperty(pWin, stuff->property), DixDestroyAccess);
-    if (result != Success) {
-	client->errorValue = stuff->property;
-	return result;
-    }
-
-    result = DeleteProperty(pWin, stuff->property);
+    result = DeleteProperty(client, pWin, stuff->property);
     if (client->noClientException != Success)
 	return(client->noClientException);
     else
diff --git a/hw/darwin/quartz/xpr/xprFrame.c b/hw/darwin/quartz/xpr/xprFrame.c
index 76c719e..c5b84f0 100644
--- a/hw/darwin/quartz/xpr/xprFrame.c
+++ b/hw/darwin/quartz/xpr/xprFrame.c
@@ -337,7 +337,7 @@ xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
 void
 xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
 {
-    DeleteProperty(oldWin, xa_native_window_id());
+    DeleteProperty(serverClient, oldWin, xa_native_window_id());
 
     xprSetNativeProperty(pFrame);
 }
diff --git a/hw/xwin/winwin32rootless.c b/hw/xwin/winwin32rootless.c
index 832e36d..4b4cd3d 100755
--- a/hw/xwin/winwin32rootless.c
+++ b/hw/xwin/winwin32rootless.c
@@ -971,7 +971,7 @@ winMWExtWMRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin)
   SetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE,
 		    WS_POPUP | WS_CLIPCHILDREN);
 
-  DeleteProperty (oldWin, AtmWindowsWmNativeHwnd ());
+  DeleteProperty (serverClient, oldWin, AtmWindowsWmNativeHwnd ());
   winMWExtWMSetNativeProperty (pFrame);
 #if CYGMULTIWINDOW_DEBUG
 #if 0
commit 473bc6ec4c59e1a962b0b897c449a69aa5064ab0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 10 19:43:12 2007 -0400

    xace: remove the special-cased "ignore" functionality from the property code.
    
    There will be no more faking of Success to hide things.  XACE does not
    provide polyinstantiation.

diff --git a/Xext/xace.h b/Xext/xace.h
index e9fe9f3..fc96458 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -20,11 +20,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _XACE_H
 #define _XACE_H
 
-/* Special value used for ignore operation.  This is a deprecated feature
- * only for Security extension support.  Do not use in new code.
- */
-#define XaceIgnoreError BadRequest
-
 #ifdef XACE
 
 #define XACE_EXTENSION_NAME		"XAccessControlExtension"
diff --git a/dix/property.c b/dix/property.c
index 5f12dec..cff51d8 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -161,7 +161,7 @@ ProcRotateProperties(ClientPtr client)
 	if (rc != Success) {
             DEALLOCATE_LOCAL(props);
 	    client->errorValue = atoms[i];
-            return (rc == XaceIgnoreError) ? Success : rc;
+            return rc;
 	}
         props[i] = pProp;
     }
@@ -282,7 +282,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 	    xfree(data);
 	    xfree(pProp);
 	    pClient->errorValue = property;
-	    return (rc == XaceIgnoreError) ? Success : rc;
+	    return rc;
 	}
         pProp->next = pWin->optional->userProps;
         pWin->optional->userProps = pProp;
@@ -293,7 +293,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 		      DixWriteAccess);
 	if (rc != Success) {
 	    pClient->errorValue = property;
-	    return (rc == XaceIgnoreError) ? Success : rc;
+	    return rc;
 	}
 	/* To append or prepend to a property the request format and type
 		must match those of the already defined property.  The
@@ -499,8 +499,7 @@ ProcGetProperty(ClientPtr client)
     rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, access_mode);
     if (rc != Success) {
 	client->errorValue = stuff->property;
-	return (rc == XaceIgnoreError) ? 
-	    NullPropertyReply(client, pProp->type, pProp->format, &reply) : rc;
+	return rc;
     }
 
     /* If the request type and actual type don't match. Return the
@@ -641,7 +640,7 @@ ProcDeleteProperty(ClientPtr client)
 		      FindProperty(pWin, stuff->property), DixDestroyAccess);
     if (result != Success) {
 	client->errorValue = stuff->property;
-	return (result == XaceIgnoreError) ? Success : result;
+	return result;
     }
 
     result = DeleteProperty(pWin, stuff->property);
commit 7e9e01a4a34fa45521067d43c5bbff942dd5d51a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 10 17:40:22 2007 -0400

    dix: pass a valid ClientPtr to SetFontPath in all cases.

diff --git a/dix/main.c b/dix/main.c
index 03e0013..119828b 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -388,9 +388,9 @@ main(int argc, char *argv[], char *envp[])
 	    FatalError("failed to initialize core devices");
 
 	InitFonts();
-	if (loadableFonts) {
-	    SetFontPath(0, 0, (unsigned char *)defaultFontPath, &error);
-	}
+	if (loadableFonts)
+	    SetFontPath(serverClient, 0, (unsigned char *)defaultFontPath,
+			&error);
         else {
 	    if (SetDefaultFontPath(defaultFontPath) != Success)
 		ErrorF("failed to set default font path '%s'",
diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c
index e5f8635..b70f7d2 100644
--- a/hw/dmx/dmxfont.c
+++ b/hw/dmx/dmxfont.c
@@ -361,7 +361,8 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont)
 		}
 	    }
 
-	    if (SetFontPath(NULL, newnpaths, (unsigned char *)newfp, &error)) {
+	    if (SetFontPath(serverClient, newnpaths, (unsigned char *)newfp,
+			    &error)) {
 		/* Note that this should never happen since all of the
 		 * FPEs were previously valid. */
 		dmxLog(dmxError, "Cannot reset the default font path.\n");
commit 59cebcd2e9302d15a52588ecafbbc2d2c5ae3a6c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 2 13:39:25 2007 -0400

    xace: add creation hook for new input devices.
    
    Unfortunately, more information is needed to properly label the device.
    This will come from the configuration file, the hotplug messages, etc.
    It will either have to be passed into this function,
    or this hook moved down into the callers.

diff --git a/dix/devices.c b/dix/devices.c
index b6cb4a5..3395cd3 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -119,7 +119,6 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
     dev->name = (char *)NULL;
     dev->type = 0;
     dev->id = devid;
-    inputInfo.numDevices++;
     dev->public.on = FALSE;
     dev->public.processInputProc = (ProcessInputProc)NoopDDA;
     dev->public.realInputProc = (ProcessInputProc)NoopDDA;
@@ -156,6 +155,15 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
     dev->inited = FALSE;
     dev->enabled = FALSE;
 
+    /*  security creation/labeling check
+     */
+    if (XaceHook(XACE_DEVICE_ACCESS, serverClient, dev, DixCreateAccess)) {
+	xfree(dev);
+	return NULL;
+    }
+
+    inputInfo.numDevices++;
+
     for (prev = &inputInfo.off_devices; *prev; prev = &(*prev)->next)
         ;
     *prev = dev;
commit b77d272d7555c1e0f176ee74b8717030a6d6c7b0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 2 13:21:53 2007 -0400

    xace: add hooks + new access codes: XTEST extension

diff --git a/Xext/xtest.c b/Xext/xtest.c
index add9966..79c53b4 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -141,7 +141,7 @@ ProcXTestCompareCursor(client)
     register int n, rc;
 
     REQUEST_SIZE_MATCH(xXTestCompareCursorReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
     if (stuff->cursor == None)
@@ -149,11 +149,12 @@ ProcXTestCompareCursor(client)
     else if (stuff->cursor == XTestCurrentCursor)
 	pCursor = GetSpriteCursor();
     else {
-	pCursor = (CursorPtr)LookupIDByType(stuff->cursor, RT_CURSOR);
-	if (!pCursor) 
+	rc = dixLookupResource((pointer *)&pCursor, stuff->cursor, RT_CURSOR,
+			       client, DixReadAccess);
+	if (rc != Success) 
 	{
 	    client->errorValue = stuff->cursor;
-	    return (BadCursor);
+	    return (rc == BadValue) ? BadCursor : rc;
 	}
     }
     rep.type = X_Reply;
@@ -366,7 +367,7 @@ ProcXTestFakeInput(client)
 	else
 	{
 	    rc = dixLookupWindow(&root, ev->u.keyButtonPointer.root, client,
-				 DixUnknownAccess);
+				 DixGetAttrAccess);
 	    if (rc != Success)
 		return rc;
 	    if (root->parent)
commit 50551ec693f40b91652fe4814e9fe2e1f9ab6517
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 28 15:04:33 2007 -0400

    xace: remove obsoleted DRAWABLE_ACCESS hook.

diff --git a/Xext/security.c b/Xext/security.c
index fe1e48a..ec414a0 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1836,7 +1836,6 @@ SecurityExtensionInit(INITARGS)
     XaceRC(XACE_RESOURCE_ACCESS, SecurityCheckResourceIDAccess, NULL);
     XaceRC(XACE_DEVICE_ACCESS, SecurityCheckDeviceAccess, NULL);
     XaceRC(XACE_PROPERTY_ACCESS, SecurityCheckPropertyAccess, NULL);
-    XaceRC(XACE_DRAWABLE_ACCESS, SecurityCheckDrawableAccess, NULL);
     XaceRC(XACE_MAP_ACCESS, SecurityCheckMapAccess, NULL);
     XaceRC(XACE_EXT_DISPATCH, SecurityCheckExtAccess, NULL);
     XaceRC(XACE_EXT_ACCESS, SecurityCheckExtAccess, NULL);
diff --git a/Xext/xace.c b/Xext/xace.c
index 92f0e40..3de259f 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -105,16 +105,6 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_DRAWABLE_ACCESS: {
-	    XaceDrawableAccessRec rec = {
-		va_arg(ap, ClientPtr),
-		va_arg(ap, DrawablePtr),
-		Success /* default allow */
-	    };
-	    calldata = &rec;
-	    prv = &rec.status;
-	    break;
-	}
 	case XACE_SEND_ACCESS: {
 	    XaceSendAccessRec rec = {
 		va_arg(ap, ClientPtr),
diff --git a/Xext/xace.h b/Xext/xace.h
index c1fc071..e9fe9f3 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -45,20 +45,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_RESOURCE_ACCESS		2
 #define XACE_DEVICE_ACCESS		3
 #define XACE_PROPERTY_ACCESS		4
-#define XACE_DRAWABLE_ACCESS		5
-#define XACE_SEND_ACCESS		6
-#define XACE_RECEIVE_ACCESS		7
-#define XACE_CLIENT_ACCESS		8
-#define XACE_EXT_ACCESS			9
-#define XACE_SERVER_ACCESS		10
-#define XACE_SELECTION_ACCESS		11
-#define XACE_SCREEN_ACCESS		12
-#define XACE_SCREENSAVER_ACCESS		13
-#define XACE_AUTH_AVAIL			14
-#define XACE_KEY_AVAIL			15
-#define XACE_AUDIT_BEGIN		16
-#define XACE_AUDIT_END			17
-#define XACE_NUM_HOOKS			18
+#define XACE_SEND_ACCESS		5
+#define XACE_RECEIVE_ACCESS		6
+#define XACE_CLIENT_ACCESS		7
+#define XACE_EXT_ACCESS			8
+#define XACE_SERVER_ACCESS		9
+#define XACE_SELECTION_ACCESS		10
+#define XACE_SCREEN_ACCESS		11
+#define XACE_SCREENSAVER_ACCESS		12
+#define XACE_AUTH_AVAIL			13
+#define XACE_KEY_AVAIL			14
+#define XACE_AUDIT_BEGIN		15
+#define XACE_AUDIT_END			16
+#define XACE_NUM_HOOKS			17
 
 extern CallbackListPtr XaceHooks[XACE_NUM_HOOKS];
 
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index e12a52c..1dae4d6 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -65,13 +65,6 @@ typedef struct {
     int status;
 } XacePropertyAccessRec;
 
-/* XACE_DRAWABLE_ACCESS */
-typedef struct {
-    ClientPtr client;
-    DrawablePtr pDraw;
-    int status;
-} XaceDrawableAccessRec;
-
 /* XACE_SEND_ACCESS */
 typedef struct {
     ClientPtr client;
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 1ffd79d..bc86a32 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1389,7 +1389,6 @@ XSELinuxExtensionInit(INITARGS)
     XaceRegisterCallback(XACE_RESOURCE_ACCESS, XSELinuxResLookup, NULL);
     XaceRegisterCallback(XACE_MAP_ACCESS, XSELinuxMap, NULL);
     XaceRegisterCallback(XACE_SERVER_ACCESS, XSELinuxServer, NULL);
-    XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
     XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
     /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
     XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 65eb8cc..50384db 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2273,8 +2273,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
 	WriteReplyToClient(client, sizeof (xGetImageReply), &xgi);
     }
 
-    if (pDraw->type == DRAWABLE_WINDOW &&
-	XaceHook(XACE_DRAWABLE_ACCESS, client, pDraw) != Success)
+    if (pDraw->type == DRAWABLE_WINDOW)
     {
 	pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
 	if (pVisibleRegion)
commit 8b548657204000e18c7a38706a0071ae2f93159f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 28 13:34:18 2007 -0400

    xace: add hooks + new access codes: XKB extension.
    
    Removes "LookupKeyboardDevice" and "LookupPointerDevice" in favor of
    inputInfo.keyboard and inputInfo.pointer, respectively; all use cases
    are non-XI compliant anyway.

diff --git a/XTrap/xtrapddmi.c b/XTrap/xtrapddmi.c
index 73a20c1..3f1a72a 100644
--- a/XTrap/xtrapddmi.c
+++ b/XTrap/xtrapddmi.c
@@ -52,7 +52,7 @@ SOFTWARE.
 #define NEED_REPLIES
 #define NEED_EVENTS
 #include <X11/X.h>        /* From library include environment */
-#include "input.h"    /* From server include env. (must be before Xlib.h!) */
+#include "inputstr.h"    /* From server include env. (must be before Xlib.h!) */
 #ifdef PC
 # include "scrintst.h"          /* Screen struct */
 # include "extnsist.h"
@@ -96,8 +96,8 @@ int XETrapSimulateXEvent(register xXTrapInputReq *request,
     xEvent xev;
     register int x = request->input.x;
     register int y = request->input.y;
-    DevicePtr keydev = LookupKeyboardDevice();
-    DevicePtr ptrdev = LookupPointerDevice();
+    DevicePtr keydev = (DevicePtr)inputInfo.keyboard;
+    DevicePtr ptrdev = (DevicePtr)inputInfo.pointer;
 
     if (request->input.screen < screenInfo.numScreens)
     {
diff --git a/XTrap/xtrapdi.c b/XTrap/xtrapdi.c
index 23d3bde..efad36f 100644
--- a/XTrap/xtrapdi.c
+++ b/XTrap/xtrapdi.c
@@ -58,7 +58,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <X11/Xos.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
-#include "input.h"              /* Server DevicePtr definitions */
+#include "inputstr.h"           /* Server DevicePtr definitions */
 #include "misc.h"               /* Server swapping macros */
 #include "dixstruct.h"          /* Server ClientRec definitions */
 #include "resource.h"           /* Used with the MakeAtom call */
@@ -277,7 +277,7 @@ Bool XETrapRedirectDevices()
     /* Do we need to redirect the keyboard device? */
     if (XETrapKbdDev == NULL)
     {
-        if ((XETrapKbdDev = LookupKeyboardDevice()) == NULL)
+        if ((XETrapKbdDev = (DevicePtr)inputInfo.keyboard) == NULL)
         {
             retval = False;
         }
@@ -302,7 +302,7 @@ Bool XETrapRedirectDevices()
 #ifndef VECTORED_EVENTS
     if (XETrapPtrDev == NULL)
     {
-        if ((XETrapPtrDev = LookupPointerDevice()) == 0L)
+        if ((XETrapPtrDev = (DevicePtr)inputInfo.pointer) == 0L)
         {
             retval = False;
         }
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 42cf817..add9966 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -316,7 +316,7 @@ ProcXTestFakeInput(client)
 #ifdef XINPUT
 	if (!extension)
 #endif /* XINPUT */
-	    dev = (DeviceIntPtr)LookupKeyboardDevice();
+	    dev = inputInfo.keyboard;
 	if (ev->u.u.detail < dev->key->curKeySyms.minKeyCode ||
 	    ev->u.u.detail > dev->key->curKeySyms.maxKeyCode)
 	{
@@ -360,7 +360,7 @@ ProcXTestFakeInput(client)
 	    break;
 	}
 #endif /* XINPUT */
-	dev = (DeviceIntPtr)LookupPointerDevice();
+	dev = inputInfo.pointer;
 	if (ev->u.keyButtonPointer.root == None)
 	    root = GetCurrentRootWindow();
 	else
@@ -449,7 +449,7 @@ ProcXTestFakeInput(client)
 #ifdef XINPUT
 	if (!extension)
 #endif /* XINPUT */
-	    dev = (DeviceIntPtr)LookupPointerDevice();
+	    dev = inputInfo.pointer;
 	if (!ev->u.u.detail || ev->u.u.detail > dev->button->numButtons)
 	{
 	    client->errorValue = ev->u.u.detail;
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 7eb5422..c2661e8 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -62,6 +62,7 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
 #include "exglobals.h"
+#include "xace.h"
 
 #include "grabdev.h"
 #include "grabdevb.h"
@@ -127,8 +128,12 @@ ProcXGrabDeviceButton(ClientPtr client)
 	    return ret;
 	if (mdev->key == NULL)
 	    return BadMatch;
-    } else
-	mdev = (DeviceIntPtr) LookupKeyboardDevice();
+    } else {
+	mdev = inputInfo.keyboard;
+	ret = XaceHook(XACE_DEVICE_ACCESS, client, mdev, DixReadAccess);
+	if (ret != Success)
+	    return ret;
+    }
 
     class = (XEventClass *) (&stuff[1]);	/* first word of values */
 
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index e187a4f..43b1928 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -62,6 +62,7 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
 #include "exglobals.h"
+#include "xace.h"
 
 #include "grabdev.h"
 #include "grabdevk.h"
@@ -125,8 +126,12 @@ ProcXGrabDeviceKey(ClientPtr client)
 	    return ret;
 	if (mdev->key == NULL)
 	    return BadMatch;
-    } else
-	mdev = (DeviceIntPtr) LookupKeyboardDevice();
+    } else {
+	mdev = inputInfo.keyboard;
+	ret = XaceHook(XACE_DEVICE_ACCESS, client, mdev, DixReadAccess);
+	if (ret != Success)
+	    return ret;
+    }
 
     class = (XEventClass *) (&stuff[1]);	/* first word of values */
 
diff --git a/Xi/ungrdevb.c b/Xi/ungrdevb.c
index 85ca5c6..590699f 100644
--- a/Xi/ungrdevb.c
+++ b/Xi/ungrdevb.c
@@ -120,7 +120,7 @@ ProcXUngrabDeviceButton(ClientPtr client)
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
-	mdev = (DeviceIntPtr) LookupKeyboardDevice();
+	mdev = inputInfo.keyboard;
 
     rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
diff --git a/Xi/ungrdevk.c b/Xi/ungrdevk.c
index ac40035..521765e 100644
--- a/Xi/ungrdevk.c
+++ b/Xi/ungrdevk.c
@@ -120,7 +120,7 @@ ProcXUngrabDeviceKey(ClientPtr client)
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
-	mdev = (DeviceIntPtr) LookupKeyboardDevice();
+	mdev = inputInfo.keyboard;
 
     rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
diff --git a/dix/devices.c b/dix/devices.c
index bd1bef7..b6cb4a5 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -705,18 +705,6 @@ RegisterKeyboardDevice(DeviceIntPtr device)
     RegisterOtherDevice(device);
 }
 
-_X_EXPORT DevicePtr
-LookupKeyboardDevice(void)
-{
-    return inputInfo.keyboard ? &inputInfo.keyboard->public : NULL;
-}
-
-_X_EXPORT DevicePtr
-LookupPointerDevice(void)
-{
-    return inputInfo.pointer ? &inputInfo.pointer->public : NULL;
-}
-
 int
 dixLookupDevice(DeviceIntPtr *pDev, int id, ClientPtr client, Mask access_mode)
 {
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index e8001df..2e0c004 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -691,7 +691,7 @@ ephyrUpdateModifierState(unsigned int state)
   int          i;
   CARD8        mask;
 
-  pkeydev = (DeviceIntPtr)LookupKeyboardDevice();
+  pkeydev = inputInfo.keyboard;
 
   if (!pkeydev)
     return;
diff --git a/hw/kdrive/vxworks/vxkbd.c b/hw/kdrive/vxworks/vxkbd.c
index be528c7..ac83ef7 100644
--- a/hw/kdrive/vxworks/vxkbd.c
+++ b/hw/kdrive/vxworks/vxkbd.c
@@ -232,7 +232,7 @@ VxWorksKeyboardRead (int fd)
 void
 VxWorksKeyboardLeds (int leds)
 {
-    DeviceIntPtr	pKeyboard = (DeviceIntPtr) LookupKeyboardDevice ();
+    DeviceIntPtr	pKeyboard = inputInfo.keyboard;
     KeyboardCtrl		*ctrl = &pKeyboard->kbdfeed->ctrl;
     led_ioctl_info	led_info;
     int			i;
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 4b3b66a..0eaa2d3 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -139,8 +139,6 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(InitKeyboardDeviceStruct)
     SYMFUNC(SendMappingNotify)
     SYMFUNC(InitPointerDeviceStruct)
-    SYMFUNC(LookupKeyboardDevice)
-    SYMFUNC(LookupPointerDevice)
     /* dispatch.c */
     SYMFUNC(SetInputCheck)
     SYMFUNC(SendErrorToClient)
diff --git a/hw/xgl/egl/kinput.c b/hw/xgl/egl/kinput.c
index 981cffc..774e00e 100644
--- a/hw/xgl/egl/kinput.c
+++ b/hw/xgl/egl/kinput.c
@@ -439,7 +439,7 @@ KdKeybdProc(DeviceIntPtr pDevice, int onoff)
     switch (onoff)
     {
     case DEVICE_INIT:
-	if (pDev != LookupKeyboardDevice())
+	if (pDev != (DevicePtr)inputInfo.keyboard)
 	{
 	    return !Success;
 	}
diff --git a/hw/xgl/glx/xglx.c b/hw/xgl/glx/xglx.c
index 89bd72e..33b276b 100644
--- a/hw/xgl/glx/xglx.c
+++ b/hw/xgl/glx/xglx.c
@@ -1100,7 +1100,7 @@ xglxKeybdProc (DeviceIntPtr pDevice,
       int	      xkbOp, xkbEvent, xkbError, xkbMajor, xkbMinor;
 #endif
 
-      if (pDev != LookupKeyboardDevice ())
+      if (pDev != (DevicePtr)inputInfo.keyboard)
 	  return !Success;
 
       xmodMap = XGetModifierMapping (xdisplay);
diff --git a/hw/xgl/xglinput.c b/hw/xgl/xglinput.c
index cda21ad..9499fcf 100644
--- a/hw/xgl/xglinput.c
+++ b/hw/xgl/xglinput.c
@@ -224,7 +224,7 @@ xglKeybdProc (DeviceIntPtr pDevice,
 
     switch (onoff) {
     case DEVICE_INIT:
-	if (pDev != LookupKeyboardDevice ())
+	if (pDev != (DevicePtr)inputInfo.keyboard)
 	    return !Success;
 
 	ret = InitKeyboardDeviceStruct (pDev,
diff --git a/include/input.h b/include/input.h
index d8a9fe8..ca67cfa 100644
--- a/include/input.h
+++ b/include/input.h
@@ -197,10 +197,6 @@ extern void RegisterPointerDevice(
 extern void RegisterKeyboardDevice(
     DeviceIntPtr /*device*/);
 
-extern DevicePtr LookupKeyboardDevice(void);
-
-extern DevicePtr LookupPointerDevice(void);
-
 extern int dixLookupDevice(
     DeviceIntPtr *         /* dev */,
     int                    /* id */,
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 71ea115..e4a1db3 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -262,6 +262,7 @@ typedef struct
 extern int	XkbReqCode;
 extern int	XkbEventBase;
 extern int	XkbDisableLockActions;
+extern int	XkbKeyboardErrorCode;
 extern char *	XkbBaseDirectory;
 extern char *	XkbBinDirectory;
 extern char *	XkbInitialMap;
@@ -352,29 +353,44 @@ extern	void XkbFreeNames(
 	Bool			/* freeMap */
 );
 
-extern DeviceIntPtr _XkbLookupAnyDevice(
-    int			/* id */,
-    int *		/* why_rtrn */
+extern int _XkbLookupAnyDevice(
+    DeviceIntPtr *pDev,
+    int id,
+    ClientPtr client,
+    Mask access_mode,
+    int *xkb_err
 );
 
-extern DeviceIntPtr _XkbLookupKeyboard(
-    int			/* id */,
-    int *		/* why_rtrn */
+extern int _XkbLookupKeyboard(
+    DeviceIntPtr *pDev,
+    int id,
+    ClientPtr client,
+    Mask access_mode,
+    int *xkb_err
 );
 
-extern DeviceIntPtr _XkbLookupBellDevice(
-    int			/* id */,
-    int *		/* why_rtrn */
+extern int _XkbLookupBellDevice(
+    DeviceIntPtr *pDev,
+    int id,
+    ClientPtr client,
+    Mask access_mode,
+    int *xkb_err
 );
 
-extern DeviceIntPtr _XkbLookupLedDevice(
-    int			/* id */,
-    int *		/* why_rtrn */
+extern int _XkbLookupLedDevice(
+    DeviceIntPtr *pDev,
+    int id,
+    ClientPtr client,
+    Mask access_mode,
+    int *xkb_err
 );
 
-extern DeviceIntPtr _XkbLookupButtonDevice(
-    int			/* id */,
-    int *		/* why_rtrn */
+extern int _XkbLookupButtonDevice(
+    DeviceIntPtr *pDev,
+    int id,
+    ClientPtr client,
+    Mask access_mode,
+    int *xkb_err
 );
 
 extern	XkbDescPtr XkbAllocKeyboard(
diff --git a/xkb/ddxDevBtn.c b/xkb/ddxDevBtn.c
index 7e27c51..5313a1e 100644
--- a/xkb/ddxDevBtn.c
+++ b/xkb/ddxDevBtn.c
@@ -53,7 +53,7 @@ deviceValuator *	val;
 int			x,y;
 int			nAxes, i, count;
 
-    if ((dev==(DeviceIntPtr)LookupPointerDevice())||(!dev->public.on))
+    if (dev == inputInfo.pointer || !dev->public.on)
 	return;
 
     nAxes = (dev->valuator?dev->valuator->numAxes:0);
diff --git a/xkb/ddxFakeBtn.c b/xkb/ddxFakeBtn.c
index 8144fd2..2dad54f 100644
--- a/xkb/ddxFakeBtn.c
+++ b/xkb/ddxFakeBtn.c
@@ -46,7 +46,7 @@ xEvent	ev;
 int	x,y;
 DevicePtr ptr;
 
-    if ((ptr = LookupPointerDevice())==NULL)
+    if ((ptr = (DevicePtr)inputInfo.pointer)==NULL)
 	return;
     GetSpritePosition(&x,&y);
     ev.u.u.type = event;
diff --git a/xkb/xkb.c b/xkb/xkb.c
index cf42430..9efdfb6 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -38,6 +38,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define	XKBSRV_NEED_FILE_FUNCS
 #include <xkbsrv.h>
 #include "extnsionst.h"
+#include "xace.h"
 #include "xkb.h"
 
 #include <X11/extensions/XI.h>
@@ -45,7 +46,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 	int	XkbEventBase;
 static	int	XkbErrorBase;
 	int	XkbReqCode;
-static  int	XkbKeyboardErrorCode;
+	int	XkbKeyboardErrorCode;
 CARD32	xkbDebugFlags = 0;
 static CARD32	xkbDebugCtrls = 0;
 
@@ -53,19 +54,23 @@ static RESTYPE	RT_XKBCLIENT;
 
 /***====================================================================***/
 
-#define	CHK_DEVICE(d,sp,lf) {\
+#define	CHK_DEVICE(dev, id, client, access_mode, lf) {\
     int why;\
-    d = (DeviceIntPtr)lf((sp),&why);\
-    if  (!dev) {\
-	client->errorValue = _XkbErrCode2(why,(sp));\
-	return XkbKeyboardErrorCode;\
+    int rc = lf(&(dev), id, client, access_mode, &why);\
+    if (rc != Success) {\
+	client->errorValue = _XkbErrCode2(why, id);\
+	return rc;\
     }\
 }
 
-#define	CHK_KBD_DEVICE(d,sp) 	CHK_DEVICE(d,sp,_XkbLookupKeyboard)
-#define	CHK_LED_DEVICE(d,sp) 	CHK_DEVICE(d,sp,_XkbLookupLedDevice)
-#define	CHK_BELL_DEVICE(d,sp) 	CHK_DEVICE(d,sp,_XkbLookupBellDevice)
-#define	CHK_ANY_DEVICE(d,sp) 	CHK_DEVICE(d,sp,_XkbLookupAnyDevice)
+#define	CHK_KBD_DEVICE(dev, id, client, mode) \
+    CHK_DEVICE(dev, id, client, mode, _XkbLookupKeyboard)
+#define	CHK_LED_DEVICE(dev, id, client, mode) \
+    CHK_DEVICE(dev, id, client, mode, _XkbLookupLedDevice)
+#define	CHK_BELL_DEVICE(dev, id, client, mode) \
+    CHK_DEVICE(dev, id, client, mode, _XkbLookupBellDevice)
+#define	CHK_ANY_DEVICE(dev, id, client, mode) \
+    CHK_DEVICE(dev, id, client, mode, _XkbLookupAnyDevice)
 
 #define	CHK_ATOM_ONLY2(a,ev,er) {\
 	if (((a)==None)||(!ValidAtom((a)))) {\
@@ -206,7 +211,7 @@ ProcXkbSelectEvents(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_ANY_DEVICE(dev,stuff->deviceSpec);
+    CHK_ANY_DEVICE(dev, stuff->deviceSpec, client, DixReadAccess);
 
     if (((stuff->affectWhich&XkbMapNotifyMask)!=0)&&(stuff->affectMap)) {
 	client->mapNotifyMask&= ~stuff->affectMap;
@@ -351,7 +356,7 @@ ProcXkbBell(ClientPtr client)
     REQUEST(xkbBellReq);
     DeviceIntPtr dev;
     WindowPtr	 pWin;
-    int base;
+    int rc, base;
     int newPercent,oldPitch,oldDuration;
     pointer ctrl;
 
@@ -360,7 +365,7 @@ ProcXkbBell(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_BELL_DEVICE(dev,stuff->deviceSpec);
+    CHK_BELL_DEVICE(dev, stuff->deviceSpec, client, DixBellAccess);
     CHK_ATOM_OR_NONE(stuff->name);
 
     if ((stuff->forceSound)&&(stuff->eventOnly)) {
@@ -448,10 +453,10 @@ ProcXkbBell(ClientPtr client)
 	return BadValue;
     }
     if (stuff->window!=None) {
-	pWin= (WindowPtr)LookupIDByType(stuff->window,RT_WINDOW);
-	if (pWin==NULL) {
+	rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
+	if (rc != Success) {
 	    client->errorValue= stuff->window;
-	    return BadValue;
+	    return rc;
 	}
     }
     else pWin= NULL;
@@ -499,7 +504,7 @@ ProcXkbGetState(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixReadAccess);
 
     xkb= &dev->key->xkbInfo->state;
     bzero(&rep,sizeof(xkbGetStateReply));
@@ -544,7 +549,7 @@ ProcXkbLatchLockState(ClientPtr client)
     if (!(client->xkbClientFlags & _XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev, stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
     CHK_MASK_MATCH(0x01, stuff->affectModLocks, stuff->modLocks);
     CHK_MASK_MATCH(0x01, stuff->affectModLatches, stuff->modLatches);
 
@@ -612,7 +617,7 @@ ProcXkbGetControls(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
     
     xkb = dev->key->xkbInfo->desc->ctrls;
     rep.type = X_Reply;
@@ -689,7 +694,7 @@ ProcXkbSetControls(ClientPtr client)
     if (!(client->xkbClientFlags & _XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev, stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
     CHK_MASK_LEGAL(0x01, stuff->changeCtrls, XkbAllControlsMask);
 
     for (tmpd = inputInfo.keyboard; tmpd; tmpd = tmpd->next) {
@@ -1370,7 +1375,7 @@ ProcXkbGetMap(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
     CHK_MASK_OVERLAP(0x01,stuff->full,stuff->partial);
     CHK_MASK_LEGAL(0x02,stuff->full,XkbAllMapComponentsMask);
     CHK_MASK_LEGAL(0x03,stuff->partial,XkbAllMapComponentsMask);
@@ -2299,7 +2304,7 @@ ProcXkbSetMap(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
     CHK_MASK_LEGAL(0x01,stuff->present,XkbAllMapComponentsMask);
 
     XkbSetCauseXkbReq(&cause,X_kbSetMap,client);
@@ -2569,7 +2574,7 @@ ProcXkbGetCompatMap(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
 
     xkb = dev->key->xkbInfo->desc;
     compat= xkb->compat;
@@ -2613,7 +2618,7 @@ ProcXkbSetCompatMap(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
 
     data = (char *)&stuff[1];
     xkbi = dev->key->xkbInfo;
@@ -2748,7 +2753,7 @@ ProcXkbGetIndicatorState(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixReadAccess);
 
     sli= XkbFindSrvLedInfo(dev,XkbDfltXIClass,XkbDfltXIId,
 						XkbXI_IndicatorStateMask);
@@ -2859,7 +2864,7 @@ XkbIndicatorPtr		leds;
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
 
     xkb= dev->key->xkbInfo->desc;
     leds= xkb->indicators;
@@ -2878,7 +2883,7 @@ int
 ProcXkbSetIndicatorMap(ClientPtr client)
 {
     register int 	i,bit;
-    int			nIndicators,why;
+    int			nIndicators;
     DeviceIntPtr 	dev;
     XkbSrvInfoPtr	xkbi;
     xkbIndicatorMapWireDesc *from;
@@ -2891,11 +2896,8 @@ ProcXkbSetIndicatorMap(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    dev = _XkbLookupKeyboard(stuff->deviceSpec,&why);
-    if (!dev) {
-	client->errorValue = _XkbErrCode2(why,stuff->deviceSpec);
-	return XkbKeyboardErrorCode;
-    }
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
+
     xkbi= dev->key->xkbInfo;
 
     if (stuff->which==0)
@@ -2971,7 +2973,7 @@ ProcXkbGetNamedIndicator(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_LED_DEVICE(dev,stuff->deviceSpec);
+    CHK_LED_DEVICE(dev, stuff->deviceSpec, client, DixReadAccess);
     CHK_ATOM_ONLY(stuff->indicator);
 
     sli= XkbFindSrvLedInfo(dev,stuff->ledClass,stuff->ledID,0);
@@ -3057,7 +3059,7 @@ ProcXkbSetNamedIndicator(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_LED_DEVICE(dev,stuff->deviceSpec);
+    CHK_LED_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
     CHK_ATOM_ONLY(stuff->indicator);
     CHK_MASK_LEGAL(0x10,stuff->whichGroups,XkbIM_UseAnyGroup);
     CHK_MASK_LEGAL(0x11,stuff->whichMods,XkbIM_UseAnyMods);
@@ -3125,7 +3127,7 @@ ProcXkbSetNamedIndicator(ClientPtr client)
 
     kbd= dev;
     if ((sli->flags&XkbSLI_HasOwnState)==0)
-	kbd= (DeviceIntPtr)LookupKeyboardDevice();
+	kbd = inputInfo.keyboard;
     XkbFlushLedEvents(dev,kbd,sli,&ed,&changes,&cause);
     return client->noClientException;
 }
@@ -3433,7 +3435,7 @@ ProcXkbGetNames(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
     CHK_MASK_LEGAL(0x01,stuff->which,XkbAllNamesMask);
 
     xkb = dev->key->xkbInfo->desc;
@@ -3543,7 +3545,7 @@ ProcXkbSetNames(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixUnknownAccess);
     CHK_MASK_LEGAL(0x01,stuff->which,XkbAllNamesMask);
 
     xkb = dev->key->xkbInfo->desc;
@@ -4379,7 +4381,7 @@ ProcXkbGetGeometry(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
     CHK_ATOM_OR_NONE(stuff->name);
 
     geom= XkbLookupNamedGeometry(dev,stuff->name,&shouldFree);
@@ -4842,7 +4844,7 @@ ProcXkbSetGeometry(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
     CHK_ATOM_OR_NONE(stuff->name);
 
     xkb= dev->key->xkbInfo->desc;
@@ -4897,6 +4899,7 @@ ProcXkbPerClientFlags(ClientPtr client)
     DeviceIntPtr 		dev;
     xkbPerClientFlagsReply 	rep;
     XkbInterestPtr		interest;
+    Mask access_mode = DixGetAttrAccess | DixSetAttrAccess;
 
     REQUEST(xkbPerClientFlagsReq);
     REQUEST_SIZE_MATCH(xkbPerClientFlagsReq);
@@ -4904,7 +4907,7 @@ ProcXkbPerClientFlags(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, access_mode);
     CHK_MASK_LEGAL(0x01,stuff->change,XkbPCF_AllFlagsMask);
     CHK_MASK_MATCH(0x02,stuff->change,stuff->value);
 
@@ -5040,7 +5043,7 @@ ProcXkbListComponents(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
 
     status= Success;
     str= (unsigned char *)&stuff[1];
@@ -5123,6 +5126,7 @@ ProcXkbGetKbdByName(ClientPtr client)
     Bool			geom_changed;
     XkbSrvLedInfoPtr            old_sli;
     XkbSrvLedInfoPtr            sli;
+    Mask access_mode = DixGetAttrAccess | DixSetAttrAccess;
 
     REQUEST(xkbGetKbdByNameReq);
     REQUEST_AT_LEAST_SIZE(xkbGetKbdByNameReq);
@@ -5130,7 +5134,7 @@ ProcXkbGetKbdByName(ClientPtr client)
     if (!(client->xkbClientFlags&_XkbClientInitialized))
 	return BadAccess;
 
-    CHK_KBD_DEVICE(dev,stuff->deviceSpec);
+    CHK_KBD_DEVICE(dev, stuff->deviceSpec, client, access_mode);
 
     xkb = dev->key->xkbInfo->desc;
     status= Success;
@@ -5664,7 +5668,7 @@ char *			str;
 
     wanted= stuff->wanted;
 
-    CHK_ANY_DEVICE(dev,stuff->deviceSpec);
+    CHK_ANY_DEVICE(dev, stuff->deviceSpec, client, DixGetAttrAccess);
     CHK_MASK_LEGAL(0x01,wanted,XkbXI_AllDeviceFeaturesMask);
 
     if ((!dev->button)||((stuff->nBtns<1)&&(!stuff->allBtns)))
@@ -5968,7 +5972,7 @@ DeviceIntPtr			kbd;
 
 	kbd= dev;
 	if ((sli->flags&XkbSLI_HasOwnState)==0)
-	    kbd= (DeviceIntPtr)LookupKeyboardDevice();
+	    kbd = inputInfo.keyboard;
 
 	XkbFlushLedEvents(dev,kbd,sli,&ed,&changes,&cause);
 	ledWire= (xkbDeviceLedsWireDesc *)mapWire;
@@ -5993,7 +5997,7 @@ xkbExtensionDeviceNotify ed;
 
     change= stuff->change;
 
-    CHK_ANY_DEVICE(dev,stuff->deviceSpec);
+    CHK_ANY_DEVICE(dev, stuff->deviceSpec, client, DixSetAttrAccess);
     CHK_MASK_LEGAL(0x01,change,XkbXI_AllFeaturesMask);
 
     wire= (char *)&stuff[1];
@@ -6043,7 +6047,7 @@ xkbExtensionDeviceNotify ed;
 	ed.nBtns=	stuff->nBtns;
 
 	if (dev->key)	kbd= dev;
-	else		kbd= (DeviceIntPtr)LookupKeyboardDevice();
+	else		kbd= inputInfo.keyboard;
 	acts= &dev->button->xkb_acts[stuff->firstBtn];
 	for (i=0;i<stuff->nBtns;i++,acts++) {
 	    if (acts->type!=XkbSA_NoAction)
@@ -6069,10 +6073,15 @@ ProcXkbSetDebuggingFlags(ClientPtr client)
 {
 CARD32 				newFlags,newCtrls,extraLength;
 xkbSetDebuggingFlagsReply 	rep;
+int rc;
 
     REQUEST(xkbSetDebuggingFlagsReq);
     REQUEST_AT_LEAST_SIZE(xkbSetDebuggingFlagsReq);
 
+    rc = XaceHook(XACE_SERVER_ACCESS, client, DixDebugAccess);
+    if (rc != Success)
+	return rc;
+
     newFlags=  xkbDebugFlags&(~stuff->affectFlags);
     newFlags|= (stuff->flags&stuff->affectFlags);
     newCtrls=  xkbDebugCtrls&(~stuff->affectCtrls);
diff --git a/xkb/xkbAccessX.c b/xkb/xkbAccessX.c
index 2954a0c..fbd2815 100644
--- a/xkb/xkbAccessX.c
+++ b/xkb/xkbAccessX.c
@@ -689,7 +689,7 @@ ProcessPointerEvent(	register xEvent  *	xE,
 			register DeviceIntPtr	mouse, 
 			int		        count)
 {
-DeviceIntPtr	dev = (DeviceIntPtr)LookupKeyboardDevice();
+DeviceIntPtr	dev = inputInfo.keyboard;
 XkbSrvInfoPtr	xkbi = dev->key->xkbInfo;
 unsigned 	changed = 0;
 
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 7f0f74d..822afff 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -1026,8 +1026,9 @@ DeviceIntPtr	dev;
 int		button;
 
     if (filter->keycode==0) {		/* initial press */
-	dev= _XkbLookupButtonDevice(pAction->devbtn.device,NULL);
-	if ((!dev)||(!dev->public.on)||(&dev->public==LookupPointerDevice()))
+	_XkbLookupButtonDevice(&dev, pAction->devbtn.device, serverClient,
+			       DixUnknownAccess, &button);
+	if (!dev || !dev->public.on || dev == inputInfo.pointer)
 	    return 1;
 
 	button= pAction->devbtn.button;
@@ -1066,8 +1067,9 @@ int		button;
 	int	button;
 
 	filter->active= 0;
-	dev= _XkbLookupButtonDevice(filter->upAction.devbtn.device,NULL);
-	if ((!dev)||(!dev->public.on)||(&dev->public==LookupPointerDevice()))
+	_XkbLookupButtonDevice(&dev, filter->upAction.devbtn.device,
+			       serverClient, DixUnknownAccess, &button);
+	if (!dev || !dev->public.on || dev == inputInfo.pointer)
 	    return 1;
 
 	button= filter->upAction.btn.button;
diff --git a/xkb/xkbEvents.c b/xkb/xkbEvents.c
index 11dc17a..15b4949 100644
--- a/xkb/xkbEvents.c
+++ b/xkb/xkbEvents.c
@@ -806,7 +806,7 @@ Bool
 XkbFilterEvents(ClientPtr pClient,int nEvents,xEvent *xE)
 {
 int	i, button_mask;
-DeviceIntPtr pXDev = (DeviceIntPtr)LookupKeyboardDevice();
+DeviceIntPtr pXDev = inputInfo.keyboard;
 XkbSrvInfoPtr	xkbi;
 
     xkbi= pXDev->key->xkbInfo;
diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
index d607d90..2877af0 100644
--- a/xkb/xkbLEDs.c
+++ b/xkb/xkbLEDs.c
@@ -239,7 +239,7 @@ unsigned			oldState;
 
     if (dev->key && dev->key->xkbInfo)
 	 kbd= dev;
-    else kbd= (DeviceIntPtr)LookupKeyboardDevice();
+    else kbd= inputInfo.keyboard;
 
     state= &kbd->key->xkbInfo->state;
     ctrls= kbd->key->xkbInfo->desc->ctrls;
@@ -444,7 +444,7 @@ XkbIndicatorMapPtr	map;
 XkbDescPtr		xkb;
 
     if ((sli->flags&XkbSLI_HasOwnState)==0)
-	dev= (DeviceIntPtr)LookupKeyboardDevice();
+	dev= inputInfo.keyboard;
 
     sli->usesBase&=	 ~which;
     sli->usesLatched&=	 ~which;
@@ -731,7 +731,7 @@ xkbExtensionDeviceNotify	my_ed;
 	return;
     if (dev->key && dev->key->xkbInfo)
 	 kbd= dev;
-    else kbd= (DeviceIntPtr)LookupKeyboardDevice();
+    else kbd= inputInfo.keyboard;
 
     if (ed==NULL) {
 	ed= &my_ed;
@@ -808,7 +808,7 @@ xkbExtensionDeviceNotify	my_ed;
 	return;
     if (dev->key && dev->key->xkbInfo)
 	 kbd= dev;
-    else kbd= (DeviceIntPtr)LookupKeyboardDevice();
+    else kbd= inputInfo.keyboard;
 
     if (ed==NULL) {
 	ed= &my_ed;
@@ -869,7 +869,7 @@ Bool				kb_changed;
 	return;
     if (dev->key && dev->key->xkbInfo)
 	 kbd= dev;
-    else kbd= (DeviceIntPtr)LookupKeyboardDevice();
+    else kbd= inputInfo.keyboard;
     xkbi= kbd->key->xkbInfo;
 
     if (changes==NULL) {
diff --git a/xkb/xkbPrOtherEv.c b/xkb/xkbPrOtherEv.c
index a2ea090..d65107c 100644
--- a/xkb/xkbPrOtherEv.c
+++ b/xkb/xkbPrOtherEv.c
@@ -71,7 +71,7 @@ Bool	xkbCares,isBtn;
 	if ((!isBtn)||((dev->button)&&(dev->button->xkb_acts))) {
 	   DeviceIntPtr	kbd;
 	   if (dev->key)	kbd= dev;
-	   else		kbd= (DeviceIntPtr)LookupKeyboardDevice();
+	   else		kbd= inputInfo.keyboard;
 	   XkbHandleActions(dev,kbd,xE,count);
 	   return;
 	}
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 877d4d2..31c1a9f 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -49,92 +49,115 @@ int	XkbDisableLockActions = 0;
 
 /***====================================================================***/
 
-DeviceIntPtr
-_XkbLookupAnyDevice(int id,int *why_rtrn)
+int
+_XkbLookupAnyDevice(DeviceIntPtr *pDev, int id, ClientPtr client,
+		    Mask access_mode, int *xkb_err)
 {
-DeviceIntPtr dev = NULL;
+    int rc = XkbKeyboardErrorCode;
 
-    dev= (DeviceIntPtr)LookupKeyboardDevice();
-    if ((id==XkbUseCoreKbd)||(dev->id==id))
-	return dev;
-
-    dev= (DeviceIntPtr)LookupPointerDevice();
-    if ((id==XkbUseCorePtr)||(dev->id==id))
-	return dev;
-
-    if (id&(~0xff))
-	 dev = NULL;
-
-    dixLookupDevice(&dev, id, serverClient, DixUnknownAccess);
-    if (dev!=NULL) 
-	return dev;
-    if ((!dev)&&(why_rtrn))
-	*why_rtrn= XkbErr_BadDevice;
-    return dev;
+    if (id == XkbUseCoreKbd) {
+	if (inputInfo.keyboard)
+	    id = inputInfo.keyboard->id;
+	else
+	    goto out;
+    }
+    if (id == XkbUseCorePtr) {
+	if (inputInfo.pointer)
+	    id = inputInfo.pointer->id;
+	else
+	    goto out;
+    }
+    rc = dixLookupDevice(pDev, id, client, access_mode);
+out:
+    if (rc != Success)
+	*xkb_err = XkbErr_BadDevice;
+    return rc;
 }
 
-DeviceIntPtr
-_XkbLookupKeyboard(int id,int *why_rtrn)
+int
+_XkbLookupKeyboard(DeviceIntPtr *pDev, int id, ClientPtr client,
+		   Mask access_mode, int *xkb_err)
 {
-DeviceIntPtr dev = NULL;
+    DeviceIntPtr dev;
+    int rc;
 
     if (id == XkbDfltXIId)
         id = XkbUseCoreKbd;
-    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
-	return NULL;
-    else if ((!dev->key)||(!dev->key->xkbInfo)) {
-	if (why_rtrn)
-	   *why_rtrn= XkbErr_BadClass;
-	return NULL;
+
+    rc = _XkbLookupAnyDevice(pDev, id, client, access_mode, xkb_err);
+    if (rc != Success)
+	return rc;
+
+    dev = *pDev;
+    if (!dev->key || !dev->key->xkbInfo) {
+	*pDev = NULL;
+	*xkb_err= XkbErr_BadClass;
+	return XkbKeyboardErrorCode;
     }
-    return dev;
+    return Success;
 }
 
-DeviceIntPtr
-_XkbLookupBellDevice(int id,int *why_rtrn)
+int
+_XkbLookupBellDevice(DeviceIntPtr *pDev, int id, ClientPtr client,
+		     Mask access_mode, int *xkb_err)
 {
-DeviceIntPtr dev = NULL;
-
-    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
-	return NULL;
-    else if ((!dev->kbdfeed)&&(!dev->bell)) {
-	if (why_rtrn)
-	   *why_rtrn= XkbErr_BadClass;
-	return NULL;
+    DeviceIntPtr dev;
+    int rc;
+
+    rc = _XkbLookupAnyDevice(pDev, id, client, access_mode, xkb_err);
+    if (rc != Success)
+	return rc;
+
+    dev = *pDev;
+    if (!dev->kbdfeed && !dev->bell) {
+	*pDev = NULL;
+	*xkb_err= XkbErr_BadClass;
+	return XkbKeyboardErrorCode;
     }
-    return dev;
+    return Success;
 }
 
-DeviceIntPtr
-_XkbLookupLedDevice(int id,int *why_rtrn)
+int
+_XkbLookupLedDevice(DeviceIntPtr *pDev, int id, ClientPtr client,
+		    Mask access_mode, int *xkb_err)
 {
-DeviceIntPtr dev = NULL;
+    DeviceIntPtr dev;
+    int rc;
 
     if (id == XkbDfltXIId)
         id = XkbUseCorePtr;
-    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
-	return NULL;
-    else if ((!dev->kbdfeed)&&(!dev->leds)) {
-	if (why_rtrn)
-	   *why_rtrn= XkbErr_BadClass;
-	return NULL;
+
+    rc = _XkbLookupAnyDevice(pDev, id, client, access_mode, xkb_err);
+    if (rc != Success)
+	return rc;
+
+    dev = *pDev;
+    if (!dev->kbdfeed && !dev->leds) {
+	*pDev = NULL;
+	*xkb_err= XkbErr_BadClass;
+	return XkbKeyboardErrorCode;
     }
-    return dev;
+    return Success;
 }
 
-DeviceIntPtr
-_XkbLookupButtonDevice(int id,int *why_rtrn)
+int
+_XkbLookupButtonDevice(DeviceIntPtr *pDev, int id, ClientPtr client,
+		       Mask access_mode, int *xkb_err)
 {
-DeviceIntPtr dev = NULL;
-
-    if ((dev= _XkbLookupAnyDevice(id,why_rtrn))==NULL)
-	return NULL;
-    else if (!dev->button) {
-	if (why_rtrn)
-	   *why_rtrn= XkbErr_BadClass;
-	return NULL;
+    DeviceIntPtr dev;
+    int rc;
+
+    rc = _XkbLookupAnyDevice(pDev, id, client, access_mode, xkb_err);
+    if (rc != Success)
+	return rc;
+
+    dev = *pDev;
+    if (!dev->button) {
+	*pDev = NULL;
+	*xkb_err= XkbErr_BadClass;
+	return XkbKeyboardErrorCode;
     }
-    return dev;
+    return Success;
 }
 
 void
commit 5c03d131815cfe2f78792277ab8352e69e830196
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 28 08:02:00 2007 -0400

    xace: add new hooks + access controls: XInput extension.
    
    Introduces new dix API to lookup a device, dixLookupDevice(), which
    replaces LookupDeviceIntRec and LookupDevice.

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 8d879c7..42cf817 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -49,7 +49,6 @@ from The Open Group.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #define EXTENSION_EVENT_BASE	64
-#include "extinit.h"		/* LookupDeviceIntRec */
 #endif /* XINPUT */
 
 #include "modinit.h"
@@ -286,11 +285,12 @@ ProcXTestFakeInput(client)
 #ifdef XINPUT
     if (extension)
     {
-	dev = LookupDeviceIntRec(stuff->deviceid & 0177);
-	if (!dev)
+	rc = dixLookupDevice(&dev, stuff->deviceid & 0177, client,
+			     DixWriteAccess);
+	if (rc != Success)
 	{
 	    client->errorValue = stuff->deviceid & 0177;
-	    return BadValue;
+	    return rc;
 	}
 	if (nev > 1)
 	{
diff --git a/Xi/allowev.c b/Xi/allowev.c
index cf075e1..0043cb1 100644
--- a/Xi/allowev.c
+++ b/Xi/allowev.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "allowev.h"
@@ -95,13 +94,14 @@ ProcXAllowDeviceEvents(ClientPtr client)
 {
     TimeStamp time;
     DeviceIntPtr thisdev;
+    int rc;
 
     REQUEST(xAllowDeviceEventsReq);
     REQUEST_SIZE_MATCH(xAllowDeviceEventsReq);
 
-    thisdev = LookupDeviceIntRec(stuff->deviceid);
-    if (thisdev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&thisdev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     time = ClientTimeToServerTime(stuff->time);
 
     switch (stuff->mode) {
diff --git a/Xi/chgdctl.c b/Xi/chgdctl.c
index 055f459..e7d04a7 100644
--- a/Xi/chgdctl.c
+++ b/Xi/chgdctl.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>	/* control constants */
 #include "XIstubs.h"
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "exevents.h"
 
@@ -112,11 +111,9 @@ ProcXChangeDeviceControl(ClientPtr client)
     REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
 
     len = stuff->length - (sizeof(xChangeDeviceControlReq) >> 2);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
-        ret = BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
         goto out;
-    }
 
     rep.repType = X_Reply;
     rep.RepType = X_ChangeDeviceControl;
diff --git a/Xi/chgfctl.c b/Xi/chgfctl.c
index 46bb8e7..8fc24d5 100644
--- a/Xi/chgfctl.c
+++ b/Xi/chgfctl.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>	/* control constants */
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "chgfctl.h"
@@ -444,14 +443,15 @@ ProcXChangeFeedbackControl(ClientPtr client)
     StringFeedbackPtr s;
     BellFeedbackPtr b;
     LedFeedbackPtr l;
+    int rc;
 
     REQUEST(xChangeFeedbackControlReq);
     REQUEST_AT_LEAST_SIZE(xChangeFeedbackControlReq);
 
     len = stuff->length - (sizeof(xChangeFeedbackControlReq) >> 2);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     switch (stuff->feedbackid) {
     case KbdFeedbackClass:
diff --git a/Xi/chgkmap.c b/Xi/chgkmap.c
index bfdc1ce..3361e98 100644
--- a/Xi/chgkmap.c
+++ b/Xi/chgkmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -107,9 +106,9 @@ ProcXChangeDeviceKeyMapping(ClientPtr client)
     REQUEST(xChangeDeviceKeyMappingReq);
     REQUEST_AT_LEAST_SIZE(xChangeDeviceKeyMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
     len = stuff->length - (sizeof(xChangeDeviceKeyMappingReq) >> 2);
 
     ret = ChangeKeyMapping(client, dev, len, DeviceMappingNotify,
diff --git a/Xi/chgprop.c b/Xi/chgprop.c
index 13463dd..58db886 100644
--- a/Xi/chgprop.c
+++ b/Xi/chgprop.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 
 #include "exevents.h"
 #include "exglobals.h"
@@ -115,7 +114,7 @@ ProcXChangeDeviceDontPropagateList(ClientPtr client)
 	stuff->count)
 	return BadLength;
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/chgptr.c b/Xi/chgptr.c
index 2ce81d1..2895091 100644
--- a/Xi/chgptr.c
+++ b/Xi/chgptr.c
@@ -63,8 +63,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include "scrnintstr.h"	/* screen structure  */
 
-#include "extinit.h"	/* LookupDeviceIntRec */
-
 #include "dixevents.h"
 #include "exevents.h"
 #include "exglobals.h"
diff --git a/Xi/closedev.c b/Xi/closedev.c
index 1ec3fa1..b2b5f69 100644
--- a/Xi/closedev.c
+++ b/Xi/closedev.c
@@ -62,7 +62,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "closedev.h"
@@ -140,16 +139,16 @@ DeleteEventsFromChildren(DeviceIntPtr dev, WindowPtr p1, ClientPtr client)
 int
 ProcXCloseDevice(ClientPtr client)
 {
-    int i;
+    int rc, i;
     WindowPtr pWin, p1;
     DeviceIntPtr d;
 
     REQUEST(xCloseDeviceReq);
     REQUEST_SIZE_MATCH(xCloseDeviceReq);
 
-    d = LookupDeviceIntRec(stuff->deviceid);
-    if (d == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&d, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     if (d->grab && SameClient(d->grab, client))
 	(*d->DeactivateGrab) (d);	/* release active grab */
diff --git a/Xi/devbell.c b/Xi/devbell.c
index 83e844d..264f648 100644
--- a/Xi/devbell.c
+++ b/Xi/devbell.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "devbell.h"
@@ -93,7 +92,7 @@ ProcXDeviceBell(ClientPtr client)
     DeviceIntPtr dev;
     KbdFeedbackPtr k;
     BellFeedbackPtr b;
-    int base;
+    int rc, base;
     int newpercent;
     CARD8 class;
     pointer ctrl;
@@ -102,10 +101,10 @@ ProcXDeviceBell(ClientPtr client)
     REQUEST(xDeviceBellReq);
     REQUEST_SIZE_MATCH(xDeviceBellReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL) {
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixBellAccess);
+    if (rc != Success) {
 	client->errorValue = stuff->deviceid;
-	return BadDevice;
+	return rc;
     }
 
     if (stuff->percent < -100 || stuff->percent > 100) {
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 377311e..9a17950 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -67,11 +67,11 @@ SOFTWARE.
 #include "region.h"
 #include "exevents.h"
 #include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixevents.h"	/* DeliverFocusedEvent */
 #include "dixgrabs.h"	/* CreateGrab() */
 #include "scrnintstr.h"
+#include "xace.h"
 
 #ifdef XKB
 #include "xkbsrv.h"
@@ -511,6 +511,7 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
     WindowPtr pWin, confineTo;
     CursorPtr cursor;
     GrabPtr grab;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     if ((this_device_mode != GrabModeSync) &&
@@ -531,25 +532,33 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
 	client->errorValue = ownerEvents;
 	return BadValue;
     }
-    rc = dixLookupWindow(&pWin, grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     if (rconfineTo == None)
 	confineTo = NullWindow;
     else {
-	rc = dixLookupWindow(&confineTo, rconfineTo, client, DixUnknownAccess);
+	rc = dixLookupWindow(&confineTo, rconfineTo, client, DixSetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
     if (rcursor == None)
 	cursor = NullCursor;
     else {
-	cursor = (CursorPtr) LookupIDByType(rcursor, RT_CURSOR);
-	if (!cursor) {
+	rc = dixLookupResource((pointer *)&cursor, rcursor, RT_CURSOR,
+			       client, DixUseAccess);
+	if (rc != Success)
+	{
 	    client->errorValue = rcursor;
-	    return BadCursor;
+	    return (rc == BadValue) ? BadCursor : rc;
 	}
+	access_mode |= DixForceAccess;
     }
+    if (this_device_mode == GrabModeSync || other_devices_mode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
+    if (rc != Success)
+	return rc;
 
     grab = CreateGrab(client->index, dev, pWin, eventMask,
 		      (Bool) ownerEvents, (Bool) this_device_mode,
@@ -569,6 +578,7 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
     WindowPtr pWin;
     GrabPtr grab;
     KeyClassPtr k = dev->key;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     if (k == NULL)
@@ -596,7 +606,12 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
 	client->errorValue = ownerEvents;
 	return BadValue;
     }
-    rc = dixLookupWindow(&pWin, grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
+    if (this_device_mode == GrabModeSync || other_devices_mode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
     if (rc != Success)
 	return rc;
 
@@ -837,7 +852,7 @@ SendEvent(ClientPtr client, DeviceIntPtr d, Window dest, Bool propagate,
 	    if (!mask)
 		break;
 	}
-    } else
+    } else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, ev, count))
 	(void)(DeliverEventsToWindow(pWin, ev, count, mask, NullGrab, d->id));
     return Success;
 }
@@ -1101,7 +1116,8 @@ MaybeSendDeviceMotionNotifyHint(deviceKeyButtonPointer * pEvents, Mask mask)
 {
     DeviceIntPtr dev;
 
-    dev = LookupDeviceIntRec(pEvents->deviceid & DEVICE_BITS);
+    dixLookupDevice(&dev, pEvents->deviceid & DEVICE_BITS, serverClient,
+		    DixReadAccess);
     if (!dev)
         return 0;
 
@@ -1125,7 +1141,8 @@ CheckDeviceGrabAndHintWindow(WindowPtr pWin, int type,
 {
     DeviceIntPtr dev;
 
-    dev = LookupDeviceIntRec(xE->deviceid & DEVICE_BITS);
+    dixLookupDevice(&dev, xE->deviceid & DEVICE_BITS, serverClient,
+		    DixReadAccess);
     if (!dev)
         return;
 
diff --git a/Xi/extinit.c b/Xi/extinit.c
index 73bae5e..1a435ed 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -856,29 +856,6 @@ MakeDeviceTypeAtoms(void)
 	    MakeAtom(dev_type[i].name, strlen(dev_type[i].name), 1);
 }
 
-/**************************************************************************
- * Return a DeviceIntPtr corresponding to a specified device id.
- *
- */
-
-DeviceIntPtr
-LookupDeviceIntRec(CARD8 id)
-{
-    DeviceIntPtr dev;
-
-    for (dev = inputInfo.devices; dev; dev = dev->next) {
-	if (dev->id == id)
-	    return dev;
-    }
-
-    for (dev = inputInfo.off_devices; dev; dev = dev->next) {
-	if (dev->id == id)
-	    return dev;
-    }
-
-    return NULL;
-}
-
 /*****************************************************************************
  *
  *	SEventIDispatch
diff --git a/Xi/getbmap.c b/Xi/getbmap.c
index ebb0613..9f93b06 100644
--- a/Xi/getbmap.c
+++ b/Xi/getbmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getbmap.h"
@@ -92,6 +91,7 @@ ProcXGetDeviceButtonMapping(ClientPtr client)
     DeviceIntPtr dev;
     xGetDeviceButtonMappingReply rep;
     ButtonClassPtr b;
+    int rc;
 
     REQUEST(xGetDeviceButtonMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceButtonMappingReq);
@@ -102,9 +102,9 @@ ProcXGetDeviceButtonMapping(ClientPtr client)
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     b = dev->button;
     if (b == NULL)
diff --git a/Xi/getdctl.c b/Xi/getdctl.c
index 8a84e91..3f2bb29 100644
--- a/Xi/getdctl.c
+++ b/Xi/getdctl.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getdctl.h"
@@ -238,7 +237,7 @@ SRepXGetDeviceControl(ClientPtr client, int size, xGetDeviceControlReply * rep)
 int
 ProcXGetDeviceControl(ClientPtr client)
 {
-    int total_length = 0;
+    int rc, total_length = 0;
     char *buf, *savbuf;
     DeviceIntPtr dev;
     xGetDeviceControlReply rep;
@@ -246,9 +245,9 @@ ProcXGetDeviceControl(ClientPtr client)
     REQUEST(xGetDeviceControlReq);
     REQUEST_SIZE_MATCH(xGetDeviceControlReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     rep.repType = X_Reply;
     rep.RepType = X_GetDeviceControl;
diff --git a/Xi/getfctl.c b/Xi/getfctl.c
index 7dff32f..1b1e594 100644
--- a/Xi/getfctl.c
+++ b/Xi/getfctl.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getfctl.h"
@@ -290,7 +289,7 @@ SRepXGetFeedbackControl(ClientPtr client, int size,
 int
 ProcXGetFeedbackControl(ClientPtr client)
 {
-    int total_length = 0;
+    int rc, total_length = 0;
     char *buf, *savbuf;
     DeviceIntPtr dev;
     KbdFeedbackPtr k;
@@ -304,9 +303,9 @@ ProcXGetFeedbackControl(ClientPtr client)
     REQUEST(xGetFeedbackControlReq);
     REQUEST_SIZE_MATCH(xGetFeedbackControlReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     rep.repType = X_Reply;
     rep.RepType = X_GetFeedbackControl;
diff --git a/Xi/getfocus.c b/Xi/getfocus.c
index 073913b..dfef22f 100644
--- a/Xi/getfocus.c
+++ b/Xi/getfocus.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getfocus.h"
@@ -93,12 +92,15 @@ ProcXGetDeviceFocus(ClientPtr client)
     DeviceIntPtr dev;
     FocusClassPtr focus;
     xGetDeviceFocusReply rep;
+    int rc;
 
     REQUEST(xGetDeviceFocusReq);
     REQUEST_SIZE_MATCH(xGetDeviceFocusReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL || !dev->focus)
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetFocusAccess);
+    if (rc != Success)
+	return rc;
+    if (!dev->focus)
 	return BadDevice;
 
     rep.repType = X_Reply;
diff --git a/Xi/getkmap.c b/Xi/getkmap.c
index eaa0cff..0eec1d8 100644
--- a/Xi/getkmap.c
+++ b/Xi/getkmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "swaprep.h"
 
@@ -94,13 +93,14 @@ ProcXGetDeviceKeyMapping(ClientPtr client)
     xGetDeviceKeyMappingReply rep;
     DeviceIntPtr dev;
     KeySymsPtr k;
+    int rc;
 
     REQUEST(xGetDeviceKeyMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceKeyMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     if (dev->key == NULL)
 	return BadMatch;
     k = &dev->key->curKeySyms;
diff --git a/Xi/getmmap.c b/Xi/getmmap.c
index 8a99d63..c6c9c33 100644
--- a/Xi/getmmap.c
+++ b/Xi/getmmap.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>	/* Request macro     */
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getmmap.h"
@@ -94,13 +93,14 @@ ProcXGetDeviceModifierMapping(ClientPtr client)
     DeviceIntPtr dev;
     xGetDeviceModifierMappingReply rep;
     KeyClassPtr kp;
+    int rc;
 
     REQUEST(xGetDeviceModifierMappingReq);
     REQUEST_SIZE_MATCH(xGetDeviceModifierMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
 
     kp = dev->key;
     if (kp == NULL)
diff --git a/Xi/getprop.c b/Xi/getprop.c
index 531e65f..188f549 100644
--- a/Xi/getprop.c
+++ b/Xi/getprop.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structs    */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "swaprep.h"
 
@@ -112,7 +111,7 @@ ProcXGetDeviceDontPropagateList(ClientPtr client)
     rep.length = 0;
     rep.count = 0;
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/getselev.c b/Xi/getselev.c
index 819b2db..caa376f 100644
--- a/Xi/getselev.c
+++ b/Xi/getselev.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include "windowstr.h"	/* window struct     */
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "swaprep.h"
 
@@ -114,7 +113,7 @@ ProcXGetSelectedExtensionEvents(ClientPtr client)
     rep.this_client_count = 0;
     rep.all_clients_count = 0;
 
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/getvers.c b/Xi/getvers.c
index a223a5d..a4afe80 100644
--- a/Xi/getvers.c
+++ b/Xi/getvers.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "getvers.h"
diff --git a/Xi/grabdev.c b/Xi/grabdev.c
index b303695..110fc6b 100644
--- a/Xi/grabdev.c
+++ b/Xi/grabdev.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixevents.h"	/* GrabDevice */
 
@@ -122,9 +121,9 @@ ProcXGrabDevice(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.length = 0;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
 
     if ((rc = CreateMaskFromList(client, (XEventClass *) & stuff[1],
 				 stuff->event_count, tmp, dev,
@@ -153,7 +152,7 @@ int
 CreateMaskFromList(ClientPtr client, XEventClass * list, int count,
 		   struct tmask *mask, DeviceIntPtr dev, int req)
 {
-    int i, j;
+    int rc, i, j;
     int device;
     DeviceIntPtr tdev;
 
@@ -167,8 +166,10 @@ CreateMaskFromList(ClientPtr client, XEventClass * list, int count,
 	if (device > 255)
 	    return BadClass;
 
-	tdev = LookupDeviceIntRec(device);
-	if (tdev == NULL || (dev != NULL && tdev != dev))
+	rc = dixLookupDevice(&tdev, device, client, DixReadAccess);
+	if (rc != BadDevice && rc != Success)
+	    return rc;
+	if (rc == BadDevice || (dev != NULL && tdev != dev))
 	    return BadClass;
 
 	for (j = 0; j < ExtEventIndex; j++)
diff --git a/Xi/grabdevb.c b/Xi/grabdevb.c
index 21e46fc..7eb5422 100644
--- a/Xi/grabdevb.c
+++ b/Xi/grabdevb.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "grabdev.h"
@@ -117,14 +116,15 @@ ProcXGrabDeviceButton(ClientPtr client)
 	(sizeof(xGrabDeviceButtonReq) >> 2) + stuff->event_count)
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (ret != Success)
+	return ret;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
-	    return BadDevice;
+	ret = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			      DixReadAccess);
+	if (ret != Success)
+	    return ret;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
diff --git a/Xi/grabdevk.c b/Xi/grabdevk.c
index 8da36ba..e187a4f 100644
--- a/Xi/grabdevk.c
+++ b/Xi/grabdevk.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "grabdev.h"
@@ -115,14 +114,15 @@ ProcXGrabDeviceKey(ClientPtr client)
     if (stuff->length != (sizeof(xGrabDeviceKeyReq) >> 2) + stuff->event_count)
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (ret != Success)
+	return ret;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
-	    return BadDevice;
+	ret = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			      DixReadAccess);
+	if (ret != Success)
+	    return ret;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
diff --git a/Xi/gtmotion.c b/Xi/gtmotion.c
index 51d4248..de22d04 100644
--- a/Xi/gtmotion.c
+++ b/Xi/gtmotion.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -96,7 +95,7 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
     INT32 *coords = NULL, *bufptr;
     xGetDeviceMotionEventsReply rep;
     unsigned long i;
-    int num_events, axes, size = 0, tsize;
+    int rc, num_events, axes, size = 0, tsize;
     unsigned long nEvents;
     DeviceIntPtr dev;
     TimeStamp start, stop;
@@ -106,9 +105,9 @@ ProcXGetDeviceMotionEvents(ClientPtr client)
     REQUEST(xGetDeviceMotionEventsReq);
 
     REQUEST_SIZE_MATCH(xGetDeviceMotionEventsReq);
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
     v = dev->valuator;
     if (v == NULL || v->numAxes == 0)
 	return BadMatch;
diff --git a/Xi/listdev.c b/Xi/listdev.c
index 160ad02..041de76 100644
--- a/Xi/listdev.c
+++ b/Xi/listdev.c
@@ -63,8 +63,8 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
 #include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"	/* FIXME */
+#include "xace.h"
 
 #include "listdev.h"
 
@@ -310,7 +310,7 @@ ProcXListInputDevices(ClientPtr client)
     xListInputDevicesReply rep;
     int numdevs = 0;
     int namesize = 1;	/* need 1 extra byte for strcpy */
-    int size = 0;
+    int rc, size = 0;
     int total_length;
     char *devbuf;
     char *classbuf;
@@ -329,10 +329,16 @@ ProcXListInputDevices(ClientPtr client)
     AddOtherInputDevices();
 
     for (d = inputInfo.devices; d; d = d->next) {
+	rc = XaceHook(XACE_DEVICE_ACCESS, client, d, DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
 	SizeDeviceInfo(d, &namesize, &size);
         numdevs++;
     }
     for (d = inputInfo.off_devices; d; d = d->next) {
+	rc = XaceHook(XACE_DEVICE_ACCESS, client, d, DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
 	SizeDeviceInfo(d, &namesize, &size);
         numdevs++;
     }
diff --git a/Xi/opendev.c b/Xi/opendev.c
index dfefe05..128b1bd 100644
--- a/Xi/opendev.c
+++ b/Xi/opendev.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
 #include "windowstr.h"	/* window structure  */
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "opendev.h"
@@ -107,13 +106,15 @@ ProcXOpenDevice(ClientPtr client)
 	stuff->deviceid == inputInfo.keyboard->id)
 	return BadDevice;
 
-    if ((dev = LookupDeviceIntRec(stuff->deviceid)) == NULL) {	/* not open */
+    status = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
+    if (status == BadDevice) {  /* not open */
 	for (dev = inputInfo.off_devices; dev; dev = dev->next)
 	    if (dev->id == stuff->deviceid)
 		break;
 	if (dev == NULL)
 	    return BadDevice;
-    }
+    } else if (status != Success)
+	return status;
 
     OpenInputDevice(dev, client, &status);
     if (status != Success)
diff --git a/Xi/queryst.c b/Xi/queryst.c
index 2b66b7e..71ab79b 100644
--- a/Xi/queryst.c
+++ b/Xi/queryst.c
@@ -42,7 +42,6 @@ from The Open Group.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -74,7 +73,7 @@ int
 ProcXQueryDeviceState(ClientPtr client)
 {
     char n;
-    int i;
+    int rc, i;
     int num_classes = 0;
     int total_length = 0;
     char *buf, *savbuf;
@@ -96,9 +95,9 @@ ProcXQueryDeviceState(ClientPtr client)
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
+    if (rc != Success)
+	return rc;
 
     v = dev->valuator;
     if (v != NULL && v->motionHintWindow != NULL)
diff --git a/Xi/selectev.c b/Xi/selectev.c
index a5cf567..b93618a 100644
--- a/Xi/selectev.c
+++ b/Xi/selectev.c
@@ -61,7 +61,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -164,7 +163,7 @@ ProcXSelectExtensionEvent(ClientPtr client)
     if (stuff->length != (sizeof(xSelectExtensionEventReq) >> 2) + stuff->count)
 	return BadLength;
 
-    ret = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    ret = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
     if (ret != Success)
 	return ret;
 
diff --git a/Xi/sendexev.c b/Xi/sendexev.c
index 20b415a..e4e38d7 100644
--- a/Xi/sendexev.c
+++ b/Xi/sendexev.c
@@ -59,9 +59,9 @@ SOFTWARE.
 
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include "windowstr.h"	/* Window            */
+#include "extnsionst.h" /* EventSwapPtr      */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exevents.h"
 #include "exglobals.h"
 
@@ -131,9 +131,9 @@ ProcXSendExtensionEvent(ClientPtr client)
 	(stuff->num_events * (sizeof(xEvent) >> 2)))
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixWriteAccess);
+    if (ret != Success)
+	return ret;
 
     /* The client's event type must be one defined by an extension. */
 
diff --git a/Xi/setbmap.c b/Xi/setbmap.c
index 40f0f9a..3035c64 100644
--- a/Xi/setbmap.c
+++ b/Xi/setbmap.c
@@ -63,7 +63,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setbmap.h"
@@ -110,9 +109,9 @@ ProcXSetDeviceButtonMapping(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.status = MappingSuccess;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
 
     ret = SetButtonMapping(client, dev, stuff->map_length, (BYTE *) & stuff[1]);
 
diff --git a/Xi/setdval.c b/Xi/setdval.c
index cb35b91..b1e22fc 100644
--- a/Xi/setdval.c
+++ b/Xi/setdval.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setdval.h"
@@ -92,6 +91,7 @@ ProcXSetDeviceValuators(ClientPtr client)
 {
     DeviceIntPtr dev;
     xSetDeviceValuatorsReply rep;
+    int rc;
 
     REQUEST(xSetDeviceValuatorsReq);
     REQUEST_AT_LEAST_SIZE(xSetDeviceValuatorsReq);
@@ -106,9 +106,9 @@ ProcXSetDeviceValuators(ClientPtr client)
 	stuff->num_valuators)
 	return BadLength;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
     if (dev->valuator == NULL)
 	return BadMatch;
 
diff --git a/Xi/setfocus.c b/Xi/setfocus.c
index 74de17e..c6edbc2 100644
--- a/Xi/setfocus.c
+++ b/Xi/setfocus.c
@@ -63,7 +63,6 @@ SOFTWARE.
 
 #include "dixevents.h"
 
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setfocus.h"
@@ -102,8 +101,10 @@ ProcXSetDeviceFocus(ClientPtr client)
     REQUEST(xSetDeviceFocusReq);
     REQUEST_SIZE_MATCH(xSetDeviceFocusReq);
 
-    dev = LookupDeviceIntRec(stuff->device);
-    if (dev == NULL || !dev->focus)
+    ret = dixLookupDevice(&dev, stuff->device, client, DixSetFocusAccess);
+    if (ret != Success)
+	return ret;
+    if (!dev->focus)
 	return BadDevice;
 
     ret = SetInputFocus(client, dev, stuff->focus, stuff->revertTo,
diff --git a/Xi/setmmap.c b/Xi/setmmap.c
index 19ec71b..be3d3cb 100644
--- a/Xi/setmmap.c
+++ b/Xi/setmmap.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "exevents.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setmmap.h"
@@ -99,9 +98,9 @@ ProcXSetDeviceModifierMapping(ClientPtr client)
     REQUEST(xSetDeviceModifierMappingReq);
     REQUEST_AT_LEAST_SIZE(xSetDeviceModifierMappingReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
 
     rep.repType = X_Reply;
     rep.RepType = X_SetDeviceModifierMapping;
diff --git a/Xi/setmode.c b/Xi/setmode.c
index 957721c..8b6003a 100644
--- a/Xi/setmode.c
+++ b/Xi/setmode.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "setmode.h"
@@ -92,6 +91,7 @@ ProcXSetDeviceMode(ClientPtr client)
 {
     DeviceIntPtr dev;
     xSetDeviceModeReply rep;
+    int rc;
 
     REQUEST(xSetDeviceModeReq);
     REQUEST_SIZE_MATCH(xSetDeviceModeReq);
@@ -101,9 +101,9 @@ ProcXSetDeviceMode(ClientPtr client)
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
     if (dev->valuator == NULL)
 	return BadMatch;
     if ((dev->grab) && !SameClient(dev->grab, client))
diff --git a/Xi/stubs.c b/Xi/stubs.c
index 40cd02f..80ddd73 100644
--- a/Xi/stubs.c
+++ b/Xi/stubs.c
@@ -65,6 +65,7 @@ SOFTWARE.
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
 #include "XIstubs.h"
+#include "xace.h"
 
 /***********************************************************************
  *
@@ -153,6 +154,7 @@ AddOtherInputDevices(void)
 void
 OpenInputDevice(DeviceIntPtr dev, ClientPtr client, int *status)
 {
+    *status = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess);
 }
 
 /****************************************************************************
diff --git a/Xi/ungrdev.c b/Xi/ungrdev.c
index 505d669..7abb1d0 100644
--- a/Xi/ungrdev.c
+++ b/Xi/ungrdev.c
@@ -59,7 +59,6 @@ SOFTWARE.
 #include "inputstr.h"	/* DeviceIntPtr      */
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 
 #include "ungrdev.h"
@@ -94,13 +93,14 @@ ProcXUngrabDevice(ClientPtr client)
     DeviceIntPtr dev;
     GrabPtr grab;
     TimeStamp time;
+    int rc;
 
     REQUEST(xUngrabDeviceReq);
     REQUEST_SIZE_MATCH(xUngrabDeviceReq);
 
-    dev = LookupDeviceIntRec(stuff->deviceid);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     grab = dev->grab;
 
     time = ClientTimeToServerTime(stuff->time);
diff --git a/Xi/ungrdevb.c b/Xi/ungrdevb.c
index 0dfe805..85ca5c6 100644
--- a/Xi/ungrdevb.c
+++ b/Xi/ungrdevb.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixgrabs.h"
 
@@ -107,22 +106,23 @@ ProcXUngrabDeviceButton(ClientPtr client)
     REQUEST(xUngrabDeviceButtonReq);
     REQUEST_SIZE_MATCH(xUngrabDeviceButtonReq);
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
     if (dev->button == NULL)
 	return BadMatch;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
+	rc = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			     DixReadAccess);
+	if (rc != Success)
 	    return BadDevice;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
 	mdev = (DeviceIntPtr) LookupKeyboardDevice();
 
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/Xi/ungrdevk.c b/Xi/ungrdevk.c
index e6307af..ac40035 100644
--- a/Xi/ungrdevk.c
+++ b/Xi/ungrdevk.c
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "windowstr.h"	/* window structure  */
 #include <X11/extensions/XI.h>
 #include <X11/extensions/XIproto.h>
-#include "extinit.h"	/* LookupDeviceIntRec */
 #include "exglobals.h"
 #include "dixgrabs.h"
 
@@ -107,22 +106,23 @@ ProcXUngrabDeviceKey(ClientPtr client)
     REQUEST(xUngrabDeviceKeyReq);
     REQUEST_SIZE_MATCH(xUngrabDeviceKeyReq);
 
-    dev = LookupDeviceIntRec(stuff->grabbed_device);
-    if (dev == NULL)
-	return BadDevice;
+    rc = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
     if (dev->key == NULL)
 	return BadMatch;
 
     if (stuff->modifier_device != UseXKeyboard) {
-	mdev = LookupDeviceIntRec(stuff->modifier_device);
-	if (mdev == NULL)
+	rc = dixLookupDevice(&mdev, stuff->modifier_device, client,
+			     DixReadAccess);
+	if (rc != Success)
 	    return BadDevice;
 	if (mdev->key == NULL)
 	    return BadMatch;
     } else
 	mdev = (DeviceIntPtr) LookupKeyboardDevice();
 
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/config/dbus.c b/config/dbus.c
index c867512..e564c90 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -213,7 +213,7 @@ remove_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         MALFORMED_MESSAGE_ERROR();
     }
 
-    dev = LookupDeviceIntRec(deviceid);
+    dixLookupDevice(&dev, deviceid, serverClient, DixUnknownAccess);
     if (!dev) {
         DebugF("[config/dbus] bogus device id %d given\n", deviceid);
         ret = BadMatch;
diff --git a/dix/devices.c b/dix/devices.c
index 3f4a33d..bd1bef7 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -717,20 +717,28 @@ LookupPointerDevice(void)
     return inputInfo.pointer ? &inputInfo.pointer->public : NULL;
 }
 
-DevicePtr
-LookupDevice(int id)
+int
+dixLookupDevice(DeviceIntPtr *pDev, int id, ClientPtr client, Mask access_mode)
 {
     DeviceIntPtr dev;
+    int rc;
+    *pDev = NULL;
 
     for (dev=inputInfo.devices; dev; dev=dev->next) {
         if (dev->id == (CARD8)id)
-            return (DevicePtr)dev;
+            goto found;
     }
     for (dev=inputInfo.off_devices; dev; dev=dev->next) {
         if (dev->id == (CARD8)id)
-            return (DevicePtr)dev;
+	    goto found;
     }
-    return NULL;
+    return BadDevice;
+
+found:
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
+    if (rc == Success)
+	*pDev = dev;
+    return rc;
 }
 
 void
diff --git a/hw/dmx/input/dmxeq.c b/hw/dmx/input/dmxeq.c
index 3e98fb7..dff0b44 100644
--- a/hw/dmx/input/dmxeq.c
+++ b/hw/dmx/input/dmxeq.c
@@ -82,7 +82,6 @@
 #ifdef XINPUT
 #include <X11/extensions/XIproto.h>
 #define EXTENSION_PROC_ARGS void *
-#include "extinit.h"            /* For LookupDeviceIntRec */
 #endif
 
 #if DMX_EQ_DEBUG
@@ -217,8 +216,9 @@ static void dmxeqProcessXInputEvent(xEvent *xe, EventRec *e)
 {
     deviceKeyButtonPointer *ev     = (deviceKeyButtonPointer *)xe;
     int                    id      = ev->deviceid & DEVICE_BITS;
-    DeviceIntPtr           pDevice = LookupDeviceIntRec(id);
+    DeviceIntPtr           pDevice;
     
+    dixLookupDevice(&pDevice, id, serverClient, DixUnknownAccess);
     if (!pDevice) {
         dmxLog(dmxError, "dmxeqProcessInputEvents: id %d not found\n", id);
         return;
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index e45d44c..b694b73 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -77,7 +77,6 @@
 
 #define EXTENSION_PROC_ARGS void *
 #include "extnsionst.h"
-#include "extinit.h"	/* LookupDeviceIntRec */
 
 #include "windowstr.h"	/* screenIsSaved */
 
diff --git a/include/extinit.h b/include/extinit.h
index e616b6d..df9773c 100644
--- a/include/extinit.h
+++ b/include/extinit.h
@@ -44,9 +44,4 @@ AssignTypeAndName (
 	char *                 /* name */
 	);
 
-DeviceIntPtr
-LookupDeviceIntRec (
-	CARD8                  /* id */
-	);
-
 #endif /* EXTINIT_H */
diff --git a/include/input.h b/include/input.h
index 4f9164a..d8a9fe8 100644
--- a/include/input.h
+++ b/include/input.h
@@ -201,8 +201,11 @@ extern DevicePtr LookupKeyboardDevice(void);
 
 extern DevicePtr LookupPointerDevice(void);
 
-extern DevicePtr LookupDevice(
-    int /* id */);
+extern int dixLookupDevice(
+    DeviceIntPtr *         /* dev */,
+    int                    /* id */,
+    ClientPtr              /* client */,
+    Mask                   /* access_mode */);
 
 extern void QueryMinMaxKeyCodes(
     KeyCode* /*minCode*/,
@@ -436,9 +439,6 @@ extern int GetMotionHistory(
 extern void SwitchCoreKeyboard(DeviceIntPtr pDev);
 extern void SwitchCorePointer(DeviceIntPtr pDev);
 
-extern DeviceIntPtr LookupDeviceIntRec(
-    CARD8 deviceid);
-
 /* Implemented by the DDX. */
 extern int NewInputDeviceRequest(
     InputOption *options,
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index c7f9a26..877d4d2 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -65,7 +65,7 @@ DeviceIntPtr dev = NULL;
     if (id&(~0xff))
 	 dev = NULL;
 
-    dev= (DeviceIntPtr)LookupDevice(id);
+    dixLookupDevice(&dev, id, serverClient, DixUnknownAccess);
     if (dev!=NULL) 
 	return dev;
     if ((!dev)&&(why_rtrn))
commit 27612748e0ec20f3a23839f0a12e39f598dd722c
Merge: b614614... 3b114f2...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 26 07:47:29 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	dix/devices.c

diff --cc dix/devices.c
index 3c2aad8,e05444e..3f4a33d
--- a/dix/devices.c
+++ b/dix/devices.c
@@@ -1348,8 -1358,9 +1347,9 @@@ in
  ProcSetModifierMapping(ClientPtr client)
  {
      xSetModifierMappingReply rep;
+     DeviceIntPtr dev;
 +    int rc;
      REQUEST(xSetModifierMappingReq);
 -    
      REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
  
      if (client->req_len != ((stuff->numKeyPerModifier << 1) +
@@@ -1360,13 -1371,13 +1360,15 @@@
      rep.length = 0;
      rep.sequenceNumber = client->sequence;
  
 -    rep.success = DoSetModifierMapping(client, (KeyCode *)&stuff[1],
 -                                       stuff->numKeyPerModifier);
 +    rc = DoSetModifierMapping(client, (KeyCode *)&stuff[1],
 +			      stuff->numKeyPerModifier, &rep);
 +    if (rc != Success)
 +	return rc;
  
-     /* FIXME: Send mapping notifies for all the extended devices as well. */
      SendMappingNotify(MappingModifier, 0, 0, client);
+     for (dev = inputInfo.devices; dev; dev = dev->next)
+         if (dev->key && dev->coreEvents)
+             SendDeviceMappingNotify(client, MappingModifier, 0, 0, dev);
      WriteReplyToClient(client, sizeof(xSetModifierMappingReply), &rep);
      return client->noClientException;
  }
diff --cc exa/exa_priv.h
index 27749d7,a26933d..b1023a6
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@@ -150,10 -150,14 +150,14 @@@ extern DevPrivateKey exaPixmapPrivateKe
  #define EXA_PIXMAP_SCORE_PINNED	    1000
  #define EXA_PIXMAP_SCORE_INIT	    1001
  
 -#define ExaGetPixmapPriv(p)	((ExaPixmapPrivPtr)(p)->devPrivates[exaPixmapPrivateIndex].ptr)
 -#define ExaSetPixmapPriv(p,a)	((p)->devPrivates[exaPixmapPrivateIndex].ptr = (pointer) (a))
 +#define ExaGetPixmapPriv(p) ((ExaPixmapPrivPtr)dixLookupPrivate(&(p)->devPrivates, exaPixmapPrivateKey))
 +#define ExaSetPixmapPriv(p,a) dixSetPrivate(&(p)->devPrivates, exaPixmapPrivateKey, a)
  #define ExaPixmapPriv(p)	ExaPixmapPrivPtr pExaPixmap = ExaGetPixmapPriv(p)
  
+ #define EXA_RANGE_PITCH (1 << 0)
+ #define EXA_RANGE_WIDTH (1 << 1)
+ #define EXA_RANGE_HEIGHT (1 << 2)
+ 
  typedef struct {
      ExaOffscreenArea *area;
      int		    score;	/**< score for the move-in vs move-out heuristic */
commit b61461425eb15fcff2a58330d74fe5a5a1f226fc
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Sep 25 09:56:00 2007 -0400

    xace: add hooks + new access codes: XV extension.
    
    May need to revisit this extension in the future, depending on observed use.

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index a2dac75..f6130df 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -383,7 +383,7 @@ ProcXvQueryAdaptors(ClientPtr client)
   REQUEST(xvQueryAdaptorsReq);
   REQUEST_SIZE_MATCH(xvQueryAdaptorsReq);
 
-  rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+  rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
   if (rc != Success)
       return rc;
 
@@ -718,7 +718,7 @@ ProcXvSelectVideoNotify(ClientPtr client)
   REQUEST(xvSelectVideoNotifyReq);
   REQUEST_SIZE_MATCH(xvSelectVideoNotifyReq);
 
-  rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixUnknownAccess);
+  rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReceiveAccess);
   if (rc != Success)
     return rc;
 
@@ -835,7 +835,7 @@ ProcXvStopVideo(ClientPtr client)
       return (status);
     }
 
-  rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixUnknownAccess);
+  rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess);
   if (rc != Success)
     return rc;
 
commit 9bd04055a2175ec16756d3bf73ae03b5e163a28a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Sep 25 09:33:51 2007 -0400

    xace: change prototype of VALIDATE_DRAWABLE_AND_GC macro to allow access
    mode to be passed to dixLookupDrawable.

diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 1c53a1e..5933c02 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -1049,8 +1049,7 @@ int PanoramiXCopyArea(ClientPtr client)
 
 	FOR_NSCREENS_BACKWARD(j) {
 	    stuff->gc = gc->info[j].id;
-	    VALIDATE_DRAWABLE_AND_GC(dst->info[j].id, pDst, pGC, client);
-
+	    VALIDATE_DRAWABLE_AND_GC(dst->info[j].id, pDst, DixWriteAccess);
 	    if(drawables[0]->depth != pDst->depth) {
 		client->errorValue = stuff->dstDrawable;
 		xfree(data);
@@ -1086,7 +1085,8 @@ int PanoramiXCopyArea(ClientPtr client)
 		stuff->dstY = dsty - panoramiXdataPtr[j].y;
 	    }
 
-	    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); 
+	    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess);
+
 	    if (stuff->dstDrawable != stuff->srcDrawable) {
 		rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0,
 				       DixReadAccess);
@@ -1195,7 +1195,7 @@ int PanoramiXCopyPlane(ClientPtr client)
 	    stuff->dstY = dsty - panoramiXdataPtr[j].y;
 	}
 
-	VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client);
+	VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess);
 	if (stuff->dstDrawable != stuff->srcDrawable) {
 	    rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0,
 				   DixReadAccess);
diff --git a/Xext/shm.c b/Xext/shm.c
index 2afe055..ee4c340 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -795,7 +795,7 @@ ProcShmPutImage(client)
     REQUEST(xShmPutImageReq);
 
     REQUEST_SIZE_MATCH(xShmPutImageReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client);
     if ((stuff->sendEvent != xTrue) && (stuff->sendEvent != xFalse))
 	return BadValue;
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index af2e09b..a2dac75 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -535,7 +535,7 @@ ProcXvPutVideo(ClientPtr client)
   REQUEST(xvPutVideoReq);
   REQUEST_SIZE_MATCH(xvPutVideoReq);
 
-  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
   if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
     {
@@ -581,7 +581,7 @@ ProcXvPutStill(ClientPtr client)
   REQUEST(xvPutStillReq);
   REQUEST_SIZE_MATCH(xvPutStillReq);
 
-  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
   if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
     {
@@ -628,7 +628,7 @@ ProcXvGetVideo(ClientPtr client)
   REQUEST(xvGetVideoReq);
   REQUEST_SIZE_MATCH(xvGetVideoReq);
 
-  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess);
 
   if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
     {
@@ -675,7 +675,7 @@ ProcXvGetStill(ClientPtr client)
   REQUEST(xvGetStillReq);
   REQUEST_SIZE_MATCH(xvGetStillReq);
 
-  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess);
 
   if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
     {
@@ -1036,7 +1036,7 @@ ProcXvPutImage(ClientPtr client)
   REQUEST(xvPutImageReq);
   REQUEST_AT_LEAST_SIZE(xvPutImageReq);
 
-  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
   if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
     {
@@ -1124,7 +1124,7 @@ ProcXvShmPutImage(ClientPtr client)
   REQUEST(xvShmPutImageReq);
   REQUEST_SIZE_MATCH(xvShmPutImageReq);
 
-  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+  VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
   if(!(pPort = LOOKUP_PORT(stuff->port, client) ))
     {
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 952ef60..65eb8cc 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1791,7 +1791,7 @@ ProcCopyArea(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xCopyAreaReq);
 
-    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, pGC, client); 
+    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess); 
     if (stuff->dstDrawable != stuff->srcDrawable)
     {
 	rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0,
@@ -1832,7 +1832,7 @@ ProcCopyPlane(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xCopyPlaneReq);
 
-    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess);
     if (stuff->dstDrawable != stuff->srcDrawable)
     {
 	rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0,
@@ -1885,7 +1885,7 @@ ProcPolyPoint(ClientPtr client)
 	client->errorValue = stuff->coordMode;
         return BadValue;
     }
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client); 
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess); 
     npoint = ((client->req_len << 2) - sizeof(xPolyPointReq)) >> 2;
     if (npoint)
         (*pGC->ops->PolyPoint)(pDraw, pGC, stuff->coordMode, npoint,
@@ -1908,7 +1908,7 @@ ProcPolyLine(ClientPtr client)
 	client->errorValue = stuff->coordMode;
         return BadValue;
     }
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     npoint = ((client->req_len << 2) - sizeof(xPolyLineReq)) >> 2;
     if (npoint > 1)
 	(*pGC->ops->Polylines)(pDraw, pGC, stuff->coordMode, npoint, 
@@ -1925,7 +1925,7 @@ ProcPolySegment(ClientPtr client)
     REQUEST(xPolySegmentReq);
 
     REQUEST_AT_LEAST_SIZE(xPolySegmentReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
     if (nsegs & 4)
 	return(BadLength);
@@ -1944,7 +1944,7 @@ ProcPolyRectangle (ClientPtr client)
     REQUEST(xPolyRectangleReq);
 
     REQUEST_AT_LEAST_SIZE(xPolyRectangleReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
     if (nrects & 4)
 	return(BadLength);
@@ -1964,7 +1964,7 @@ ProcPolyArc(ClientPtr client)
     REQUEST(xPolyArcReq);
 
     REQUEST_AT_LEAST_SIZE(xPolyArcReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
     if (narcs % sizeof(xArc))
 	return(BadLength);
@@ -1996,7 +1996,7 @@ ProcFillPoly(ClientPtr client)
         return BadValue;
     }
 
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     things = ((client->req_len << 2) - sizeof(xFillPolyReq)) >> 2;
     if (things)
         (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
@@ -2014,7 +2014,7 @@ ProcPolyFillRectangle(ClientPtr client)
     REQUEST(xPolyFillRectangleReq);
 
     REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
     if (things & 4)
 	return(BadLength);
@@ -2035,7 +2035,7 @@ ProcPolyFillArc(ClientPtr client)
     REQUEST(xPolyFillArcReq);
 
     REQUEST_AT_LEAST_SIZE(xPolyFillArcReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
     if (narcs % sizeof(xArc))
 	return(BadLength);
@@ -2110,7 +2110,7 @@ ProcPutImage(ClientPtr client)
     REQUEST(xPutImageReq);
 
     REQUEST_AT_LEAST_SIZE(xPutImageReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     if (stuff->format == XYBitmap)
     {
         if ((stuff->depth != 1) ||
@@ -2396,7 +2396,7 @@ ProcPolyText(ClientPtr client)
     GC *pGC;
 
     REQUEST_AT_LEAST_SIZE(xPolyTextReq);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
     err = PolyText(client,
 		   pDraw,
@@ -2426,7 +2426,7 @@ ProcImageText8(ClientPtr client)
     REQUEST(xImageTextReq);
 
     REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
     err = ImageText(client,
 		    pDraw,
@@ -2456,7 +2456,7 @@ ProcImageText16(ClientPtr client)
     REQUEST(xImageTextReq);
 
     REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1);
-    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
+    VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
 
     err = ImageText(client,
 		    pDraw,
diff --git a/include/dix.h b/include/dix.h
index 54629cd..59533ba 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -81,11 +81,9 @@ SOFTWARE.
         return(BadIDChoice);\
     }
 
-#define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, pGC, client)\
+#define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, mode)\
     {\
-	int rc;\
-	rc = dixLookupDrawable(&(pDraw), drawID, client, M_ANY,\
-			       DixWriteAccess);\
+	int rc = dixLookupDrawable(&(pDraw), drawID, client, M_ANY, mode);\
 	if (rc != Success)\
 	    return rc;\
 	rc = dixLookupGC(&(pGC), stuff->gc, client, DixUseAccess);\
commit a247886b082cea93fa8f8980616a9c388ba70111
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Sep 20 13:06:38 2007 -0400

    xace: add hooks + new access codes: XF86-Bigfont extension

diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index c2f891a..29f07a6 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -445,10 +445,10 @@ ProcXF86BigfontQueryFont(
 #endif
     client->errorValue = stuff->id;		/* EITHER font or gc */
     pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
-					    DixReadAccess);
+					    DixGetAttrAccess);
     if (!pFont) {
 	GC *pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
-						DixReadAccess);
+						DixGetAttrAccess);
         if (!pGC) {
 	    client->errorValue = stuff->id;
             return BadFont;    /* procotol spec says only error is BadFont */
commit f6532a81eec5f096e27285687964b77c17987f72
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Sep 20 12:17:17 2007 -0400

    xace: add hooks + new access codes: APPGROUP extension

diff --git a/Xext/appgroup.c b/Xext/appgroup.c
index 7bd2055..c40782d 100644
--- a/Xext/appgroup.c
+++ b/Xext/appgroup.c
@@ -345,7 +345,7 @@ int AttrValidate(
     ColormapPtr pColormap;
 
     rc = dixLookupWindow(&pWin, pAppGrp->default_root, client,
-			 DixUnknownAccess);
+			 DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     pScreen = pWin->drawable.pScreen;
@@ -367,8 +367,10 @@ int AttrValidate(
     }
     if (pAppGrp->default_colormap) {
 
-	pColormap = (ColormapPtr)LookupIDByType (pAppGrp->default_colormap, RT_COLORMAP);
-	/* XXX check that pColormap is not NULL */
+	rc = dixLookupResource((pointer *)&pColormap, pAppGrp->default_colormap,
+			       RT_COLORMAP, client, DixUseAccess);
+	if (rc != Success)
+	    return rc;
 	if (pColormap->pScreen != pScreen)
 	    return BadColor;
 	if (pColormap->pVisual->vid != (pAppGrp->root_visual ? pAppGrp->root_visual : pScreen->rootVisual))
@@ -470,7 +472,7 @@ int ProcXagQuery(
     int n, rc;
 
     REQUEST_SIZE_MATCH (xXagQueryReq);
-    rc = dixLookupClient(&pClient, stuff->resource, client, DixUnknownAccess);
+    rc = dixLookupClient(&pClient, stuff->resource, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
commit 82f7195a628cc7ec94abc0cfe5bae2be8af443bc
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Sep 20 09:17:09 2007 -0400

    xace: modifications to ChangeWindowAttributes special case: separate
    Receive and SetAttr.  Refer to 963e69b8efc39369915e7f0c6f370ac0d5d2b60f

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 8c68e55..952ef60 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -571,11 +571,11 @@ ProcChangeWindowAttributes(ClientPtr client)
     WindowPtr pWin;
     REQUEST(xChangeWindowAttributesReq);
     int result, len, rc;
-    Mask access_mode = DixSetAttrAccess;
+    Mask access_mode = 0;
 
     REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
-    if (stuff->valueMask == CWEventMask)
-	access_mode = DixReceiveAccess;
+    access_mode |= (stuff->valueMask & CWEventMask) ? DixReceiveAccess : 0;
+    access_mode |= (stuff->valueMask & ~CWEventMask) ? DixSetAttrAccess : 0;
     rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
     if (rc != Success)
         return rc;
commit 661b1328cf992d8855552677a94d60de1d8ce942
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Sep 20 08:41:26 2007 -0400

    xace: add hooks + new access codes: SYNC extension
    
    May need to revisit this extension in the future, depending on observed use.

diff --git a/Xext/sync.c b/Xext/sync.c
index d9b6a9f..81b0cc4 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -433,18 +433,18 @@ SyncInitTrigger(client, pTrigger, counter, changes)
     Mask	     changes;
 {
     SyncCounter *pCounter = pTrigger->pCounter;
-    int		status;
+    int		rc;
     Bool	newcounter = FALSE;
 
     if (changes & XSyncCACounter)
     {
 	if (counter == None)
 	    pCounter = NULL;
-	else if (!(pCounter = (SyncCounter *)SecurityLookupIDByType(
-			client, counter, RTCounter, DixReadAccess)))
+	else if (Success != (rc = dixLookupResource((pointer *)&pCounter,
+				counter, RTCounter, client, DixReadAccess)))
 	{
 	    client->errorValue = counter;
-	    return SyncErrorBase + XSyncBadCounter;
+	    return (rc == BadValue) ? SyncErrorBase + XSyncBadCounter : rc;
 	}
 	if (pCounter != pTrigger->pCounter)
 	{ /* new counter for trigger */
@@ -526,8 +526,8 @@ SyncInitTrigger(client, pTrigger, counter, changes)
      */
     if (newcounter)
     {
-	if ((status = SyncAddTriggerToCounter(pTrigger)) != Success)
-	    return status;
+	if ((rc = SyncAddTriggerToCounter(pTrigger)) != Success)
+	    return rc;
     }
     else if (IsSystemCounter(pCounter))
     {
@@ -1465,7 +1465,7 @@ ProcSyncSetPriority(client)
 	priorityclient = client;
     else {
 	rc = dixLookupClient(&priorityclient, stuff->id, client,
-			     DixUnknownAccess);
+			     DixSetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
@@ -1502,7 +1502,7 @@ ProcSyncGetPriority(client)
 	priorityclient = client;
     else {
 	rc = dixLookupClient(&priorityclient, stuff->id, client,
-			     DixUnknownAccess);
+			     DixGetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
commit 90bacdef723e1e49c72775144916750758d3568c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Sep 20 06:53:51 2007 -0400

    xace: add hooks + new access codes: MIT-SHM extension

diff --git a/Xext/shm.c b/Xext/shm.c
index 8fa5842..2afe055 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -58,6 +58,7 @@ in this Software without prior written authorization from The Open Group.
 #include "extnsionst.h"
 #include "servermd.h"
 #include "shmint.h"
+#include "xace.h"
 #define _XSHM_SERVER_
 #include <X11/extensions/shmstr.h>
 #include <X11/Xfuncproto.h>
@@ -907,7 +908,7 @@ ProcShmGetImage(client)
         return(BadValue);
     }
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
-			   DixUnknownAccess);
+			   DixReadAccess);
     if (rc != Success)
 	return rc;
     VERIFY_SHMPTR(stuff->shmseg, stuff->offset, TRUE, shmdesc, client);
@@ -1039,7 +1040,7 @@ ProcShmCreatePixmap(client)
 	return BadImplementation;
     LEGAL_NEW_RESOURCE(stuff->pid, client);
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY,
-			   DixUnknownAccess);
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
@@ -1068,6 +1069,12 @@ CreatePmap:
 			    shmdesc->addr + stuff->offset);
     if (pMap)
     {
+	rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP,
+		      pMap, RT_NONE, NULL, DixCreateAccess);
+	if (rc != Success) {
+	    pDraw->pScreen->DestroyPixmap(pMap);
+	    return rc;
+	}
 	dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
 	shmdesc->refcnt++;
 	pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
@@ -1076,6 +1083,7 @@ CreatePmap:
 	{
 	    return(client->noClientException);
 	}
+	pDraw->pScreen->DestroyPixmap(pMap);
     }
     return (BadAlloc);
 }
commit e93cff52fed9074aa007c2e6ec6b578f69aef3cb
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 19 14:48:20 2007 -0400

    xace: add hooks + new access codes: DOUBLE-BUFFER extension

diff --git a/dbe/dbe.c b/dbe/dbe.c
index 223b0c9..8175a35 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -54,6 +54,7 @@
 #define NEED_DBE_PROTOCOL
 #include "dbestruct.h"
 #include "midbe.h"
+#include "xace.h"
 
 /* GLOBALS */
 
@@ -233,7 +234,7 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
     REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq);
 
     /* The window must be valid. */
-    status = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    status = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
     if (status != Success)
 	return status;
 
@@ -720,7 +721,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
         for (i = 0; i < stuff->n; i++)
         {
 	    rc = dixLookupDrawable(pDrawables+i, drawables[i], client, 0,
-				   DixReadAccess);
+				   DixGetAttrAccess);
 	    if (rc != Success) {
                 Xfree(pDrawables);
                 return rc;
@@ -748,7 +749,9 @@ ProcDbeGetVisualInfo(ClientPtr client)
                                     pDrawables[i]->pScreen;
         pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
 
-        if (!(*pDbeScreenPriv->GetVisualInfo)(pScreen, &pScrVisInfo[i]))
+	rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess);
+	if ((rc != Success) ||
+	    !(*pDbeScreenPriv->GetVisualInfo)(pScreen, &pScrVisInfo[i]))
         {
             /* We failed to alloc pScrVisInfo[i].visinfo. */
 
@@ -764,7 +767,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
                 Xfree(pDrawables);
             }
 
-            return(BadAlloc);
+            return (rc == Success) ? BadAlloc : rc;
         }
 
         /* Account for n, number of xDbeVisInfo items in list. */
@@ -877,7 +880,7 @@ ProcDbeGetBackBufferAttributes(ClientPtr client)
     REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq);
 
     if (!(pDbeWindowPriv = (DbeWindowPrivPtr)SecurityLookupIDByType(client,
-		stuff->buffer, dbeWindowPrivResType, DixReadAccess)))
+		stuff->buffer, dbeWindowPrivResType, DixGetAttrAccess)))
     {
         rep.attributes = None;
     }
@@ -1615,6 +1618,9 @@ DbeExtensionInit(void)
         CreateNewResourceType(DbeDrawableDelete) | RC_DRAWABLE;
     dbeWindowPrivResType =
         CreateNewResourceType(DbeWindowPrivDelete);
+    if (!dixRegisterPrivateOffset(dbeDrawableResType,
+				  offsetof(PixmapRec, devPrivates)))
+	return;
 
     for (i = 0; i < screenInfo.numScreens; i++)
     {
diff --git a/dbe/midbe.c b/dbe/midbe.c
index f26a09c..e1c7f8d 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -56,6 +56,7 @@
 #include "gcstruct.h"
 #include "inputstr.h"
 #include "midbe.h"
+#include "xace.h"
 
 #include <stdio.h>
 
@@ -153,6 +154,7 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
     DbeScreenPrivPtr		pDbeScreenPriv;
     GCPtr			pGC;
     xRectangle			clearRect;
+    int				rc;
 
 
     pScreen = pWin->drawable.pScreen;
@@ -191,14 +193,18 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
             return(BadAlloc);
         }
 
+	/* Security creation/labeling check. */
+	rc = XaceHook(XACE_RESOURCE_ACCESS, serverClient, bufId,
+		      dbeDrawableResType, pDbeWindowPrivPriv->pBackBuffer,
+		      RT_WINDOW, pWin, DixCreateAccess);
 
         /* Make the back pixmap a DBE drawable resource. */
-        if (!AddResource(bufId, dbeDrawableResType,
-            (pointer)pDbeWindowPrivPriv->pBackBuffer))
+        if (rc != Success || !AddResource(bufId, dbeDrawableResType,
+					  pDbeWindowPrivPriv->pBackBuffer))
         {
             /* free the buffer and the drawable resource */
             FreeResource(bufId, RT_NONE);
-            return(BadAlloc);
+            return (rc == Success) ? BadAlloc : rc;
         }
 
 
commit 082c0f7fb34458ebb303cf875d1d75686eca25e6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 19 13:59:35 2007 -0400

    devPrivates rework: move devPrivates field in drawable structure types
    to just below the DrawableRec.  Wish there were a better way to do this
    but it has to be in the same place for all drawable types.

diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 4162c66..5f0e0c5 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -72,10 +72,10 @@ typedef struct _Drawable {
 
 typedef struct _Pixmap {
     DrawableRec		drawable;
+    PrivateRec		*devPrivates;
     int			refcnt;
     int			devKind;
     DevUnion		devPrivate;
-    PrivateRec		*devPrivates;
 #ifdef COMPOSITE
     short		screen_x;
     short		screen_y;
diff --git a/include/windowstr.h b/include/windowstr.h
index ca212ad..4359481 100644
--- a/include/windowstr.h
+++ b/include/windowstr.h
@@ -124,6 +124,7 @@ typedef struct _WindowOpt {
 
 typedef struct _Window {
     DrawableRec		drawable;
+    PrivateRec		*devPrivates;
     WindowPtr		parent;		/* ancestor chain */
     WindowPtr		nextSib;	/* next lower sibling */
     WindowPtr		prevSib;	/* next higher sibling */
@@ -160,7 +161,6 @@ typedef struct _Window {
 #ifdef COMPOSITE
     unsigned		redirectDraw:2;	/* rendering is redirected from here */
 #endif
-    PrivateRec		*devPrivates;
 } WindowRec;
 
 /*
diff --git a/render/picture.c b/render/picture.c
index 660ef12..184edb4 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -728,7 +728,7 @@ CreatePicture (Picture		pid,
 
     /* security creation/labeling check */
     *error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType, pPicture,
-		      RC_DRAWABLE, pDrawable, DixCreateAccess|DixSetAttrAccess);
+		      RT_PIXMAP, pDrawable, DixCreateAccess|DixSetAttrAccess);
     if (*error != Success)
 	goto out;
 
commit 5b36b64192517e2470766ce7ff1d4dc04c936fad
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 19 11:11:54 2007 -0400

    xace: add missing argument to hook call.

diff --git a/dix/events.c b/dix/events.c
index 42c3ba1..0d82d19 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2892,7 +2892,7 @@ DeliverGrabbedEvent(xEvent *xE, DeviceIntPtr thisDev,
     if (!deliveries)
     {
 	FixUpEventFromWindow(xE, grab->window, None, TRUE);
-	if (!XaceHook(XACE_SEND_ACCESS, thisDev, grab->window, xE, count) &&
+	if (!XaceHook(XACE_SEND_ACCESS, 0, thisDev, grab->window, xE, count) &&
 	    !XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), grab->window, xE,
 		      count))
 	    deliveries = TryClientEvents(rClient(grab), xE, count,
commit 963e69b8efc39369915e7f0c6f370ac0d5d2b60f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 19 11:11:41 2007 -0400

    xace: add special-case for just setting the event mask on a window,
    this should only check "receive" permission, not "setattr" permission.

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 507854e..8c68e55 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -570,11 +570,13 @@ ProcChangeWindowAttributes(ClientPtr client)
 {
     WindowPtr pWin;
     REQUEST(xChangeWindowAttributesReq);
-    int result;
-    int len, rc;
+    int result, len, rc;
+    Mask access_mode = DixSetAttrAccess;
 
     REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
+    if (stuff->valueMask == CWEventMask)
+	access_mode = DixReceiveAccess;
+    rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
     if (rc != Success)
         return rc;
     len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
commit 97c150b61bbe436453b05d3c07cd2173870aac40
Merge: 57907e0... 547ad21...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 19 07:25:55 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	afb/afbpntwin.c
    	afb/afbscrinit.c
    	afb/afbwindow.c
    	cfb/cfb.h
    	cfb/cfballpriv.c
    	cfb/cfbscrinit.c
    	cfb/cfbwindow.c
    	configure.ac
    	fb/wfbrename.h
    	hw/xfree86/xf4bpp/ppcIO.c
    	hw/xfree86/xf4bpp/ppcPntWin.c
    	hw/xfree86/xf4bpp/ppcWindow.c
    	hw/xfree86/xf8_32bpp/cfbscrinit.c
    	mfb/mfb.h
    	mfb/mfbpntwin.c
    	mfb/mfbscrinit.c
    	mfb/mfbwindow.c
    	mi/miexpose.c
    
    Note: conflicts caused by devPrivates rework vs. paintwindow changes.

diff --cc afb/afb.h
index 5cfbddf,943c2c6..2111030
--- a/afb/afb.h
+++ b/afb/afb.h
@@@ -743,18 -737,8 +738,8 @@@ extern DevPrivateKey frameWindowPrivate
  #endif
  
  #define afbGetGCPrivate(pGC) \
 -	((afbPrivGC *)((pGC)->devPrivates[afbGCPrivateIndex].ptr))
 +    ((afbPrivGC *)dixLookupPrivate(&(pGC)->devPrivates, afbGCPrivateKey))
  
- /* private field of window */
- typedef struct {
- 	unsigned char fastBorder;	/* non-zero if border tile is 32 bits wide */
- 	unsigned char fastBackground;
- 	unsigned short unused; /* pad for alignment with Sun compiler */
- 	DDXPointRec oldRotate;
- 	PixmapPtr pRotatedBackground;
- 	PixmapPtr pRotatedBorder;
- } afbPrivWin;
- 
  /* Common macros for extracting drawing information */
  
  #define afbGetTypedWidth(pDrawable,wtype)( \
diff --cc afb/afbscrinit.c
index 8615d93,f3a0542..cbabb89
--- a/afb/afbscrinit.c
+++ b/afb/afbscrinit.c
@@@ -69,11 -69,12 +69,10 @@@ SOFTWARE
  #include "servermd.h"
  
  #ifdef PIXMAP_PER_WINDOW
 -int frameWindowPrivateIndex;
 +DevPrivateKey frameWindowPrivateKey = &frameWindowPrivateKey;
  #endif
- DevPrivateKey afbWindowPrivateKey = &afbWindowPrivateKey;
 -int afbGCPrivateIndex;
 -int afbScreenPrivateIndex;
 -
 -static unsigned long afbGeneration = 0;
 +DevPrivateKey afbGCPrivateKey = &afbGCPrivateKey;
 +DevPrivateKey afbScreenPrivateKey = &afbScreenPrivateKey;
  
  static Bool
  afbCloseScreen(int index, ScreenPtr pScreen)
@@@ -135,18 -133,22 +134,14 @@@ afbSetWindowPixmap(WindowPtr pWin, Pixm
  }
  
  static Bool
- afbAllocatePrivates(ScreenPtr pScreen,
- 		    DevPrivateKey *pWinKey, DevPrivateKey *pGCKey)
 -afbAllocatePrivates(ScreenPtr pScreen, int *pWinIndex, int *pGCIndex)
++afbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
  {
- 	if (pWinKey)
- 		*pWinKey = afbWindowPrivateKey;
 -	if (afbGeneration != serverGeneration) {
 -#ifdef PIXMAP_PER_WINDOW
 -		frameWindowPrivateIndex = AllocateWindowPrivateIndex();
 -#endif
 -		afbGCPrivateIndex = AllocateGCPrivateIndex();
 -		afbGeneration = serverGeneration;
 -	}
 -	if (pGCIndex)
 -		*pGCIndex = afbGCPrivateIndex;
 +	if (pGCKey)
 +		*pGCKey = afbGCPrivateKey;
  
 -	afbScreenPrivateIndex = AllocateScreenPrivateIndex();
  	pScreen->GetWindowPixmap = afbGetWindowPixmap;
  	pScreen->SetWindowPixmap = afbSetWindowPixmap;
- 	return(dixRequestPrivate(afbWindowPrivateKey, sizeof(afbPrivWin)) &&
- 	       dixRequestPrivate(afbGCPrivateKey, sizeof(afbPrivGC)));
 -	return(AllocateGCPrivate(pScreen, afbGCPrivateIndex, sizeof(afbPrivGC)));
++	return dixRequestPrivate(afbGCPrivateKey, sizeof(afbPrivGC));
  }
  
  /* dts * (inch/dot) * (25.4 mm / inch) = mm */
@@@ -172,7 -174,7 +167,7 @@@ afbScreenInit(register ScreenPtr pScree
  		ErrorF("afbInitVisuals: FALSE\n");
  		return FALSE;
  	}
- 	if (!afbAllocatePrivates(pScreen, NULL, NULL)) {
 -	if (!afbAllocatePrivates(pScreen,(int *)NULL, (int *)NULL)) {
++	if (!afbAllocatePrivates(pScreen, NULL)) {
  		ErrorF("afbAllocatePrivates: FALSE\n");
  		return FALSE;
  	}
diff --cc cfb/cfb.h
index 44d4ad0,c9ceda9..b74a82f
--- a/cfb/cfb.h
+++ b/cfb/cfb.h
@@@ -56,8 -55,7 +56,7 @@@ THE USE OR PERFORMANCE OF THIS SOFTWARE
     pixmap.devKind = width_of_pixmap_in_bytes
  */
  
 -extern int  cfbGCPrivateIndex;
 +extern DevPrivateKey cfbGCPrivateKey;
- extern DevPrivateKey cfbWindowPrivateKey;
  
  /* private field of GC */
  typedef struct {
@@@ -82,22 -80,8 +81,6 @@@ typedef struct 
      CfbBits	xor, and;
  } cfbRRopRec, *cfbRRopPtr;
  
- /* private field of window */
- typedef struct {
-     unsigned	char fastBorder; /* non-zero if border is 32 bits wide */
-     unsigned	char fastBackground;
-     unsigned short unused; /* pad for alignment with Sun compiler */
-     DDXPointRec	oldRotate;
-     PixmapPtr	pRotatedBackground;
-     PixmapPtr	pRotatedBorder;
-     } cfbPrivWin;
- 
- #define cfbGetWindowPrivate(_pWin) ((cfbPrivWin *)\
-     dixLookupPrivate(&(_pWin)->devPrivates, cfbWindowPrivateKey))
- 
- 
--/* cfb8bit.c */
--
  extern int cfbSetStipple(
      int /*alu*/,
      CfbBits /*fg*/,
@@@ -314,8 -298,7 +297,7 @@@ extern int cfb8SegmentSS1RectXor
  
  extern Bool cfbAllocatePrivates(
      ScreenPtr /*pScreen*/,
-     DevPrivateKey * /*window_key*/,
 -    int * /*gc_index*/
 +    DevPrivateKey * /*gc_key*/
  );
  /* cfbbitblt.c */
  
diff --cc cfb/cfballpriv.c
index e6ab93a,858ff60..3b58266
--- a/cfb/cfballpriv.c
+++ b/cfb/cfballpriv.c
@@@ -45,37 -45,38 +45,26 @@@ in this Software without prior written 
  #include "mibstore.h"
  
  #if 1 || PSZ==8
- DevPrivateKey cfbWindowPrivateKey = &cfbWindowPrivateKey;
 -int cfbGCPrivateIndex = -1;
 +DevPrivateKey cfbGCPrivateKey = &cfbGCPrivateKey;
  #endif
  #ifdef CFB_NEED_SCREEN_PRIVATE
 -int cfbScreenPrivateIndex = -1;
 -static unsigned long cfbGeneration = 0;
 +DevPrivateKey cfbScreenPrivateKey = &cfbScreenPrivateKey;
  #endif
  
  
  Bool
- cfbAllocatePrivates(pScreen, window_key, gc_key)
-     ScreenPtr	pScreen;
-     DevPrivateKey *window_key, *gc_key;
 -cfbAllocatePrivates(ScreenPtr pScreen, int *gc_index)
++cfbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *gc_key)
  {
-     if (!window_key || !gc_key || (!*window_key && !*gc_key))
 -    if (!gc_index || *gc_index == -1)
++    if (!gc_key || !*gc_key)
      {
-     	if (!mfbAllocatePrivates(pScreen,
- 			     	 &cfbWindowPrivateKey, &cfbGCPrivateKey))
 -    	if (!mfbAllocatePrivates(pScreen, &cfbGCPrivateIndex))
++    	if (!mfbAllocatePrivates(pScreen, &cfbGCPrivateKey))
  	    return FALSE;
-     	if (window_key)
- 	    *window_key = cfbWindowPrivateKey;
 -    	if (gc_index)
 -	    *gc_index = cfbGCPrivateIndex;
 +    	if (gc_key)
 +	    *gc_key = cfbGCPrivateKey;
      }
      else
      {
- 	cfbWindowPrivateKey = *window_key;
 -	cfbGCPrivateIndex = *gc_index;
 +	cfbGCPrivateKey = *gc_key;
      }
-     if (!dixRequestPrivate(cfbWindowPrivateKey, sizeof(cfbPrivWin)))
- 	return FALSE;
-     if (!dixRequestPrivate(cfbGCPrivateKey, sizeof(cfbPrivGC)))
- 	return FALSE;
-     return TRUE;
 -    if (!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
 -	return FALSE;
 -#ifdef CFB_NEED_SCREEN_PRIVATE
 -    if (cfbGeneration != serverGeneration)
 -    {
 -      cfbScreenPrivateIndex = AllocateScreenPrivateIndex ();
 -      cfbGeneration = serverGeneration;
 -    }
 -    if (cfbScreenPrivateIndex == -1)
 -	return FALSE;
 -#endif
 -    return TRUE;
++    return dixRequestPrivate(cfbGCPrivateKey, sizeof(cfbPrivGC));
  }
diff --cc cfb/cfbwindow.c
index 49cc6f0,c4f027b..2b582d4
--- a/cfb/cfbwindow.c
+++ b/cfb/cfbwindow.c
@@@ -60,23 -60,12 +60,12 @@@ SOFTWARE
  #include "cfbmskbits.h"
  
  Bool
- cfbCreateWindow(pWin)
-     WindowPtr pWin;
+ cfbCreateWindow(WindowPtr pWin)
  {
-     cfbPrivWin *pPrivWin;
- 
-     pPrivWin = cfbGetWindowPrivate(pWin);
-     pPrivWin->pRotatedBorder = NullPixmap;
-     pPrivWin->pRotatedBackground = NullPixmap;
-     pPrivWin->fastBackground = FALSE;
-     pPrivWin->fastBorder = FALSE;
-     pPrivWin->oldRotate.x = 0;
-     pPrivWin->oldRotate.y = 0;
- 
  #ifdef PIXMAP_PER_WINDOW
      /* Setup pointer to Screen pixmap */
 -    pWin->devPrivates[frameWindowPrivateIndex].ptr =
 -	(pointer) cfbGetScreenPixmap(pWin->drawable.pScreen);
 +    dixSetPrivate(&pWin->devPrivates, frameWindowPrivateKey,
 +		  cfbGetScreenPixmap(pWin->drawable.pScreen));
  #endif
  
      return TRUE;
diff --cc configure.ac
index 43bc357,24b12df..dd9d500
--- a/configure.ac
+++ b/configure.ac
@@@ -1312,7 -1301,7 +1314,7 @@@ if test "x$XORG" = xyes -o "x$XGL" = xy
  	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
  	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
  	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
- 	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB $OS_LIB"
 -	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB"
++	XORG_LIBS="$COMPOSITE_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB"
  
  dnl Check to see if dlopen is in default libraries (like Solaris, which
  dnl has it in libc), or if libdl is needed to get it.
diff --cc exa/exa.c
index 4260cba,eac2d91..8f219fb
--- a/exa/exa.c
+++ b/exa/exa.c
@@@ -40,9 -40,21 +40,20 @@@
  #include "exa.h"
  #include "cw.h"
  
 -static int exaGeneration;
 -int exaScreenPrivateIndex;
 -int exaPixmapPrivateIndex;
 +DevPrivateKey exaScreenPrivateKey = &exaScreenPrivateKey;
 +DevPrivateKey exaPixmapPrivateKey = &exaPixmapPrivateKey;
  
+ static _X_INLINE void*
+ ExaGetPixmapAddress(PixmapPtr p)
+ {
+     ExaPixmapPriv(p);
+ 
+     if (pExaPixmap->offscreen && pExaPixmap->fb_ptr)
+ 	return pExaPixmap->fb_ptr;
+     else
+ 	return pExaPixmap->sys_ptr;
+ }
+ 
  /**
   * exaGetPixmapOffset() returns the offset (in bytes) within the framebuffer of
   * the beginning of the given pixmap.
diff --cc fb/wfbrename.h
index a6296fb,93ce41b..9382244
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@@ -117,10 -117,9 +117,9 @@@
  #define fbOverlayCreateWindow wfbOverlayCreateWindow
  #define fbOverlayFinishScreenInit wfbOverlayFinishScreenInit
  #define fbOverlayGeneration wfbOverlayGeneration
 -#define fbOverlayGetScreenPrivateIndex wfbOverlayGetScreenPrivateIndex
 +#define fbOverlayGetScreenPrivateKey wfbOverlayGetScreenPrivateKey
  #define fbOverlayPaintKey wfbOverlayPaintKey
- #define fbOverlayPaintWindow wfbOverlayPaintWindow
 -#define fbOverlayScreenPrivateIndex wfbOverlayScreenPrivateIndex
 +#define fbOverlayScreenPrivateKey wfbOverlayScreenPrivateKey
  #define fbOverlaySetupScreen wfbOverlaySetupScreen
  #define fbOverlayUpdateLayerRegion wfbOverlayUpdateLayerRegion
  #define fbOverlayWindowExposures wfbOverlayWindowExposures
diff --cc hw/xfree86/xf8_32bpp/cfbscrinit.c
index fffd8d3,5e2657f..c3432b8
--- a/hw/xfree86/xf8_32bpp/cfbscrinit.c
+++ b/hw/xfree86/xf8_32bpp/cfbscrinit.c
@@@ -55,17 -56,13 +55,13 @@@ cfb8_32AllocatePrivates(ScreenPtr pScre
     
     
     /* All cfb will have the same GC and Window private indicies */
-    if(!mfbAllocatePrivates(pScreen, &cfbWindowPrivateKey, &cfbGCPrivateKey))
- 	return FALSE;
- 
-    /* The cfb indicies are the mfb indicies. Reallocating them resizes them */ 
-    if(!dixRequestPrivate(cfbWindowPrivateKey, sizeof(cfbPrivWin)))
 -   if(!mfbAllocatePrivates(pScreen, &cfbGCPrivateIndex))
++   if(!mfbAllocatePrivates(pScreen, &cfbGCPrivateKey))
  	return FALSE;
  
 -   if(!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
 +   if(!dixRequestPrivate(cfbGCPrivateKey, sizeof(cfbPrivGC)))
          return FALSE;
  
 -   if(!AllocateGCPrivate(pScreen, cfb8_32GCPrivateIndex, sizeof(cfb8_32GCRec)))
 +   if(!dixRequestPrivate(cfb8_32GCPrivateKey, sizeof(cfb8_32GCRec)))
          return FALSE;
  
     return TRUE;
diff --cc mfb/mfb.h
index 42f3002,69d2d69..4d503f9
--- a/mfb/mfb.h
+++ b/mfb/mfb.h
@@@ -705,8 -697,7 +698,7 @@@ extern Bool mfbCloseScreen
  
  extern Bool mfbAllocatePrivates(
      ScreenPtr /*pScreen*/,
-     DevPrivateKey *pWinKey,
-     DevPrivateKey *pGCIndex
 -    int * /*pGCIndex*/
++    DevPrivateKey * /*pGCKey*/
  );
  
  extern Bool mfbScreenInit(
@@@ -891,10 -882,12 +883,9 @@@ typedef struct 
  typedef mfbPrivGC	*mfbPrivGCPtr;
  #endif
  
 -/* XXX these should be static, but it breaks the ABI */
 -extern int  mfbGCPrivateIndex;		/* index into GC private array */
 -extern int  mfbGetGCPrivateIndex(void);
 +extern DevPrivateKey mfbGetGCPrivateKey(void);
- extern DevPrivateKey mfbGetWindowPrivateKey(void);
  #ifdef PIXMAP_PER_WINDOW
 -extern int  frameWindowPrivateIndex;	/* index into Window private array */
 -extern int  frameGetWindowPrivateIndex(void);
 +extern DevPrivateKey frameGetWindowPrivateKey(void);
  #endif
  
  #ifndef MFB_PROTOTYPES_ONLY
diff --cc mfb/mfbscrinit.c
index 515e9e3,6d364b7..8873a1b
--- a/mfb/mfbscrinit.c
+++ b/mfb/mfbscrinit.c
@@@ -68,13 -68,11 +68,11 @@@ SOFTWARE
  #include "servermd.h"
  
  #ifdef PIXMAP_PER_WINDOW
 -int frameWindowPrivateIndex;
 -int frameGetWindowPrivateIndex(void) { return frameWindowPrivateIndex; }
 +static DevPrivateKey frameWindowPrivateKey = &frameWindowPrivateKey;
 +DevPrivateKey frameGetWindowPrivateKey(void) { return frameWindowPrivateKey; }
  #endif
- static DevPrivateKey mfbWindowPrivateKey = &mfbWindowPrivateKey;
- DevPrivateKey mfbGetWindowPrivateKey(void) { return mfbWindowPrivateKey; }
 -int mfbGCPrivateIndex;
 -int mfbGetGCPrivateIndex(void) { return mfbGCPrivateIndex; }
 +static DevPrivateKey mfbGCPrivateKey = &mfbGCPrivateKey;
 +DevPrivateKey mfbGetGCPrivateKey(void) { return mfbGCPrivateKey; }
  static unsigned long mfbGeneration = 0;
  
  static VisualRec visual = {
@@@ -90,8 -88,7 +88,7 @@@ static DepthRec depth = 
  };
  
  Bool
- mfbAllocatePrivates(ScreenPtr pScreen,
- 		    DevPrivateKey *pWinIndex, DevPrivateKey *pGCIndex)
 -mfbAllocatePrivates(ScreenPtr pScreen, int *pGCIndex)
++mfbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
  {
      if (mfbGeneration != serverGeneration)
      {
@@@ -99,14 -100,11 +96,11 @@@
  	VID = visual.vid;
  	mfbGeneration = serverGeneration;
      }
-     if (pWinIndex)
- 	*pWinIndex = mfbWindowPrivateKey;
--    if (pGCIndex)
- 	*pGCIndex = mfbGCPrivateKey;
 -	*pGCIndex = mfbGCPrivateIndex;
++    if (pGCKey)
++	*pGCKey = mfbGCPrivateKey;
      pScreen->GetWindowPixmap = mfbGetWindowPixmap;
      pScreen->SetWindowPixmap = mfbSetWindowPixmap;
-     return (dixRequestPrivate(mfbWindowPrivateKey, sizeof(mfbPrivWin)) &&
- 	    dixRequestPrivate(mfbGCPrivateKey, sizeof(mfbPrivGC)));
 -    return AllocateGCPrivate(pScreen, mfbGCPrivateIndex, sizeof(mfbPrivGC));
++    return dixRequestPrivate(mfbGCPrivateKey, sizeof(mfbPrivGC));
  }
  
  
diff --cc mi/mibank.c
index b52399c,3492f1e..05813e5
--- a/mi/mibank.c
+++ b/mi/mibank.c
@@@ -2263,11 -2200,9 +2194,9 @@@ miInitializeBanking
      SCREEN_WRAP(GetImage,              miBankGetImage);
      SCREEN_WRAP(GetSpans,              miBankGetSpans);
      SCREEN_WRAP(CreateGC,              miBankCreateGC);
-     SCREEN_WRAP(PaintWindowBackground, miBankPaintWindow);
-     SCREEN_WRAP(PaintWindowBorder,     miBankPaintWindow);
      SCREEN_WRAP(CopyWindow,            miBankCopyWindow);
  
 -    BANK_SCRPRIVLVAL = (pointer)pScreenPriv;
 +    dixSetPrivate(&pScreen->devPrivates, miBankScreenKey, pScreenPriv);
  
      return TRUE;
  }
diff --cc render/picturestr.h
index fad9741,09a7131..5444e51
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@@ -24,10 -24,9 +24,10 @@@
  #ifndef _PICTURESTR_H_
  #define _PICTURESTR_H_
  
- #include "glyphstr.h"
  #include "scrnintstr.h"
+ #include "glyphstr.h"
  #include "resource.h"
 +#include "privates.h"
  
  typedef struct _DirectFormat {
      CARD16	    red, redMask;
commit 57907e0943da0c3fd3bf6c128d210b544629ce72
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Sep 6 16:55:51 2007 -0400

    devPrivates rework: register an offset for every resource type, use
    signed values so -1 actually works correctly, and provide a macro for
    adding an offset to a pointer.

diff --git a/dix/privates.c b/dix/privates.c
index 38c5523..e04da41 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -35,6 +35,7 @@ from The Open Group.
 #include "resource.h"
 #include "privates.h"
 #include "gcstruct.h"
+#include "cursorstr.h"
 #include "colormapst.h"
 #include "inputstr.h"
 
@@ -174,21 +175,34 @@ dixRegisterPrivateDeleteFunc(const DevPrivateKey key,
 }
 
 /* Table of devPrivates offsets */
-static unsigned *offsets = NULL;
-static unsigned offsetsSize = 0;
+static const int offsetDefaults[] = {
+    -1,					/* RT_NONE */
+    offsetof(WindowRec, devPrivates),	/* RT_WINDOW */
+    offsetof(PixmapRec, devPrivates),	/* RT_PIXMAP */
+    offsetof(GC, devPrivates),		/* RT_GC */
+    -1,		    			/* RT_FONT */
+    offsetof(CursorRec, devPrivates),	/* RT_CURSOR */
+    offsetof(ColormapRec, devPrivates),	/* RT_COLORMAP */
+    -1,			  		/* RT_CMAPENTRY */
+    -1,					/* RT_OTHERCLIENT */
+    -1					/* RT_PASSIVEGRAB */
+};
+    
+static int *offsets = NULL;
+static int offsetsSize = 0;
 
 /*
  * Specify where the devPrivates field is located in a structure type
  */
 _X_EXPORT int
-dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
+dixRegisterPrivateOffset(RESTYPE type, int offset)
 {
     type = type & TypeMask;
 
     /* resize offsets table if necessary */
     while (type >= offsetsSize) {
 	unsigned i = offsetsSize * 2 * sizeof(int);
-	offsets = (unsigned *)xrealloc(offsets, i);
+	offsets = (int *)xrealloc(offsets, i);
 	if (!offsets) {
 	    offsetsSize = 0;
 	    return FALSE;
@@ -214,7 +228,6 @@ int
 dixResetPrivates(void)
 {
     PrivateDescRec *next;
-    unsigned i;
 
     /* reset internal structures */
     while (items) {
@@ -224,20 +237,11 @@ dixResetPrivates(void)
     }
     if (offsets)
 	xfree(offsets);
-    offsetsSize = 16;
-    offsets = (unsigned *)xalloc(offsetsSize * sizeof(unsigned));
+    offsetsSize = sizeof(offsetDefaults);
+    offsets = (int *)xalloc(offsetsSize);
+    offsetsSize /= sizeof(int);
     if (!offsets)
 	return FALSE;
-    for (i=0; i < offsetsSize; i++)
-	offsets[i] = -1;
-
-    /* register basic resource offsets */
-    return dixRegisterPrivateOffset(RT_WINDOW,
-				    offsetof(WindowRec, devPrivates)) &&
-	dixRegisterPrivateOffset(RT_PIXMAP,
-				 offsetof(PixmapRec, devPrivates)) &&
-	dixRegisterPrivateOffset(RT_GC,
-				 offsetof(GC, devPrivates)) &&
-	dixRegisterPrivateOffset(RT_COLORMAP,
-				 offsetof(ColormapRec, devPrivates));
+    memcpy(offsets, offsetDefaults, sizeof(offsetDefaults));
+    return TRUE;
 }
diff --git a/dix/resource.c b/dix/resource.c
index a557ba4..c892cf9 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -225,6 +225,8 @@ CreateNewResourceType(DeleteType deleteFunc)
 				   (next + 1) * sizeof(DeleteType));
     if (!funcs)
 	return 0;
+    if (!dixRegisterPrivateOffset(next, -1))
+	return 0;
 
 #ifdef XResExtension
     {
diff --git a/include/privates.h b/include/privates.h
index 9539a29..8d59b72 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -143,8 +143,15 @@ dixLookupPrivateOffset(RESTYPE type);
 
 /*
  * Specifies the offset where the devPrivates field is located.
+ * A negative value indicates no devPrivates field is available.
  */
 extern int
-dixRegisterPrivateOffset(RESTYPE type, unsigned offset);
+dixRegisterPrivateOffset(RESTYPE type, int offset);
+
+/*
+ * Convenience macro for adding an offset to an object pointer
+ * when making a call to one of the devPrivates functions
+ */
+#define DEVPRIV_AT(ptr, offset) ((PrivateRec **)((char *)ptr + offset))
 
 #endif /* PRIVATES_H */
commit 0003ccfcdfae1b473aa024342304b84256d378b9
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Sep 5 11:18:36 2007 -0400

    xace: add new fields to resource access hook to allow parent resource objects
    to be passed in at create time.  Also added a missing devPrivates initializer.

diff --git a/Xext/xace.c b/Xext/xace.c
index cc68986..92f0e40 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -72,8 +72,10 @@ int XaceHook(int hook, ...)
 		va_arg(ap, ClientPtr),
 		va_arg(ap, XID),
 		va_arg(ap, RESTYPE),
-		va_arg(ap, Mask),
 		va_arg(ap, pointer),
+		va_arg(ap, RESTYPE),
+		va_arg(ap, pointer),
+		va_arg(ap, Mask),
 		Success /* default allow */
 	    };
 	    calldata = &rec;
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 0957f0d..e12a52c 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -41,8 +41,10 @@ typedef struct {
     ClientPtr client;
     XID id;
     RESTYPE rtype;
-    Mask access_mode;
     pointer res;
+    RESTYPE ptype;
+    pointer parent;
+    Mask access_mode;
     int status;
 } XaceResourceAccessRec;
 
diff --git a/composite/compext.c b/composite/compext.c
index b329679..2d3bafa 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -459,7 +459,7 @@ ProcCompositeGetOverlayWindow (ClientPtr client)
     }
 
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cs->pOverlayWin->drawable.id,
-		  RT_WINDOW, DixGetAttrAccess, cs->pOverlayWin);
+		  RT_WINDOW, cs->pOverlayWin, RT_NONE, NULL, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
diff --git a/dix/colormap.c b/dix/colormap.c
index 98f2f1b..d07cff7 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -397,7 +397,7 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
      * Security creation/labeling check
      */
     i = XaceHook(XACE_RESOURCE_ACCESS, clients[client], mid, RT_COLORMAP,
-		 DixCreateAccess, pmap);
+		 pmap, RT_NONE, NULL, DixCreateAccess);
     if (i != Success) {
 	FreeResource(mid, RT_NONE);
 	return i;
diff --git a/dix/cursor.c b/dix/cursor.c
index 324faa1..0ddf9d7 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -212,12 +212,12 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     pCurs->backGreen = backGreen;
     pCurs->backBlue = backBlue;
 
-    pCurs->devPrivates = NULL;
     pCurs->id = cid;
+    pCurs->devPrivates = NULL;
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
-		  DixCreateAccess, pCurs);
+		  pCurs, RT_NONE, NULL, DixCreateAccess);
     if (rc != Success) {
 	dixFreePrivates(pCurs->devPrivates);
 	FreeCursorBits(bits);
@@ -365,6 +365,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 	bits->height = cm.height;
 	bits->xhot = cm.xhot;
 	bits->yhot = cm.yhot;
+	bits->devPrivates = NULL;
 	if (sourcefont != maskfont)
 	    bits->refcnt = -1;
 	else
@@ -406,7 +407,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
-		  DixCreateAccess, pCurs);
+		  pCurs, RT_NONE, NULL, DixCreateAccess);
     if (rc != Success) {
 	dixFreePrivates(pCurs->devPrivates);
 	FreeCursorBits(bits);
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 7adfe02..507854e 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1558,7 +1558,7 @@ CreatePmap:
 	pMap->drawable.id = stuff->pid;
 	/* security creation/labeling check */
 	rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP,
-		      DixCreateAccess, pMap);
+		      pMap, RT_NONE, NULL, DixCreateAccess);
 	if (rc != Success) {
 	    (*pDraw->pScreen->DestroyPixmap)(pMap);
 	    return rc;
diff --git a/dix/gc.c b/dix/gc.c
index d77932c..443f6c6 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -638,8 +638,8 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
     pGC->stipple->refcnt++;
 
     /* security creation/labeling check */
-    *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC,
-			DixCreateAccess|DixSetAttrAccess, pGC);
+    *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC, pGC,
+			RT_NONE, NULL, DixCreateAccess|DixSetAttrAccess);
     if (*pStatus != Success)
 	goto out;
 
diff --git a/dix/resource.c b/dix/resource.c
index 844d12e..a557ba4 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -901,7 +901,7 @@ dixLookupResource(pointer *result, XID id, RESTYPE rtype,
     if (client) {
 	client->errorValue = id;
 	cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type,
-		       mode, res->value);
+		       res->value, RT_NONE, NULL, mode);
 	if (cid != Success)
 	    return cid;
     }
diff --git a/dix/window.c b/dix/window.c
index 70ce2ad..6c65319 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -698,8 +698,8 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 
     /*  security creation/labeling check
      */
-    *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW,
-		      DixCreateAccess|DixSetAttrAccess, pWin);
+    *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW, pWin,
+		RT_WINDOW, pWin->parent, DixCreateAccess|DixSetAttrAccess);
     if (*error != Success) {
 	xfree(pWin);
 	return NullWindow;
@@ -955,7 +955,7 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client)
     while (pWin->lastChild) {
 	int rc = XaceHook(XACE_RESOURCE_ACCESS, client,
 			  pWin->lastChild->drawable.id, RT_WINDOW,
-			  DixDestroyAccess, pWin->lastChild);
+			  pWin->lastChild, RT_NONE, NULL, DixDestroyAccess);
 	if (rc != Success)
 	    return rc;
 	FreeResource(pWin->lastChild->drawable.id, RT_NONE);
@@ -1275,7 +1275,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 	    }
 	    if (val == xTrue) {
 		rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id,
-			      RT_WINDOW, DixGrabAccess, pWin);
+			      RT_WINDOW, pWin, RT_NONE, NULL, DixGrabAccess);
 		if (rc != Success) {
 		    error = rc;
 		    client->errorValue = pWin->drawable.id;
@@ -2745,7 +2745,7 @@ MapWindow(WindowPtr pWin, ClientPtr client)
 
     /*  general check for permission to map window */
     if (XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, RT_WINDOW,
-		 DixShowAccess, pWin) != Success)
+		 pWin, RT_NONE, NULL, DixShowAccess) != Success)
 	return Success;
 
     pScreen = pWin->drawable.pScreen;
diff --git a/render/animcur.c b/render/animcur.c
index da3d4a0..1259289 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -377,12 +377,12 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
     pCursor->backGreen = cursors[0]->backGreen;
     pCursor->backBlue = cursors[0]->backBlue;
 
-    pCursor->devPrivates = NULL;
     pCursor->id = cid;
+    pCursor->devPrivates = NULL;
 
     /* security creation/labeling check */
-    rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
-		  DixCreateAccess, pCursor);
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR, pCursor,
+		  RT_NONE, NULL, DixCreateAccess);
     if (rc != Success) {
 	dixFreePrivates(pCursor->devPrivates);
 	xfree(pCursor);
diff --git a/render/picture.c b/render/picture.c
index 7b200ee..660ef12 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -727,8 +727,8 @@ CreatePicture (Picture		pid,
     pPicture->devPrivates = NULL;
 
     /* security creation/labeling check */
-    *error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType,
-		      DixCreateAccess|DixSetAttrAccess, pPicture);
+    *error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType, pPicture,
+		      RC_DRAWABLE, pDrawable, DixCreateAccess|DixSetAttrAccess);
     if (*error != Success)
 	goto out;
 
diff --git a/render/render.c b/render/render.c
index 37d2d62..40d5add 100644
--- a/render/render.c
+++ b/render/render.c
@@ -1025,7 +1025,7 @@ ProcRenderCreateGlyphSet (ClientPtr client)
 	return BadAlloc;
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->gsid, GlyphSetType,
-		  DixCreateAccess, glyphSet);
+		  glyphSet, RT_NONE, NULL, DixCreateAccess);
     if (rc != Success)
 	return rc;
     if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
@@ -1903,7 +1903,7 @@ static int ProcRenderCreateSolidFill(ClientPtr client)
 	return error;
     /* security creation/labeling check */
     error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
-		  DixCreateAccess, pPicture);
+		     pPicture, RT_NONE, NULL, DixCreateAccess);
     if (error != Success)
 	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
@@ -1937,7 +1937,7 @@ static int ProcRenderCreateLinearGradient (ClientPtr client)
 	return error;
     /* security creation/labeling check */
     error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
-		  DixCreateAccess, pPicture);
+		     pPicture, RT_NONE, NULL, DixCreateAccess);
     if (error != Success)
 	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
@@ -1972,7 +1972,7 @@ static int ProcRenderCreateRadialGradient (ClientPtr client)
 	return error;
     /* security creation/labeling check */
     error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
-		  DixCreateAccess, pPicture);
+		     pPicture, RT_NONE, NULL, DixCreateAccess);
     if (error != Success)
 	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
@@ -2006,7 +2006,7 @@ static int ProcRenderCreateConicalGradient (ClientPtr client)
 	return error;
     /* security creation/labeling check */
     error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
-		  DixCreateAccess, pPicture);
+		     pPicture, RT_NONE, NULL, DixCreateAccess);
     if (error != Success)
 	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 52f483e..1d122fa 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -351,7 +351,7 @@ ProcXFixesGetCursorImage (ClientPtr client)
     if (!pCursor)
 	return BadCursor;
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, RT_CURSOR,
-		  DixReadAccess, pCursor);
+		  pCursor, RT_NONE, NULL, DixReadAccess);
     if (rc != Success)
 	return rc;
     GetSpritePosition (&x, &y);
@@ -503,7 +503,7 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
     if (!pCursor)
 	return BadCursor;
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, RT_CURSOR,
-		  DixReadAccess|DixGetAttrAccess, pCursor);
+		  pCursor, RT_NONE, NULL, DixReadAccess|DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     GetSpritePosition (&x, &y);
commit ce9e83d913511fe619da42f805d7bcd1a2a60d90
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Sep 4 14:01:55 2007 -0400

    xace: add hooks + new access codes: Damage extension

diff --git a/damageext/damageext.c b/damageext/damageext.c
index 1597465..517c72d 100755
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -185,7 +185,7 @@ ProcDamageCreate (ClientPtr client)
     REQUEST_SIZE_MATCH(xDamageCreateReq);
     LEGAL_NEW_RESOURCE(stuff->damage, client);
     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
-			   DixReadAccess);
+			   DixGetAttrAccess|DixReadAccess);
     if (rc != Success)
 	return rc;
 
@@ -295,7 +295,7 @@ ProcDamageAdd (ClientPtr client)
     REQUEST_SIZE_MATCH(xDamageAddReq);
     VERIFY_REGION(pRegion, stuff->region, client, DixWriteAccess);
     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
-			   DixReadAccess);
+			   DixWriteAccess);
     if (rc != Success)
 	return rc;
 
commit c9ceb4878063ca22487c708d9d1f86e367f2cec8
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Aug 31 11:03:54 2007 -0400

    xace: add hooks + new access codes: Composite extension

diff --git a/composite/compext.c b/composite/compext.c
index 8d2a2d7..b329679 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -45,6 +45,7 @@
 #endif
 
 #include "compint.h"
+#include "xace.h"
 
 #define SERVER_COMPOSITE_MAJOR	0
 #define SERVER_COMPOSITE_MINOR	4
@@ -157,14 +158,16 @@ static int
 ProcCompositeRedirectWindow (ClientPtr client)
 {
     WindowPtr	pWin;
+    int rc;
     REQUEST(xCompositeRedirectWindowReq);
 
     REQUEST_SIZE_MATCH(xCompositeRedirectWindowReq);
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW, client,
+			   DixSetAttrAccess|DixManageAccess|DixBlendAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
     return compRedirectWindow (client, pWin, stuff->update);
 }
@@ -173,14 +176,16 @@ static int
 ProcCompositeRedirectSubwindows (ClientPtr client)
 {
     WindowPtr	pWin;
+    int rc;
     REQUEST(xCompositeRedirectSubwindowsReq);
 
     REQUEST_SIZE_MATCH(xCompositeRedirectSubwindowsReq);
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW, client,
+			   DixSetAttrAccess|DixManageAccess|DixBlendAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
     return compRedirectSubwindows (client, pWin, stuff->update);
 }
@@ -223,14 +228,16 @@ ProcCompositeCreateRegionFromBorderClip (ClientPtr client)
     WindowPtr	    pWin;
     CompWindowPtr   cw;
     RegionPtr	    pBorderClip, pRegion;
+    int rc;
     REQUEST(xCompositeCreateRegionFromBorderClipReq);
 
     REQUEST_SIZE_MATCH(xCompositeCreateRegionFromBorderClipReq);
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW, client,
+			   DixGetAttrAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
     
     LEGAL_NEW_RESOURCE (stuff->region, client);
@@ -257,14 +264,16 @@ ProcCompositeNameWindowPixmap (ClientPtr client)
     WindowPtr	    pWin;
     CompWindowPtr   cw;
     PixmapPtr	    pPixmap;
+    int rc;
     REQUEST(xCompositeNameWindowPixmapReq);
 
     REQUEST_SIZE_MATCH(xCompositeNameWindowPixmapReq);
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW, client,
+			   DixGetAttrAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
 
     if (!pWin->viewable)
@@ -429,13 +438,15 @@ ProcCompositeGetOverlayWindow (ClientPtr client)
     ScreenPtr pScreen;
     CompScreenPtr cs;
     CompOverlayClientPtr pOc;
+    int rc;
 
     REQUEST_SIZE_MATCH(xCompositeGetOverlayWindowReq);
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW, client,
+			   DixGetAttrAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
     pScreen = pWin->drawable.pScreen;
 
@@ -446,6 +457,12 @@ ProcCompositeGetOverlayWindow (ClientPtr client)
 	    return BadAlloc;
 	}
     }
+
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, cs->pOverlayWin->drawable.id,
+		  RT_WINDOW, DixGetAttrAccess, cs->pOverlayWin);
+    if (rc != Success)
+	return rc;
+
     MapWindow(cs->pOverlayWin, serverClient);
 
     /* Record that client is using this overlay window */
commit fd04b983db6a70bf747abe02ca07c1fbbaae6343
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Aug 31 09:55:27 2007 -0400

    xace: add hooks + new access codes: Render extension

diff --git a/render/animcur.c b/render/animcur.c
index 444d706..da3d4a0 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -44,6 +44,7 @@
 #include "dixfontstr.h"
 #include "opaque.h"
 #include "picturestr.h"
+#include "xace.h"
 
 typedef struct _AnimCurElt {
     CursorPtr	pCursor;    /* cursor to show */
@@ -346,10 +347,10 @@ AnimCurInit (ScreenPtr pScreen)
 }
 
 int
-AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor)
+AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor, ClientPtr client, XID cid)
 {
     CursorPtr	pCursor;
-    int		i;
+    int		rc, i;
     AnimCurPtr	ac;
 
     for (i = 0; i < screenInfo.numScreens; i++)
@@ -366,7 +367,6 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
     if (!pCursor)
 	return BadAlloc;
     pCursor->bits = &animCursorBits;
-    animCursorBits.refcnt++;
     pCursor->refcnt = 1;
     
     pCursor->foreRed = cursors[0]->foreRed;
@@ -377,9 +377,22 @@ AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *pp
     pCursor->backGreen = cursors[0]->backGreen;
     pCursor->backBlue = cursors[0]->backBlue;
 
+    pCursor->devPrivates = NULL;
+    pCursor->id = cid;
+
+    /* security creation/labeling check */
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
+		  DixCreateAccess, pCursor);
+    if (rc != Success) {
+	dixFreePrivates(pCursor->devPrivates);
+	xfree(pCursor);
+	return rc;
+    }
+	
     /*
      * Fill in the AnimCurRec
      */
+    animCursorBits.refcnt++;
     ac = GetAnimCur (pCursor);
     ac->nelt = ncursor;
     ac->elts = (AnimCurElt *) (ac + 1);
diff --git a/render/picture.c b/render/picture.c
index bc2c3b5..7b200ee 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -40,6 +40,7 @@
 #include "gcstruct.h"
 #include "servermd.h"
 #include "picturestr.h"
+#include "xace.h"
 
 _X_EXPORT DevPrivateKey PictureScreenPrivateKey = &PictureScreenPrivateKey;
 DevPrivateKey	PictureWindowPrivateKey = &PictureWindowPrivateKey;
@@ -724,6 +725,13 @@ CreatePicture (Picture		pid,
     pPicture->pFormat = pFormat;
     pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24);
     pPicture->devPrivates = NULL;
+
+    /* security creation/labeling check */
+    *error = XaceHook(XACE_RESOURCE_ACCESS, client, pid, PictureType,
+		      DixCreateAccess|DixSetAttrAccess, pPicture);
+    if (*error != Success)
+	goto out;
+
     if (pDrawable->type == DRAWABLE_PIXMAP)
     {
 	++((PixmapPtr)pDrawable)->refcnt;
@@ -743,6 +751,7 @@ CreatePicture (Picture		pid,
 	*error = Success;
     if (*error == Success)
 	*error = (*ps->CreatePicture) (pPicture);
+out:
     if (*error != Success)
     {
 	FreePicture (pPicture, (XID) 0);
@@ -1060,14 +1069,13 @@ ChangePicture (PicturePtr	pPicture,
 			pAlpha = 0;
 		    else
 		    {
-			pAlpha = (PicturePtr) SecurityLookupIDByType(client,
-								     pid, 
-								     PictureType, 
-								     DixWriteAccess|DixReadAccess);
-			if (!pAlpha)
+			error = dixLookupResource((pointer *)&pAlpha, pid,
+						  PictureType, client,
+						  DixReadAccess);
+			if (error != Success)
 			{
 			    client->errorValue = pid;
-			    error = BadPixmap;
+			    error = (error == BadValue) ? BadPixmap : error;
 			    break;
 			}
 			if (pAlpha->pDrawable == NULL ||
@@ -1122,14 +1130,13 @@ ChangePicture (PicturePtr	pPicture,
 		    else
 		    {
 			clipType = CT_PIXMAP;
-			pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
-								    pid, 
-								    RT_PIXMAP,
-								    DixReadAccess);
-			if (!pPixmap)
+			error = dixLookupResource((pointer *)&pPixmap, pid,
+						  RT_PIXMAP, client,
+						  DixReadAccess);
+			if (error != Success)
 			{
 			    client->errorValue = pid;
-			    error = BadPixmap;
+			    error = (error == BadValue) ? BadPixmap : error;
 			    break;
 			}
 		    }
diff --git a/render/picturestr.h b/render/picturestr.h
index aafe4e8..fad9741 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -630,7 +630,7 @@ Bool
 AnimCurInit (ScreenPtr pScreen);
 
 int
-AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor);
+AnimCursorCreate (CursorPtr *cursors, CARD32 *deltas, int ncursor, CursorPtr *ppCursor, ClientPtr client, XID cid);
 
 void
 AddTraps (PicturePtr	pPicture,
diff --git a/render/render.c b/render/render.c
index 7b27457..37d2d62 100644
--- a/render/render.c
+++ b/render/render.c
@@ -46,6 +46,7 @@
 #include "glyphstr.h"
 #include <X11/Xfuncproto.h>
 #include "cursorstr.h"
+#include "xace.h"
 
 #if HAVE_STDINT_H
 #include <stdint.h>
@@ -623,7 +624,7 @@ ProcRenderCreatePicture (ClientPtr client)
 
     LEGAL_NEW_RESOURCE(stuff->pid, client);
     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
-			   DixWriteAccess);
+			   DixReadAccess|DixAddAccess);
     if (rc != Success)
 	return rc;
 
@@ -664,7 +665,7 @@ ProcRenderChangePicture (ClientPtr client)
     int len;
 
     REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq);
-    VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
+    VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess,
 		    RenderErrBase + BadPicture);
 
     len = client->req_len - (sizeof(xRenderChangePictureReq) >> 2);
@@ -684,7 +685,7 @@ ProcRenderSetPictureClipRectangles (ClientPtr client)
     int		    result;
 
     REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq);
-    VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
+    VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess,
 		    RenderErrBase + BadPicture);
     if (!pPicture->pDrawable)
         return BadDrawable;
@@ -983,7 +984,7 @@ ProcRenderCreateGlyphSet (ClientPtr client)
 {
     GlyphSetPtr	    glyphSet;
     PictFormatPtr   format;
-    int		    f;
+    int		    rc, f;
     REQUEST(xRenderCreateGlyphSetReq);
 
     REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq);
@@ -1022,6 +1023,11 @@ ProcRenderCreateGlyphSet (ClientPtr client)
     glyphSet = AllocateGlyphSet (f, format);
     if (!glyphSet)
 	return BadAlloc;
+    /* security creation/labeling check */
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->gsid, GlyphSetType,
+		  DixCreateAccess, glyphSet);
+    if (rc != Success)
+	return rc;
     if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
 	return BadAlloc;
     return Success;
@@ -1031,20 +1037,19 @@ static int
 ProcRenderReferenceGlyphSet (ClientPtr client)
 {
     GlyphSetPtr     glyphSet;
+    int rc;
     REQUEST(xRenderReferenceGlyphSetReq);
 
     REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq);
 
     LEGAL_NEW_RESOURCE(stuff->gsid, client);
 
-    glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
-						     stuff->existing,
-						     GlyphSetType,
-						     DixWriteAccess);
-    if (!glyphSet)
+    rc = dixLookupResource((pointer *)&glyphSet, stuff->existing, GlyphSetType,
+			   client, DixGetAttrAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->existing;
-	return RenderErrBase + BadGlyphSet;
+	return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
     }
     glyphSet->refcnt++;
     if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
@@ -1059,17 +1064,16 @@ static int
 ProcRenderFreeGlyphSet (ClientPtr client)
 {
     GlyphSetPtr     glyphSet;
+    int rc;
     REQUEST(xRenderFreeGlyphSetReq);
 
     REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq);
-    glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
-						     stuff->glyphset,
-						     GlyphSetType,
-						     DixDestroyAccess);
-    if (!glyphSet)
+    rc = dixLookupResource((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
+			   client, DixDestroyAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->glyphset;
-	return RenderErrBase + BadGlyphSet;
+	return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
     }
     FreeResource (stuff->glyphset, RT_NONE);
     return client->noClientException;
@@ -1093,19 +1097,18 @@ ProcRenderAddGlyphs (ClientPtr client)
     xGlyphInfo	    *gi;
     CARD8	    *bits;
     int		    size;
-    int		    err = BadAlloc;
+    int		    err;
 
     REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq);
-    glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
-						     stuff->glyphset,
-						     GlyphSetType,
-						     DixWriteAccess);
-    if (!glyphSet)
+    err = dixLookupResource((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
+			    client, DixAddAccess);
+    if (err != Success)
     {
 	client->errorValue = stuff->glyphset;
-	return RenderErrBase + BadGlyphSet;
+	return (err == BadValue) ? RenderErrBase + BadGlyphSet : err;
     }
 
+    err = BadAlloc;
     nglyphs = stuff->nglyphs;
     if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec))
 	    return BadAlloc;
@@ -1195,19 +1198,17 @@ ProcRenderFreeGlyphs (ClientPtr client)
 {
     REQUEST(xRenderFreeGlyphsReq);
     GlyphSetPtr     glyphSet;
-    int		    nglyph;
+    int		    rc, nglyph;
     CARD32	    *gids;
     CARD32	    glyph;
 
     REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq);
-    glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
-						     stuff->glyphset,
-						     GlyphSetType,
-						     DixWriteAccess);
-    if (!glyphSet)
+    rc = dixLookupResource((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
+			   client, DixRemoveAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->glyphset;
-	return RenderErrBase + BadGlyphSet;
+	return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
     }
     nglyph = ((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)) >> 2;
     gids = (CARD32 *) (stuff + 1);
@@ -1284,7 +1285,7 @@ ProcRenderCompositeGlyphs (ClientPtr client)
     glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
 						     stuff->glyphset,
 						     GlyphSetType,
-						     DixReadAccess);
+						     DixUseAccess);
     if (!glyphSet)
     {
 	client->errorValue = stuff->glyphset;
@@ -1346,7 +1347,7 @@ ProcRenderCompositeGlyphs (ClientPtr client)
 		glyphSet = (GlyphSetPtr) SecurityLookupIDByType (client,
 								 gs,
 								 GlyphSetType,
-								 DixReadAccess);
+								 DixUseAccess);
 		if (!glyphSet)
 		{
 		    client->errorValue = gs;
@@ -1679,7 +1680,7 @@ ProcRenderSetPictureTransform (ClientPtr client)
     int		result;
 
     REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
-    VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
+    VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess,
 		    RenderErrBase + BadPicture);
     result = SetPictureTransform (pPicture, (PictTransform *) &stuff->transform);
     if (client->noClientException != Success)
@@ -1704,7 +1705,7 @@ ProcRenderQueryFilters (ClientPtr client)
 
     REQUEST_SIZE_MATCH(xRenderQueryFiltersReq);
     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
-			   DixReadAccess);
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     
@@ -1809,7 +1810,7 @@ ProcRenderSetPictureFilter (ClientPtr client)
     char	*name;
     
     REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq);
-    VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess,
+    VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess,
 		    RenderErrBase + BadPicture);
     name = (char *) (stuff + 1);
     params = (xFixed *) (name + ((stuff->nbytes + 3) & ~3));
@@ -1853,7 +1854,8 @@ ProcRenderCreateAnimCursor (ClientPtr client)
 	deltas[i] = elt->delay;
 	elt++;
     }
-    ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor);
+    ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor, client,
+			    stuff->cid);
     xfree (cursors);
     if (ret != Success)
 	return ret;
@@ -1899,6 +1901,11 @@ static int ProcRenderCreateSolidFill(ClientPtr client)
     pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error);
     if (!pPicture)
 	return error;
+    /* security creation/labeling check */
+    error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
+		  DixCreateAccess, pPicture);
+    if (error != Success)
+	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
 	return BadAlloc;
     return Success;
@@ -1928,6 +1935,11 @@ static int ProcRenderCreateLinearGradient (ClientPtr client)
                                             stuff->nStops, stops, colors, &error);
     if (!pPicture)
 	return error;
+    /* security creation/labeling check */
+    error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
+		  DixCreateAccess, pPicture);
+    if (error != Success)
+	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
 	return BadAlloc;
     return Success;
@@ -1958,6 +1970,11 @@ static int ProcRenderCreateRadialGradient (ClientPtr client)
                                             stuff->nStops, stops, colors, &error);
     if (!pPicture)
 	return error;
+    /* security creation/labeling check */
+    error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
+		  DixCreateAccess, pPicture);
+    if (error != Success)
+	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
 	return BadAlloc;
     return Success;
@@ -1987,6 +2004,11 @@ static int ProcRenderCreateConicalGradient (ClientPtr client)
                                              stuff->nStops, stops, colors, &error);
     if (!pPicture)
 	return error;
+    /* security creation/labeling check */
+    error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
+		  DixCreateAccess, pPicture);
+    if (error != Success)
+	return error;
     if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
 	return BadAlloc;
     return Success;
commit 1005b29cc6939851b40397cc9cd0de9476ad3046
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 30 14:48:24 2007 -0400

    xace: Correct some access modes.

diff --git a/dix/window.c b/dix/window.c
index b6bbdd4..70ce2ad 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1396,7 +1396,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 	    else
 	    {
 		rc = dixLookupResource((pointer *)&pCursor, cursorID,
-				       RT_CURSOR, client, DixReadAccess);
+				       RT_CURSOR, client, DixUseAccess);
 		if (rc != Success)
 		{
 		    error = (rc == BadValue) ? BadCursor : rc;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 91f149e..52f483e 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -239,7 +239,7 @@ ProcXFixesSelectCursorInput (ClientPtr client)
     int		rc;
 
     REQUEST_SIZE_MATCH (xXFixesSelectCursorInputReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
     if (stuff->eventMask & ~CursorAllEvents)
diff --git a/xfixes/select.c b/xfixes/select.c
index 9de152f..2321212 100755
--- a/xfixes/select.c
+++ b/xfixes/select.c
@@ -203,7 +203,7 @@ ProcXFixesSelectSelectionInput (ClientPtr client)
     int		rc;
 
     REQUEST_SIZE_MATCH (xXFixesSelectSelectionInputReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
     if (stuff->eventMask & ~SelectionAllEvents)
commit 53f346b158fa8e10de5a8777fa6d8d86f918878b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 30 13:20:04 2007 -0400

    xace: add hooks + new access codes: SHAPE extension

diff --git a/Xext/shape.c b/Xext/shape.c
index 928eeee..0f49f73 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -323,7 +323,7 @@ ProcShapeRectangles (client)
 
     REQUEST_AT_LEAST_SIZE (xShapeRectanglesReq);
     UpdateCurrentTime();
-    rc = dixLookupWindow(&pWin, stuff->dest, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     switch (stuff->destKind) {
@@ -423,7 +423,7 @@ ProcShapeMask (client)
 
     REQUEST_SIZE_MATCH (xShapeMaskReq);
     UpdateCurrentTime();
-    rc = dixLookupWindow(&pWin, stuff->dest, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     switch (stuff->destKind) {
@@ -444,10 +444,10 @@ ProcShapeMask (client)
     if (stuff->src == None)
 	srcRgn = 0;
     else {
-        pPixmap = (PixmapPtr) SecurityLookupIDByType(client, stuff->src,
-						RT_PIXMAP, DixReadAccess);
-        if (!pPixmap)
-	    return BadPixmap;
+	rc = dixLookupResource((pointer *)&pPixmap, stuff->src, RT_PIXMAP,
+			       client, DixReadAccess);
+        if (rc != Success)
+	    return (rc == BadValue) ? BadPixmap : rc;
 	if (pPixmap->drawable.pScreen != pScreen ||
 	    pPixmap->drawable.depth != 1)
 	    return BadMatch;
@@ -531,7 +531,7 @@ ProcShapeCombine (client)
 
     REQUEST_SIZE_MATCH (xShapeCombineReq);
     UpdateCurrentTime();
-    rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     if (!pDestWin->optional)
@@ -552,7 +552,7 @@ ProcShapeCombine (client)
     }
     pScreen = pDestWin->drawable.pScreen;
 
-    rc = dixLookupWindow(&pSrcWin, stuff->src, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pSrcWin, stuff->src, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     switch (stuff->srcKind) {
@@ -651,7 +651,7 @@ ProcShapeOffset (client)
 
     REQUEST_SIZE_MATCH (xShapeOffsetReq);
     UpdateCurrentTime();
-    rc = dixLookupWindow(&pWin, stuff->dest, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->dest, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     switch (stuff->destKind) {
@@ -716,7 +716,7 @@ ProcShapeQueryExtents (client)
     RegionPtr		region;
 
     REQUEST_SIZE_MATCH (xShapeQueryExtentsReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     rep.type = X_Reply;
@@ -826,7 +826,7 @@ ProcShapeSelectInput (client)
     int			rc;
 
     REQUEST_SIZE_MATCH (xShapeSelectInputReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
     if (rc != Success)
 	return rc;
     pHead = (ShapeEventPtr *)SecurityLookupIDByType(client,
@@ -999,7 +999,7 @@ ProcShapeInputSelected (client)
     register int		n;
 
     REQUEST_SIZE_MATCH (xShapeInputSelectedReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     pHead = (ShapeEventPtr *) SecurityLookupIDByType(client,
@@ -1041,7 +1041,7 @@ ProcShapeGetRectangles (client)
     register int		n;
 
     REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     switch (stuff->kind) {
commit 766c693ef3637ee6fc402df594060ed2c1346761
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 30 13:06:28 2007 -0400

    xace: add hooks + new access codes: MIT-SCREEN-SAVER extension

diff --git a/Xext/saver.c b/Xext/saver.c
index 0042583..d282173 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -48,6 +48,7 @@ in this Software without prior written authorization from the X Consortium.
 #include "gcstruct.h"
 #include "cursorstr.h"
 #include "colormapst.h"
+#include "xace.h"
 #ifdef PANORAMIX
 #include "panoramiX.h"
 #include "panoramiXsrv.h"
@@ -789,7 +790,11 @@ ProcScreenSaverQueryInfo (client)
 
     REQUEST_SIZE_MATCH (xScreenSaverQueryInfoReq);
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
-			   DixUnknownAccess);
+			   DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+    rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, pDraw->pScreen,
+		  DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
@@ -858,9 +863,15 @@ ProcScreenSaverSelectInput (client)
 
     REQUEST_SIZE_MATCH (xScreenSaverSelectInputReq);
     rc = dixLookupDrawable (&pDraw, stuff->drawable, client, 0,
-			    DixUnknownAccess);
+			    DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
+    rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, pDraw->pScreen,
+		  DixSetAttrAccess);
     if (rc != Success)
 	return rc;
+
     if (!setEventMask (pDraw->pScreen, client, stuff->eventMask))
 	return BadAlloc;
     return Success;
@@ -894,12 +905,16 @@ ScreenSaverSetAttributes (ClientPtr client)
 
     REQUEST_AT_LEAST_SIZE (xScreenSaverSetAttributesReq);
     ret = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
-			    DixUnknownAccess);
+			    DixGetAttrAccess);
     if (ret != Success)
 	return ret;
     pScreen = pDraw->pScreen;
     pParent = WindowTable[pScreen->myNum];
 
+    ret = XaceHook(XACE_SCREENSAVER_ACCESS, client, pScreen, DixSetAttrAccess);
+    if (ret != Success)
+	return ret;
+
     len = stuff->length -  (sizeof(xScreenSaverSetAttributesReq) >> 2);
     if (Ones(stuff->mask) != len)
         return BadLength;
@@ -1055,8 +1070,9 @@ ScreenSaverSetAttributes (ClientPtr client)
 	    }
             else
 	    {	
-                pPixmap = (PixmapPtr)LookupIDByType(pixID, RT_PIXMAP);
-                if (pPixmap != (PixmapPtr) NULL)
+		ret = dixLookupResource((pointer *)&pPixmap, pixID, RT_PIXMAP,
+					client, DixReadAccess);
+		if (ret == Success)
 		{
                     if  ((pPixmap->drawable.depth != depth) ||
 			 (pPixmap->drawable.pScreen != pScreen))
@@ -1070,7 +1086,7 @@ ScreenSaverSetAttributes (ClientPtr client)
 		}
 	        else
 		{
-		    ret = BadPixmap;
+		    ret = (ret == BadValue) ? BadPixmap : ret;
 		    client->errorValue = pixID;
 		    goto PatchUp;
 		}
@@ -1092,8 +1108,9 @@ ScreenSaverSetAttributes (ClientPtr client)
 	    }
 	    else
 	    {	
-		pPixmap = (PixmapPtr)LookupIDByType(pixID, RT_PIXMAP);
-		if (pPixmap)
+		ret = dixLookupResource((pointer *)&pPixmap, pixID, RT_PIXMAP,
+					client, DixReadAccess);
+		if (ret == Success)
 		{
                     if  ((pPixmap->drawable.depth != depth) ||
 			 (pPixmap->drawable.pScreen != pScreen))
@@ -1107,7 +1124,7 @@ ScreenSaverSetAttributes (ClientPtr client)
 		}
     	        else
 		{
-		    ret = BadPixmap;
+		    ret = (ret == BadValue) ? BadPixmap : ret;
 		    client->errorValue = pixID;
 		    goto PatchUp;
 		}
@@ -1185,10 +1202,11 @@ ScreenSaverSetAttributes (ClientPtr client)
 	    break;
 	case CWColormap:
 	    cmap = (Colormap) *pVlist;
-	    pCmap = (ColormapPtr)LookupIDByType(cmap, RT_COLORMAP);
-	    if (!pCmap)
+	    ret = dixLookupResource((pointer *)&pCmap, cmap, RT_COLORMAP,
+				    client, DixUseAccess);
+	    if (ret != Success)
 	    {
-		ret = BadColor;
+		ret = (ret == BadValue) ? BadColor : ret;
 		client->errorValue = cmap;
 		goto PatchUp;
 	    }
@@ -1208,10 +1226,11 @@ ScreenSaverSetAttributes (ClientPtr client)
 	    }
 	    else
 	    {
-	    	pCursor = (CursorPtr)LookupIDByType(cursorID, RT_CURSOR);
-	    	if (!pCursor)
+		ret = dixLookupResource((pointer *)&pCursor, cursorID,
+					RT_CURSOR, client, DixUseAccess);
+	    	if (ret != Success)
 	    	{
-		    ret = BadCursor;
+		    ret = (ret == BadValue) ? BadCursor : ret;
 		    client->errorValue = cursorID;
 		    goto PatchUp;
 	    	}
@@ -1253,7 +1272,7 @@ ScreenSaverUnsetAttributes (ClientPtr client)
 
     REQUEST_SIZE_MATCH (xScreenSaverUnsetAttributesReq);
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
-			   DixUnknownAccess);
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     pPriv = GetScreenPrivate (pDraw->pScreen);
commit cda92bbf12107865e93c03c71b901ef51466dc31
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 30 11:48:45 2007 -0400

    xace: add hooks + new access codes: XFixes extension.
    
    Required a new name argument to the selection access hook to handle
    XFixesSelectSelectionInput.

diff --git a/Xext/xace.c b/Xext/xace.c
index 3091ecd..cc68986 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -173,6 +173,7 @@ int XaceHook(int hook, ...)
 	case XACE_SELECTION_ACCESS: {
 	    XaceSelectionAccessRec rec = {
 		va_arg(ap, ClientPtr),
+		va_arg(ap, Atom),
 		va_arg(ap, Selection*),
 		va_arg(ap, Mask),
 		Success /* default allow */
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 15d39b7..0957f0d 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -115,6 +115,7 @@ typedef struct {
 /* XACE_SELECTION_ACCESS */
 typedef struct {
     ClientPtr client;
+    Atom name;
     Selection *selection;
     Mask access_mode;
     int status;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 1ad3c94..7adfe02 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1013,10 +1013,6 @@ ProcSetSelectionOwner(ClientPtr client)
         {        
 	    xEvent event;
 
-	    rc = XaceHook(XACE_SELECTION_ACCESS, client, CurrentSelections[i],
-			  DixSetAttrAccess);
-	    if (rc != Success)
-		return rc;
 	    /* If the timestamp in client's request is in the past relative
 		to the time stamp indicating the last time the owner of the
 		selection was set, do not set the selection, just return 
@@ -1024,6 +1020,12 @@ ProcSetSelectionOwner(ClientPtr client)
             if (CompareTimeStamps(time, CurrentSelections[i].lastTimeChanged)
 		== EARLIER)
 		return Success;
+
+	    rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
+			  CurrentSelections[i], DixSetAttrAccess);
+	    if (rc != Success)
+		return rc;
+
 	    if (CurrentSelections[i].client &&
 		(!pWin || (CurrentSelections[i].client != client)))
 	    {
@@ -1054,19 +1056,17 @@ ProcSetSelectionOwner(ClientPtr client)
 	    CurrentSelections = newsels;
 	    CurrentSelections[i].selection = stuff->selection;
 	    CurrentSelections[i].devPrivates = NULL;
-	    rc = XaceHook(XACE_SELECTION_ACCESS, CurrentSelections[i],
-			  DixSetAttrAccess);
+	    rc = XaceHook(XACE_SELECTION_ACCESS, stuff->selection,
+			  CurrentSelections[i], DixSetAttrAccess);
 	    if (rc != Success)
 		return rc;
 	}
-	dixFreePrivates(CurrentSelections[i].devPrivates);
         CurrentSelections[i].lastTimeChanged = time;
 	CurrentSelections[i].window = stuff->window;
 	CurrentSelections[i].destwindow = stuff->window;
 	CurrentSelections[i].pWin = pWin;
 	CurrentSelections[i].client = (pWin ? client : NullClient);
 	CurrentSelections[i].destclient = (pWin ? client : NullClient);
-	CurrentSelections[i].devPrivates = NULL;
 	if (SelectionCallback)
 	{
 	    SelectionInfoRec	info;
@@ -1092,7 +1092,7 @@ ProcGetSelectionOwner(ClientPtr client)
     REQUEST_SIZE_MATCH(xResourceReq);
     if (ValidAtom(stuff->id))
     {
-	int i;
+	int rc, i;
         xGetSelectionOwnerReply reply;
 
 	i = 0;
@@ -1101,12 +1101,16 @@ ProcGetSelectionOwner(ClientPtr client)
         reply.type = X_Reply;
 	reply.length = 0;
 	reply.sequenceNumber = client->sequence;
-        if (i < NumCurrentSelections &&
-	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
-		     DixGetAttrAccess) == Success)
+        if (i < NumCurrentSelections)
             reply.owner = CurrentSelections[i].destwindow;
         else
             reply.owner = None;
+
+	rc = XaceHook(XACE_SELECTION_ACCESS, client, stuff->id, NULL,
+		      DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
+
         WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
         return(client->noClientException);
     }
@@ -1143,8 +1147,8 @@ ProcConvertSelection(ClientPtr client)
 	       CurrentSelections[i].selection != stuff->selection) i++;
 	if ((i < NumCurrentSelections) &&
 	    (CurrentSelections[i].window != None) &&
-	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
-		     DixReadAccess) == Success)
+	    XaceHook(XACE_SELECTION_ACCESS, client, stuff->selection,
+		     &CurrentSelections[i], DixReadAccess) == Success)
 	{        
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 975ebc3..91f149e 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -51,6 +51,7 @@
 #include "servermd.h"
 #include "inputstr.h"
 #include "windowstr.h"
+#include "xace.h"
 
 static RESTYPE		CursorClientType;
 static RESTYPE		CursorHideCountType;
@@ -238,7 +239,7 @@ ProcXFixesSelectCursorInput (ClientPtr client)
     int		rc;
 
     REQUEST_SIZE_MATCH (xXFixesSelectCursorInputReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
     if (rc != Success)
         return rc;
     if (stuff->eventMask & ~CursorAllEvents)
@@ -343,14 +344,16 @@ ProcXFixesGetCursorImage (ClientPtr client)
     xXFixesGetCursorImageReply	*rep;
     CursorPtr			pCursor;
     CARD32			*image;
-    int				npixels;
-    int				width, height;
-    int				x, y;
+    int				npixels, width, height, rc, x, y;
 
     REQUEST_SIZE_MATCH(xXFixesGetCursorImageReq);
     pCursor = CursorCurrent;
     if (!pCursor)
 	return BadCursor;
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, RT_CURSOR,
+		  DixReadAccess, pCursor);
+    if (rc != Success)
+	return rc;
     GetSpritePosition (&x, &y);
     width = pCursor->bits->width;
     height = pCursor->bits->height;
@@ -411,7 +414,7 @@ ProcXFixesSetCursorName (ClientPtr client)
     Atom atom;
 
     REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq);
-    VERIFY_CURSOR(pCursor, stuff->cursor, client, DixWriteAccess);
+    VERIFY_CURSOR(pCursor, stuff->cursor, client, DixSetAttrAccess);
     tchar = (char *) &stuff[1];
     atom = MakeAtom (tchar, stuff->nbytes, TRUE);
     if (atom == BAD_RESOURCE)
@@ -444,7 +447,7 @@ ProcXFixesGetCursorName (ClientPtr client)
     int len;
 
     REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq);
-    VERIFY_CURSOR(pCursor, stuff->cursor, client, DixReadAccess);
+    VERIFY_CURSOR(pCursor, stuff->cursor, client, DixGetAttrAccess);
     if (pCursor->name)
 	str = NameForAtom (pCursor->name);
     else
@@ -493,12 +496,16 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
     char			*name;
     int				nbytes, nbytesRound;
     int				width, height;
-    int				x, y;
+    int				rc, x, y;
 
     REQUEST_SIZE_MATCH(xXFixesGetCursorImageAndNameReq);
     pCursor = CursorCurrent;
     if (!pCursor)
 	return BadCursor;
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, pCursor->id, RT_CURSOR,
+		  DixReadAccess|DixGetAttrAccess, pCursor);
+    if (rc != Success)
+	return rc;
     GetSpritePosition (&x, &y);
     width = pCursor->bits->width;
     height = pCursor->bits->height;
@@ -675,8 +682,10 @@ ProcXFixesChangeCursor (ClientPtr client)
     REQUEST(xXFixesChangeCursorReq);
 
     REQUEST_SIZE_MATCH(xXFixesChangeCursorReq);
-    VERIFY_CURSOR (pSource, stuff->source, client, DixReadAccess);
-    VERIFY_CURSOR (pDestination, stuff->destination, client, DixWriteAccess);
+    VERIFY_CURSOR (pSource, stuff->source, client,
+		   DixReadAccess|DixGetAttrAccess);
+    VERIFY_CURSOR (pDestination, stuff->destination, client,
+		   DixWriteAccess|DixSetAttrAccess);
 
     ReplaceCursor (pSource, TestForCursor, (pointer) pDestination);
     return (client->noClientException);
@@ -710,7 +719,8 @@ ProcXFixesChangeCursorByName (ClientPtr client)
     REQUEST(xXFixesChangeCursorByNameReq);
 
     REQUEST_FIXED_SIZE(xXFixesChangeCursorByNameReq, stuff->nbytes);
-    VERIFY_CURSOR(pSource, stuff->source, client, DixReadAccess);
+    VERIFY_CURSOR(pSource, stuff->source, client,
+		  DixReadAccess|DixGetAttrAccess);
     tchar = (char *) &stuff[1];
     name = MakeAtom (tchar, stuff->nbytes, FALSE);
     if (name)
@@ -838,10 +848,11 @@ ProcXFixesHideCursor (ClientPtr client)
 
     REQUEST_SIZE_MATCH (xXFixesHideCursorReq);
 
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin) {
+    ret = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
+			    client, DixGetAttrAccess);
+    if (ret != Success) {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (ret == BadValue) ? BadWindow : ret;
     }
 
     /* 
@@ -859,6 +870,11 @@ ProcXFixesHideCursor (ClientPtr client)
      * This is the first time this client has hid the cursor 
      * for this screen.
      */
+    ret = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen,
+		   DixHideAccess);
+    if (ret != Success)
+	return ret;
+
     ret = createCursorHideCount(client, pWin->drawable.pScreen);
 
     if (ret == Success) {
@@ -885,14 +901,16 @@ ProcXFixesShowCursor (ClientPtr client)
 {
     WindowPtr pWin;
     CursorHideCountPtr pChc;
+    int rc;
     REQUEST(xXFixesShowCursorReq);
 
     REQUEST_SIZE_MATCH (xXFixesShowCursorReq);
 
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin) {
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
+			   client, DixGetAttrAccess);
+    if (rc != Success) {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
 
     /* 
@@ -904,6 +922,11 @@ ProcXFixesShowCursor (ClientPtr client)
 	return BadMatch;
     }
 
+    rc = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen,
+		  DixShowAccess);
+    if (rc != Success)
+	return rc;
+
     pChc->hideCount--;
     if (pChc->hideCount <= 0) {
 	FreeResource(pChc->resource, 0);
diff --git a/xfixes/region.c b/xfixes/region.c
index d4316be..d90b1e0 100755
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -109,18 +109,18 @@ ProcXFixesCreateRegionFromBitmap (ClientPtr client)
 {
     RegionPtr	pRegion;
     PixmapPtr	pPixmap;
+    int rc;
     REQUEST (xXFixesCreateRegionFromBitmapReq);
 
     REQUEST_SIZE_MATCH (xXFixesCreateRegionFromBitmapReq);
     LEGAL_NEW_RESOURCE (stuff->region, client);
 
-    pPixmap = (PixmapPtr) SecurityLookupIDByType (client, stuff->bitmap,
-						  RT_PIXMAP,
-						  DixReadAccess);
-    if (!pPixmap)
+    rc = dixLookupResource((pointer *)&pPixmap, stuff->bitmap, RT_PIXMAP,
+			   client, DixReadAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->bitmap;
-	return BadPixmap;
+	return (rc == BadValue) ? BadPixmap : rc;
     }
     if (pPixmap->drawable.depth != 1)
 	return BadMatch;
@@ -155,15 +155,17 @@ ProcXFixesCreateRegionFromWindow (ClientPtr client)
     RegionPtr	pRegion;
     Bool	copy = TRUE;
     WindowPtr	pWin;
+    int rc;
     REQUEST (xXFixesCreateRegionFromWindowReq);
     
     REQUEST_SIZE_MATCH (xXFixesCreateRegionFromWindowReq);
     LEGAL_NEW_RESOURCE (stuff->region, client);
-    pWin = (WindowPtr) LookupIDByType (stuff->window, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->window, RT_WINDOW,
+			   client, DixGetAttrAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
     switch (stuff->kind) {
     case WindowRegionBounding:
@@ -224,7 +226,7 @@ ProcXFixesCreateRegionFromGC (ClientPtr client)
     REQUEST_SIZE_MATCH (xXFixesCreateRegionFromGCReq);
     LEGAL_NEW_RESOURCE (stuff->region, client);
 
-    rc = dixLookupGC(&pGC, stuff->gc, client, DixReadAccess);
+    rc = dixLookupGC(&pGC, stuff->gc, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     
@@ -274,7 +276,7 @@ ProcXFixesCreateRegionFromPicture (ClientPtr client)
     REQUEST_SIZE_MATCH (xXFixesCreateRegionFromPictureReq);
     LEGAL_NEW_RESOURCE (stuff->region, client);
 
-    VERIFY_PICTURE(pPicture, stuff->picture, client, DixReadAccess,
+    VERIFY_PICTURE(pPicture, stuff->picture, client, DixGetAttrAccess,
 		   RenderErrBase + BadPicture);
     
     switch (pPicture->clientClipType) {
@@ -635,7 +637,7 @@ ProcXFixesSetGCClipRegion (ClientPtr client)
     REQUEST(xXFixesSetGCClipRegionReq);
     REQUEST_SIZE_MATCH(xXFixesSetGCClipRegionReq);
 
-    rc = dixLookupGC(&pGC, stuff->gc, client, DixWriteAccess);
+    rc = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
@@ -681,14 +683,16 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
     ScreenPtr	    pScreen;
     RegionPtr	    pRegion;
     RegionPtr	    *pDestRegion;
+    int rc;
     REQUEST(xXFixesSetWindowShapeRegionReq);
 
     REQUEST_SIZE_MATCH(xXFixesSetWindowShapeRegionReq);
-    pWin = (WindowPtr) LookupIDByType (stuff->dest, RT_WINDOW);
-    if (!pWin)
+    rc = dixLookupResource((pointer *)&pWin, stuff->dest, RT_WINDOW,
+			   client, DixSetAttrAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->dest;
-	return BadWindow;
+	return (rc == BadValue) ? BadWindow : rc;
     }
     VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixWriteAccess);
     pScreen = pWin->drawable.pScreen;
@@ -780,7 +784,7 @@ ProcXFixesSetPictureClipRegion (ClientPtr client)
     REQUEST(xXFixesSetPictureClipRegionReq);
     
     REQUEST_SIZE_MATCH (xXFixesSetPictureClipRegionReq);
-    VERIFY_PICTURE(pPicture, stuff->picture, client, DixWriteAccess,
+    VERIFY_PICTURE(pPicture, stuff->picture, client, DixSetAttrAccess,
 		   RenderErrBase + BadPicture);
     pScreen = pPicture->pDrawable->pScreen;
     ps = GetPictureScreen (pScreen);
diff --git a/xfixes/saveset.c b/xfixes/saveset.c
index 8d66843..e6e2976 100755
--- a/xfixes/saveset.c
+++ b/xfixes/saveset.c
@@ -35,7 +35,7 @@ ProcXFixesChangeSaveSet(ClientPtr client)
     REQUEST(xXFixesChangeSaveSetReq);
 		  
     REQUEST_SIZE_MATCH(xXFixesChangeSaveSetReq);
-    result = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    result = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
     if (result != Success)
         return result;
     if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
diff --git a/xfixes/select.c b/xfixes/select.c
index c007680..9de152f 100755
--- a/xfixes/select.c
+++ b/xfixes/select.c
@@ -25,6 +25,7 @@
 #endif
 
 #include "xfixesint.h"
+#include "xace.h"
 
 static RESTYPE		SelectionClientType, SelectionWindowType;
 static Bool		SelectionCallbackRegistered = FALSE;
@@ -131,8 +132,14 @@ XFixesSelectSelectionInput (ClientPtr	pClient,
 			    WindowPtr	pWindow,
 			    CARD32	eventMask)
 {
+    int rc;
     SelectionEventPtr	*prev, e;
 
+    rc = XaceHook(XACE_SELECTION_ACCESS, pClient, selection, NULL,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
     for (prev = &selectionEvents; (e = *prev); prev = &e->next)
     {
 	if (e->selection == selection &&
@@ -196,7 +203,7 @@ ProcXFixesSelectSelectionInput (ClientPtr client)
     int		rc;
 
     REQUEST_SIZE_MATCH (xXFixesSelectSelectionInputReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
     if (rc != Success)
         return rc;
     if (stuff->eventMask & ~SelectionAllEvents)
commit 47ab4d648b31ea1d5800e0bc84cf5f25025bffe3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 30 11:40:39 2007 -0400

    devPrivates rework: convert CursorRec and CursorBits over to new interface.

diff --git a/dix/cursor.c b/dix/cursor.c
index b188e3f..324faa1 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -99,6 +99,7 @@ FreeCursorBits(CursorBitsPtr bits)
 	    CloseFont(this->font, (Font)0);
 	    xfree(this);
 	}
+	dixFreePrivates(bits->devPrivates);
 	xfree(bits);
     }
 }
@@ -124,6 +125,7 @@ FreeCursor(pointer value, XID cid)
 	pscr = screenInfo.screens[nscr];
 	(void)( *pscr->UnrealizeCursor)( pscr, pCurs);
     }
+    dixFreePrivates(pCurs->devPrivates);
     FreeCursorBits(pCurs->bits);
     xfree( pCurs);
     return(Success);
@@ -192,9 +194,9 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     bits->height = cm->height;
     bits->xhot = cm->xhot;
     bits->yhot = cm->yhot;
+    bits->devPrivates = NULL;
     bits->refcnt = -1;
     CheckForEmptyMask(bits);
-
     pCurs->bits = bits;
     pCurs->refcnt = 1;		
 #ifdef XFIXES
@@ -210,10 +212,14 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
     pCurs->backGreen = backGreen;
     pCurs->backBlue = backBlue;
 
+    pCurs->devPrivates = NULL;
+    pCurs->id = cid;
+
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
 		  DixCreateAccess, pCurs);
     if (rc != Success) {
+	dixFreePrivates(pCurs->devPrivates);
 	FreeCursorBits(bits);
 	xfree(pCurs);
 	return rc;
@@ -232,6 +238,7 @@ AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
 		pscr = screenInfo.screens[nscr];
 		( *pscr->UnrealizeCursor)( pscr, pCurs);
 	    }
+	    dixFreePrivates(pCurs->devPrivates);
 	    FreeCursorBits(bits);
 	    xfree(pCurs);
 	    return BadAlloc;
@@ -394,10 +401,14 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     pCurs->backGreen = backGreen;
     pCurs->backBlue = backBlue;
 
+    pCurs->id = cid;
+    pCurs->devPrivates = NULL;
+
     /* security creation/labeling check */
     rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
 		  DixCreateAccess, pCurs);
     if (rc != Success) {
+	dixFreePrivates(pCurs->devPrivates);
 	FreeCursorBits(bits);
 	xfree(pCurs);
 	return rc;
@@ -416,6 +427,7 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 		pscr = screenInfo.screens[nscr];
 		( *pscr->UnrealizeCursor)( pscr, pCurs);
 	    }
+	    dixFreePrivates(pCurs->devPrivates);
 	    FreeCursorBits(pCurs->bits);
 	    xfree(pCurs);
 	    return BadAlloc;
diff --git a/hw/darwin/iokit/xfIOKitCursor.c b/hw/darwin/iokit/xfIOKitCursor.c
index 2247101..3101a89 100644
--- a/hw/darwin/iokit/xfIOKitCursor.c
+++ b/hw/darwin/iokit/xfIOKitCursor.c
@@ -202,7 +202,7 @@ XFIOKitRealizeCursor8(
     }
 
     // save the result
-    pCursor->devPriv[pScreen->myNum] = (pointer) newCursor;
+    dixSetPrivate(&pCursor->devPrivates, pScreen, newCursor);
     return TRUE;
 }
 
@@ -285,7 +285,7 @@ XFIOKitRealizeCursor15(
 #endif
 
     // save the result
-    pCursor->devPriv[pScreen->myNum] = (pointer) newCursor;
+    dixSetPrivate(&pCursor->devPrivates, pScreen, newCursor);
     return TRUE;
 }
 
@@ -369,7 +369,7 @@ XFIOKitRealizeCursor24(
 #endif
 
     // save the result
-    pCursor->devPriv[pScreen->myNum] = (pointer) newCursor;
+    dixSetPrivate(&pCursor->devPrivates, pScreen, newCursor);
     return TRUE;
 }
 
@@ -422,7 +422,7 @@ XFIOKitUnrealizeCursor(
         !ScreenPriv->canHWCursor) {
         result = (*ScreenPriv->spriteFuncs->UnrealizeCursor)(pScreen, pCursor);
     } else {
-        xfree( pCursor->devPriv[pScreen->myNum] );
+        xfree(dixLookupPrivate(&pCursor->devPrivates, pScreen));
         result = TRUE;
     }
 
@@ -476,20 +476,20 @@ XFIOKitSetCursor(
 
         // change the cursor image in shared memory
         if (dfb->bitsPerPixel == 8) {
-            cursorPrivPtr newCursor =
-                    (cursorPrivPtr) pCursor->devPriv[pScreen->myNum];
+            cursorPrivPtr newCursor = dixLookupPrivate(&pCursor->devPrivates,
+						       pScreen);
             memcpy(cshmem->cursor.bw8.image[0], newCursor->image,
                         CURSORWIDTH*CURSORHEIGHT);
             memcpy(cshmem->cursor.bw8.mask[0], newCursor->mask,
                         CURSORWIDTH*CURSORHEIGHT);
         } else if (dfb->bitsPerPixel == 16) {
-            unsigned short *newCursor =
-                    (unsigned short *) pCursor->devPriv[pScreen->myNum];
+            unsigned short *newCursor = dixLookupPrivate(&pCursor->devPrivates,
+							 pScreen);
             memcpy(cshmem->cursor.rgb.image[0], newCursor,
                         2*CURSORWIDTH*CURSORHEIGHT);
         } else {
-            unsigned int *newCursor =
-                    (unsigned int *) pCursor->devPriv[pScreen->myNum];
+            unsigned int *newCursor = dixLookupPrivate(&pCursor->devPrivates,
+						       pScreen);
             memcpy(cshmem->cursor.rgb24.image[0], newCursor,
                         4*CURSORWIDTH*CURSORHEIGHT);
         }
diff --git a/hw/darwin/quartz/fullscreen/quartzCursor.c b/hw/darwin/quartz/fullscreen/quartzCursor.c
index bee83b8..797149e 100644
--- a/hw/darwin/quartz/fullscreen/quartzCursor.c
+++ b/hw/darwin/quartz/fullscreen/quartzCursor.c
@@ -318,7 +318,7 @@ QuartzRealizeCursor(
     if (!qdCursor) return FALSE;
 
     // save the result
-    pCursor->devPriv[pScreen->myNum] = (pointer) qdCursor;
+    dixSetPrivate(&pCursor->devPrivates, pScreen, qdCursor);
 
     return TRUE;
 }
@@ -345,13 +345,13 @@ QuartzUnrealizeCursor(
                         (pScreen, pCursor);
         }
     } else {
-        CCrsrHandle oldCursor = (CCrsrHandle) pCursor->devPriv[pScreen->myNum];
-
+        CCrsrHandle oldCursor = dixLookupPrivate(&pCursor->devPrivates,
+						 pScreen);
         if (currentCursor != oldCursor) {
             // This should only fail when quitting, in which case we just leak.
             FreeQDCursor(oldCursor);
         }
-        pCursor->devPriv[pScreen->myNum] = NULL;
+	dixSetPrivate(&pCursor->devPrivates, pScreen, NULL);
         return TRUE;
     }
 }
@@ -391,7 +391,7 @@ QuartzSetCursor(
             (*ScreenPriv->spriteFuncs->SetCursor)(pScreen, 0, x, y);
         ScreenPriv->qdCursorMode = TRUE;
 
-        CHANGE_QD_CURSOR(pCursor->devPriv[pScreen->myNum]);
+        CHANGE_QD_CURSOR(dixLookupPrivate(&pCursor->devPrivates, pScreen));
         SHOW_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
     }
     else if (quartzRootless) {
diff --git a/hw/darwin/quartz/quartzCursor.c b/hw/darwin/quartz/quartzCursor.c
index a121ce1..aa7ce22 100644
--- a/hw/darwin/quartz/quartzCursor.c
+++ b/hw/darwin/quartz/quartzCursor.c
@@ -321,7 +321,7 @@ QuartzRealizeCursor(
     if (!qdCursor) return FALSE;
 
     // save the result
-    pCursor->devPriv[pScreen->myNum] = (pointer) qdCursor;
+    dixSetPrivate(&pCursor->devPrivates, pScreen, qdCursor);
 
     return TRUE;
 }
@@ -348,13 +348,13 @@ QuartzUnrealizeCursor(
                         (pScreen, pCursor);
         }
     } else {
-        CCrsrHandle oldCursor = (CCrsrHandle) pCursor->devPriv[pScreen->myNum];
-
+        CCrsrHandle oldCursor = dixLookupPrivate(&pCursor->devPrivates,
+						 pScreen);
         if (currentCursor != oldCursor) {
             // This should only fail when quitting, in which case we just leak.
             FreeQDCursor(oldCursor);
         }
-        pCursor->devPriv[pScreen->myNum] = NULL;
+	dixSetPrivate(&pCursor->devPrivates, pScreen, NULL);
         return TRUE;
     }
 }
@@ -394,7 +394,7 @@ QuartzSetCursor(
             (*ScreenPriv->spriteFuncs->SetCursor)(pScreen, 0, x, y);
         ScreenPriv->qdCursorMode = TRUE;
 
-        CHANGE_QD_CURSOR(pCursor->devPriv[pScreen->myNum]);
+        CHANGE_QD_CURSOR(dixLookupPrivate(&pCursor->devPrivates, pScreen));
         SHOW_QD_CURSOR(pScreen, ScreenPriv->qdCursorVisible);
     }
     else if (quartzRootless) {
diff --git a/hw/dmx/dmxcursor.c b/hw/dmx/dmxcursor.c
index 1ad199d..8a80116 100644
--- a/hw/dmx/dmxcursor.c
+++ b/hw/dmx/dmxcursor.c
@@ -662,8 +662,8 @@ static Bool _dmxRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 
     DMXDBG2("_dmxRealizeCursor(%d,%p)\n", pScreen->myNum, pCursor);
 
-    pCursor->devPriv[pScreen->myNum] = xalloc(sizeof(*pCursorPriv));
-    if (!pCursor->devPriv[pScreen->myNum])
+    DMX_SET_CURSOR_PRIV(pCursor, pScreen, xalloc(sizeof(*pCursorPriv)));
+    if (!DMX_GET_CURSOR_PRIV(pCursor, pScreen))
 	return FALSE;
 
     pCursorPriv = DMX_GET_CURSOR_PRIV(pCursor, pScreen);
@@ -700,9 +700,9 @@ static Bool _dmxUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 
     if (dmxScreen->beDisplay) {
 	if (dmxBEFreeCursor(pScreen, pCursor))
-	    xfree(pCursor->devPriv[pScreen->myNum]);
+	    xfree(DMX_GET_CURSOR_PRIV(pCursor, pScreen));
     }
-    pCursor->devPriv[pScreen->myNum] = NULL;
+    DMX_SET_CURSOR_PRIV(pCursor, pScreen, NULL);
 
     return TRUE;
 }
diff --git a/hw/dmx/dmxcursor.h b/hw/dmx/dmxcursor.h
index 7b70c62..d909bd0 100644
--- a/hw/dmx/dmxcursor.h
+++ b/hw/dmx/dmxcursor.h
@@ -63,7 +63,10 @@ extern void dmxHideCursor(DMXScreenInfo *dmxScreen);
 extern void dmxBECreateCursor(ScreenPtr pScreen, CursorPtr pCursor);
 extern Bool dmxBEFreeCursor(ScreenPtr pScreen, CursorPtr pCursor);
 
-#define DMX_GET_CURSOR_PRIV(_pCursor, _pScreen)				\
-    (dmxCursorPrivPtr)(_pCursor)->devPriv[(_pScreen)->myNum]
+#define DMX_GET_CURSOR_PRIV(_pCursor, _pScreen) \
+    ((dmxCursorPrivPtr)dixLookupPrivate(&(_pCursor)->devPrivates, _pScreen))
+
+#define DMX_SET_CURSOR_PRIV(_pCursor, _pScreen, v) \
+    dixSetPrivate(&(_pCursor)->devPrivates, _pScreen, v)
 
 #endif /* DMXCURSOR_H */
diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c
index b510164..acf34c1 100644
--- a/hw/xfree86/modes/xf86Cursors.c
+++ b/hw/xfree86/modes/xf86Cursors.c
@@ -226,7 +226,8 @@ xf86_set_cursor_colors (ScrnInfoPtr scrn, int bg, int fg)
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
     CursorPtr		cursor = xf86_config->cursor;
     int			c;
-    CARD8		*bits = cursor ? cursor->devPriv[screen->myNum] : NULL;
+    CARD8		*bits = cursor ? dixLookupPrivate(&cursor->devPrivates,
+							  screen) : NULL;
 
     /* Save ARGB versions of these colors */
     xf86_config->cursor_fg = (CARD32) fg | 0xff000000;
@@ -612,7 +613,7 @@ xf86_reload_cursors (ScreenPtr screen)
 	else
 #endif
 	    (*cursor_info->LoadCursorImage)(cursor_info->pScrn,
-					    cursor->devPriv[screen->myNum]);
+			dixLookupPrivate(&cursor->devPrivates, screen));
 
 	(*cursor_info->SetCursorPosition)(cursor_info->pScrn, x, y);
 	(*cursor_info->ShowCursor)(cursor_info->pScrn);
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 1c2d6a8..5b1ce5e 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -251,7 +251,7 @@ xf86CursorRealizeCursor(ScreenPtr pScreen, CursorPtr pCurs)
 	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (pCurs->refcnt <= 1)
-	pCurs->devPriv[pScreen->myNum] = NULL;
+	dixSetPrivate(&pCurs->devPrivates, pScreen, NULL);
 
     return (*ScreenPriv->spriteFuncs->RealizeCursor)(pScreen, pCurs);
 }
@@ -263,8 +263,8 @@ xf86CursorUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCurs)
 	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (pCurs->refcnt <= 1) {
-	xfree(pCurs->devPriv[pScreen->myNum]);
-	pCurs->devPriv[pScreen->myNum] = NULL;
+	xfree(dixLookupPrivate(&pCurs->devPrivates, pScreen));
+	dixSetPrivate(&pCurs->devPrivates, pScreen, NULL);
     }
 
     return (*ScreenPriv->spriteFuncs->UnrealizeCursor)(pScreen, pCurs);
diff --git a/hw/xfree86/ramdac/xf86HWCurs.c b/hw/xfree86/ramdac/xf86HWCurs.c
index 0a753be..d10e283 100644
--- a/hw/xfree86/ramdac/xf86HWCurs.c
+++ b/hw/xfree86/ramdac/xf86HWCurs.c
@@ -123,7 +123,7 @@ xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
 	return;
     }
 
-    bits = pCurs->devPriv[pScreen->myNum];
+    bits = (unsigned char *)dixLookupPrivate(&pCurs->devPrivates, pScreen);
 
     x -= infoPtr->pScrn->frameX0 + ScreenPriv->HotX;
     y -= infoPtr->pScrn->frameY0 + ScreenPriv->HotY;
@@ -133,7 +133,7 @@ xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
 #endif
     if (!bits) {
 	bits = (*infoPtr->RealizeCursor)(infoPtr, pCurs);
-	pCurs->devPriv[pScreen->myNum] = bits;
+	dixSetPrivate(&pCurs->devPrivates, pScreen, bits);
     }
 
     if (!(infoPtr->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN))
diff --git a/hw/xgl/glx/xglx.c b/hw/xgl/glx/xglx.c
index 657afc0..d7f0ed3 100644
--- a/hw/xgl/glx/xglx.c
+++ b/hw/xgl/glx/xglx.c
@@ -121,10 +121,10 @@ typedef struct _xglxCursor {
 } xglxCursorRec, *xglxCursorPtr;
 
 #define XGLX_GET_CURSOR_PRIV(pCursor, pScreen)		   \
-    ((xglxCursorPtr) (pCursor)->devPriv[(pScreen)->myNum])
+    ((xglxCursorPtr)dixLookupPrivate(&(pCursor)->devPrivates, pScreen))
 
 #define XGLX_SET_CURSOR_PRIV(pCursor, pScreen, v)	 \
-    ((pCursor)->devPriv[(pScreen)->myNum] = (pointer) v)
+    dixSetPrivate(&(pCursor)->devPrivates, pScreen, v)
 
 #define XGLX_CURSOR_PRIV(pCursor, pScreen)			        \
     xglxCursorPtr pCursorPriv = XGLX_GET_CURSOR_PRIV (pCursor, pScreen)
diff --git a/hw/xnest/Cursor.c b/hw/xnest/Cursor.c
index 134276e..1386980 100644
--- a/hw/xnest/Cursor.c
+++ b/hw/xnest/Cursor.c
@@ -104,8 +104,8 @@ xnestRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
   bg_color.green = pCursor->backGreen;
   bg_color.blue = pCursor->backBlue;
 
-  pCursor->devPriv[pScreen->myNum] = (pointer)xalloc(sizeof(xnestPrivCursor));
-  xnestCursorPriv(pCursor, pScreen)->cursor = 
+  xnestSetCursorPriv(pCursor, pScreen, xalloc(sizeof(xnestPrivCursor)));
+  xnestCursor(pCursor, pScreen) = 
     XCreatePixmapCursor(xnestDisplay, source, mask, &fg_color, &bg_color,
 			pCursor->bits->xhot, pCursor->bits->yhot);
   
@@ -119,7 +119,7 @@ Bool
 xnestUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
 {
   XFreeCursor(xnestDisplay, xnestCursor(pCursor, pScreen));
-  xfree(xnestCursorPriv(pCursor, pScreen));
+  xfree(xnestGetCursorPriv(pCursor, pScreen));
   return True;
 }
 
diff --git a/hw/xnest/XNCursor.h b/hw/xnest/XNCursor.h
index ffec9eb..9705f6b 100644
--- a/hw/xnest/XNCursor.h
+++ b/hw/xnest/XNCursor.h
@@ -19,11 +19,14 @@ typedef struct {
   Cursor cursor;
 } xnestPrivCursor;
 
-#define xnestCursorPriv(pCursor, pScreen) \
-  ((xnestPrivCursor *)((pCursor)->devPriv[pScreen->myNum]))
+#define xnestGetCursorPriv(pCursor, pScreen) \
+    ((xnestPrivCursor *)dixLookupPrivate(&(pCursor)->devPrivates, pScreen))
+
+#define xnestSetCursorPriv(pCursor, pScreen, v) \
+    dixSetPrivate(&(pCursor)->devPrivates, pScreen, v)
 
 #define xnestCursor(pCursor, pScreen) \
-  (xnestCursorPriv(pCursor, pScreen)->cursor)
+  (xnestGetCursorPriv(pCursor, pScreen)->cursor)
 
 Bool xnestRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor);
 Bool xnestUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor);
diff --git a/include/cursorstr.h b/include/cursorstr.h
index b7beaa0..bca3596 100644
--- a/include/cursorstr.h
+++ b/include/cursorstr.h
@@ -49,6 +49,7 @@ SOFTWARE.
 #define CURSORSTRUCT_H 
 
 #include "cursor.h"
+#include "privates.h"
 /* 
  * device-independent cursor storage
  */
@@ -63,7 +64,7 @@ typedef struct _CursorBits {
     Bool emptyMask;				/* all zeros mask */
     unsigned short width, height, xhot, yhot;	/* metrics */
     int refcnt;					/* can be shared */
-    pointer devPriv[MAXSCREENS];		/* set by pScr->RealizeCursor*/
+    PrivateRec *devPrivates;			/* set by pScr->RealizeCursor*/
 #ifdef ARGB_CURSOR
     CARD32 *argb;				/* full-color alpha blended */
 #endif
@@ -74,7 +75,8 @@ typedef struct _Cursor {
     unsigned short foreRed, foreGreen, foreBlue; /* device-independent color */
     unsigned short backRed, backGreen, backBlue; /* device-independent color */
     int refcnt;
-    pointer devPriv[MAXSCREENS];		/* set by pScr->RealizeCursor*/
+    PrivateRec *devPrivates;			/* set by pScr->RealizeCursor*/
+    XID id;
 #ifdef XFIXES
     CARD32 serialNumber;
     Atom name;
diff --git a/mi/midispcur.c b/mi/midispcur.c
index 8b78292..f974c08 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -190,7 +190,7 @@ miDCRealizeCursor (pScreen, pCursor)
     CursorPtr	pCursor;
 {
     if (pCursor->bits->refcnt <= 1)
-	pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
+	dixSetPrivate(&pCursor->bits->devPrivates, pScreen, NULL);
     return TRUE;
 }
 
@@ -290,7 +290,7 @@ miDCRealize (
 	    xfree ((pointer) pPriv);
 	    return (miDCCursorPtr)NULL;
 	}
-	pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv;
+	dixSetPrivate(&pCursor->bits->devPrivates, pScreen, pPriv);
 	return pPriv;
     }
     pPriv->pPicture = 0;
@@ -308,7 +308,7 @@ miDCRealize (
 	xfree ((pointer) pPriv);
 	return (miDCCursorPtr)NULL;
     }
-    pCursor->bits->devPriv[pScreen->myNum] = (pointer) pPriv;
+    dixSetPrivate(&pCursor->bits->devPrivates, pScreen, pPriv);
 
     /* create the two sets of bits, clipping as appropriate */
 
@@ -354,7 +354,8 @@ miDCUnrealizeCursor (pScreen, pCursor)
 {
     miDCCursorPtr   pPriv;
 
-    pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
+					    pScreen);
     if (pPriv && (pCursor->bits->refcnt <= 1))
     {
 	if (pPriv->sourceBits)
@@ -366,7 +367,7 @@ miDCUnrealizeCursor (pScreen, pCursor)
 	    FreePicture (pPriv->pPicture, 0);
 #endif
 	xfree ((pointer) pPriv);
-	pCursor->bits->devPriv[pScreen->myNum] = (pointer)NULL;
+	dixSetPrivate(&pCursor->bits->devPrivates, pScreen, NULL);
     }
     return TRUE;
 }
@@ -461,7 +462,8 @@ miDCPutUpCursor (pScreen, pCursor, x, y, source, mask)
     miDCCursorPtr   pPriv;
     WindowPtr	    pWin;
 
-    pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
+					    pScreen);
     if (!pPriv)
     {
 	pPriv = miDCRealize(pScreen, pCursor);
@@ -711,7 +713,8 @@ miDCMoveCursor (pScreen, pCursor, x, y, w, h, dx, dy, source, mask)
     XID		    gcval = FALSE;
     PixmapPtr	    pTemp;
 
-    pPriv = (miDCCursorPtr) pCursor->bits->devPriv[pScreen->myNum];
+    pPriv = (miDCCursorPtr)dixLookupPrivate(&pCursor->bits->devPrivates,
+					    pScreen);
     if (!pPriv)
     {
 	pPriv = miDCRealize(pScreen, pCursor);
commit 4795df62456b73c6790f271e0a20a83c60496490
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Aug 29 14:40:10 2007 -0400

    xace: add hooks + new access codes: TOG-CUP extension.

diff --git a/Xext/cup.c b/Xext/cup.c
index 6bfa278..b544a75 100644
--- a/Xext/cup.c
+++ b/Xext/cup.c
@@ -224,12 +224,13 @@ int ProcStoreColors(
 {
     REQUEST (xXcupStoreColorsReq);
     ColormapPtr pcmp;
+    int rc;
 
     REQUEST_AT_LEAST_SIZE (xXcupStoreColorsReq);
-    pcmp = (ColormapPtr) SecurityLookupIDByType (client, stuff->cmap,
-						 RT_COLORMAP, DixWriteAccess);
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP,
+			   client, DixAddAccess);
 
-    if (pcmp) {
+    if (rc == Success) {
 	int ncolors, n;
 	xXcupStoreColorsReply rep;
 	xColorItem* cptr;
@@ -273,7 +274,7 @@ int ProcStoreColors(
 	return client->noClientException;
     } else {
 	client->errorValue = stuff->cmap;
-	return BadColor;
+	return (rc == BadValue) ? BadColor : rc;
     }
 }
 
commit e39694789e31e221fc8dec44ace9c697daf7acad
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Aug 29 14:16:46 2007 -0400

    xace: drop map-window checking hook, add new hooks for controlling the
    delivery of events to windows and clients.
    
    This is tentative.  It's likely that an additional last-resort hook will
    be necessary for code that calls TryClientEvents or WriteEventsToClient
    directly.  It's also possible that new xace machinery will be necessary
    to classify events and pull useful resource ID's out of them.
    
    The failure case also needs some thinking through.  Should event delivery
    "succeed" or should it report undeliverable?
    
    Finally, XKB appears to call WriteToClient to pass events.  Sigh.

diff --git a/Xext/xace.c b/Xext/xace.c
index 4d34dc3..3091ecd 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -113,10 +113,25 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_MAP_ACCESS: {
-	    XaceMapAccessRec rec = {
+	case XACE_SEND_ACCESS: {
+	    XaceSendAccessRec rec = {
 		va_arg(ap, ClientPtr),
+		va_arg(ap, DeviceIntPtr),
 		va_arg(ap, WindowPtr),
+		va_arg(ap, xEventPtr),
+		va_arg(ap, int),
+		Success /* default allow */
+	    };
+	    calldata = &rec;
+	    prv = &rec.status;
+	    break;
+	}
+	case XACE_RECEIVE_ACCESS: {
+	    XaceReceiveAccessRec rec = {
+		va_arg(ap, ClientPtr),
+		va_arg(ap, WindowPtr),
+		va_arg(ap, xEventPtr),
+		va_arg(ap, int),
 		Success /* default allow */
 	    };
 	    calldata = &rec;
diff --git a/Xext/xace.h b/Xext/xace.h
index f1a6e9d..c1fc071 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -46,18 +46,19 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_DEVICE_ACCESS		3
 #define XACE_PROPERTY_ACCESS		4
 #define XACE_DRAWABLE_ACCESS		5
-#define XACE_MAP_ACCESS			6
-#define XACE_CLIENT_ACCESS		7
-#define XACE_EXT_ACCESS			8
-#define XACE_SERVER_ACCESS		9
-#define XACE_SELECTION_ACCESS		10
-#define XACE_SCREEN_ACCESS		11
-#define XACE_SCREENSAVER_ACCESS		12
-#define XACE_AUTH_AVAIL			13
-#define XACE_KEY_AVAIL			14
-#define XACE_AUDIT_BEGIN		15
-#define XACE_AUDIT_END			16
-#define XACE_NUM_HOOKS			17
+#define XACE_SEND_ACCESS		6
+#define XACE_RECEIVE_ACCESS		7
+#define XACE_CLIENT_ACCESS		8
+#define XACE_EXT_ACCESS			9
+#define XACE_SERVER_ACCESS		10
+#define XACE_SELECTION_ACCESS		11
+#define XACE_SCREEN_ACCESS		12
+#define XACE_SCREENSAVER_ACCESS		13
+#define XACE_AUTH_AVAIL			14
+#define XACE_KEY_AVAIL			15
+#define XACE_AUDIT_BEGIN		16
+#define XACE_AUDIT_END			17
+#define XACE_NUM_HOOKS			18
 
 extern CallbackListPtr XaceHooks[XACE_NUM_HOOKS];
 
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index c98be3d..15d39b7 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -70,12 +70,24 @@ typedef struct {
     int status;
 } XaceDrawableAccessRec;
 
-/* XACE_MAP_ACCESS */
+/* XACE_SEND_ACCESS */
+typedef struct {
+    ClientPtr client;
+    DeviceIntPtr dev;
+    WindowPtr pWin;
+    xEventPtr events;
+    int count;
+    int status;
+} XaceSendAccessRec;
+
+/* XACE_RECEIVE_ACCESS */
 typedef struct {
     ClientPtr client;
     WindowPtr pWin;
+    xEventPtr events;
+    int count;
     int status;
-} XaceMapAccessRec;
+} XaceReceiveAccessRec;
 
 /* XACE_CLIENT_ACCESS */
 typedef struct {
diff --git a/dix/events.c b/dix/events.c
index deae4e3..42c3ba1 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1753,8 +1753,10 @@ DeliverEventsToWindow(WindowPtr pWin, xEvent *pEvents, int count,
 	if (filter != CantBeFiltered &&
 	    !((wOtherEventMasks(pWin)|pWin->eventMask) & filter))
 	    return 0;
-	if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count,
-				      pWin->eventMask, filter, grab)) )
+	if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count))
+	    nondeliveries--;
+	else if ( (attempt = TryClientEvents(wClient(pWin), pEvents, count,
+					     pWin->eventMask, filter, grab)) )
 	{
 	    if (attempt > 0)
 	    {
@@ -1781,7 +1783,10 @@ DeliverEventsToWindow(WindowPtr pWin, xEvent *pEvents, int count,
 	    other = (InputClients *)wOtherClients(pWin);
 	for (; other; other = other->next)
 	{
-	    if ( (attempt = TryClientEvents(rClient(other), pEvents, count,
+	    if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin, pEvents,
+			 count))
+		nondeliveries--;
+	    else if ( (attempt = TryClientEvents(rClient(other), pEvents, count,
 					  other->mask[mskidx], filter, grab)) )
 	    {
 		if (attempt > 0)
@@ -1878,6 +1883,8 @@ MaybeDeliverEventsToClient(WindowPtr pWin, xEvent *pEvents,
 	    return XineramaTryClientEventsResult(
 			wClient(pWin), NullGrab, pWin->eventMask, filter);
 #endif
+	if (XaceHook(XACE_RECEIVE_ACCESS, wClient(pWin), pWin, pEvents, count))
+	    return 0;
 	return TryClientEvents(wClient(pWin), pEvents, count,
 			       pWin->eventMask, filter, NullGrab);
     }
@@ -1892,6 +1899,9 @@ MaybeDeliverEventsToClient(WindowPtr pWin, xEvent *pEvents,
 	      return XineramaTryClientEventsResult(
 			rClient(other), NullGrab, other->mask, filter);
 #endif
+	    if (XaceHook(XACE_RECEIVE_ACCESS, rClient(other), pWin, pEvents,
+			 count))
+		return 0;
 	    return TryClientEvents(rClient(other), pEvents, count,
 				   other->mask, filter, NullGrab);
 	}
@@ -1986,6 +1996,9 @@ DeliverDeviceEvents(WindowPtr pWin, xEvent *xE, GrabPtr grab,
     Mask filter = filters[type];
     int deliveries = 0;
 
+    if (XaceHook(XACE_SEND_ACCESS, NULL, dev, pWin, xE, count))
+	return 0;
+
     if (type & EXTENSION_EVENT_BASE)
     {
 	OtherInputMasks *inputMasks;
@@ -2829,6 +2842,8 @@ DeliverFocusedEvent(DeviceIntPtr keybd, xEvent *xE, WindowPtr window, int count)
 	    return;
     }
     /* just deliver it to the focus window */
+    if (XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, xE, count))
+	return;
     FixUpEventFromWindow(xE, focus, None, FALSE);
     if (xE->u.u.type & EXTENSION_EVENT_BASE)
 	mskidx = keybd->id;
@@ -2877,9 +2892,12 @@ DeliverGrabbedEvent(xEvent *xE, DeviceIntPtr thisDev,
     if (!deliveries)
     {
 	FixUpEventFromWindow(xE, grab->window, None, TRUE);
-	deliveries = TryClientEvents(rClient(grab), xE, count,
-				     (Mask)grab->eventMask,
-				     filters[xE->u.u.type], grab);
+	if (!XaceHook(XACE_SEND_ACCESS, thisDev, grab->window, xE, count) &&
+	    !XaceHook(XACE_RECEIVE_ACCESS, rClient(grab), grab->window, xE,
+		      count))
+	    deliveries = TryClientEvents(rClient(grab), xE, count,
+					 (Mask)grab->eventMask,
+					 filters[xE->u.u.type], grab);
 	if (deliveries && (xE->u.u.type == MotionNotify
 #ifdef XINPUT
 			   || xE->u.u.type == DeviceMotionNotify
@@ -4530,6 +4548,9 @@ ProcSendEvent(ClientPtr client)
     {
 	for (;pWin; pWin = pWin->parent)
 	{
+	    if (XaceHook(XACE_SEND_ACCESS, client, NULL, pWin,
+			 &stuff->event, 1))
+		return Success;
 	    if (DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask,
 				      NullGrab, 0))
 		return Success;
@@ -4540,7 +4561,7 @@ ProcSendEvent(ClientPtr client)
 		break;
 	}
     }
-    else
+    else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, &stuff->event, 1))
 	(void)DeliverEventsToWindow(pWin, &stuff->event, 1, stuff->eventMask,
 				    NullGrab, 0);
     return Success;
diff --git a/dix/window.c b/dix/window.c
index 1a598fa..b6bbdd4 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -2744,8 +2744,9 @@ MapWindow(WindowPtr pWin, ClientPtr client)
 	return(Success);
 
     /*  general check for permission to map window */
-    if (XaceHook(XACE_MAP_ACCESS, client, pWin) != Success)
-	 return Success;
+    if (XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id, RT_WINDOW,
+		 DixShowAccess, pWin) != Success)
+	return Success;
 
     pScreen = pWin->drawable.pScreen;
     if ( (pParent = pWin->parent) )
commit 41355a53c29bbf879da0c6ea562294fcc7ef89ff
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Aug 28 15:10:20 2007 -0400

    xace: add hooks + new access codes: core protocol input requests

diff --git a/Xext/xace.c b/Xext/xace.c
index 54e910f..4d34dc3 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -84,7 +84,7 @@ int XaceHook(int hook, ...)
 	    XaceDeviceAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, DeviceIntPtr),
-		va_arg(ap, Bool),
+		va_arg(ap, Mask),
 		Success /* default allow */
 	    };
 	    calldata = &rec;
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 10c625b..c98be3d 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -50,7 +50,7 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     DeviceIntPtr dev;
-    Bool fromRequest;
+    Mask access_mode;
     int status;
 } XaceDeviceAccessRec;
 
diff --git a/dix/devices.c b/dix/devices.c
index a62ab65..dfbd2bf 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1271,10 +1271,10 @@ AllModifierKeysAreUp(dev, map1, per1, map2, per2)
 
 static int
 DoSetModifierMapping(ClientPtr client, KeyCode *inputMap,
-                     int numKeyPerModifier)
+                     int numKeyPerModifier, xSetModifierMappingReply *rep)
 {
     DeviceIntPtr pDev = NULL;
-    int i = 0, inputMapLen = numKeyPerModifier * 8;
+    int rc, i = 0, inputMapLen = numKeyPerModifier * 8;
 
     for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
         if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
@@ -1289,8 +1289,9 @@ DoSetModifierMapping(ClientPtr client, KeyCode *inputMap,
                 }
             }
 
-            if (XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE) != Success)
-                return BadAccess;
+	    rc = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixSetAttrAccess);
+	    if (rc != Success)
+		return rc;
 
             /* None of the modifiers (old or new) may be down while we change
              * the map. */
@@ -1300,7 +1301,8 @@ DoSetModifierMapping(ClientPtr client, KeyCode *inputMap,
                 !AllModifierKeysAreUp(pDev, inputMap, numKeyPerModifier,
                                       pDev->key->modifierKeyMap,
                                       pDev->key->maxKeysPerModifier)) {
-                return MappingBusy;
+		rep->success = MappingBusy;
+                return Success;
             }
         }
     }
@@ -1337,6 +1339,7 @@ DoSetModifierMapping(ClientPtr client, KeyCode *inputMap,
         }
     }
 
+    rep->success = Success;
     return Success;
 }
 
@@ -1344,8 +1347,8 @@ int
 ProcSetModifierMapping(ClientPtr client)
 {
     xSetModifierMappingReply rep;
+    int rc;
     REQUEST(xSetModifierMappingReq);
-    
     REQUEST_AT_LEAST_SIZE(xSetModifierMappingReq);
 
     if (client->req_len != ((stuff->numKeyPerModifier << 1) +
@@ -1356,8 +1359,10 @@ ProcSetModifierMapping(ClientPtr client)
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
 
-    rep.success = DoSetModifierMapping(client, (KeyCode *)&stuff[1],
-                                       stuff->numKeyPerModifier);
+    rc = DoSetModifierMapping(client, (KeyCode *)&stuff[1],
+			      stuff->numKeyPerModifier, &rep);
+    if (rc != Success)
+	return rc;
 
     /* FIXME: Send mapping notifies for all the extended devices as well. */
     SendMappingNotify(MappingModifier, 0, 0, client);
@@ -1370,8 +1375,14 @@ ProcGetModifierMapping(ClientPtr client)
 {
     xGetModifierMappingReply rep;
     KeyClassPtr keyc = inputInfo.keyboard->key;
-
+    int rc;
     REQUEST_SIZE_MATCH(xReq);
+
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
     rep.type = X_Reply;
     rep.numKeyPerModifier = keyc->maxKeysPerModifier;
     rep.sequenceNumber = client->sequence;
@@ -1394,6 +1405,7 @@ ProcChangeKeyboardMapping(ClientPtr client)
     KeySymsRec keysyms;
     KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
     DeviceIntPtr pDev = NULL;
+    int rc;
     REQUEST_AT_LEAST_SIZE(xChangeKeyboardMappingReq);
 
     len = client->req_len - (sizeof(xChangeKeyboardMappingReq) >> 2);  
@@ -1414,8 +1426,9 @@ ProcChangeKeyboardMapping(ClientPtr client)
 
     for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
         if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
-            if (XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE) != Success)
-                return BadAccess;
+            rc = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixSetAttrAccess);
+	    if (rc != Success)
+                return rc;
         }
     }
 
@@ -1437,9 +1450,9 @@ ProcChangeKeyboardMapping(ClientPtr client)
 }
 
 static int
-DoSetPointerMapping(DeviceIntPtr device, BYTE *map, int n)
+DoSetPointerMapping(ClientPtr client, DeviceIntPtr device, BYTE *map, int n)
 {
-    int i = 0;
+    int rc, i = 0;
     DeviceIntPtr dev = NULL;
 
     if (!device || !device->button)
@@ -1447,6 +1460,14 @@ DoSetPointerMapping(DeviceIntPtr device, BYTE *map, int n)
 
     for (dev = inputInfo.devices; dev; dev = dev->next) {
         if ((dev->coreEvents || dev == inputInfo.pointer) && dev->button) {
+	    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixSetAttrAccess);
+	    if (rc != Success)
+		return rc;
+	}
+    }
+
+    for (dev = inputInfo.devices; dev; dev = dev->next) {
+        if ((dev->coreEvents || dev == inputInfo.pointer) && dev->button) {
             for (i = 0; i < n; i++) {
                 if ((device->button->map[i + 1] != map[i]) &&
                     BitIsOn(device->button->down, i + 1)) {
@@ -1469,12 +1490,12 @@ DoSetPointerMapping(DeviceIntPtr device, BYTE *map, int n)
 int
 ProcSetPointerMapping(ClientPtr client)
 {
-    REQUEST(xSetPointerMappingReq);
     BYTE *map;
     int ret;
     xSetPointerMappingReply rep;
-
+    REQUEST(xSetPointerMappingReq);
     REQUEST_AT_LEAST_SIZE(xSetPointerMappingReq);
+
     if (client->req_len != (sizeof(xSetPointerMappingReq)+stuff->nElts+3) >> 2)
 	return BadLength;
     rep.type = X_Reply;
@@ -1492,7 +1513,7 @@ ProcSetPointerMapping(ClientPtr client)
     if (BadDeviceMap(&map[0], (int)stuff->nElts, 1, 255, &client->errorValue))
 	return BadValue;
 
-    ret = DoSetPointerMapping(inputInfo.pointer, map, stuff->nElts);
+    ret = DoSetPointerMapping(client, inputInfo.pointer, map, stuff->nElts);
     if (ret != Success) {
         rep.success = ret;
         WriteReplyToClient(client, sizeof(xSetPointerMappingReply), &rep);
@@ -1509,11 +1530,16 @@ int
 ProcGetKeyboardMapping(ClientPtr client)
 {
     xGetKeyboardMappingReply rep;
-    REQUEST(xGetKeyboardMappingReq);
     KeySymsPtr curKeySyms = &inputInfo.keyboard->key->curKeySyms;
-
+    int rc;
+    REQUEST(xGetKeyboardMappingReq);
     REQUEST_SIZE_MATCH(xGetKeyboardMappingReq);
 
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
     if ((stuff->firstKeyCode < curKeySyms->minKeyCode) ||
         (stuff->firstKeyCode > curKeySyms->maxKeyCode)) {
 	client->errorValue = stuff->firstKeyCode;
@@ -1546,8 +1572,14 @@ ProcGetPointerMapping(ClientPtr client)
 {
     xGetPointerMappingReply rep;
     ButtonClassPtr butc = inputInfo.pointer->button;
-
+    int rc;
     REQUEST_SIZE_MATCH(xReq);
+
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.pointer,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
     rep.nElts = butc->numButtons;
@@ -1766,8 +1798,9 @@ ProcChangeKeyboardControl (ClientPtr client)
     for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
         if ((pDev->coreEvents || pDev == inputInfo.keyboard) &&
             pDev->kbdfeed && pDev->kbdfeed->CtrlProc) {
-            if (XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE) != Success)
-                return BadAccess;
+            ret = XaceHook(XACE_DEVICE_ACCESS, client, pDev, DixSetAttrAccess);
+	    if (ret != Success)
+                return ret;
         }
     }
 
@@ -1786,11 +1819,16 @@ ProcChangeKeyboardControl (ClientPtr client)
 int
 ProcGetKeyboardControl (ClientPtr client)
 {
-    int i;
+    int rc, i;
     KeybdCtrl *ctrl = &inputInfo.keyboard->kbdfeed->ctrl;
     xGetKeyboardControlReply rep;
-
     REQUEST_SIZE_MATCH(xReq);
+
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
     rep.type = X_Reply;
     rep.length = 5;
     rep.sequenceNumber = client->sequence;
@@ -1812,6 +1850,7 @@ ProcBell(ClientPtr client)
     DeviceIntPtr keybd = inputInfo.keyboard;
     int base = keybd->kbdfeed->ctrl.bell;
     int newpercent;
+    int rc;
     REQUEST(xBellReq);
     REQUEST_SIZE_MATCH(xBellReq);
 
@@ -1832,6 +1871,10 @@ ProcBell(ClientPtr client)
     for (keybd = inputInfo.devices; keybd; keybd = keybd->next) {
         if ((keybd->coreEvents || keybd == inputInfo.keyboard) &&
             keybd->kbdfeed && keybd->kbdfeed->BellProc) {
+
+	    rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixBellAccess);
+	    if (rc != Success)
+		return rc;
 #ifdef XKB
             if (!noXkbExtension)
                 XkbHandleBell(FALSE, FALSE, keybd, newpercent,
@@ -1851,8 +1894,8 @@ ProcChangePointerControl(ClientPtr client)
 {
     DeviceIntPtr mouse = inputInfo.pointer;
     PtrCtrl ctrl;		/* might get BadValue part way through */
+    int rc;
     REQUEST(xChangePointerControlReq);
-
     REQUEST_SIZE_MATCH(xChangePointerControlReq);
     
     if (!mouse->ptrfeed->CtrlProc)
@@ -1903,6 +1946,14 @@ ProcChangePointerControl(ClientPtr client)
         }
     }
 
+    for (mouse = inputInfo.devices; mouse; mouse = mouse->next) {
+        if ((mouse->coreEvents || mouse == inputInfo.pointer) &&
+            mouse->ptrfeed && mouse->ptrfeed->CtrlProc) {
+	    rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixSetAttrAccess);
+	    if (rc != Success)
+		return rc;
+	}
+    }
 
     for (mouse = inputInfo.devices; mouse; mouse = mouse->next) {
         if ((mouse->coreEvents || mouse == inputInfo.pointer) &&
@@ -1920,8 +1971,14 @@ ProcGetPointerControl(ClientPtr client)
 {
     PtrCtrl *ctrl = &inputInfo.pointer->ptrfeed->ctrl;
     xGetPointerControlReply rep;
-
+    int rc;
     REQUEST_SIZE_MATCH(xReq);
+
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.pointer,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -1959,11 +2016,15 @@ ProcGetMotionEvents(ClientPtr client)
     DeviceIntPtr mouse = inputInfo.pointer;
     TimeStamp start, stop;
     REQUEST(xGetMotionEventsReq);
-
     REQUEST_SIZE_MATCH(xGetMotionEventsReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixUnknownAccess);
+
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess);
     if (rc != Success)
 	return rc;
+
     if (mouse->valuator->motionHintWindow)
 	MaybeStopHint(mouse, client);
     rep.type = X_Reply;
@@ -2019,7 +2080,7 @@ int
 ProcQueryKeymap(ClientPtr client)
 {
     xQueryKeymapReply rep;
-    int i;
+    int rc, i;
     CARD8 *down = inputInfo.keyboard->key->down;
 
     REQUEST_SIZE_MATCH(xReq);
@@ -2027,11 +2088,13 @@ ProcQueryKeymap(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.length = 2;
 
-    if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
-	bzero((char *)&rep.map[0], 32);
-    else
-	for (i = 0; i<32; i++)
-	    rep.map[i] = down[i];
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard,
+		  DixReadAccess);
+    if (rc != Success)
+	return rc;
+
+    for (i = 0; i<32; i++)
+	rep.map[i] = down[i];
 
     WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
     return Success;
diff --git a/dix/events.c b/dix/events.c
index f109dad..deae4e3 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2523,18 +2523,24 @@ ProcWarpPointer(ClientPtr client)
     WindowPtr	dest = NULL;
     int		x, y, rc;
     ScreenPtr	newScreen;
-
+    DeviceIntPtr dev;
     REQUEST(xWarpPointerReq);
-
     REQUEST_SIZE_MATCH(xWarpPointerReq);
 
+    for (dev = inputInfo.devices; dev; dev = dev->next) {
+        if ((dev->coreEvents || dev == inputInfo.pointer) && dev->button) {
+	    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixWriteAccess);
+	    if (rc != Success)
+		return rc;
+	}
+    }
 #ifdef PANORAMIX
     if(!noPanoramiXExtension)
 	return XineramaWarpPointer(client);
 #endif
 
     if (stuff->dstWid != None) {
-	rc = dixLookupWindow(&dest, stuff->dstWid, client, DixReadAccess);
+	rc = dixLookupWindow(&dest, stuff->dstWid, client, DixGetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
@@ -2547,7 +2553,7 @@ ProcWarpPointer(ClientPtr client)
  	XID 	winID = stuff->srcWid;
         WindowPtr source;
 	
-	rc = dixLookupWindow(&source, winID, client, DixReadAccess);
+	rc = dixLookupWindow(&source, winID, client, DixGetAttrAccess);
 	if (rc != Success)
 	    return rc;
 
@@ -2689,8 +2695,6 @@ CheckPassiveGrabsOnWindow(
 	     (grab->confineTo->realized && 
 				BorderSizeNotEmpty(grab->confineTo))))
 	{
-	    if (XaceHook(XACE_DEVICE_ACCESS, wClient(pWin), device, FALSE))
-		return FALSE;
 #ifdef XKB
 	    if (!noXkbExtension) {
 		XE_KBPTR.state &= 0x1f00;
@@ -3546,10 +3550,10 @@ EnterLeaveEvent(
 	xKeymapEvent ke;
 	ClientPtr client = grab ? rClient(grab)
 				: clients[CLIENT_ID(pWin->drawable.id)];
-	if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, FALSE) == Success)
-	    memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31);
-	else
+	if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess))
 	    bzero((char *)&ke.map[0], 31);
+	else
+	    memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31);
 
 	ke.type = KeymapNotify;
 	if (grab)
@@ -3653,10 +3657,10 @@ FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
     {
 	xKeymapEvent ke;
 	ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)];
-	if (XaceHook(XACE_DEVICE_ACCESS, client, dev, FALSE) == Success)
-	    memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31);
-	else
+	if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess))
 	    bzero((char *)&ke.map[0], 31);
+	else
+	    memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31);
 
 	ke.type = KeymapNotify;
 	(void)DeliverEventsToWindow(pWin, (xEvent *)&ke, 1,
@@ -3881,7 +3885,7 @@ SetInputFocus(
     else if ((focusID == FollowKeyboard) && followOK)
 	focusWin = inputInfo.keyboard->focus->win;
     else {
-	rc = dixLookupWindow(&focusWin, focusID, client, DixReadAccess);
+	rc = dixLookupWindow(&focusWin, focusID, client, DixSetAttrAccess);
 	if (rc != Success)
 	    return rc;
  	/* It is a match error to try to set the input focus to an 
@@ -3889,6 +3893,10 @@ SetInputFocus(
 	if(!focusWin->realized)
 	    return(BadMatch);
     }
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixSetFocusAccess);
+    if (rc != Success)
+	return Success;
+
     focus = dev->focus;
     if ((CompareTimeStamps(time, currentTime) == LATER) ||
 	(CompareTimeStamps(time, focus->time) == EARLIER))
@@ -3941,9 +3949,6 @@ ProcSetInputFocus(client)
 
     REQUEST_SIZE_MATCH(xSetInputFocusReq);
 
-    if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
-	return Success;
-
     return SetInputFocus(client, inputInfo.keyboard, stuff->focus,
 			 stuff->revertTo, stuff->time, FALSE);
 }
@@ -3958,10 +3963,16 @@ int
 ProcGetInputFocus(ClientPtr client)
 {
     xGetInputFocusReply rep;
-    /* REQUEST(xReq); */
     FocusClassPtr focus = inputInfo.keyboard->focus;
-
+    int rc;
+    /* REQUEST(xReq); */
     REQUEST_SIZE_MATCH(xReq);
+
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard,
+		  DixGetFocusAccess);
+    if (rc != Success)
+	return rc;
+
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -3991,6 +4002,7 @@ ProcGrabPointer(ClientPtr client)
     CursorPtr cursor, oldCursor;
     REQUEST(xGrabPointerReq);
     TimeStamp time;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     REQUEST_SIZE_MATCH(xGrabPointerReq);
@@ -4017,7 +4029,7 @@ ProcGrabPointer(ClientPtr client)
 	client->errorValue = stuff->eventMask;
         return BadValue;
     }
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     if (stuff->confineTo == None)
@@ -4025,7 +4037,7 @@ ProcGrabPointer(ClientPtr client)
     else 
     {
 	rc = dixLookupWindow(&confineTo, stuff->confineTo, client,
-			     DixReadAccess);
+			     DixSetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
@@ -4033,14 +4045,22 @@ ProcGrabPointer(ClientPtr client)
 	cursor = NullCursor;
     else
     {
-	cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
-						RT_CURSOR, DixReadAccess);
-	if (!cursor)
+	rc = dixLookupResource((pointer *)&cursor, stuff->cursor, RT_CURSOR,
+			       client, DixUseAccess);
+	if (rc != Success)
 	{
 	    client->errorValue = stuff->cursor;
-	    return BadCursor;
+	    return (rc == BadValue) ? BadCursor : rc;
 	}
+	access_mode |= DixForceAccess;
     }
+    if (stuff->pointerMode == GrabModeSync ||
+	stuff->keyboardMode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, device, access_mode);
+    if (rc != Success)
+	return rc;
+
 	/* at this point, some sort of reply is guaranteed. */
     time = ClientTimeToServerTime(stuff->time);
     rep.type = X_Reply;
@@ -4192,6 +4212,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
     WindowPtr pWin;
     GrabPtr grab;
     TimeStamp time;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     UpdateCurrentTime();
@@ -4210,9 +4231,16 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
 	client->errorValue = ownerEvents;
         return BadValue;
     }
-    rc = dixLookupWindow(&pWin, grabWindow, client, DixReadAccess);
+
+    rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
+    if (rc != Success)
+	return rc;
+    if (this_mode == GrabModeSync || other_mode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
     if (rc != Success)
 	return rc;
+
     time = ClientTimeToServerTime(ctime);
     grab = dev->grab;
     if (grab && !SameClient(grab, client))
@@ -4256,14 +4284,10 @@ ProcGrabKeyboard(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xGrabKeyboardReq);
 
-    if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE)) {
-	result = Success;
-	rep.status = AlreadyGrabbed;
-    } else
-        result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode,
-			    stuff->pointerMode, stuff->grabWindow,
-			    stuff->ownerEvents, stuff->time,
-			    KeyPressMask | KeyReleaseMask, &rep.status);
+    result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode,
+			stuff->pointerMode, stuff->grabWindow,
+			stuff->ownerEvents, stuff->time,
+			KeyPressMask | KeyReleaseMask, &rep.status);
 
     if (result != Success)
 	return result;
@@ -4308,14 +4332,18 @@ ProcQueryPointer(ClientPtr client)
 {
     xQueryPointerReply rep;
     WindowPtr pWin, t;
-    REQUEST(xResourceReq);
     DeviceIntPtr mouse = inputInfo.pointer;
     int rc;
-
+    REQUEST(xResourceReq);
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess);
+    if (rc != Success)
+	return rc;
+
     if (mouse->valuator->motionHintWindow)
 	MaybeStopHint(mouse, client);
     rep.type = X_Reply;
@@ -4488,7 +4516,7 @@ ProcSendEvent(ClientPtr client)
 	    effectiveFocus = pWin = inputFocus;
     }
     else
-	dixLookupWindow(&pWin, stuff->destination, client, DixReadAccess);
+	dixLookupWindow(&pWin, stuff->destination, client, DixSendAccess);
 
     if (!pWin)
 	return BadWindow;
@@ -4612,7 +4640,7 @@ ProcGrabKey(ClientPtr client)
 	client->errorValue = stuff->modifiers;
 	return BadValue;
     }
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
 
@@ -4640,6 +4668,7 @@ ProcGrabButton(ClientPtr client)
     REQUEST(xGrabButtonReq);
     CursorPtr cursor;
     GrabPtr grab;
+    Mask access_mode = DixGrabAccess;
     int rc;
 
     REQUEST_SIZE_MATCH(xGrabButtonReq);
@@ -4671,14 +4700,14 @@ ProcGrabButton(ClientPtr client)
 	client->errorValue = stuff->eventMask;
         return BadValue;
     }
-    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
     if (rc != Success)
 	return rc;
     if (stuff->confineTo == None)
        confineTo = NullWindow;
     else {
 	rc = dixLookupWindow(&confineTo, stuff->confineTo, client,
-			     DixReadAccess);
+			     DixSetAttrAccess);
 	if (rc != Success)
 	    return rc;
     }
@@ -4686,15 +4715,22 @@ ProcGrabButton(ClientPtr client)
 	cursor = NullCursor;
     else
     {
-	cursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
-						RT_CURSOR, DixReadAccess);
+	rc = dixLookupResource((pointer *)&cursor, stuff->cursor, RT_CURSOR,
+			       client, DixUseAccess);
+	if (rc != Success)
 	if (!cursor)
 	{
 	    client->errorValue = stuff->cursor;
-	    return BadCursor;
+	    return (rc == BadValue) ? BadCursor : rc;
 	}
+	access_mode |= DixForceAccess;
     }
-
+    if (stuff->pointerMode == GrabModeSync ||
+	stuff->keyboardMode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.pointer, access_mode);
+    if (rc != Success)
+	return rc;
 
     grab = CreateGrab(client->index, inputInfo.pointer, pWin, 
         (Mask)stuff->eventMask, (Bool)stuff->ownerEvents,
diff --git a/dix/grabs.c b/dix/grabs.c
index 2210cd0..b8d0df8 100644
--- a/dix/grabs.c
+++ b/dix/grabs.c
@@ -58,6 +58,7 @@ SOFTWARE.
 #include "inputstr.h"
 #include "cursorstr.h"
 #include "dixgrabs.h"
+#include "xace.h"
 
 #define BITMASK(i) (((Mask)1) << ((i) & 31))
 #define MASKIDX(i) ((i) >> 5)
@@ -309,6 +310,8 @@ int
 AddPassiveGrabToList(GrabPtr pGrab)
 {
     GrabPtr grab;
+    Mask access_mode = DixGrabAccess;
+    int rc;
 
     for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next)
     {
@@ -322,6 +325,13 @@ AddPassiveGrabToList(GrabPtr pGrab)
 	}
     }
 
+    if (grab->keyboardMode == GrabModeSync || grab->pointerMode == GrabModeSync)
+	access_mode |= DixFreezeAccess;
+    rc = XaceHook(XACE_DEVICE_ACCESS, clients[CLIENT_ID(grab->resource)],
+		  grab->device, access_mode);
+    if (rc != Success)
+	return rc;
+
     /* Remove all grabs that match the new one exactly */
     for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next)
     {
commit 4017d3190234e189a0bbd33193a148d4d3c7556b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Aug 28 09:28:25 2007 -0400

    devPrivates rework: since API is already broken, switch everything
    over to new system.
    
    Need to update documentation and address some remaining vestiges of
    old system such as CursorRec structure, fb "offman" structure, and
    FontRec privates.

diff --git a/Xext/dpmsstubs.c b/Xext/dpmsstubs.c
index 8d58935..fad07bd 100644
--- a/Xext/dpmsstubs.c
+++ b/Xext/dpmsstubs.c
@@ -48,5 +48,5 @@ int DPMSGet(int *plevel)
 
 int DPMSSet(ClientPtr client, int level)
 {
-
+    return Success;
 }
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 95df043..26c2809 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -110,8 +110,8 @@ static void PanoramiXResetProc(ExtensionEntry*);
 
 int (* SavedProcVector[256]) (ClientPtr client) = { NULL, };
 
-static int PanoramiXGCIndex = -1;
-static int PanoramiXScreenIndex = -1;
+static DevPrivateKey PanoramiXGCKey = &PanoramiXGCKey;
+static DevPrivateKey PanoramiXScreenKey = &PanoramiXScreenKey;
 
 typedef struct {
   DDXPointRec clipOrg;
@@ -140,8 +140,8 @@ static GCFuncs XineramaGCFuncs = {
 };
 
 #define Xinerama_GC_FUNC_PROLOGUE(pGC)\
-    PanoramiXGCPtr  pGCPriv = \
-		(PanoramiXGCPtr) (pGC)->devPrivates[PanoramiXGCIndex].ptr;\
+    PanoramiXGCPtr  pGCPriv = (PanoramiXGCPtr) \
+	dixLookupPrivate(&(pGC)->devPrivates, PanoramiXGCKey); \
     (pGC)->funcs = pGCPriv->wrapFuncs;
 
 #define Xinerama_GC_FUNC_EPILOGUE(pGC)\
@@ -152,8 +152,8 @@ static GCFuncs XineramaGCFuncs = {
 static Bool
 XineramaCloseScreen (int i, ScreenPtr pScreen)
 {
-    PanoramiXScreenPtr pScreenPriv = 
-        (PanoramiXScreenPtr) pScreen->devPrivates[PanoramiXScreenIndex].ptr;
+    PanoramiXScreenPtr pScreenPriv = (PanoramiXScreenPtr)
+	dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey);
 
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     pScreen->CreateGC = pScreenPriv->CreateGC;
@@ -171,14 +171,14 @@ static Bool
 XineramaCreateGC(GCPtr pGC)
 {
     ScreenPtr pScreen = pGC->pScreen;
-    PanoramiXScreenPtr pScreenPriv = 
-        (PanoramiXScreenPtr) pScreen->devPrivates[PanoramiXScreenIndex].ptr;
+    PanoramiXScreenPtr pScreenPriv = (PanoramiXScreenPtr)
+	dixLookupPrivate(&pScreen->devPrivates, PanoramiXScreenKey);
     Bool ret;
 
     pScreen->CreateGC = pScreenPriv->CreateGC;
     if((ret = (*pScreen->CreateGC)(pGC))) {
-	PanoramiXGCPtr pGCPriv = 
-		(PanoramiXGCPtr) pGC->devPrivates[PanoramiXGCIndex].ptr;
+	PanoramiXGCPtr pGCPriv = (PanoramiXGCPtr)
+	    dixLookupPrivate(&pGC->devPrivates, PanoramiXGCKey);
 
 	pGCPriv->wrapFuncs = pGC->funcs;
         pGC->funcs = &XineramaGCFuncs;
@@ -284,8 +284,8 @@ XineramaCopyGC (
     unsigned long   mask,
     GCPtr	    pGCDst
 ){
-    PanoramiXGCPtr pSrcPriv =
-                (PanoramiXGCPtr) pGCSrc->devPrivates[PanoramiXGCIndex].ptr;
+    PanoramiXGCPtr pSrcPriv = (PanoramiXGCPtr)
+	dixLookupPrivate(&pGCSrc->devPrivates, PanoramiXGCKey);
     Xinerama_GC_FUNC_PROLOGUE (pGCDst);
 
     if(mask & GCTileStipXOrigin)
@@ -484,20 +484,17 @@ void PanoramiXExtensionInit(int argc, char *argv[])
 		xcalloc(PanoramiXNumScreens, sizeof(PanoramiXData));
 
         BREAK_IF(!panoramiXdataPtr);
-	BREAK_IF((PanoramiXGCIndex = AllocateGCPrivateIndex()) < 0);
-	BREAK_IF((PanoramiXScreenIndex = AllocateScreenPrivateIndex()) < 0);
+
+	if (!dixRequestPrivate(PanoramiXGCKey, sizeof(PanoramiXGCRec))) {
+		noPanoramiXExtension = TRUE;
+		return;
+	}
 	
 	for (i = 0; i < PanoramiXNumScreens; i++) {
 	   pScreen = screenInfo.screens[i];
-	   if(!AllocateGCPrivate(pScreen, PanoramiXGCIndex, 
-						sizeof(PanoramiXGCRec))) {
-		noPanoramiXExtension = TRUE;
-		return;
-	   }
-
 	   pScreenPriv = xalloc(sizeof(PanoramiXScreenRec));
-	   pScreen->devPrivates[PanoramiXScreenIndex].ptr = 
-						(pointer)pScreenPriv;
+	   dixSetPrivate(&pScreen->devPrivates, PanoramiXScreenKey,
+			 pScreenPriv);
 	   if(!pScreenPriv) {
 		noPanoramiXExtension = TRUE;
 		return;
diff --git a/Xext/saver.c b/Xext/saver.c
index dabfbea..0042583 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -234,10 +234,12 @@ MakeScreenPrivate (
 	ScreenPtr /* pScreen */
 	);
 
-static int ScreenPrivateIndex;
+static DevPrivateKey ScreenPrivateKey = &ScreenPrivateKey;
 
-#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr)(s)->devPrivates[ScreenPrivateIndex].ptr)
-#define SetScreenPrivate(s,v) ((s)->devPrivates[ScreenPrivateIndex].ptr = (pointer) v);
+#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
+    dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
+#define SetScreenPrivate(s,v) \
+    dixSetPrivate(&(s)->devPrivates, ScreenPrivateKey, v);
 #define SetupScreen(s)	ScreenSaverScreenPrivatePtr pPriv = (s ? GetScreenPrivate(s) : NULL)
 
 #define New(t)	((t *) xalloc (sizeof (t)))
@@ -260,14 +262,13 @@ ScreenSaverExtensionInit(INITARGS)
     AttrType = CreateNewResourceType(ScreenSaverFreeAttr);
     EventType = CreateNewResourceType(ScreenSaverFreeEvents);
     SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend);
-    ScreenPrivateIndex = AllocateScreenPrivateIndex ();
 
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	pScreen = screenInfo.screens[i];
 	SetScreenPrivate (pScreen, NULL);
     }
-    if (AttrType && EventType && SuspendType && ScreenPrivateIndex != -1 &&
+    if (AttrType && EventType && SuspendType &&
 	(extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0,
 				 ProcScreenSaverDispatch, SProcScreenSaverDispatch,
 				 ScreenSaverResetProc, StandardMinorOpcode)))
diff --git a/Xext/shm.c b/Xext/shm.c
index 7fa8349..8fa5842 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -119,7 +119,7 @@ static int pixmapFormat;
 static int shmPixFormat[MAXSCREENS];
 static ShmFuncsPtr shmFuncs[MAXSCREENS];
 static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS];
-static int  shmPixmapPrivate;
+static DevPrivateKey shmPixmapPrivate = &shmPixmapPrivate;
 static ShmFuncs miFuncs = {NULL, miShmPutImage};
 static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage};
 
@@ -229,20 +229,11 @@ ShmExtensionInit(INITARGS)
       if (!pixmapFormat)
 	pixmapFormat = ZPixmap;
       if (sharedPixmaps)
-      {
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
 	    destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap;
 	    screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
 	}
-	shmPixmapPrivate = AllocatePixmapPrivateIndex();
-	for (i = 0; i < screenInfo.numScreens; i++)
-	{
-	    if (!AllocatePixmapPrivate(screenInfo.screens[i],
-				       shmPixmapPrivate, 0))
-		return;
-	}
-      }
     }
     ShmSegType = CreateNewResourceType(ShmDetachSegment);
     if (ShmSegType &&
@@ -295,7 +286,8 @@ ShmDestroyPixmap (PixmapPtr pPixmap)
     if (pPixmap->refcnt == 1)
     {
 	ShmDescPtr  shmdesc;
-	shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr;
+	shmdesc = (ShmDescPtr)dixLookupPrivate(&pPixmap->devPrivates,
+					       shmPixmapPrivate);
 	if (shmdesc)
 	    ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id);
     }
@@ -762,7 +754,7 @@ CreatePmap:
 				shmdesc->addr + stuff->offset);
 
 	if (pMap) {
-            pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc;
+	    dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
             shmdesc->refcnt++;
 	    pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	    pMap->drawable.id = newPix->info[j].id;
@@ -1076,7 +1068,7 @@ CreatePmap:
 			    shmdesc->addr + stuff->offset);
     if (pMap)
     {
-	pMap->devPrivates[shmPixmapPrivate].ptr = (pointer) shmdesc;
+	dixSetPrivate(&pMap->devPrivates, shmPixmapPrivate, shmdesc);
 	shmdesc->refcnt++;
 	pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	pMap->drawable.id = stuff->pid;
diff --git a/Xext/xevie.c b/Xext/xevie.c
index 7922913..7dd67bb 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -76,11 +76,11 @@ DeviceIntPtr		xeviemouse = NULL;
 Mask			xevieMask = 0;
 int       		xevieEventSent = 0;
 int			xevieKBEventSent = 0;
-static unsigned int             xevieServerGeneration;
-static int                      xevieDevicePrivateIndex;
+static DevPrivateKey    xevieDevicePrivateKey = &xevieDevicePrivateKey;
 static Bool                     xevieModifiersOn = FALSE;
 
-#define XEVIEINFO(dev)  ((xevieDeviceInfoPtr)dev->devPrivates[xevieDevicePrivateIndex].ptr)
+#define XEVIEINFO(dev)  ((xevieDeviceInfoPtr) \
+    dixLookupPrivate(&(dev)->devPrivates, xevieDevicePrivateKey))
 
 Mask xevieFilters[128] = 
 {
@@ -134,12 +134,6 @@ XevieExtensionInit (void)
 {
     ExtensionEntry* extEntry;
 
-    if (serverGeneration != xevieServerGeneration) {
-        if ((xevieDevicePrivateIndex = AllocateDevicePrivateIndex()) == -1)
-            return;
-        xevieServerGeneration = serverGeneration;
-    }
-
     if (!AddCallback(&ServerGrabCallback,XevieServerGrabStateCallback,NULL))
        return;
 
@@ -618,14 +612,11 @@ XevieAdd(DeviceIntPtr device, void* data)
 {
     xevieDeviceInfoPtr xeviep;
 
-    if (!AllocateDevicePrivate(device, xevieDevicePrivateIndex))
-        return FALSE;
-
     xeviep = xalloc (sizeof (xevieDeviceInfoRec));
     if (!xeviep)
             return FALSE;
 
-    device->devPrivates[xevieDevicePrivateIndex].ptr = xeviep;
+    dixSetPrivate(&device->devPrivates, xevieDevicePrivateKey, xeviep);
     XevieUnwrapAdd(device, data);
 
     return TRUE;
@@ -642,7 +633,7 @@ XevieRemove(DeviceIntPtr device,pointer data)
     UNWRAP_UNWRAPPROC(device,xeviep->unwrapProc);
 
     xfree(xeviep);
-    device->devPrivates[xevieDevicePrivateIndex].ptr = NULL;
+    dixSetPrivate(&device->devPrivates, xevieDevicePrivateKey, NULL);
     return TRUE;
 }
 
diff --git a/Xext/xprint.c b/Xext/xprint.c
index ff739c0..ef51118 100644
--- a/Xext/xprint.c
+++ b/Xext/xprint.c
@@ -153,8 +153,6 @@ static int XpFreePage(pointer, XID);
 static Bool XpCloseScreen(int, ScreenPtr);
 static CARD32 GetAllEventMasks(XpContextPtr);
 static struct _XpClient *CreateXpClient(ClientPtr);
-static void InitContextPrivates(XpContextPtr);
-static void ResetContextPrivates(void);
 static struct _XpClient *FindClient(XpContextPtr, ClientPtr);
 static struct _XpClient *AcquireClient(XpContextPtr, ClientPtr);
 
@@ -233,21 +231,12 @@ static XpScreenPtr XpScreens[MAXSCREENS];
 static unsigned char XpReqCode;
 static int XpEventBase;
 static int XpErrorBase;
-static unsigned long XpGeneration = 0;
-static int XpClientPrivateIndex;
-
-/* Variables for the context private machinery. 
- * These must be initialized at compile time because
- * main() calls InitOutput before InitExtensions, and the
- * output drivers are likely to call AllocateContextPrivate.
- * These variables are reset at CloseScreen time.  CloseScreen
- * is used because it occurs after FreeAllResources, and before
- * the next InitOutput cycle.
- */
-static int  contextPrivateCount = 0;
-static int contextPrivateLen = 0;
-static unsigned *contextPrivateSizes = (unsigned *)NULL;
-static unsigned totalContextSize = sizeof(XpContextRec);
+static DevPrivateKey XpClientPrivateKey = &XpClientPrivateKey;
+
+#define XP_GETPRIV(pClient) ((XpContextPtr) \
+    dixLookupPrivate(&(pClient)->devPrivates, XpClientPrivateKey))
+#define XP_SETPRIV(pClient, p) \
+    dixSetPrivate(&(pClient)->devPrivates, XpClientPrivateKey, p)
 
 /*
  * There are three types of resources involved.  One is the resource associated
@@ -305,20 +294,6 @@ XpExtensionInit(INITARGS)
         EventSwapVector[XpEventBase+1] = (EventSwapPtr) SwapXpAttributeEvent;
     }
 
-    if(XpGeneration != serverGeneration)
-    {
-	XpClientPrivateIndex = AllocateClientPrivateIndex();
-	/*
-	 * We allocate 0 length & simply stuff a pointer to the
-	 * ContextRec in the DevUnion.
-	 */
-	if(AllocateClientPrivate(XpClientPrivateIndex, 0) != TRUE)
-	{
-		/* we can't alloc a client private, should we bail??? XXX */
-	}
-	XpGeneration = serverGeneration;
-    }
-
     for(i = 0; i < MAXSCREENS; i++)
     {
 	/*
@@ -377,14 +352,6 @@ XpCloseScreen(int index, ScreenPtr pScreen)
     }
     XpScreens[index] = (XpScreenPtr)NULL;
 
-    /*
-     * It's wasteful to call ResetContextPrivates() at every CloseScreen, 
-     * but it's the best we know how to do for now.  We do this because we
-     * have to wait until after all resources have been freed (so we know
-     * how to free the ContextRecs), and before the next InitOutput cycle.
-     * See dix/main.c for the order of initialization and reset.
-     */
-    ResetContextPrivates();
     return (*CloseScreen)(index, pScreen);
 }
 
@@ -956,12 +923,10 @@ ProcXpCreateContext(ClientPtr client)
     /*
      * Allocate and add the context resource.
      */
-    if((pContext = (XpContextPtr) xalloc(totalContextSize)) == 
+    if((pContext = (XpContextPtr) xalloc(sizeof(XpContextRec))) == 
        (XpContextPtr) NULL)
 	return BadAlloc;
 
-    InitContextPrivates(pContext);
-
     if(AddResource(stuff->contextID, RTcontext, (pointer) pContext)
        != TRUE)
     {
@@ -975,6 +940,7 @@ ProcXpCreateContext(ClientPtr client)
     pContext->state = 0;
     pContext->clientSlept = (ClientPtr)NULL;
     pContext->imageRes = 0;
+    pContext->devPrivates = NULL;
 
     pContext->funcs.DestroyContext = 0;
     pContext->funcs.StartJob = 0;
@@ -1041,8 +1007,7 @@ ProcXpSetContext(ClientPtr client)
 
     REQUEST_AT_LEAST_SIZE(xPrintSetContextReq);
 
-    if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) != 
-       (pointer)NULL)
+    if((pContext = XP_GETPRIV(client)) != (pointer)NULL)
     {
 	/*
 	 * Erase this client's knowledge of its old context, if any.
@@ -1055,7 +1020,7 @@ ProcXpSetContext(ClientPtr client)
 		FreeXpClient(pPrintClient, TRUE);
         }
 
-        client->devPrivates[XpClientPrivateIndex].ptr = (pointer)NULL;
+	XP_SETPRIV(client, NULL);
     }
     if(stuff->printContext == None)
         return Success;
@@ -1077,7 +1042,7 @@ ProcXpSetContext(ClientPtr client)
     if((pPrintClient = AcquireClient(pContext, client)) == (XpClientPtr)NULL)
         return BadAlloc;
 
-    client->devPrivates[XpClientPrivateIndex].ptr = pContext;
+    XP_SETPRIV(client, pContext);
 
     XpSetFontResFunc(client);
 
@@ -1090,7 +1055,7 @@ ProcXpSetContext(ClientPtr client)
 XpContextPtr
 XpGetPrintContext(ClientPtr client)
 {
-    return (client->devPrivates[XpClientPrivateIndex].ptr);
+    return XP_GETPRIV(client);
 }
 
 static int
@@ -1105,8 +1070,7 @@ ProcXpGetContext(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xPrintGetContextReq);
 
-    if((pContext = client->devPrivates[XpClientPrivateIndex].ptr) == 
-       (pointer)NULL)
+    if((pContext = XP_GETPRIV(client)) == (pointer)NULL)
 	rep.printContext = None;
     else
         rep.printContext = pContext->contextID;
@@ -1249,6 +1213,7 @@ XpFreeContext(pointer data, XID id)
     }
 
     xfree(pContext->printerName);
+    dixFreePrivates(pContext->devPrivates);
     xfree(pContext);
     return Success; /* ??? */
 }
@@ -1284,11 +1249,9 @@ FreeXpClient(XpClientPtr pXpClient, Bool freeResource)
      * If we're freeing the clientRec associated with the context tied
      * to the client's devPrivates, then we need to clear the devPrivates.
      */
-    if(pXpClient->client->devPrivates[XpClientPrivateIndex].ptr == 
-       pXpClient->context)
+    if(XP_GETPRIV(pXpClient->client) == pXpClient->context)
     {
-        pXpClient->client->devPrivates[XpClientPrivateIndex].ptr = 
-					(pointer)NULL;
+	XP_SETPRIV(pXpClient->client, NULL);
     }
 
     for(pPrev = (XpClientPtr)NULL, pCurrent = pContext->clientHead; 
@@ -1372,87 +1335,6 @@ XpFreePage(pointer data, XID id)
     return result;
 }
 
-/*
- * ContextPrivate machinery.
- * Context privates are intended for use by the drivers, allowing the
- * drivers to maintain context-specific data.  The driver should free
- * the associated data at DestroyContext time.
- */
-
-static void
-InitContextPrivates(XpContextPtr context)
-{
-    register char *ptr;
-    DevUnion *ppriv;
-    register unsigned *sizes;
-    register unsigned size;
-    register int i;
-
-    if (totalContextSize == sizeof(XpContextRec))
-        ppriv = (DevUnion *)NULL;
-    else 
-        ppriv = (DevUnion *)(context + 1);
-
-    context->devPrivates = ppriv;
-    sizes = contextPrivateSizes;
-    ptr = (char *)(ppriv + contextPrivateLen);
-    for (i = contextPrivateLen; --i >= 0; ppriv++, sizes++)
-    {
-        if ( (size = *sizes) )
-        {
-            ppriv->ptr = (pointer)ptr;
-            ptr += size;
-        }
-        else
-            ppriv->ptr = (pointer)NULL;
-    }
-}
-
-static void
-ResetContextPrivates(void)
-{
-    contextPrivateCount = 0;
-    contextPrivateLen = 0;
-    xfree(contextPrivateSizes);
-    contextPrivateSizes = (unsigned *)NULL;
-    totalContextSize = sizeof(XpContextRec);
-
-}
-
-int
-XpAllocateContextPrivateIndex(void)
-{
-    return contextPrivateCount++;
-}
-
-Bool
-XpAllocateContextPrivate(int index, unsigned amount)
-{
-    unsigned oldamount;
-
-    if (index >= contextPrivateLen)
-    {
-        unsigned *nsizes;
-        nsizes = (unsigned *)xrealloc(contextPrivateSizes,
-                                      (index + 1) * sizeof(unsigned));
-        if (!nsizes)
-            return FALSE;
-        while (contextPrivateLen <= index)
-        {
-            nsizes[contextPrivateLen++] = 0;
-            totalContextSize += sizeof(DevUnion);
-        }
-        contextPrivateSizes = nsizes;
-    }
-    oldamount = contextPrivateSizes[index];
-    if (amount > oldamount)
-    {
-        contextPrivateSizes[index] = amount;
-        totalContextSize += (amount - oldamount);
-    }
-    return TRUE;
-}
-
 static XpClientPtr
 AcquireClient(XpContextPtr pContext, ClientPtr client)
 {
@@ -1501,8 +1383,7 @@ ProcXpStartJob(ClientPtr client)
     REQUEST_SIZE_MATCH(xPrintStartJobReq);
 
     /* Check to see that a context has been established by this client. */
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadContext;
 
     if(pContext->state != 0)
@@ -1542,8 +1423,7 @@ ProcXpEndJob(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xPrintEndJobReq);
 
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadSequence;
 
     if(!(pContext->state & JOB_STARTED))
@@ -1648,8 +1528,7 @@ ProcXpStartDoc(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xPrintStartDocReq);
 
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadSequence;
 
     if(!(pContext->state & JOB_STARTED) || 
@@ -1684,8 +1563,7 @@ ProcXpEndDoc(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xPrintEndDocReq);
 
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadSequence;
 
     if(!(pContext->state & DOC_RAW_STARTED) &&
@@ -1837,8 +1715,7 @@ ProcXpStartPage(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xPrintStartPageReq);
 
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadSequence;
 
     if(!(pContext->state & JOB_STARTED))
@@ -1882,8 +1759,7 @@ ProcXpEndPage(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xPrintEndPageReq);
 
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadSequence;
 
     if(!(pContext->state & PAGE_STARTED))
@@ -1932,8 +1808,7 @@ ProcXpPutDocumentData(ClientPtr client)
 
     REQUEST_AT_LEAST_SIZE(xPrintPutDocumentDataReq);
 
-    if((pContext = (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr)
-       == (XpContextPtr)NULL)
+    if((pContext = XP_GETPRIV(client)) == (XpContextPtr)NULL)
         return XpErrorBase+XPBadSequence;
 
     if(!(pContext->state & DOC_RAW_STARTED) &&
@@ -2443,7 +2318,7 @@ GetAllEventMasks(XpContextPtr pContext)
 XpContextPtr
 XpContextOfClient(ClientPtr client)
 {
-    return (XpContextPtr)client->devPrivates[XpClientPrivateIndex].ptr;
+    return XP_GETPRIV(client);
 }
 
 
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 21d00aa..af2e09b 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -388,8 +388,8 @@ ProcXvQueryAdaptors(ClientPtr client)
       return rc;
 
   pScreen = pWin->drawable.pScreen;
-  pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr;
-
+  pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+				       XvGetScreenKey());
   if (!pxvs)
     {
       rep.type = X_Reply;
@@ -2099,7 +2099,8 @@ XineramaXvPutStill(ClientPtr client)
 void XineramifyXv(void)
 {
    ScreenPtr pScreen, screen0 = screenInfo.screens[0];
-   XvScreenPtr xvsp0 = (XvScreenPtr)screen0->devPrivates[XvScreenIndex].ptr;
+   XvScreenPtr xvsp0 = (XvScreenPtr)dixLookupPrivate(&screen0->devPrivates,
+						     XvGetScreenKey());
    XvAdaptorPtr refAdapt, pAdapt;
    XvAttributePtr pAttr;
    XvScreenPtr xvsp;
@@ -2132,8 +2133,8 @@ void XineramifyXv(void)
    
       for(j = 1; j < PanoramiXNumScreens; j++) {
          pScreen = screenInfo.screens[j];
-	 xvsp = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr;
-
+	 xvsp = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+					      XvGetScreenKey());
          /* Do not try to go on if xv is not supported on this screen */
          if (xvsp==NULL) continue ;
 	 
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 9e94e05..a516cf1 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -55,7 +55,6 @@ SOFTWARE.
 #include "scrnintstr.h"
 #include <X11/extensions/Xvproto.h>
 
-extern int  XvScreenIndex;
 extern unsigned long XvExtensionGeneration;
 extern unsigned long XvScreenGeneration;
 extern unsigned long XvResourceGeneration;
@@ -224,10 +223,8 @@ typedef struct {
   DevUnion devPriv;
 } XvScreenRec, *XvScreenPtr;
 
-#define SCREEN_PROLOGUE(pScreen, field)\
-  ((pScreen)->field = \
-   ((XvScreenPtr) \
-    (pScreen)->devPrivates[XvScreenIndex].ptr)->field)
+#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = ((XvScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, XvScreenKey))->field)
 
 #define SCREEN_EPILOGUE(pScreen, field, wrapper)\
     ((pScreen)->field = wrapper)
@@ -242,7 +239,7 @@ extern int SProcXvDispatch(ClientPtr);
 
 extern void XvExtensionInit(void);
 extern int XvScreenInit(ScreenPtr);
-extern int XvGetScreenIndex(void);
+extern DevPrivateKey XvGetScreenKey(void);
 extern unsigned long XvGetRTPort(void);
 extern int XvdiSendPortNotify(XvPortPtr, Atom, INT32);
 extern int XvdiVideoStopped(XvPortPtr, int);
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index ddf3d1d..a2fc108 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -105,7 +105,7 @@ SOFTWARE.
 #include "xvdisp.h"
 #endif
 
-int  XvScreenIndex = -1;
+static DevPrivateKey XvScreenKey = &XvScreenKey;
 unsigned long XvExtensionGeneration = 0;
 unsigned long XvScreenGeneration = 0;
 unsigned long XvResourceGeneration = 0;
@@ -166,12 +166,6 @@ XvExtensionInit(void)
 	  ErrorF("XvExtensionInit: Unable to allocate resource types\n");
 	  return;
 	}
-      XvScreenIndex = AllocateScreenPrivateIndex ();
-      if (XvScreenIndex < 0)
-	{
-	  ErrorF("XvExtensionInit: Unable to allocate screen private index\n");
-	  return;
-	}
 #ifdef PANORAMIX
         XineramaRegisterConnectionBlockCallback(XineramifyXv);
 #endif
@@ -265,19 +259,13 @@ XvScreenInit(ScreenPtr pScreen)
 	  ErrorF("XvScreenInit: Unable to allocate resource types\n");
 	  return BadAlloc;
 	}
-      XvScreenIndex = AllocateScreenPrivateIndex ();
-      if (XvScreenIndex < 0)
-	{
-	  ErrorF("XvScreenInit: Unable to allocate screen private index\n");
-	  return BadAlloc;
-	}
 #ifdef PANORAMIX
         XineramaRegisterConnectionBlockCallback(XineramifyXv);
 #endif
       XvScreenGeneration = serverGeneration; 
     }
 
-  if (pScreen->devPrivates[XvScreenIndex].ptr)
+  if (dixLookupPrivate(&pScreen->devPrivates, XvScreenKey))
     {
       ErrorF("XvScreenInit: screen devPrivates ptr non-NULL before init\n");
     }
@@ -291,7 +279,7 @@ XvScreenInit(ScreenPtr pScreen)
       return BadAlloc;
     }
 
-  pScreen->devPrivates[XvScreenIndex].ptr = (pointer)pxvs;
+  dixSetPrivate(&pScreen->devPrivates, XvScreenKey, pxvs);
 
   
   pxvs->DestroyPixmap = pScreen->DestroyPixmap;
@@ -313,7 +301,7 @@ XvCloseScreen(
 
   XvScreenPtr pxvs;
 
-  pxvs = (XvScreenPtr) pScreen->devPrivates[XvScreenIndex].ptr;
+  pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XvScreenKey);
 
   pScreen->DestroyPixmap = pxvs->DestroyPixmap;
   pScreen->DestroyWindow = pxvs->DestroyWindow;
@@ -323,7 +311,7 @@ XvCloseScreen(
 
   xfree(pxvs);
 
-  pScreen->devPrivates[XvScreenIndex].ptr = (pointer)NULL;
+  dixSetPrivate(&pScreen->devPrivates, XvScreenKey, NULL);
 
   return (*pScreen->CloseScreen)(ii, pScreen);
 
@@ -334,10 +322,10 @@ XvResetProc(ExtensionEntry* extEntry)
 {
 }
 
-_X_EXPORT int
-XvGetScreenIndex(void)
+_X_EXPORT DevPrivateKey
+XvGetScreenKey(void)
 {
-  return XvScreenIndex;
+    return XvScreenKey;
 }
 
 _X_EXPORT unsigned long
@@ -361,7 +349,7 @@ XvDestroyPixmap(PixmapPtr pPix)
 
   SCREEN_PROLOGUE(pScreen, DestroyPixmap);
 
-  pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr;
+  pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XvScreenKey);
 
   /* CHECK TO SEE IF THIS PORT IS IN USE */
 
@@ -413,7 +401,7 @@ XvDestroyWindow(WindowPtr pWin)
 
   SCREEN_PROLOGUE(pScreen, DestroyWindow);
 
-  pxvs = (XvScreenPtr)pScreen->devPrivates[XvScreenIndex].ptr;
+  pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XvScreenKey);
 
   /* CHECK TO SEE IF THIS PORT IS IN USE */
 
diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index ae35893..7ae8cc0 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -39,7 +39,7 @@
 #define DR_CLIENT_DRIVER_NAME_SIZE 48
 #define DR_BUSID_SIZE 48
 
-int XvMCScreenIndex = -1;
+static DevPrivateKey XvMCScreenKey = NULL;
 
 unsigned long XvMCGeneration = 0;
 
@@ -63,7 +63,7 @@ typedef struct {
 } XvMCScreenRec, *XvMCScreenPtr; 
 
 #define XVMC_GET_PRIVATE(pScreen) \
-   (XvMCScreenPtr)((pScreen)->devPrivates[XvMCScreenIndex].ptr)
+    (XvMCScreenPtr)(dixLookupPrivate(&(pScreen)->devPrivates, XvMCScreenKey))
 
 
 static int
@@ -153,7 +153,7 @@ ProcXvMCListSurfaceTypes(ClientPtr client)
         return _XvBadPort;
     }
 
-    if(XvMCScreenIndex >= 0) { /* any adaptors at all */
+    if(XvMCScreenKey) { /* any adaptors at all */
        ScreenPtr pScreen = pPort->pAdaptor->pScreen;
        if((pScreenPriv = XVMC_GET_PRIVATE(pScreen))) {  /* any this screen */
           for(i = 0; i < pScreenPriv->num_adaptors; i++) {
@@ -211,7 +211,7 @@ ProcXvMCCreateContext(ClientPtr client)
 
     pScreen = pPort->pAdaptor->pScreen;
 
-    if(XvMCScreenIndex < 0) /* no XvMC adaptors */
+    if(XvMCScreenKey == NULL) /* no XvMC adaptors */
        return BadMatch;
  
     if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) /* none this screen */
@@ -494,7 +494,7 @@ ProcXvMCListSubpictureTypes(ClientPtr client)
 
     pScreen = pPort->pAdaptor->pScreen;
 
-    if(XvMCScreenIndex < 0) /* No XvMC adaptors */
+    if(XvMCScreenKey == NULL) /* No XvMC adaptors */
         return BadMatch;
 
     if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen)))
@@ -679,7 +679,7 @@ XvMCExtensionInit(void)
 {
    ExtensionEntry *extEntry;
 
-   if(XvMCScreenIndex < 0) /* nobody supports it */
+   if(XvMCScreenKey == NULL) /* nobody supports it */
 	return; 
 
    if(!(XvMCRTContext = CreateNewResourceType(XvMCDestroyContextRes)))
@@ -720,17 +720,12 @@ XvMCScreenInit(ScreenPtr pScreen, int num, XvMCAdaptorPtr pAdapt)
 {
    XvMCScreenPtr pScreenPriv;
 
-   if(XvMCGeneration != serverGeneration) {
-	if((XvMCScreenIndex = AllocateScreenPrivateIndex()) < 0)
-	   return BadAlloc;
-
-	XvMCGeneration = serverGeneration;
-   }
+   XvMCScreenKey = &XvMCScreenKey;
 
    if(!(pScreenPriv = (XvMCScreenPtr)xalloc(sizeof(XvMCScreenRec))))
 	return BadAlloc;
 
-   pScreen->devPrivates[XvMCScreenIndex].ptr = (pointer)pScreenPriv;
+   dixSetPrivate(&pScreen->devPrivates, XvMCScreenKey, pScreenPriv);
 
    pScreenPriv->CloseScreen = pScreen->CloseScreen;
    pScreen->CloseScreen = XvMCCloseScreen;
@@ -754,7 +749,7 @@ XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id)
     XvMCAdaptorPtr adaptor = NULL;
     int i;
 
-    if(XvMCScreenIndex < 0) return NULL;
+    if(XvMCScreenKey == NULL) return NULL;
 
     if(!(pScreenPriv = XVMC_GET_PRIVATE(pScreen))) 
         return NULL;
diff --git a/afb/afb.h b/afb/afb.h
index 31ccff9..5cfbddf 100644
--- a/afb/afb.h
+++ b/afb/afb.h
@@ -60,7 +60,6 @@ SOFTWARE.
 #include "mfb.h"
 
 extern int afbInverseAlu[];
-extern int afbScreenPrivateIndex;
 /* warning: PixelType definition duplicated in maskbits.h */
 #ifndef PixelType
 #define PixelType CARD32
@@ -736,14 +735,15 @@ typedef struct {
 } afbPrivGC;
 typedef afbPrivGC *afbPrivGCPtr;
 
-extern int afbGCPrivateIndex;			/* index into GC private array */
-extern int afbWindowPrivateIndex;		/* index into Window private array */
+extern DevPrivateKey afbScreenPrivateKey;
+extern DevPrivateKey afbGCPrivateKey;
+extern DevPrivateKey afbWindowPrivateKey;
 #ifdef PIXMAP_PER_WINDOW
-extern int frameWindowPrivateIndex;		/* index into Window private array */
+extern DevPrivateKey frameWindowPrivateKey;
 #endif
 
 #define afbGetGCPrivate(pGC) \
-	((afbPrivGC *)((pGC)->devPrivates[afbGCPrivateIndex].ptr))
+    ((afbPrivGC *)dixLookupPrivate(&(pGC)->devPrivates, afbGCPrivateKey))
 
 /* private field of window */
 typedef struct {
@@ -759,7 +759,7 @@ typedef struct {
 
 #define afbGetTypedWidth(pDrawable,wtype)( \
 	(((pDrawable)->type == DRAWABLE_WINDOW) ? \
-	 (int)(((PixmapPtr)((pDrawable)->pScreen->devPrivates[afbScreenPrivateIndex].ptr))->devKind) : \
+	 (int)(((PixmapPtr)dixLookupPrivate(&(pDrawable)->pScreen->devPrivates, afbScreenPrivateKey)->devKind) : \
 	 (int)(((PixmapPtr)pDrawable)->devKind)) / sizeof (wtype))
 
 #define afbGetByteWidth(pDrawable) afbGetTypedWidth(pDrawable, unsigned char)
@@ -769,7 +769,7 @@ typedef struct {
 #define afbGetTypedWidthAndPointer(pDrawable, width, pointer, wtype, ptype) {\
 	PixmapPtr   _pPix; \
 	if ((pDrawable)->type == DRAWABLE_WINDOW) \
-		_pPix = (PixmapPtr)(pDrawable)->pScreen->devPrivates[afbScreenPrivateIndex].ptr; \
+		_pPix = (PixmapPtr)dixLookupPrivate(&(pDrawable)->pScreen->devPrivates, afbScreenPrivateKey); \
 	else \
 		_pPix = (PixmapPtr)(pDrawable); \
 	(pointer) = (ptype *) _pPix->devPrivate.ptr; \
@@ -779,7 +779,7 @@ typedef struct {
 #define afbGetPixelWidthSizeDepthAndPointer(pDrawable, width, size, dep, pointer) {\
 	PixmapPtr _pPix; \
 	if ((pDrawable)->type == DRAWABLE_WINDOW) \
-		_pPix = (PixmapPtr)(pDrawable)->pScreen->devPrivates[afbScreenPrivateIndex].ptr; \
+		_pPix = (PixmapPtr)dixLookupPrivate(&(pDrawable)->pScreen->devPrivates, afbScreenPrivateKey); \
 	else \
 		_pPix = (PixmapPtr)(pDrawable); \
 	(pointer) = (PixelType *)_pPix->devPrivate.ptr; \
@@ -795,7 +795,7 @@ typedef struct {
 	afbGetTypedWidthAndPointer(pDrawable, width, pointer, PixelType, PixelType)
 
 #define afbGetWindowTypedWidthAndPointer(pWin, width, pointer, wtype, ptype) {\
-	PixmapPtr	_pPix = (PixmapPtr)(pWin)->drawable.pScreen->devPrivates[afbScreenPrivateIndex].ptr; \
+	PixmapPtr _pPix = (PixmapPtr)dixLookupPrivate(&(pWin)->drawable.pScreen->devPrivates, afbScreenPrivateKey); \
 	(pointer) = (ptype *) _pPix->devPrivate.ptr; \
 	(width) = ((int) _pPix->devKind) / sizeof (wtype); \
 }
diff --git a/afb/afbfillarc.c b/afb/afbfillarc.c
index fa685ba..cfc3133 100644
--- a/afb/afbfillarc.c
+++ b/afb/afbfillarc.c
@@ -321,7 +321,8 @@ afbPolyFillArcSolid(register DrawablePtr pDraw, GCPtr pGC, int narcs, xArc *parc
 	RegionPtr cclip;
 	unsigned char *rrops;
 
-	priv = (afbPrivGC *) pGC->devPrivates[afbGCPrivateIndex].ptr;
+	priv = (afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					     afbGCPrivateKey);
 	rrops = priv->rrops;
 	cclip = pGC->pCompositeClip;
 	for (arc = parcs, i = narcs; --i >= 0; arc++) {
diff --git a/afb/afbfillrct.c b/afb/afbfillrct.c
index 06fb373..b4936f0 100644
--- a/afb/afbfillrct.c
+++ b/afb/afbfillrct.c
@@ -93,7 +93,8 @@ afbPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrectFill, xRectangle *pre
 	unsigned char *rrops;
 	unsigned char *rropsOS;
 
-	priv = (afbPrivGC *)pGC->devPrivates[afbGCPrivateIndex].ptr;
+	priv = (afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					     afbGCPrivateKey);
 	prgnClip = pGC->pCompositeClip;
 	rrops = priv->rrops;
 	rropsOS = priv->rropOS;
diff --git a/afb/afbfillsp.c b/afb/afbfillsp.c
index 539c345..0118b47 100644
--- a/afb/afbfillsp.c
+++ b/afb/afbfillsp.c
@@ -123,7 +123,8 @@ afbSolidFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
 
 	afbGetPixelWidthSizeDepthAndPointer(pDrawable, nlwidth, sizeDst, depthDst,
 													 pBase);
-	rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
+	rrops = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       afbGCPrivateKey))->rrops;
 	while (n--) {
 		addrlBase = afbScanline(pBase, ppt->x, ppt->y, nlwidth);
 
@@ -238,8 +239,8 @@ afbStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
 	tileHeight = pStipple->drawable.height;
 	psrc = (PixelType *)(pStipple->devPrivate.ptr);
 
-	rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
-
+	rrops = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       afbGCPrivateKey))->rrops;
 	while (n--) {
 		src = psrc[ppt->y % tileHeight];
 		addrlBase = afbScanline(pBase, ppt->x, ppt->y, nlwidth);
@@ -484,8 +485,8 @@ afbOpaqueStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
 	tileHeight = pTile->drawable.height;
 	psrc = (PixelType *)(pTile->devPrivate.ptr);
 	rop = pGC->alu;
-	rropsOS = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rropOS;
-
+	rropsOS = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+						 afbGCPrivateKey))->rropOS;
 	switch(rop) {
 		case GXcopy:
 			while (n--) {
@@ -793,8 +794,8 @@ afbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
 
 	tileWidth = pTile->drawable.width;
 	tileHeight = pTile->drawable.height;
-	rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
-
+	rrops = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       afbGCPrivateKey))->rrops;
 	/* this replaces rotating the stipple.  Instead, we just adjust the offset
 	 * at which we start grabbing bits from the stipple.
 	 * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
diff --git a/afb/afbgc.c b/afb/afbgc.c
index 59c09e0..1d1fdc5 100644
--- a/afb/afbgc.c
+++ b/afb/afbgc.c
@@ -154,7 +154,8 @@ afbCreateGC(pGC)
 	/* afb wants to translate before scan convesion */
 	pGC->miTranslate = 1;
 
-	pPriv = (afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr);
+	pPriv = (afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					      afbGCPrivateKey);
 	afbReduceRop(pGC->alu, pGC->fgPixel, pGC->planemask, pGC->depth,
 		pPriv->rrops);
 	afbReduceOpaqueStipple(pGC->fgPixel, pGC->bgPixel, pGC->planemask,
@@ -295,8 +296,8 @@ afbValidateGC(pGC, changes, pDrawable)
 					 (oldOrg.y != pGC->lastWinOrg.y);
 
 
-	devPriv = ((afbPrivGCPtr)(pGC->devPrivates[afbGCPrivateIndex].ptr));
-
+	devPriv = (afbPrivGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						 afbGCPrivateKey);
 
 	/*
 		if the client clip is different or moved OR
diff --git a/afb/afbimggblt.c b/afb/afbimggblt.c
index de02aa4..824f918 100644
--- a/afb/afbimggblt.c
+++ b/afb/afbimggblt.c
@@ -145,8 +145,8 @@ afbImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
 	register int nFirst;/* bits of glyph in current longword */
 	PixelType *pdstSave;
 	int oldFill;
-	afbPrivGC *pPriv = (afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr);
-
+	afbPrivGC *pPriv = (afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+							 afbGCPrivateKey);
 	xorg = pDrawable->x;
 	yorg = pDrawable->y;
 	afbGetPixelWidthSizeDepthAndPointer(pDrawable, widthDst, sizeDst, depthDst,
diff --git a/afb/afbline.c b/afb/afbline.c
index 9e2e4b9..d056758 100644
--- a/afb/afbline.c
+++ b/afb/afbline.c
@@ -147,7 +147,8 @@ afbLineSS(pDrawable, pGC, mode, npt, pptInit)
 	RegionPtr cclip;
 
 	cclip = pGC->pCompositeClip;
-	rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
+	rrops = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       afbGCPrivateKey))->rrops;
 	pboxInit = REGION_RECTS(cclip);
 	nboxInit = REGION_NUM_RECTS(cclip);
 
@@ -487,7 +488,8 @@ afbLineSD(pDrawable, pGC, mode, npt, pptInit)
 #endif
 
 	cclip = pGC->pCompositeClip;
-	rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
+	rrops = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       afbGCPrivateKey))->rrops;
 	pboxInit = REGION_RECTS(cclip);
 	nboxInit = REGION_NUM_RECTS(cclip);
 
diff --git a/afb/afbpixmap.c b/afb/afbpixmap.c
index 5a81679..5ae50fb 100644
--- a/afb/afbpixmap.c
+++ b/afb/afbpixmap.c
@@ -113,7 +113,7 @@ afbDestroyPixmap(pPixmap)
 {
 	if(--pPixmap->refcnt)
 		return(TRUE);
-	dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+	dixFreePrivates(pPixmap->devPrivates);
 	xfree(pPixmap);
 	return(TRUE);
 }
diff --git a/afb/afbply1rct.c b/afb/afbply1rct.c
index 86ec174..e9d4d5e 100644
--- a/afb/afbply1rct.c
+++ b/afb/afbply1rct.c
@@ -100,8 +100,8 @@ afbFillPolygonSolid (pDrawable, pGC, shape, mode, count, ptsIn)
 	int depthDst;
 	register PixelType *pdst;
 
-	devPriv = (afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr);
-
+	devPriv = (afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+						afbGCPrivateKey);
 	if (mode == CoordModePrevious || shape != Convex ||
 		REGION_NUM_RECTS(pGC->pCompositeClip) != 1) {
 		miFillPolygon (pDrawable, pGC, shape, mode, count, ptsIn);
diff --git a/afb/afbplygblt.c b/afb/afbplygblt.c
index 289d50e..79b269b 100644
--- a/afb/afbplygblt.c
+++ b/afb/afbplygblt.c
@@ -146,8 +146,8 @@ afbPolyGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
 	bbox.y1 = y - info.overallAscent;
 	bbox.y2 = y + info.overallDescent;
 
-	rrops = ((afbPrivGCPtr) pGC->devPrivates[afbGCPrivateIndex].ptr)->rrops;
-
+	rrops = ((afbPrivGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						afbGCPrivateKey))->rrops;
 	switch (RECT_IN_REGION(pGC->pScreen, pGC->pCompositeClip, &bbox)) {
 		case rgnOUT:
 			break;
diff --git a/afb/afbpntwin.c b/afb/afbpntwin.c
index 6082f7c..89c4489 100644
--- a/afb/afbpntwin.c
+++ b/afb/afbpntwin.c
@@ -57,6 +57,7 @@ SOFTWARE.
 #include "regionstr.h"
 #include "pixmapstr.h"
 #include "scrnintstr.h"
+#include "privates.h"
 
 #include "afb.h"
 #include "maskbits.h"
@@ -71,7 +72,8 @@ afbPaintWindow(pWin, pRegion, what)
 	register afbPrivWin		*pPrivWin;
 	unsigned char rrops[AFB_MAX_DEPTH];
 
-	pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
+    pPrivWin = (afbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      afbWindowPrivateKey);
 
 	switch (what) {
 		case PW_BACKGROUND:
diff --git a/afb/afbpolypnt.c b/afb/afbpolypnt.c
index a9d96ed..b8ea3ed 100644
--- a/afb/afbpolypnt.c
+++ b/afb/afbpolypnt.c
@@ -90,8 +90,8 @@ afbPolyPoint(pDrawable, pGC, mode, npt, pptInit)
 	register unsigned char *rrops;
 	afbPrivGC *pGCPriv;
 
-	pGCPriv = (afbPrivGC *) pGC->devPrivates[afbGCPrivateIndex].ptr;
-
+	pGCPriv = (afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+						afbGCPrivateKey);
 	afbGetPixelWidthSizeDepthAndPointer(pDrawable, nlwidth, sizeDst, depthDst,
 													 pBaseSave);
 
diff --git a/afb/afbscrinit.c b/afb/afbscrinit.c
index 71e8d4c..8615d93 100644
--- a/afb/afbscrinit.c
+++ b/afb/afbscrinit.c
@@ -69,13 +69,11 @@ SOFTWARE.
 #include "servermd.h"
 
 #ifdef PIXMAP_PER_WINDOW
-int frameWindowPrivateIndex;
+DevPrivateKey frameWindowPrivateKey = &frameWindowPrivateKey;
 #endif
-int afbWindowPrivateIndex;
-int afbGCPrivateIndex;
-int afbScreenPrivateIndex;
-
-static unsigned long afbGeneration = 0;
+DevPrivateKey afbWindowPrivateKey = &afbWindowPrivateKey;
+DevPrivateKey afbGCPrivateKey = &afbGCPrivateKey;
+DevPrivateKey afbScreenPrivateKey = &afbScreenPrivateKey;
 
 static Bool
 afbCloseScreen(int index, ScreenPtr pScreen)
@@ -87,7 +85,7 @@ afbCloseScreen(int index, ScreenPtr pScreen)
 		xfree(depths[d].vids);
 	xfree(depths);
 	xfree(pScreen->visuals);
-	xfree(pScreen->devPrivates[afbScreenPrivateIndex].ptr);
+	xfree(dixLookupPrivate(&pScreen->devPrivates, afbScreenPrivateKey));
 	return(TRUE);
 }
 
@@ -98,7 +96,8 @@ afbCreateScreenResources(ScreenPtr pScreen)
 
 	pointer oldDevPrivate = pScreen->devPrivate;
 
-	pScreen->devPrivate = pScreen->devPrivates[afbScreenPrivateIndex].ptr;
+	pScreen->devPrivate = dixLookupPrivate(&pScreen->devPrivates,
+					       afbScreenPrivateKey);
 	retval = miCreateScreenResources(pScreen);
 
 	/* Modify screen's pixmap devKind value stored off devPrivate to
@@ -106,7 +105,8 @@ afbCreateScreenResources(ScreenPtr pScreen)
 	 * of a chunky screen in longs as incorrectly setup by the mi routine.
 	 */
 	((PixmapPtr)pScreen->devPrivate)->devKind = BitmapBytePad(pScreen->width);
-	pScreen->devPrivates[afbScreenPrivateIndex].ptr = pScreen->devPrivate;
+	dixSetPrivate(&pScreen->devPrivates, afbScreenPrivateKey,
+		      pScreen->devPrivate);
 	pScreen->devPrivate = oldDevPrivate;
 	return(retval);
 }
@@ -115,7 +115,8 @@ static PixmapPtr
 afbGetWindowPixmap(WindowPtr pWin)
 {
 #ifdef PIXMAP_PER_WINDOW
-    return (PixmapPtr)(pWin->devPrivates[frameWindowPrivateIndex].ptr);
+    return (PixmapPtr)dixLookupPrivate(&pWin->devPrivates,
+				       frameWindowPrivateKey);
 #else
     ScreenPtr pScreen = pWin->drawable.pScreen;
 
@@ -127,33 +128,25 @@ static void
 afbSetWindowPixmap(WindowPtr pWin, PixmapPtr pPix)
 {
 #ifdef PIXMAP_PER_WINDOW
-    pWin->devPrivates[frameWindowPrivateIndex].ptr = (pointer)pPix;
+    dixSetPrivate(&pWin->devPrivates, frameWindowPrivateKey, pPix);
 #else
     (* pWin->drawable.pScreen->SetScreenPixmap)(pPix);
 #endif
 }
 
 static Bool
-afbAllocatePrivates(ScreenPtr pScreen, int *pWinIndex, int *pGCIndex)
+afbAllocatePrivates(ScreenPtr pScreen,
+		    DevPrivateKey *pWinKey, DevPrivateKey *pGCKey)
 {
-	if (afbGeneration != serverGeneration) {
-#ifdef PIXMAP_PER_WINDOW
-		frameWindowPrivateIndex = AllocateWindowPrivateIndex();
-#endif
-		afbWindowPrivateIndex = AllocateWindowPrivateIndex();
-		afbGCPrivateIndex = AllocateGCPrivateIndex();
-		afbGeneration = serverGeneration;
-	}
-	if (pWinIndex)
-		*pWinIndex = afbWindowPrivateIndex;
-	if (pGCIndex)
-		*pGCIndex = afbGCPrivateIndex;
+	if (pWinKey)
+		*pWinKey = afbWindowPrivateKey;
+	if (pGCKey)
+		*pGCKey = afbGCPrivateKey;
 
-	afbScreenPrivateIndex = AllocateScreenPrivateIndex();
 	pScreen->GetWindowPixmap = afbGetWindowPixmap;
 	pScreen->SetWindowPixmap = afbSetWindowPixmap;
-	return(AllocateWindowPrivate(pScreen, afbWindowPrivateIndex, sizeof(afbPrivWin)) &&
-	       AllocateGCPrivate(pScreen, afbGCPrivateIndex, sizeof(afbPrivGC)));
+	return(dixRequestPrivate(afbWindowPrivateKey, sizeof(afbPrivWin)) &&
+	       dixRequestPrivate(afbGCPrivateKey, sizeof(afbPrivGC)));
 }
 
 /* dts * (inch/dot) * (25.4 mm / inch) = mm */
@@ -179,7 +172,7 @@ afbScreenInit(register ScreenPtr pScreen, pointer pbits, int xsize, int ysize, i
 		ErrorF("afbInitVisuals: FALSE\n");
 		return FALSE;
 	}
-	if (!afbAllocatePrivates(pScreen,(int *)NULL, (int *)NULL)) {
+	if (!afbAllocatePrivates(pScreen, NULL, NULL)) {
 		ErrorF("afbAllocatePrivates: FALSE\n");
 		return FALSE;
 	}
@@ -224,7 +217,8 @@ afbScreenInit(register ScreenPtr pScreen, pointer pbits, int xsize, int ysize, i
 	pScreen->CloseScreen = afbCloseScreen;
 	pScreen->CreateScreenResources = afbCreateScreenResources;
 
-	pScreen->devPrivates[afbScreenPrivateIndex].ptr = pScreen->devPrivate;
+	dixSetPrivate(&pScreen->devPrivates, afbScreenPrivateKey,
+		      pScreen->devPrivate);
 	pScreen->devPrivate = oldDevPrivate;
 
 	return TRUE;
diff --git a/afb/afbtegblt.c b/afb/afbtegblt.c
index ba889cb..c89b23a 100644
--- a/afb/afbtegblt.c
+++ b/afb/afbtegblt.c
@@ -261,8 +261,8 @@ afbTEGlyphBlt (pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
 	xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
 	ypos -= FONTASCENT(pfont);
 
-	rrops = ((afbPrivGCPtr) pGC->devPrivates[afbGCPrivateIndex].ptr)->rropOS;
-
+	rrops = ((afbPrivGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						afbGCPrivateKey))->rropOS;
 	bbox.x1 = xpos;
 	bbox.x2 = xpos + (widthGlyph * nglyph);
 	bbox.y1 = ypos;
diff --git a/afb/afbwindow.c b/afb/afbwindow.c
index a4a1602..1d99fe1 100644
--- a/afb/afbwindow.c
+++ b/afb/afbwindow.c
@@ -56,6 +56,7 @@ SOFTWARE.
 #include <X11/X.h>
 #include "scrnintstr.h"
 #include "windowstr.h"
+#include "privates.h"
 #include "afb.h"
 #include "mistruct.h"
 #include "regionstr.h"
@@ -67,14 +68,16 @@ afbCreateWindow(pWin)
 {
 	register afbPrivWin *pPrivWin;
 
-	pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
+	pPrivWin = (afbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+						  afbWindowPrivateKey);
 	pPrivWin->pRotatedBorder = NullPixmap;
 	pPrivWin->pRotatedBackground = NullPixmap;
 	pPrivWin->fastBackground = FALSE;
 	pPrivWin->fastBorder = FALSE;
 #ifdef PIXMAP_PER_WINDOW
-	pWin->devPrivates[frameWindowPrivateIndex].ptr =
-			pWin->pDrawable.pScreen->devPrivates[afbScreenPrivateIndex].ptr;
+	dixSetPrivate(&pWin->devPrivates, frameWindowPrivateKey,
+		      dixLookupPrivate(&pWin->pDrawable.pScreen->devPrivates,
+				       afbScreenPrivateKey));
 #endif
 
 	return (TRUE);
@@ -88,8 +91,8 @@ afbDestroyWindow(pWin)
 {
 	register afbPrivWin *pPrivWin;
 
-	pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
-
+    pPrivWin = (afbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      afbWindowPrivateKey);
 	if (pPrivWin->pRotatedBorder)
 		(*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
 	if (pPrivWin->pRotatedBackground)
@@ -123,7 +126,8 @@ afbPositionWindow(pWin, x, y)
 	register afbPrivWin *pPrivWin;
 	int		reset = 0;
 
-	pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
+    pPrivWin = (afbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      afbWindowPrivateKey);
 	if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground) {
 		afbXRotatePixmap(pPrivWin->pRotatedBackground,
 								pWin->drawable.x - pPrivWin->oldRotate.x);
@@ -230,7 +234,8 @@ afbChangeWindowAttributes(pWin, mask)
 	register afbPrivWin *pPrivWin;
 	WindowPtr		pBgWin;
 
-	pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
+    pPrivWin = (afbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      afbWindowPrivateKey);
 	/*
 	 * When background state changes from ParentRelative and
 	 * we had previously rotated the fast border pixmap to match
diff --git a/afb/afbzerarc.c b/afb/afbzerarc.c
index 2cc3068..e53488e 100644
--- a/afb/afbzerarc.c
+++ b/afb/afbzerarc.c
@@ -96,8 +96,8 @@ afbZeroArcSS(DrawablePtr pDraw, GCPtr pGC, xArc *arc)
 	register PixelType *paddr;
 	register unsigned char *rrops;
 
-	rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
-
+	rrops = ((afbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       afbGCPrivateKey))->rrops;
 	afbGetPixelWidthSizeDepthAndPointer(pDraw, nlwidth, sizeDst, depthDst,
 													 addrl);
 	do360 = miZeroArcSetup(arc, &info, TRUE);
diff --git a/cfb/cfb.h b/cfb/cfb.h
index 3c165ff..44d4ad0 100644
--- a/cfb/cfb.h
+++ b/cfb/cfb.h
@@ -56,8 +56,8 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
    pixmap.devKind = width_of_pixmap_in_bytes
 */
 
-extern int  cfbGCPrivateIndex;
-extern int  cfbWindowPrivateIndex;
+extern DevPrivateKey cfbGCPrivateKey;
+extern DevPrivateKey cfbWindowPrivateKey;
 
 /* private field of GC */
 typedef struct {
@@ -72,7 +72,7 @@ typedef struct {
 typedef cfbPrivGC	*cfbPrivGCPtr;
 
 #define cfbGetGCPrivate(pGC)	((cfbPrivGCPtr)\
-	(pGC)->devPrivates[cfbGCPrivateIndex].ptr)
+    dixLookupPrivate(&(pGC)->devPrivates, cfbGCPrivateKey))
 
 #define cfbGetCompositeClip(pGC) ((pGC)->pCompositeClip)
 
@@ -93,7 +93,7 @@ typedef struct {
     } cfbPrivWin;
 
 #define cfbGetWindowPrivate(_pWin) ((cfbPrivWin *)\
-	(_pWin)->devPrivates[cfbWindowPrivateIndex].ptr)
+    dixLookupPrivate(&(_pWin)->devPrivates, cfbWindowPrivateKey))
 
 
 /* cfb8bit.c */
@@ -314,8 +314,8 @@ extern int cfb8SegmentSS1RectXor(
 
 extern Bool cfbAllocatePrivates(
     ScreenPtr /*pScreen*/,
-    int * /*window_index*/,
-    int * /*gc_index*/
+    DevPrivateKey * /*window_key*/,
+    DevPrivateKey * /*gc_key*/
 );
 /* cfbbitblt.c */
 
@@ -1230,7 +1230,7 @@ extern void cfbZeroPolyArcSS8Xor(
 
 #define CFB_NEED_SCREEN_PRIVATE
 
-extern int cfbScreenPrivateIndex;
+extern DevPrivateKey cfbScreenPrivateKey;
 #endif
 
 #ifndef CFB_PROTOTYPES_ONLY
diff --git a/cfb/cfballpriv.c b/cfb/cfballpriv.c
index e0ccdf4..e6ab93a 100644
--- a/cfb/cfballpriv.c
+++ b/cfb/cfballpriv.c
@@ -45,48 +45,37 @@ in this Software without prior written authorization from The Open Group.
 #include "mibstore.h"
 
 #if 1 || PSZ==8
-int cfbWindowPrivateIndex = -1;
-int cfbGCPrivateIndex = -1;
+DevPrivateKey cfbWindowPrivateKey = &cfbWindowPrivateKey;
+DevPrivateKey cfbGCPrivateKey = &cfbGCPrivateKey;
 #endif
 #ifdef CFB_NEED_SCREEN_PRIVATE
-int cfbScreenPrivateIndex = -1;
-static unsigned long cfbGeneration = 0;
+DevPrivateKey cfbScreenPrivateKey = &cfbScreenPrivateKey;
 #endif
 
 
 Bool
-cfbAllocatePrivates(pScreen, window_index, gc_index)
+cfbAllocatePrivates(pScreen, window_key, gc_key)
     ScreenPtr	pScreen;
-    int		*window_index, *gc_index;
+    DevPrivateKey *window_key, *gc_key;
 {
-    if (!window_index || !gc_index ||
-	(*window_index == -1 && *gc_index == -1))
+    if (!window_key || !gc_key || (!*window_key && !*gc_key))
     {
     	if (!mfbAllocatePrivates(pScreen,
-			     	 &cfbWindowPrivateIndex, &cfbGCPrivateIndex))
+			     	 &cfbWindowPrivateKey, &cfbGCPrivateKey))
 	    return FALSE;
-    	if (window_index)
-	    *window_index = cfbWindowPrivateIndex;
-    	if (gc_index)
-	    *gc_index = cfbGCPrivateIndex;
+    	if (window_key)
+	    *window_key = cfbWindowPrivateKey;
+    	if (gc_key)
+	    *gc_key = cfbGCPrivateKey;
     }
     else
     {
-	cfbWindowPrivateIndex = *window_index;
-	cfbGCPrivateIndex = *gc_index;
+	cfbWindowPrivateKey = *window_key;
+	cfbGCPrivateKey = *gc_key;
     }
-    if (!AllocateWindowPrivate(pScreen, cfbWindowPrivateIndex,
-			       sizeof(cfbPrivWin)) ||
-	!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
+    if (!dixRequestPrivate(cfbWindowPrivateKey, sizeof(cfbPrivWin)))
 	return FALSE;
-#ifdef CFB_NEED_SCREEN_PRIVATE
-    if (cfbGeneration != serverGeneration)
-    {
-      cfbScreenPrivateIndex = AllocateScreenPrivateIndex ();
-      cfbGeneration = serverGeneration;
-    }
-    if (cfbScreenPrivateIndex == -1)
+    if (!dixRequestPrivate(cfbGCPrivateKey, sizeof(cfbPrivGC)))
 	return FALSE;
-#endif
     return TRUE;
 }
diff --git a/cfb/cfbpixmap.c b/cfb/cfbpixmap.c
index ed01316..247331c 100644
--- a/cfb/cfbpixmap.c
+++ b/cfb/cfbpixmap.c
@@ -107,7 +107,7 @@ cfbDestroyPixmap(pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
-    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+    dixFreePrivates(pPixmap->devPrivates);
     xfree(pPixmap);
     return TRUE;
 }
diff --git a/cfb/cfbrrop.h b/cfb/cfbrrop.h
index eeb373a..e9ca881 100644
--- a/cfb/cfbrrop.h
+++ b/cfb/cfbrrop.h
@@ -35,7 +35,8 @@ in this Software without prior written authorization from The Open Group.
 #endif
 
 #define RROP_FETCH_GC(gc) \
-    RROP_FETCH_GCPRIV(((cfbPrivGCPtr)(gc)->devPrivates[cfbGCPrivateIndex].ptr))
+    RROP_FETCH_GCPRIV((cfbPrivGCPtr)dixLookupPrivate(&(gc)->devPrivates, \
+						     cfbGCPrivateKey))
 
 #ifndef RROP
 #define RROP GXset
diff --git a/cfb/cfbscrinit.c b/cfb/cfbscrinit.c
index 83f5cf0..48e3639 100644
--- a/cfb/cfbscrinit.c
+++ b/cfb/cfbscrinit.c
@@ -59,7 +59,7 @@ cfbCloseScreen (index, pScreen)
     xfree (depths);
     xfree (pScreen->visuals);
 #ifdef CFB_NEED_SCREEN_PRIVATE
-    xfree (pScreen->devPrivates[cfbScreenPrivateIndex].ptr);
+    xfree (dixLookupPrivate(&pScreen->devPrivates, cfbScreenPrivateKey));
 #else
     xfree (pScreen->devPrivate);
 #endif
@@ -88,7 +88,7 @@ cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
     int dpix, dpiy;		/* dots per inch */
     int width;			/* pixel width of frame buffer */
 {
-    if (!cfbAllocatePrivates(pScreen, (int *) 0, (int *) 0))
+    if (!cfbAllocatePrivates(pScreen, NULL, NULL))
 	return FALSE;
     pScreen->defColormap = FakeClientID(0);
     /* let CreateDefColormap do whatever it wants for pixels */ 
@@ -132,9 +132,11 @@ cfbCreateScreenResources(pScreen)
     Bool retval;
 
     pointer oldDevPrivate = pScreen->devPrivate;
-    pScreen->devPrivate = pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
+    pScreen->devPrivate = dixLookupPrivate(&pScreen->devPrivates,
+					   cfbScreenPrivateKey);
     retval = miCreateScreenResources(pScreen);
-    pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
+    dixSetPrivate(&pScreen->devPrivates, cfbScreenPrivateKey,
+		  pScreen->devPrivate);
     pScreen->devPrivate = oldDevPrivate;
     return retval;
 }
@@ -173,7 +175,8 @@ cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
     pScreen->CloseScreen = cfbCloseScreen;
 #ifdef CFB_NEED_SCREEN_PRIVATE
     pScreen->CreateScreenResources = cfbCreateScreenResources;
-    pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
+    dixSetPrivate(&pScreen->devPrivates, cfbScreenPrivateKey,
+		  pScreen->devPrivate);
     pScreen->devPrivate = oldDevPrivate;
 #endif
     pScreen->GetScreenPixmap = cfbGetScreenPixmap;
@@ -200,7 +203,8 @@ cfbGetScreenPixmap(pScreen)
     ScreenPtr pScreen;
 {
 #ifdef CFB_NEED_SCREEN_PRIVATE
-    return (PixmapPtr)pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
+    return (PixmapPtr)dixLookupPrivate(&pScreen->devPrivates,
+				       cfbScreenPrivateKey);
 #else
     return (PixmapPtr)pScreen->devPrivate;
 #endif
@@ -212,8 +216,8 @@ cfbSetScreenPixmap(pPix)
 {
 #ifdef CFB_NEED_SCREEN_PRIVATE
     if (pPix)
-	pPix->drawable.pScreen->devPrivates[cfbScreenPrivateIndex].ptr =
-	    (pointer)pPix;
+	dixSetPrivate(&pPix->drawable.pScreen->devPrivates,
+		      cfbScreenPrivateKey, pPix);
 #else
     if (pPix)
 	pPix->drawable.pScreen->devPrivate = (pointer)pPix;
diff --git a/cfb/cfbwindow.c b/cfb/cfbwindow.c
index e04b73d..49cc6f0 100644
--- a/cfb/cfbwindow.c
+++ b/cfb/cfbwindow.c
@@ -75,8 +75,8 @@ cfbCreateWindow(pWin)
 
 #ifdef PIXMAP_PER_WINDOW
     /* Setup pointer to Screen pixmap */
-    pWin->devPrivates[frameWindowPrivateIndex].ptr =
-	(pointer) cfbGetScreenPixmap(pWin->drawable.pScreen);
+    dixSetPrivate(&pWin->devPrivates, frameWindowPrivateKey,
+		  cfbGetScreenPixmap(pWin->drawable.pScreen));
 #endif
 
     return TRUE;
@@ -213,7 +213,7 @@ cfbCopyWindow(pWin, ptOldOrg, prgnSrc)
 
 /* swap in correct PaintWindow* routine.  If we can use a fast output
 routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
-of it in devPrivates[cfbWindowPrivateIndex].ptr.
+of it in devPrivates under cfbWindowPrivateKey.
 */
 Bool
 cfbChangeWindowAttributes(pWin, mask)
diff --git a/composite/compalloc.c b/composite/compalloc.c
index f555411..dbb7f3a 100644
--- a/composite/compalloc.c
+++ b/composite/compalloc.c
@@ -137,7 +137,7 @@ compRedirectWindow (ClientPtr pClient, WindowPtr pWin, int update)
 	cw->oldy = COMP_ORIGIN_INVALID;
 	cw->damageRegistered = FALSE;
 	cw->damaged = FALSE;
-	pWin->devPrivates[CompWindowPrivateIndex].ptr = cw;
+	dixSetPrivate(&pWin->devPrivates, CompWindowPrivateKey, cw);
     }
     ccw->next = cw->clients;
     cw->clients = ccw;
@@ -212,7 +212,7 @@ compFreeClientWindow (WindowPtr pWin, XID id)
 	
 	REGION_UNINIT (pScreen, &cw->borderClip);
     
-	pWin->devPrivates[CompWindowPrivateIndex].ptr = 0;
+	dixSetPrivate(&pWin->devPrivates, CompWindowPrivateKey, NULL);
 	xfree (cw);
     }
     else if (cw->update == CompositeRedirectAutomatic &&
@@ -297,7 +297,7 @@ compRedirectSubwindows (ClientPtr pClient, WindowPtr pWin, int update)
 	}
 	csw->update = CompositeRedirectAutomatic;
 	csw->clients = 0;
-	pWin->devPrivates[CompSubwindowsPrivateIndex].ptr = csw;
+	dixSetPrivate(&pWin->devPrivates, CompSubwindowsPrivateKey, csw);
     }
     /*
      * Redirect all existing windows
@@ -312,7 +312,7 @@ compRedirectSubwindows (ClientPtr pClient, WindowPtr pWin, int update)
 	    if (!csw->clients)
 	    {
 		xfree (csw);
-		pWin->devPrivates[CompSubwindowsPrivateIndex].ptr = 0;
+		dixSetPrivate(&pWin->devPrivates, CompSubwindowsPrivateKey, 0);
 	    }
 	    xfree (ccw);
 	    return ret;
@@ -385,7 +385,7 @@ compFreeClientSubwindows (WindowPtr pWin, XID id)
      */
     if (!csw->clients)
     {
-	pWin->devPrivates[CompSubwindowsPrivateIndex].ptr = 0;
+	dixSetPrivate(&pWin->devPrivates, CompSubwindowsPrivateKey, NULL);
 	xfree (csw);
     }
 }
diff --git a/composite/compext.c b/composite/compext.c
index 944f8d8..8d2a2d7 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -50,7 +50,7 @@
 #define SERVER_COMPOSITE_MINOR	4
 
 static CARD8	CompositeReqCode;
-static int	CompositeClientPrivateIndex;
+static DevPrivateKey CompositeClientPrivateKey = &CompositeClientPrivateKey;
 RESTYPE		CompositeClientWindowType;
 RESTYPE		CompositeClientSubwindowsType;
 static RESTYPE	CompositeClientOverlayType;
@@ -63,7 +63,8 @@ typedef struct _CompositeClient {
     int	    minor_version;
 } CompositeClientRec, *CompositeClientPtr;
 
-#define GetCompositeClient(pClient)    ((CompositeClientPtr) (pClient)->devPrivates[CompositeClientPrivateIndex].ptr)
+#define GetCompositeClient(pClient) ((CompositeClientPtr) \
+    dixLookupPrivate(&(pClient)->devPrivates, CompositeClientPrivateKey))
 
 static void
 CompositeClientCallback (CallbackListPtr	*list,
@@ -712,9 +713,8 @@ CompositeExtensionInit (void)
     if (!CompositeClientOverlayType)
 	return;
 
-    CompositeClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (CompositeClientPrivateIndex, 
-				sizeof (CompositeClientRec)))
+    if (!dixRequestPrivate(CompositeClientPrivateKey,
+			   sizeof(CompositeClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, CompositeClientCallback, 0))
 	return;
diff --git a/composite/compinit.c b/composite/compinit.c
index c557eeb..757d929 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -46,10 +46,9 @@
 
 #include "compint.h"
 
-int	CompScreenPrivateIndex;
-int	CompWindowPrivateIndex;
-int	CompSubwindowsPrivateIndex;
-static int	CompGeneration;
+DevPrivateKey CompScreenPrivateKey = &CompScreenPrivateKey;
+DevPrivateKey CompWindowPrivateKey = &CompWindowPrivateKey;
+DevPrivateKey CompSubwindowsPrivateKey = &CompSubwindowsPrivateKey;
 
 
 static Bool
@@ -87,7 +86,7 @@ compCloseScreen (int index, ScreenPtr pScreen)
     cs->pOverlayWin = NULL;
 
     xfree (cs);
-    pScreen->devPrivates[CompScreenPrivateIndex].ptr = 0;
+    dixSetPrivate(&pScreen->devPrivates, CompScreenPrivateKey, NULL);
     ret = (*pScreen->CloseScreen) (index, pScreen);
 
     return ret;
@@ -375,25 +374,6 @@ compScreenInit (ScreenPtr pScreen)
 {
     CompScreenPtr   cs;
 
-    if (CompGeneration != serverGeneration)
-    {
-	CompScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (CompScreenPrivateIndex == -1)
-	    return FALSE;
-	CompWindowPrivateIndex = AllocateWindowPrivateIndex ();
-	if (CompWindowPrivateIndex == -1)
-	    return FALSE;
-	CompSubwindowsPrivateIndex = AllocateWindowPrivateIndex ();
-	if (CompSubwindowsPrivateIndex == -1)
-	    return FALSE;
-	CompGeneration = serverGeneration;
-    }
-    if (!AllocateWindowPrivate (pScreen, CompWindowPrivateIndex, 0))
-	return FALSE;
-
-    if (!AllocateWindowPrivate (pScreen, CompSubwindowsPrivateIndex, 0))
-	return FALSE;
-
     if (GetCompScreen (pScreen))
 	return TRUE;
     cs = (CompScreenPtr) xalloc (sizeof (CompScreenRec));
@@ -461,7 +441,7 @@ compScreenInit (ScreenPtr pScreen)
     cs->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = compCloseScreen;
 
-    pScreen->devPrivates[CompScreenPrivateIndex].ptr = (pointer) cs;
+    dixSetPrivate(&pScreen->devPrivates, CompScreenPrivateKey, cs);
 
     RegisterRealChildHeadProc(CompositeRealChildHead);
 
diff --git a/composite/compint.h b/composite/compint.h
index 38b1777..79699e4 100644
--- a/composite/compint.h
+++ b/composite/compint.h
@@ -64,6 +64,7 @@
 #include "globals.h"
 #include "picturestr.h"
 #include "extnsionst.h"
+#include "privates.h"
 #include "mi.h"
 #include "damage.h"
 #include "damageextint.h"
@@ -159,13 +160,16 @@ typedef struct _CompScreen {
     
 } CompScreenRec, *CompScreenPtr;
 
-extern int  CompScreenPrivateIndex;
-extern int  CompWindowPrivateIndex;
-extern int  CompSubwindowsPrivateIndex;
+extern DevPrivateKey CompScreenPrivateKey;
+extern DevPrivateKey CompWindowPrivateKey;
+extern DevPrivateKey CompSubwindowsPrivateKey;
 
-#define GetCompScreen(s) ((CompScreenPtr) ((s)->devPrivates[CompScreenPrivateIndex].ptr))
-#define GetCompWindow(w) ((CompWindowPtr) ((w)->devPrivates[CompWindowPrivateIndex].ptr))
-#define GetCompSubwindows(w) ((CompSubwindowsPtr) ((w)->devPrivates[CompSubwindowsPrivateIndex].ptr))
+#define GetCompScreen(s) ((CompScreenPtr) \
+    dixLookupPrivate(&(s)->devPrivates, CompScreenPrivateKey))
+#define GetCompWindow(w) ((CompWindowPtr) \
+    dixLookupPrivate(&(w)->devPrivates, CompWindowPrivateKey))
+#define GetCompSubwindows(w) ((CompSubwindowsPtr) \
+    dixLookupPrivate(&(w)->devPrivates, CompSubwindowsPrivateKey))
 
 extern RESTYPE		CompositeClientWindowType;
 extern RESTYPE		CompositeClientSubwindowsType;
diff --git a/configure.ac b/configure.ac
index 8ed2ef8..43bc357 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1027,7 +1027,6 @@ AC_DEFINE(XTEST, 1, [Support XTest extension])
 AC_DEFINE(XSYNC, 1, [Support XSync extension])
 AC_DEFINE(XCMISC, 1, [Support XCMisc extension])
 AC_DEFINE(BIGREQS, 1, [Support BigRequests extension])
-AC_DEFINE(PIXPRIV, 1, [Support pixmap privates])
 
 if test "x$WDTRACE" != "xno" ; then
   DIX_LIB='$(top_builddir)/dix/dix.O'
diff --git a/damageext/damageext.c b/damageext/damageext.c
index e1724ec..1597465 100755
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -29,7 +29,7 @@
 static unsigned char	DamageReqCode;
 static int		DamageEventBase;
 static int		DamageErrorBase;
-static int		DamageClientPrivateIndex;
+static DevPrivateKey	DamageClientPrivateKey = &DamageClientPrivateKey;
 static RESTYPE		DamageExtType;
 static RESTYPE		DamageExtWinType;
 
@@ -511,9 +511,7 @@ DamageExtensionInit(void)
     if (!DamageExtWinType)
 	return;
 
-    DamageClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (DamageClientPrivateIndex, 
-				sizeof (DamageClientRec)))
+    if (!dixRequestPrivate(DamageClientPrivateKey, sizeof (DamageClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, DamageClientCallback, 0))
 	return;
diff --git a/damageext/damageextint.h b/damageext/damageextint.h
index dfafc93..e06f28c 100644
--- a/damageext/damageextint.h
+++ b/damageext/damageextint.h
@@ -48,7 +48,7 @@ typedef struct _DamageClient {
     int		critical;
 } DamageClientRec, *DamageClientPtr;
 
-#define GetDamageClient(pClient)    ((DamageClientPtr) (pClient)->devPrivates[DamageClientPrivateIndex].ptr)
+#define GetDamageClient(pClient) ((DamageClientPtr)dixLookupPrivate(&(pClient)->devPrivates, DamageClientPrivateKey))
 
 typedef struct _DamageExt {
     DamagePtr		pDamage;
diff --git a/dbe/dbe.c b/dbe/dbe.c
index aec626b..223b0c9 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -58,19 +58,16 @@
 /* GLOBALS */
 
 /* Per-screen initialization functions [init'ed by DbeRegisterFunction()] */
-static Bool	(* DbeInitFunct[MAXSCREENS])();	/* pScreen, pDbeScreenPriv */
+static Bool (* DbeInitFunct[MAXSCREENS])();	/* pScreen, pDbeScreenPriv */
 
 /* These are static globals copied to DBE's screen private for use by DDX */
-static int	dbeScreenPrivIndex;
-static int	dbeWindowPrivIndex;
+static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKey;
+static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKey;
 
 /* These are static globals copied to DBE's screen private for use by DDX */
 static RESTYPE	dbeDrawableResType;
 static RESTYPE	dbeWindowPrivResType;
 
-/* This global is used by DbeAllocWinPrivPrivIndex() */
-static int	winPrivPrivCount = 0;
-
 /* Used to generate DBE's BadBuffer error. */
 static int	dbeErrorBase;
 
@@ -115,146 +112,6 @@ DbeRegisterFunction(ScreenPtr pScreen, Bool (*funct) (/* ??? */))
 
 /******************************************************************************
  *
- * DBE DIX Procedure: DbeAllocWinPriv
- *
- * Description:
- *
- *     This function was cloned from AllocateWindow() in window.c.
- *     This function allocates a window priv structure to be associated 
- *     with a double-buffered window.
- *
- *****************************************************************************/
-static DbeWindowPrivPtr
-DbeAllocWinPriv(ScreenPtr pScreen)
-{
-    DbeWindowPrivPtr		pDbeWindowPriv;
-    DbeScreenPrivPtr		pDbeScreenPriv;
-    register char		*ptr;
-    register DevUnion		*ppriv;
-    register unsigned int	*sizes;
-    register unsigned int	size;
-    register int		i;
-
-    pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
-    pDbeWindowPriv = (DbeWindowPrivPtr)xalloc(pDbeScreenPriv->totalWinPrivSize);
-
-    if (pDbeWindowPriv)
-    {
-        ppriv = (DevUnion *)(pDbeWindowPriv + 1);
-        pDbeWindowPriv->devPrivates = ppriv;
-        sizes = pDbeScreenPriv->winPrivPrivSizes;
-        ptr = (char *)(ppriv + pDbeScreenPriv->winPrivPrivLen);
-        for (i = pDbeScreenPriv->winPrivPrivLen; --i >= 0; ppriv++, sizes++)
-        {
-            if ((size = *sizes))
-            {
-                ppriv->ptr = (pointer)ptr;
-                ptr += size;
-            }
-            else
-                ppriv->ptr = (pointer)NULL;
-        }
-    }
-
-    return(pDbeWindowPriv);
-
-} /* DbeAllocWinPriv() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeFallbackAllocWinPriv
- *
- * Description:
- *
- *     This is a fallback function for AllocWinPriv().
- *
- *****************************************************************************/
-
-#if 0 /* NOT USED */
-static DbeWindowPrivPtr
-DbeFallbackAllocWinPriv(pScreen)
-    ScreenPtr	pScreen;
-{
-    return (NULL);
-} /* DbeFallbackAllocWinPriv() */
-#endif
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeAllocWinPrivPrivIndex
- *
- * Description:
- *
- *     This function was cloned from AllocateWindowPrivateIndex() in window.c.
- *     This function allocates a new window priv priv index by simply returning
- *     an incremented private counter.
- *
- *****************************************************************************/
-
-static int
-DbeAllocWinPrivPrivIndex(void)
-{
-    return winPrivPrivCount++;
-
-} /* DbeAllocWinPrivPrivIndex() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeAllocWinPrivPriv
- *
- * Description:
- *
- *     This function was cloned from AllocateWindowPrivate() in privates.c.
- *     This function allocates a private structure to be hung off
- *     a window private.
- *
- *****************************************************************************/
-
-static Bool
-DbeAllocWinPrivPriv(register ScreenPtr pScreen, int index, unsigned int amount)
-{
-    DbeScreenPrivPtr	pDbeScreenPriv;
-    unsigned int	oldamount;
-
-
-    pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
-
-    if (index >= pDbeScreenPriv->winPrivPrivLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *)xrealloc(pDbeScreenPriv->winPrivPrivSizes,
-				      (index + 1) * sizeof(unsigned));
-	if (!nsizes)
-        {
-	    return(FALSE);
-        }
-
-	while (pDbeScreenPriv->winPrivPrivLen <= index)
-	{
-	    nsizes[pDbeScreenPriv->winPrivPrivLen++] = 0;
-	    pDbeScreenPriv->totalWinPrivSize += sizeof(DevUnion);
-	}
-
-	pDbeScreenPriv->winPrivPrivSizes = nsizes;
-    }
-
-    oldamount = pDbeScreenPriv->winPrivPrivSizes[index];
-
-    if (amount > oldamount)
-    {
-	pDbeScreenPriv->winPrivPrivSizes[index] = amount;
-	pDbeScreenPriv->totalWinPrivSize += (amount - oldamount);
-    }
-    return(TRUE);
-
-} /* DbeAllocWinPrivPriv() */
-
-
-/******************************************************************************
- *
  * DBE DIX Procedure: DbeStubScreen
  *
  * Description:
@@ -269,9 +126,6 @@ DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens)
 {
     /* Stub DIX. */
     pDbeScreenPriv->SetupBackgroundPainter = NULL;
-    pDbeScreenPriv->AllocWinPriv           = NULL;
-    pDbeScreenPriv->AllocWinPrivPrivIndex  = NULL;
-    pDbeScreenPriv->AllocWinPrivPriv       = NULL;
 
     /* Do not unwrap PositionWindow nor DestroyWindow.  If the DDX
      * initialization function failed, we assume that it did not wrap
@@ -439,11 +293,10 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
          * Allocate a window priv.
          */
 
-        if (!(pDbeWindowPriv =
-            (*pDbeScreenPriv->AllocWinPriv)(pWin->drawable.pScreen)))
-        {
+        pDbeWindowPriv = (DbeWindowPrivPtr)xalloc(sizeof(DbeWindowPrivRec));
+	if (!pDbeWindowPriv)
             return(BadAlloc);
-        }
+	bzero(pDbeWindowPriv, sizeof(DbeWindowPrivRec));
 
         /* Make the window priv a DBE window priv resource. */
         if (!AddResource(stuff->buffer, dbeWindowPrivResType,
@@ -474,7 +327,7 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
 
 
         /* Actually connect the window priv to the window. */
-        pWin->devPrivates[dbeWindowPrivIndex].ptr = (pointer)pDbeWindowPriv;
+	dixSetPrivate(&pWin->devPrivates, dbeWindowPrivKey, pDbeWindowPriv);
 
     } /* if -- There is no buffer associated with the window. */
 
@@ -1592,10 +1445,11 @@ DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
     if (pDbeWindowPriv->nBufferIDs == 0)
     {
         /* Reset the DBE window priv pointer. */
-        pDbeWindowPriv->pWindow->devPrivates[dbeWindowPrivIndex].ptr =
-            (pointer)NULL;
+	dixSetPrivate(&pDbeWindowPriv->pWindow->devPrivates, dbeWindowPrivKey,
+		      NULL);
 
         /* We are done with the window priv. */
+	dixFreePrivates(pDbeWindowPriv->devPrivates);
         xfree(pDbeWindowPriv);
     }
 
@@ -1622,12 +1476,6 @@ DbeResetProc(ExtensionEntry *extEntry)
     ScreenPtr		pScreen;
     DbeScreenPrivPtr	pDbeScreenPriv;
     
-
-    if (dbeScreenPrivIndex < 0)
-    {
-	return;
-    }
-
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	pScreen = screenInfo.screens[i];
@@ -1641,11 +1489,7 @@ DbeResetProc(ExtensionEntry *extEntry)
 	    if (pDbeScreenPriv->ResetProc)
 		(*pDbeScreenPriv->ResetProc)(pScreen);
 
-            if (pDbeScreenPriv->winPrivPrivSizes)
-            {
-	        xfree(pDbeScreenPriv->winPrivPrivSizes);
-            }
-
+	    dixFreePrivates(pDbeScreenPriv->devPrivates);
 	    xfree(pDbeScreenPriv);
 	}
     }
@@ -1766,21 +1610,6 @@ DbeExtensionInit(void)
     if(!noPanoramiXExtension) return;
 #endif
 
-    /* Allocate private pointers in windows and screens. */
-
-    if ((dbeScreenPrivIndex = AllocateScreenPrivateIndex()) < 0)
-    {
-	return;
-    }
-
-    if ((dbeWindowPrivIndex = AllocateWindowPrivateIndex()) < 0)
-    {
-	return;
-    }
-
-    /* Initialize the priv priv counts between server generations. */
-    winPrivPrivCount  = 0;
-
     /* Create the resource types. */
     dbeDrawableResType =
         CreateNewResourceType(DbeDrawableDelete) | RC_DRAWABLE;
@@ -1795,8 +1624,7 @@ DbeExtensionInit(void)
 
 	pScreen = screenInfo.screens[i];
 
-	if (!AllocateWindowPrivate(pScreen, dbeWindowPrivIndex, 0) ||
-	    !(pDbeScreenPriv =
+	if (!(pDbeScreenPriv =
              (DbeScreenPrivPtr)Xcalloc(sizeof(DbeScreenPrivRec))))
 	{
             /* If we can not alloc a window or screen private,
@@ -1805,28 +1633,23 @@ DbeExtensionInit(void)
 
 	    for (j = 0; j < i; j++)
 	    {
-	      xfree(screenInfo.screens[j]->devPrivates[dbeScreenPrivIndex].ptr);
-              screenInfo.screens[j]->devPrivates[dbeScreenPrivIndex].ptr = NULL;
+		xfree(dixLookupPrivate(&screenInfo.screens[j]->devPrivates,
+				       dbeScreenPrivKey));
+		dixSetPrivate(&screenInfo.screens[j]->devPrivates,
+			      dbeScreenPrivKey, NULL);
 	    }
 	    return;
 	}
 
-	pScreen->devPrivates[dbeScreenPrivIndex].ptr = (pointer)pDbeScreenPriv;
-
-        /* Store the DBE priv priv size info for later use when allocating
-         * priv privs at the driver level.
-         */
-        pDbeScreenPriv->winPrivPrivLen   = 0;
-        pDbeScreenPriv->winPrivPrivSizes = (unsigned *)NULL;
-        pDbeScreenPriv->totalWinPrivSize = sizeof(DbeWindowPrivRec);
+	dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, pDbeScreenPriv);
 
         /* Copy the resource types */
         pDbeScreenPriv->dbeDrawableResType   = dbeDrawableResType;
         pDbeScreenPriv->dbeWindowPrivResType = dbeWindowPrivResType;
 
         /* Copy the private indices */
-        pDbeScreenPriv->dbeScreenPrivIndex = dbeScreenPrivIndex;
-        pDbeScreenPriv->dbeWindowPrivIndex = dbeWindowPrivIndex;
+        pDbeScreenPriv->dbeScreenPrivKey = dbeScreenPrivKey;
+        pDbeScreenPriv->dbeWindowPrivKey = dbeWindowPrivKey;
 
         if(DbeInitFunct[i])
         {
@@ -1834,9 +1657,6 @@ DbeExtensionInit(void)
 
             /* Setup DIX. */
             pDbeScreenPriv->SetupBackgroundPainter = DbeSetupBackgroundPainter; 
-            pDbeScreenPriv->AllocWinPriv           = DbeAllocWinPriv;
-            pDbeScreenPriv->AllocWinPrivPrivIndex  = DbeAllocWinPrivPrivIndex;
-            pDbeScreenPriv->AllocWinPrivPriv       = DbeAllocWinPrivPriv;
 
             /* Setup DDX. */
             ddxInitSuccess = (*DbeInitFunct[i])(pScreen, pDbeScreenPriv);
@@ -1868,9 +1688,6 @@ DbeExtensionInit(void)
 #ifndef DISABLE_MI_DBE_BY_DEFAULT
             /* Setup DIX. */
             pDbeScreenPriv->SetupBackgroundPainter = DbeSetupBackgroundPainter; 
-            pDbeScreenPriv->AllocWinPriv           = DbeAllocWinPriv;
-            pDbeScreenPriv->AllocWinPrivPrivIndex  = DbeAllocWinPrivPrivIndex;
-            pDbeScreenPriv->AllocWinPrivPriv       = DbeAllocWinPrivPriv;
 
             /* Setup DDX. */
             ddxInitSuccess = miDbeInit(pScreen, pDbeScreenPriv);
@@ -1909,8 +1726,9 @@ DbeExtensionInit(void)
 
         for (i = 0; i < screenInfo.numScreens; i++)
         {
-             xfree(screenInfo.screens[i]->devPrivates[dbeScreenPrivIndex].ptr);
-             pScreen->devPrivates[dbeScreenPrivIndex].ptr = NULL;
+		xfree(dixLookupPrivate(&screenInfo.screens[i]->devPrivates,
+				       dbeScreenPrivKey));
+		dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, NULL);
         }
         return;
     }
diff --git a/dbe/dbestruct.h b/dbe/dbestruct.h
index 90f1342..7d5a115 100644
--- a/dbe/dbestruct.h
+++ b/dbe/dbestruct.h
@@ -39,14 +39,13 @@
 #define NEED_DBE_PROTOCOL
 #include <X11/extensions/Xdbeproto.h>
 #include "windowstr.h"
+#include "privates.h"
 
 
 /* DEFINES */
 
-#define DBE_SCREEN_PRIV(pScreen) \
-    ((dbeScreenPrivIndex < 0) ? \
-     NULL : \
-     ((DbeScreenPrivPtr)((pScreen)->devPrivates[dbeScreenPrivIndex].ptr)))
+#define DBE_SCREEN_PRIV(pScreen) ((DbeScreenPrivPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, dbeScreenPrivKey))
 
 #define DBE_SCREEN_PRIV_FROM_DRAWABLE(pDrawable) \
     DBE_SCREEN_PRIV((pDrawable)->pScreen)
@@ -63,10 +62,8 @@
 #define DBE_SCREEN_PRIV_FROM_GC(pGC)\
     DBE_SCREEN_PRIV((pGC)->pScreen)
 
-#define DBE_WINDOW_PRIV(pWindow)\
-    ((dbeWindowPrivIndex < 0) ? \
-     NULL : \
-     ((DbeWindowPrivPtr)(pWindow->devPrivates[dbeWindowPrivIndex].ptr)))
+#define DBE_WINDOW_PRIV(pWin) ((DbeWindowPrivPtr) \
+    dixLookupPrivate(&(pWin)->devPrivates, dbeWindowPrivKey))
 
 /* Initial size of the buffer ID array in the window priv. */
 #define DBE_INIT_MAX_IDS	2
@@ -142,7 +139,7 @@ typedef struct _DbeWindowPrivRec
 
     /* Device-specific private information.
      */
-    DevUnion		*devPrivates;
+    PrivateRec		*devPrivates;
 
 } DbeWindowPrivRec, *DbeWindowPrivPtr;
 
@@ -155,18 +152,13 @@ typedef struct _DbeWindowPrivRec
 
 typedef struct _DbeScreenPrivRec
 {
-    /* Info for creating window privs */
-    int          winPrivPrivLen;    /* Length of privs in DbeWindowPrivRec   */
-    unsigned int *winPrivPrivSizes; /* Array of private record sizes         */
-    unsigned int totalWinPrivSize;  /* PrivRec + size of all priv priv ptrs  */
-
     /* Resources created by DIX to be used by DDX */
     RESTYPE	dbeDrawableResType;
     RESTYPE	dbeWindowPrivResType;
 
     /* Private indices created by DIX to be used by DDX */
-    int		dbeScreenPrivIndex;
-    int		dbeWindowPrivIndex;
+    DevPrivateKey dbeScreenPrivKey;
+    DevPrivateKey dbeWindowPrivKey;
 
     /* Wrapped functions
      * It is the responsibilty of the DDX layer to wrap PositionWindow().
@@ -180,17 +172,6 @@ typedef struct _DbeScreenPrivRec
 		WindowPtr /*pWin*/,
 		GCPtr /*pGC*/
 );
-    DbeWindowPrivPtr (*AllocWinPriv)(
-		ScreenPtr /*pScreen*/
-);
-    int		(*AllocWinPrivPrivIndex)(
-		void
-);
-    Bool	(*AllocWinPrivPriv)(
-		ScreenPtr /*pScreen*/,
-		int /*index*/,
-		unsigned /*amount*/
-);
 
     /* Per-screen DDX routines */
     Bool	(*GetVisualInfo)(
@@ -223,7 +204,7 @@ typedef struct _DbeScreenPrivRec
 
     /* Device-specific private information.
      */
-    DevUnion	*devPrivates;
+    PrivateRec	*devPrivates;
 
 } DbeScreenPrivRec, *DbeScreenPrivPtr;
 
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 014e365..f26a09c 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -59,12 +59,11 @@
 
 #include <stdio.h>
 
-static int	miDbePrivPrivGeneration  =  0;
-static int	miDbeWindowPrivPrivIndex = -1;
+static DevPrivateKey miDbeWindowPrivPrivKey = &miDbeWindowPrivPrivKey;
 static RESTYPE	dbeDrawableResType;
 static RESTYPE	dbeWindowPrivResType;
-static int	dbeScreenPrivIndex = -1;
-static int	dbeWindowPrivIndex = -1;
+static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKey;
+static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKey;
 
 
 /******************************************************************************
@@ -204,8 +203,8 @@ miDbeAllocBackBufferName(WindowPtr pWin, XID bufId, int swapAction)
 
 
         /* Attach the priv priv to the priv. */
-	pDbeWindowPriv->devPrivates[miDbeWindowPrivPrivIndex].ptr =
-            (pointer)pDbeWindowPrivPriv;
+	dixSetPrivate(&pDbeWindowPriv->devPrivates, miDbeWindowPrivPrivKey,
+		      pDbeWindowPrivPriv);
 
 
         /* Clear the back buffer. */
@@ -778,30 +777,12 @@ miDbeInit(ScreenPtr pScreen, DbeScreenPrivPtr pDbeScreenPriv)
     dbeWindowPrivResType = pDbeScreenPriv->dbeWindowPrivResType;
 
     /* Copy private indices created by DIX */
-    dbeScreenPrivIndex = pDbeScreenPriv->dbeScreenPrivIndex;
-    dbeWindowPrivIndex = pDbeScreenPriv->dbeWindowPrivIndex;
+    dbeScreenPrivKey = pDbeScreenPriv->dbeScreenPrivKey;
+    dbeWindowPrivKey = pDbeScreenPriv->dbeWindowPrivKey;
 
-    /* Reset the window priv privs if generations do not match. */
-    if (miDbePrivPrivGeneration != serverGeneration)
-    {
-        /*
-         **********************************************************************
-         ** Allocate the window priv priv.
-         **********************************************************************
-         */
-
-        miDbeWindowPrivPrivIndex = (*pDbeScreenPriv->AllocWinPrivPrivIndex)();
-
-        /* Make sure we only do this code once. */
-	miDbePrivPrivGeneration = serverGeneration;
-
-    } /* if -- Reset priv privs. */
-
-    if (!(*pDbeScreenPriv->AllocWinPrivPriv)(pScreen,
-        miDbeWindowPrivPrivIndex, sizeof(MiDbeWindowPrivPrivRec)))
-    {
+    if (!dixRequestPrivate(miDbeWindowPrivPrivKey,
+			   sizeof(MiDbeWindowPrivPrivRec)))
         return(FALSE);
-    }
 
     /* Wrap functions. */
     pDbeScreenPriv->PositionWindow = pScreen->PositionWindow;
diff --git a/dbe/midbestr.h b/dbe/midbestr.h
index 1ad0104..ae9f206 100644
--- a/dbe/midbestr.h
+++ b/dbe/midbestr.h
@@ -42,19 +42,15 @@
 /* DEFINES */
 
 #define MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv) \
-    (((miDbeWindowPrivPrivIndex < 0) || (!pDbeWindowPriv)) ? \
-    NULL : \
-    ((MiDbeWindowPrivPrivPtr) \
-     ((pDbeWindowPriv)->devPrivates[miDbeWindowPrivPrivIndex].ptr)))
+    (!(pDbeWindowPriv) ? NULL : (MiDbeWindowPrivPrivPtr) \
+     dixLookupPrivate(&(pDbeWindowPriv)->devPrivates, miDbeWindowPrivPrivKey))
 
 #define MI_DBE_WINDOW_PRIV_PRIV_FROM_WINDOW(pWin)\
     MI_DBE_WINDOW_PRIV_PRIV(DBE_WINDOW_PRIV(pWin))
 
 #define MI_DBE_SCREEN_PRIV_PRIV(pDbeScreenPriv) \
-    (((miDbeScreenPrivPrivIndex < 0) || (!pDbeScreenPriv)) ? \
-    NULL : \
-    ((MiDbeScreenPrivPrivPtr) \
-     ((pDbeScreenPriv)->devPrivates[miDbeScreenPrivPrivIndex].ptr)))
+    (!(pDbeScreenPriv) ? NULL : (MiDbeScreenPrivPrivPtr) \
+     dixLookupPrivate(&(pDbeScreenPriv)->devPrivates, miDbeScreenPrivPrivKey))
 
 
 /* TYPEDEFS */
diff --git a/dix/colormap.c b/dix/colormap.c
index 7d6e7da..98f2f1b 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -67,7 +67,6 @@ SOFTWARE.
 #include "xace.h"
 
 extern XID clientErrorValue;
-extern int colormapPrivateCount;
 
 static Pixel FindBestPixel(
     EntryPtr /*pentFirst*/,
@@ -388,30 +387,11 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	    pmap->numPixelsBlue[client] = size;
 	}
     }
-    if (!AddResource(mid, RT_COLORMAP, (pointer)pmap))
-	return (BadAlloc);
-    /* If the device wants a chance to initialize the colormap in any way,
-     * this is it.  In specific, if this is a Static colormap, this is the
-     * time to fill in the colormap's values */
+    pmap->devPrivates = NULL;
     pmap->flags |= BeingCreated;
 
-
-    /*
-     * Allocate the array of devPrivate's for this colormap.
-     */
-
-    if (colormapPrivateCount == 0)
-	pmap->devPrivates = NULL;
-    else
-    {
-	pmap->devPrivates = (DevUnion *) xcalloc (
-	    sizeof(DevUnion), colormapPrivateCount);
-	if (!pmap->devPrivates)
-	{
-	    FreeResource (mid, RT_NONE);
-	    return BadAlloc;
-	}
-    }
+    if (!AddResource(mid, RT_COLORMAP, (pointer)pmap))
+	return (BadAlloc);
 
     /*  
      * Security creation/labeling check
@@ -423,6 +403,9 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	return i;
     }
 
+    /* If the device wants a chance to initialize the colormap in any way,
+     * this is it.  In specific, if this is a Static colormap, this is the
+     * time to fill in the colormap's values */
     if (!(*pScreen->CreateColormap)(pmap))
     {
 	FreeResource (mid, RT_NONE);
@@ -486,10 +469,7 @@ FreeColormap (pointer value, XID mid)
         }
     }
 
-    dixFreePrivates(*DEVPRIV_PTR(pmap));
-    if (pmap->devPrivates)
-	xfree(pmap->devPrivates);
-
+    dixFreePrivates(pmap->devPrivates);
     xfree(pmap);
     return(Success);
 }
diff --git a/dix/devices.c b/dix/devices.c
index 4ddfa63..a62ab65 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -85,8 +85,7 @@ SOFTWARE.
  * This file handles input device-related stuff.
  */
 
-int CoreDevicePrivatesIndex = 0;
-static int CoreDevicePrivatesGeneration = -1;
+DevPrivateKey CoreDevicePrivateKey = &CoreDevicePrivateKey;
 
 /**
  * Create a new input device and init it to sane values. The device is added
@@ -151,14 +150,7 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
     dev->xkb_interest = NULL;
 #endif
     dev->config_info = NULL;
-    /* must pre-allocate one private for the new devPrivates support */
-    dev->nPrivates = 1;
-    dev->devPrivates = (DevUnion *)xcalloc(1, sizeof(DevUnion));
-    if (!dev->devPrivates) {
-	xfree(dev);
-	return NULL;
-    }
-
+    dev->devPrivates = NULL;
     dev->unwrapProc = NULL;
     dev->coreEvents = TRUE;
     dev->inited = FALSE;
@@ -358,7 +350,7 @@ CoreKeyboardProc(DeviceIntPtr pDev, int what)
         break;
 
     case DEVICE_CLOSE:
-        pDev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
+	dixSetPrivate(&pDev->devPrivates, CoreDevicePrivateKey, NULL);
         break;
 
     default:
@@ -390,7 +382,7 @@ CorePointerProc(DeviceIntPtr pDev, int what)
         break;
 
     case DEVICE_CLOSE:
-        pDev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
+	dixSetPrivate(&pDev->devPrivates, CoreDevicePrivateKey, NULL);
         break;
 
     default:
@@ -411,11 +403,6 @@ InitCoreDevices(void)
 {
     DeviceIntPtr dev;
 
-    if (CoreDevicePrivatesGeneration != serverGeneration) {
-        CoreDevicePrivatesIndex = AllocateDevicePrivateIndex();
-        CoreDevicePrivatesGeneration = serverGeneration;
-    }
-
     if (!inputInfo.keyboard) {
         dev = AddInputDevice(CoreKeyboardProc, TRUE);
         if (!dev)
@@ -433,9 +420,6 @@ InitCoreDevices(void)
         dev->ActivateGrab = ActivateKeyboardGrab;
         dev->DeactivateGrab = DeactivateKeyboardGrab;
         dev->coreEvents = FALSE;
-        if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
-            FatalError("Couldn't allocate keyboard devPrivates\n");
-        dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
         (void)ActivateDevice(dev);
         inputInfo.keyboard = dev;
     }
@@ -457,9 +441,6 @@ InitCoreDevices(void)
         dev->ActivateGrab = ActivatePointerGrab;
         dev->DeactivateGrab = DeactivatePointerGrab;
         dev->coreEvents = FALSE;
-        if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
-            FatalError("Couldn't allocate pointer devPrivates\n");
-        dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
         (void)ActivateDevice(dev);
         inputInfo.pointer = dev;
     }
@@ -609,11 +590,8 @@ CloseDevice(DeviceIntPtr dev)
 	XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
 #endif
 
-    dixFreePrivates(*DEVPRIV_PTR(dev));
-    if (dev->devPrivates)
-	xfree(dev->devPrivates);
-
     xfree(dev->sync.event);
+    dixFreePrivates(dev->devPrivates);
     xfree(dev);
 }
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index bb30619..1ad3c94 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3692,7 +3692,7 @@ CloseDownClient(ClientPtr client)
 #ifdef SMART_SCHEDULE
 	SmartLastClient = NullClient;
 #endif
-	dixFreePrivates(*DEVPRIV_PTR(client));
+	dixFreePrivates(client->devPrivates);
 	xfree(client);
 
 	while (!clients[currentMaxClients-1])
@@ -3712,10 +3712,6 @@ KillAllClients(void)
         }
 }
 
-extern int clientPrivateLen;
-extern unsigned *clientPrivateSizes;
-extern unsigned totalClientSize;
-
 void InitClient(ClientPtr client, int i, pointer ospriv)
 {
     client->index = i;
@@ -3735,6 +3731,7 @@ void InitClient(ClientPtr client, int i, pointer ospriv)
     client->big_requests = FALSE;
     client->priority = 0;
     client->clientState = ClientStateInitial;
+    client->devPrivates = NULL;
 #ifdef XKB
     if (!noXkbExtension) {
 	client->xkbClientFlags = 0;
@@ -3755,54 +3752,6 @@ void InitClient(ClientPtr client, int i, pointer ospriv)
 #endif
 }
 
-int
-InitClientPrivates(ClientPtr client)
-{
-    char *ptr;
-    DevUnion *ppriv;
-    unsigned *sizes;
-    unsigned size;
-    int i;
-
-    if (totalClientSize == sizeof(ClientRec))
-	ppriv = (DevUnion *)NULL;
-    else if (client->index)
-	ppriv = (DevUnion *)(client + 1);
-    else
-    {
-	ppriv = (DevUnion *)xalloc(totalClientSize - sizeof(ClientRec));
-	if (!ppriv)
-	    return 0;
-    }
-    client->devPrivates = ppriv;
-    sizes = clientPrivateSizes;
-    ptr = (char *)(ppriv + clientPrivateLen);
-    if (ppriv)
-	bzero(ppriv, totalClientSize - sizeof(ClientRec));
-    for (i = clientPrivateLen; --i >= 0; ppriv++, sizes++)
-    {
-	if ( (size = *sizes) )
-	{
-	    ppriv->ptr = (pointer)ptr;
-	    ptr += size;
-	}
-	else
-	    ppriv->ptr = (pointer)NULL;
-    }
-
-    /* Allow registrants to initialize the serverClient devPrivates */
-    if (!client->index && ClientStateCallback)
-    {
-	NewClientInfoRec clientinfo;
-
-	clientinfo.client = client; 
-	clientinfo.prefix = (xConnSetupPrefix *)NULL;  
-	clientinfo.setup = (xConnSetup *) NULL;
-	CallCallbacks((&ClientStateCallback), (pointer)&clientinfo);
-    } 
-    return 1;
-}
-
 /************************
  * int NextAvailableClient(ospriv)
  *
@@ -3819,11 +3768,10 @@ ClientPtr NextAvailableClient(pointer ospriv)
     i = nextFreeClientID;
     if (i == MAXCLIENTS)
 	return (ClientPtr)NULL;
-    clients[i] = client = (ClientPtr)xalloc(totalClientSize);
+    clients[i] = client = (ClientPtr)xalloc(sizeof(ClientRec));
     if (!client)
 	return (ClientPtr)NULL;
     InitClient(client, i, ospriv);
-    InitClientPrivates(client);
     if (!InitClientResources(client))
     {
 	xfree(client);
diff --git a/dix/extension.c b/dix/extension.c
index ec47ef1..c81c1a1 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -73,39 +73,6 @@ int lastEvent = EXTENSION_EVENT_BASE;
 static int lastError = FirstExtensionError;
 static unsigned int NumExtensions = 0;
 
-extern int extensionPrivateLen;
-extern unsigned *extensionPrivateSizes;
-extern unsigned totalExtensionSize;
-
-static void
-InitExtensionPrivates(ExtensionEntry *ext)
-{
-    char *ptr;
-    DevUnion *ppriv;
-    unsigned *sizes;
-    unsigned size;
-    int i;
-
-    if (totalExtensionSize == sizeof(ExtensionEntry))
-	ppriv = (DevUnion *)NULL;
-    else
-	ppriv = (DevUnion *)(ext + 1);
-
-    ext->devPrivates = ppriv;
-    sizes = extensionPrivateSizes;
-    ptr = (char *)(ppriv + extensionPrivateLen);
-    for (i = extensionPrivateLen; --i >= 0; ppriv++, sizes++)
-    {
-	if ( (size = *sizes) )
-	{
-	    ppriv->ptr = (pointer)ptr;
-	    ptr += size;
-	}
-	else
-	    ppriv->ptr = (pointer)NULL;
-    }
-}
-
 _X_EXPORT ExtensionEntry *
 AddExtension(char *name, int NumEvents, int NumErrors, 
 	     int (*MainProc)(ClientPtr c1), 
@@ -122,14 +89,13 @@ AddExtension(char *name, int NumEvents, int NumErrors,
 	        (unsigned)(lastError + NumErrors > LAST_ERROR))
         return((ExtensionEntry *) NULL);
 
-    ext = (ExtensionEntry *) xalloc(totalExtensionSize);
+    ext = (ExtensionEntry *) xalloc(sizeof(ExtensionEntry));
     if (!ext)
 	return((ExtensionEntry *) NULL);
-    bzero(ext, totalExtensionSize);
-    InitExtensionPrivates(ext);
     ext->name = (char *)xalloc(strlen(name) + 1);
     ext->num_aliases = 0;
     ext->aliases = (char **)NULL;
+    ext->devPrivates = NULL;
     if (!ext->name)
     {
 	xfree(ext);
@@ -283,7 +249,7 @@ CloseDownExtensions(void)
 	for (j = extensions[i]->num_aliases; --j >= 0;)
 	    xfree(extensions[i]->aliases[j]);
 	xfree(extensions[i]->aliases);
-	dixFreePrivates(*DEVPRIV_PTR(extensions[i]));
+	dixFreePrivates(extensions[i]->devPrivates);
 	xfree(extensions[i]);
     }
     xfree(extensions);
diff --git a/dix/gc.c b/dix/gc.c
index ccd586b..d77932c 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -573,45 +573,13 @@ BUG:
    should check for failure to create default tile
 
 */
-
-static GCPtr
-AllocateGC(ScreenPtr pScreen)
-{
-    GCPtr pGC;
-    char *ptr;
-    DevUnion *ppriv;
-    unsigned *sizes;
-    unsigned size;
-    int i;
-
-    pGC = (GCPtr)xalloc(pScreen->totalGCSize);
-    if (pGC)
-    {
-	ppriv = (DevUnion *)(pGC + 1);
-	pGC->devPrivates = ppriv;
-	sizes = pScreen->GCPrivateSizes;
-	ptr = (char *)(ppriv + pScreen->GCPrivateLen);
-	for (i = pScreen->GCPrivateLen; --i >= 0; ppriv++, sizes++)
-	{
-	    if ( (size = *sizes) )
-	    {
-		ppriv->ptr = (pointer)ptr;
-		ptr += size;
-	    }
-	    else
-		ppriv->ptr = (pointer)NULL;
-	}
-    }
-    return pGC;
-}
-
 _X_EXPORT GCPtr
 CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
 	 XID gcid, ClientPtr client)
 {
     GCPtr pGC;
 
-    pGC = AllocateGC(pDrawable->pScreen);
+    pGC = (GCPtr)xalloc(sizeof(GC));
     if (!pGC)
     {
 	*pStatus = BadAlloc;
@@ -624,7 +592,7 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
     pGC->planemask = ~0;
     pGC->serialNumber = GC_CHANGE_SERIAL_BIT;
     pGC->funcs = 0;
-
+    pGC->devPrivates = NULL;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
     pGC->lineWidth = 0;
@@ -918,7 +886,7 @@ FreeGC(pointer value, XID gid)
     (*pGC->funcs->DestroyGC) (pGC);
     if (pGC->dash != DefaultDash)
 	xfree(pGC->dash);
-    dixFreePrivates(*DEVPRIV_PTR(pGC));
+    dixFreePrivates(pGC->devPrivates);
     xfree(pGC);
     return(Success);
 }
@@ -941,7 +909,7 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
 {
     GCPtr pGC;
 
-    pGC = AllocateGC(pScreen);
+    pGC = (GCPtr)xalloc(sizeof(GC));
     if (!pGC)
 	return (GCPtr)NULL;
 
@@ -950,7 +918,7 @@ CreateScratchGC(ScreenPtr pScreen, unsigned depth)
     pGC->alu = GXcopy; /* dst <- src */
     pGC->planemask = ~0;
     pGC->serialNumber = 0;
-
+    pGC->devPrivates = NULL;
     pGC->fgPixel = 0;
     pGC->bgPixel = 1;
     pGC->lineWidth = 0;
diff --git a/dix/getevents.c b/dix/getevents.c
index 6899303..a12bcfd 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -725,7 +725,8 @@ SwitchCoreKeyboard(DeviceIntPtr pDev)
     KeyClassPtr ckeyc = inputInfo.keyboard->key;
     int i = 0;
 
-    if (inputInfo.keyboard->devPrivates[CoreDevicePrivatesIndex].ptr != pDev) {
+    if (pDev != dixLookupPrivate(&inputInfo.keyboard->devPrivates,
+				 CoreDevicePrivateKey)) {
         memcpy(ckeyc->modifierMap, pDev->key->modifierMap, MAP_LENGTH);
         if (ckeyc->modifierKeyMap)
             xfree(ckeyc->modifierKeyMap);
@@ -769,7 +770,8 @@ SwitchCoreKeyboard(DeviceIntPtr pDev)
                           (ckeyc->curKeySyms.maxKeyCode -
                            ckeyc->curKeySyms.minKeyCode),
                           serverClient);
-        inputInfo.keyboard->devPrivates[CoreDevicePrivatesIndex].ptr = pDev;
+	dixSetPrivate(&inputInfo.keyboard->devPrivates, CoreDevicePrivateKey,
+		      pDev);
     }
 }
 
@@ -783,8 +785,10 @@ SwitchCoreKeyboard(DeviceIntPtr pDev)
 _X_EXPORT void
 SwitchCorePointer(DeviceIntPtr pDev)
 {
-    if (inputInfo.pointer->devPrivates[CoreDevicePrivatesIndex].ptr != pDev)
-        inputInfo.pointer->devPrivates[CoreDevicePrivatesIndex].ptr = pDev;
+    if (pDev != dixLookupPrivate(&inputInfo.pointer->devPrivates,
+				 CoreDevicePrivateKey))
+	dixSetPrivate(&inputInfo.pointer->devPrivates,
+		      CoreDevicePrivateKey, pDev);
 }
 
 
diff --git a/dix/main.c b/dix/main.c
index 3e5d0e4..7f7bfa5 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -118,15 +118,12 @@ Equipment Corporation.
 #include "dpmsproc.h"
 #endif
 
-extern int InitClientPrivates(ClientPtr client);
-
 extern void Dispatch(void);
 
 char *ConnectionInfo;
 xConnSetupPrefix connSetupPrefix;
 
 extern FontPtr defaultFont;
-extern int screenPrivateCount;
 
 extern void InitProcVectors(void);
 extern Bool CreateGCperDepthArray(void);
@@ -136,8 +133,6 @@ static
 #endif
 Bool CreateConnectionBlock(void);
 
-static void FreeScreen(ScreenPtr);
-
 _X_EXPORT PaddingInfo PixmapWidthPaddingInfo[33];
 
 int connBlockScreenStart;
@@ -372,8 +367,6 @@ main(int argc, char *argv[], char *envp[])
 	if (screenInfo.numVideoScreens < 0)
 	    screenInfo.numVideoScreens = screenInfo.numScreens;
 	InitExtensions(argc, argv);
-	if (!InitClientPrivates(serverClient))
-	    FatalError("failed to allocate serverClient devprivates");
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
 	    ScreenPtr pScreen = screenInfo.screens[i];
@@ -472,7 +465,8 @@ main(int argc, char *argv[], char *envp[])
 	    FreeGCperDepth(i);
 	    FreeDefaultStipple(i);
 	    (* screenInfo.screens[i]->CloseScreen)(i, screenInfo.screens[i]);
-	    FreeScreen(screenInfo.screens[i]);
+	    dixFreePrivates(screenInfo.screens[i]->devPrivates);
+	    xfree(screenInfo.screens[i]);
 	    screenInfo.numScreens = i;
 	}
   	CloseDownEvents();
@@ -482,8 +476,7 @@ main(int argc, char *argv[], char *envp[])
 
 	FreeAuditTimer();
 
-	dixFreePrivates(*DEVPRIV_PTR(serverClient));
-	xfree(serverClient->devPrivates);
+	dixFreePrivates(serverClient->devPrivates);
 	serverClient->devPrivates = NULL;
 
 	if (dispatchException & DE_TERMINATE)
@@ -695,32 +688,9 @@ AddScreen(
     if (!pScreen)
 	return -1;
 
-    pScreen->devPrivates = (DevUnion *)xcalloc(sizeof(DevUnion),
-						screenPrivateCount);
-    if (!pScreen->devPrivates && screenPrivateCount)
-    {
-	xfree(pScreen);
-	return -1;
-    }
-
-    /* must pre-allocate one private for the new devPrivates support */
-    pScreen->WindowPrivateLen = 1;
-    pScreen->WindowPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
-    pScreen->totalWindowSize = PadToLong(sizeof(WindowRec)) + sizeof(DevUnion);
-    pScreen->GCPrivateLen = 1;
-    pScreen->GCPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
-    pScreen->totalGCSize = PadToLong(sizeof(GC)) + sizeof(DevUnion);
-    pScreen->PixmapPrivateLen = 1;
-    pScreen->PixmapPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
-    pScreen->totalPixmapSize = BitmapBytePad(8 * (sizeof(PixmapRec) +
-						  sizeof(DevUnion)));
-    if (!pScreen->WindowPrivateSizes || !pScreen->GCPrivateSizes ||
-	!pScreen->PixmapPrivateSizes) {
-	xfree(pScreen);
-	return -1;
-    }
-
+    pScreen->devPrivates = NULL;
     pScreen->myNum = i;
+    pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
     
@@ -772,20 +742,10 @@ AddScreen(
     screenInfo.numScreens++;
     if (!(*pfnInit)(i, pScreen, argc, argv))
     {
-	FreeScreen(pScreen);
+	dixFreePrivates(pScreen->devPrivates);
+	xfree(pScreen);
 	screenInfo.numScreens--;
 	return -1;
     }
     return i;
 }
-
-static void
-FreeScreen(ScreenPtr pScreen)
-{
-    xfree(pScreen->WindowPrivateSizes);
-    xfree(pScreen->GCPrivateSizes);
-    xfree(pScreen->PixmapPrivateSizes);
-    dixFreePrivates(*DEVPRIV_PTR(pScreen));
-    xfree(pScreen->devPrivates);
-    xfree(pScreen);
-}
diff --git a/dix/pixmap.c b/dix/pixmap.c
index c280a3b..6096cc6 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -109,11 +109,6 @@ _X_EXPORT PixmapPtr
 AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
 {
     PixmapPtr pPixmap;
-    char *ptr;
-    DevUnion *ppriv;
-    unsigned *sizes;
-    unsigned size;
-    int i;
 
     if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
 	return NullPixmap;
@@ -121,27 +116,7 @@ AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
     pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize);
     if (!pPixmap)
 	return NullPixmap;
-    ppriv = (DevUnion *)(pPixmap + 1);
-    pPixmap->devPrivates = ppriv;
-    sizes = pScreen->PixmapPrivateSizes;
-    ptr = (char *)(ppriv + pScreen->PixmapPrivateLen);
-    for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++)
-    {
-        if ((size = *sizes) != 0)
-        {
-	    ppriv->ptr = (pointer)ptr;
-	    ptr += size;
-        }
-        else
-	    ppriv->ptr = (pointer)NULL;
-    }
-
-#ifdef _XSERVER64
-    if (pPixmap) {
-	pPixmap->drawable.pad0 = 0;
-	pPixmap->drawable.pad1 = 0;
-    }
-#endif
 
+    pPixmap->devPrivates = NULL;
     return pPixmap;
 }
diff --git a/dix/privates.c b/dix/privates.c
index 4dbba43..38c5523 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -30,21 +30,13 @@ from The Open Group.
 #include <dix-config.h>
 #endif
 
-#include <X11/X.h>
 #include <stddef.h>
-#include "scrnintstr.h"
-#include "misc.h"
-#include "os.h"
 #include "windowstr.h"
 #include "resource.h"
 #include "privates.h"
-#include "dixstruct.h"
 #include "gcstruct.h"
 #include "colormapst.h"
-#include "servermd.h"
-#include "site.h"
 #include "inputstr.h"
-#include "extnsionst.h"
 
 typedef struct _PrivateDesc {
     DevPrivateKey key;
@@ -218,18 +210,6 @@ dixLookupPrivateOffset(RESTYPE type)
     return offsets[type];
 }
 
-/*
- * Called from the main loop to reset the subsystem.
- */
-static int ResetExtensionPrivates(void);
-static int ResetClientPrivates(void);
-static void ResetScreenPrivates(void);
-static void ResetWindowPrivates(void);
-static void ResetGCPrivates(void);
-static void ResetPixmapPrivates(void);
-static void ResetColormapPrivates(void);
-static void ResetDevicePrivateIndex(void);
-
 int
 dixResetPrivates(void)
 {
@@ -251,16 +231,6 @@ dixResetPrivates(void)
     for (i=0; i < offsetsSize; i++)
 	offsets[i] = -1;
 
-    /* reset legacy devPrivates support */
-    if (!ResetExtensionPrivates() || !ResetClientPrivates())
-	return FALSE;
-    ResetScreenPrivates();
-    ResetWindowPrivates();
-    ResetGCPrivates();
-    ResetPixmapPrivates();
-    ResetColormapPrivates();
-    ResetDevicePrivateIndex();
-
     /* register basic resource offsets */
     return dixRegisterPrivateOffset(RT_WINDOW,
 				    offsetof(WindowRec, devPrivates)) &&
@@ -271,421 +241,3 @@ dixResetPrivates(void)
 	dixRegisterPrivateOffset(RT_COLORMAP,
 				 offsetof(ColormapRec, devPrivates));
 }
-
-/*
- *  Following is the old devPrivates support.  These functions and variables
- *  are deprecated, and should no longer be used.
- */
-
-/*
- *  See the Wrappers and devPrivates section in "Definition of the
- *  Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
- *  for information on how to use devPrivates.
- */
-
-/*
- *  extension private machinery
- */
-
-static int  extensionPrivateCount;
-int extensionPrivateLen;
-unsigned *extensionPrivateSizes;
-unsigned totalExtensionSize;
-
-static int
-ResetExtensionPrivates(void)
-{
-    extensionPrivateCount = 1;
-    extensionPrivateLen = 1;
-    xfree(extensionPrivateSizes);
-    extensionPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
-    if (!extensionPrivateSizes)
-	return FALSE;
-    totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
-    return TRUE;
-}
-
-_X_EXPORT int
-AllocateExtensionPrivateIndex(void)
-{
-    return extensionPrivateCount++;
-}
-
-_X_EXPORT Bool
-AllocateExtensionPrivate(int index2, unsigned amount)
-{
-    unsigned oldamount;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
-
-    if (index2 >= extensionPrivateLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *)xrealloc(extensionPrivateSizes,
-				      (index2 + 1) * sizeof(unsigned));
-	if (!nsizes)
-	    return FALSE;
-	while (extensionPrivateLen <= index2)
-	{
-	    nsizes[extensionPrivateLen++] = 0;
-	    totalExtensionSize += sizeof(DevUnion);
-	}
-	extensionPrivateSizes = nsizes;
-    }
-    oldamount = extensionPrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	extensionPrivateSizes[index2] = amount;
-	totalExtensionSize += (amount - oldamount);
-    }
-    return TRUE;
-}
-
-/*
- *  client private machinery
- */
-
-static int  clientPrivateCount;
-int clientPrivateLen;
-unsigned *clientPrivateSizes;
-unsigned totalClientSize;
-
-static int
-ResetClientPrivates(void)
-{
-    clientPrivateCount = 1;
-    clientPrivateLen = 1;
-    xfree(clientPrivateSizes);
-    clientPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
-    if (!clientPrivateSizes)
-	return FALSE;
-    totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
-    return TRUE;
-}
-
-_X_EXPORT int
-AllocateClientPrivateIndex(void)
-{
-    return clientPrivateCount++;
-}
-
-_X_EXPORT Bool
-AllocateClientPrivate(int index2, unsigned amount)
-{
-    unsigned oldamount;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
-
-    if (index2 >= clientPrivateLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *)xrealloc(clientPrivateSizes,
-				      (index2 + 1) * sizeof(unsigned));
-	if (!nsizes)
-	    return FALSE;
-	while (clientPrivateLen <= index2)
-	{
-	    nsizes[clientPrivateLen++] = 0;
-	    totalClientSize += sizeof(DevUnion);
-	}
-	clientPrivateSizes = nsizes;
-    }
-    oldamount = clientPrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	clientPrivateSizes[index2] = amount;
-	totalClientSize += (amount - oldamount);
-    }
-    return TRUE;
-}
-
-/*
- *  screen private machinery
- */
-
-int  screenPrivateCount;
-
-static void
-ResetScreenPrivates(void)
-{
-    screenPrivateCount = 1;
-}
-
-/* this can be called after some screens have been created,
- * so we have to worry about resizing existing devPrivates
- */
-_X_EXPORT int
-AllocateScreenPrivateIndex(void)
-{
-    int		idx;
-    int		i;
-    ScreenPtr	pScreen;
-    DevUnion	*nprivs;
-
-    idx = screenPrivateCount++;
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	pScreen = screenInfo.screens[i];
-	nprivs = (DevUnion *)xrealloc(pScreen->devPrivates,
-				      screenPrivateCount * sizeof(DevUnion));
-	if (!nprivs)
-	{
-	    screenPrivateCount--;
-	    return -1;
-	}
-	/* Zero the new private */
-	bzero(&nprivs[idx], sizeof(DevUnion));
-	pScreen->devPrivates = nprivs;
-    }
-    return idx;
-}
-
-
-/*
- *  window private machinery
- */
-
-static int  windowPrivateCount;
-
-static void
-ResetWindowPrivates(void)
-{
-    windowPrivateCount = 1;
-}
-
-_X_EXPORT int
-AllocateWindowPrivateIndex(void)
-{
-    return windowPrivateCount++;
-}
-
-_X_EXPORT Bool
-AllocateWindowPrivate(ScreenPtr pScreen, int index2, unsigned amount)
-{
-    unsigned oldamount;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
-
-    if (index2 >= pScreen->WindowPrivateLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *)xrealloc(pScreen->WindowPrivateSizes,
-				      (index2 + 1) * sizeof(unsigned));
-	if (!nsizes)
-	    return FALSE;
-	while (pScreen->WindowPrivateLen <= index2)
-	{
-	    nsizes[pScreen->WindowPrivateLen++] = 0;
-	    pScreen->totalWindowSize += sizeof(DevUnion);
-	}
-	pScreen->WindowPrivateSizes = nsizes;
-    }
-    oldamount = pScreen->WindowPrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	pScreen->WindowPrivateSizes[index2] = amount;
-	pScreen->totalWindowSize += (amount - oldamount);
-    }
-    return TRUE;
-}
-
-
-/*
- *  gc private machinery 
- */
-
-static int  gcPrivateCount;
-
-static void
-ResetGCPrivates(void)
-{
-    gcPrivateCount = 1;
-}
-
-_X_EXPORT int
-AllocateGCPrivateIndex(void)
-{
-    return gcPrivateCount++;
-}
-
-_X_EXPORT Bool
-AllocateGCPrivate(ScreenPtr pScreen, int index2, unsigned amount)
-{
-    unsigned oldamount;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
-
-    if (index2 >= pScreen->GCPrivateLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *)xrealloc(pScreen->GCPrivateSizes,
-				      (index2 + 1) * sizeof(unsigned));
-	if (!nsizes)
-	    return FALSE;
-	while (pScreen->GCPrivateLen <= index2)
-	{
-	    nsizes[pScreen->GCPrivateLen++] = 0;
-	    pScreen->totalGCSize += sizeof(DevUnion);
-	}
-	pScreen->GCPrivateSizes = nsizes;
-    }
-    oldamount = pScreen->GCPrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	pScreen->GCPrivateSizes[index2] = amount;
-	pScreen->totalGCSize += (amount - oldamount);
-    }
-    return TRUE;
-}
-
-
-/*
- *  pixmap private machinery
- */
-static int  pixmapPrivateCount;
-
-static void
-ResetPixmapPrivates(void)
-{
-    pixmapPrivateCount = 1;
-}
-
-_X_EXPORT int
-AllocatePixmapPrivateIndex(void)
-{
-    return pixmapPrivateCount++;
-}
-
-_X_EXPORT Bool
-AllocatePixmapPrivate(ScreenPtr pScreen, int index2, unsigned amount)
-{
-    unsigned oldamount;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
-
-    if (index2 >= pScreen->PixmapPrivateLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *)xrealloc(pScreen->PixmapPrivateSizes,
-				      (index2 + 1) * sizeof(unsigned));
-	if (!nsizes)
-	    return FALSE;
-	while (pScreen->PixmapPrivateLen <= index2)
-	{
-	    nsizes[pScreen->PixmapPrivateLen++] = 0;
-	    pScreen->totalPixmapSize += sizeof(DevUnion);
-	}
-	pScreen->PixmapPrivateSizes = nsizes;
-    }
-    oldamount = pScreen->PixmapPrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	pScreen->PixmapPrivateSizes[index2] = amount;
-	pScreen->totalPixmapSize += (amount - oldamount);
-    }
-    pScreen->totalPixmapSize = BitmapBytePad(pScreen->totalPixmapSize * 8);
-    return TRUE;
-}
-
-
-/*
- *  colormap private machinery
- */
-
-int  colormapPrivateCount;
-
-static void
-ResetColormapPrivates(void)
-{
-    colormapPrivateCount = 1;
-}
-
-
-_X_EXPORT int
-AllocateColormapPrivateIndex (InitCmapPrivFunc initPrivFunc)
-{
-    int		index;
-    int		i;
-    ColormapPtr	pColormap;
-    DevUnion	*privs;
-
-    index = colormapPrivateCount++;
-
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	/*
-	 * AllocateColormapPrivateIndex may be called after the
-	 * default colormap has been created on each screen!
-	 *
-	 * We must resize the devPrivates array for the default
-	 * colormap on each screen, making room for this new private.
-	 * We also call the initialization function 'initPrivFunc' on
-	 * the new private allocated for each default colormap.
-	 */
-
-	ScreenPtr pScreen = screenInfo.screens[i];
-
-	pColormap = (ColormapPtr) LookupIDByType (
-	    pScreen->defColormap, RT_COLORMAP);
-
-	if (pColormap)
-	{
-	    privs = (DevUnion *) xrealloc (pColormap->devPrivates,
-		colormapPrivateCount * sizeof(DevUnion));
-	    if (!privs) {
-		colormapPrivateCount--;
-		return -1;
-	    }
-	    bzero(&privs[index], sizeof(DevUnion));
-	    pColormap->devPrivates = privs;
-	    if (!(*initPrivFunc)(pColormap,index))
-	    {
-		colormapPrivateCount--;
-		return -1;
-	    }
-	}
-    }
-
-    return index;
-}
-
-/*
- *  device private machinery
- */
-
-static int devicePrivateIndex = 0;
-
-_X_EXPORT int
-AllocateDevicePrivateIndex(void)
-{
-    return devicePrivateIndex++;
-}
-
-_X_EXPORT Bool
-AllocateDevicePrivate(DeviceIntPtr device, int index)
-{
-    if (device->nPrivates < ++index) {
-	DevUnion *nprivs = (DevUnion *) xrealloc(device->devPrivates,
-						 index * sizeof(DevUnion));
-	if (!nprivs)
-	    return FALSE;
-	device->devPrivates = nprivs;
-	bzero(&nprivs[device->nPrivates], sizeof(DevUnion)
-	      * (index - device->nPrivates));
-	device->nPrivates = index;
-	return TRUE;
-    } else {
-	return TRUE;
-    }
-}
-
-static void
-ResetDevicePrivateIndex(void)
-{
-    devicePrivateIndex = 1;
-}
diff --git a/dix/window.c b/dix/window.c
index f04beea..1a598fa 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -345,41 +345,6 @@ MakeRootTile(WindowPtr pWin)
 
 }
 
-WindowPtr
-AllocateWindow(ScreenPtr pScreen)
-{
-    WindowPtr pWin;
-    char *ptr;
-    DevUnion *ppriv;
-    unsigned *sizes;
-    unsigned size;
-    int i;
-
-    pWin = (WindowPtr)xalloc(pScreen->totalWindowSize);
-    if (pWin)
-    {
-	ppriv = (DevUnion *)(pWin + 1);
-	pWin->devPrivates = ppriv;
-	sizes = pScreen->WindowPrivateSizes;
-	ptr = (char *)(ppriv + pScreen->WindowPrivateLen);
-	for (i = pScreen->WindowPrivateLen; --i >= 0; ppriv++, sizes++)
-	{
-	    if ( (size = *sizes) )
-	    {
-		ppriv->ptr = (pointer)ptr;
-		ptr += size;
-	    }
-	    else
-		ppriv->ptr = (pointer)NULL;
-	}
-#if _XSERVER64
-	pWin->drawable.pad0 = 0;
-        pWin->drawable.pad1 = 0;
-#endif
-    }
-    return pWin;
-}
-
 /*****
  * CreateRootWindow
  *    Makes a window at initialization time for specified screen
@@ -392,7 +357,7 @@ CreateRootWindow(ScreenPtr pScreen)
     BoxRec	box;
     PixmapFormatRec *format;
 
-    pWin = AllocateWindow(pScreen);
+    pWin = (WindowPtr)xalloc(sizeof(WindowRec));
     if (!pWin)
 	return FALSE;
 
@@ -405,6 +370,7 @@ CreateRootWindow(ScreenPtr pScreen)
 
     pWin->drawable.pScreen = pScreen;
     pWin->drawable.type = DRAWABLE_WINDOW;
+    pWin->devPrivates = NULL;
 
     pWin->drawable.depth = pScreen->rootDepth;
     for (format = screenInfo.formats;
@@ -689,13 +655,14 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 	return NullWindow;
     }
 
-    pWin = AllocateWindow(pScreen);
+    pWin = (WindowPtr)xalloc(sizeof(WindowRec));
     if (!pWin)
     {
 	*error = BadAlloc;
 	return NullWindow;
     }
     pWin->drawable = pParent->drawable;
+    pWin->devPrivates = NULL;
     pWin->drawable.depth = depth;
     if (depth == pParent->drawable.depth)
 	pWin->drawable.bitsPerPixel = pParent->drawable.bitsPerPixel;
@@ -968,7 +935,7 @@ DeleteWindow(pointer value, XID wid)
 	if (pWin->prevSib)
 	    pWin->prevSib->nextSib = pWin->nextSib;
     }
-    dixFreePrivates(*DEVPRIV_PTR(pWin));
+    dixFreePrivates(pWin->devPrivates);
     xfree(pWin);
     return Success;
 }
diff --git a/exa/exa.c b/exa/exa.c
index 99707fa..4260cba 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -40,9 +40,8 @@
 #include "exa.h"
 #include "cw.h"
 
-static int exaGeneration;
-int exaScreenPrivateIndex;
-int exaPixmapPrivateIndex;
+DevPrivateKey exaScreenPrivateKey = &exaScreenPrivateKey;
+DevPrivateKey exaPixmapPrivateKey = &exaPixmapPrivateKey;
 
 /**
  * exaGetPixmapOffset() returns the offset (in bytes) within the framebuffer of
@@ -619,12 +618,6 @@ exaDriverInit (ScreenPtr		pScreen,
 #ifdef RENDER
     ps = GetPictureScreenIfSet(pScreen);
 #endif
-    if (exaGeneration != serverGeneration)
-    {
-	exaScreenPrivateIndex = AllocateScreenPrivateIndex();
-	exaPixmapPrivateIndex = AllocatePixmapPrivateIndex();
-	exaGeneration = serverGeneration;
-    }
 
     pExaScr = xcalloc (sizeof (ExaScreenPrivRec), 1);
 
@@ -636,7 +629,7 @@ exaDriverInit (ScreenPtr		pScreen,
 
     pExaScr->info = pScreenInfo;
 
-    pScreen->devPrivates[exaScreenPrivateIndex].ptr = (pointer) pExaScr;
+    dixSetPrivate(&pScreen->devPrivates, exaScreenPrivateKey, pExaScr);
 
     pExaScr->migration = ExaMigrationAlways;
 
@@ -698,8 +691,7 @@ exaDriverInit (ScreenPtr		pScreen,
     if ((pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) &&
 	pExaScr->info->offScreenBase < pExaScr->info->memorySize)
     {
-	if (!AllocatePixmapPrivate(pScreen, exaPixmapPrivateIndex,
-				   sizeof (ExaPixmapPrivRec))) {
+	if (!dixRequestPrivate(exaPixmapPrivateKey, sizeof(ExaPixmapPrivRec))) {
             LogMessage(X_WARNING,
 		       "EXA(%d): Failed to allocate pixmap private\n",
 		       pScreen->myNum);
@@ -716,11 +708,7 @@ exaDriverInit (ScreenPtr		pScreen,
 		   pExaScr->info->memorySize - pExaScr->info->offScreenBase);
     }
     else
-    {
         LogMessage(X_INFO, "EXA(%d): No offscreen pixmaps\n", pScreen->myNum);
-	if (!AllocatePixmapPrivate(pScreen, exaPixmapPrivateIndex, 0))
-	    return FALSE;
-    }
 
     DBG_PIXMAP(("============== %ld < %ld\n", pExaScr->info->offScreenBase,
                 pExaScr->info->memorySize));
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index a456da0..b577094 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -132,9 +132,9 @@ typedef struct {
     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
 #endif
 
-extern int exaScreenPrivateIndex;
-extern int exaPixmapPrivateIndex;
-#define ExaGetScreenPriv(s)	((ExaScreenPrivPtr)(s)->devPrivates[exaScreenPrivateIndex].ptr)
+extern DevPrivateKey exaScreenPrivateKey;
+extern DevPrivateKey exaPixmapPrivateKey;
+#define ExaGetScreenPriv(s) ((ExaScreenPrivPtr)dixLookupPrivate(&(s)->devPrivates, exaScreenPrivateKey))
 #define ExaScreenPriv(s)	ExaScreenPrivPtr    pExaScr = ExaGetScreenPriv(s)
 
 /** Align an offset to an arbitrary alignment */
@@ -150,8 +150,8 @@ extern int exaPixmapPrivateIndex;
 #define EXA_PIXMAP_SCORE_PINNED	    1000
 #define EXA_PIXMAP_SCORE_INIT	    1001
 
-#define ExaGetPixmapPriv(p)	((ExaPixmapPrivPtr)(p)->devPrivates[exaPixmapPrivateIndex].ptr)
-#define ExaSetPixmapPriv(p,a)	((p)->devPrivates[exaPixmapPrivateIndex].ptr = (pointer) (a))
+#define ExaGetPixmapPriv(p) ((ExaPixmapPrivPtr)dixLookupPrivate(&(p)->devPrivates, exaPixmapPrivateKey))
+#define ExaSetPixmapPriv(p,a) dixSetPrivate(&(p)->devPrivates, exaPixmapPrivateKey, a)
 #define ExaPixmapPriv(p)	ExaPixmapPrivPtr pExaPixmap = ExaGetPixmapPriv(p)
 
 typedef struct {
diff --git a/fb/fb.h b/fb/fb.h
index aba2bd2..da85ecf 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -37,6 +37,7 @@
 #include "miscstruct.h"
 #include "servermd.h"
 #include "windowstr.h"
+#include "privates.h"
 #include "mi.h"
 #include "migc.h"
 #include "mibstore.h"
@@ -599,13 +600,9 @@ extern void fbSetBits (FbStip *bits, int stride, FbStip data);
     }							    \
 }
 
-/* XXX fb*PrivateIndex should be static, but it breaks the ABI */
-
-extern int	fbGCPrivateIndex;
-extern int	fbGetGCPrivateIndex(void);
+extern DevPrivateKey fbGetGCPrivateKey(void);
 #ifndef FB_NO_WINDOW_PIXMAPS
-extern int	fbWinPrivateIndex;
-extern int	fbGetWinPrivateIndex(void);
+extern DevPrivateKey fbGetWinPrivateKey(void);
 #endif
 extern const GCOps	fbGCOps;
 extern const GCFuncs	fbGCFuncs;
@@ -641,8 +638,7 @@ typedef void (*FinishWrapProcPtr)(DrawablePtr pDraw);
 
 
 #ifdef FB_SCREEN_PRIVATE
-extern int	fbScreenPrivateIndex;
-extern int	fbGetScreenPrivateIndex(void);
+extern DevPrivateKey fbGetScreenPrivateKey(void);
 
 /* private field of a screen */
 typedef struct {
@@ -655,7 +651,7 @@ typedef struct {
 } FbScreenPrivRec, *FbScreenPrivPtr;
 
 #define fbGetScreenPrivate(pScreen) ((FbScreenPrivPtr) \
-				     (pScreen)->devPrivates[fbGetScreenPrivateIndex()].ptr)
+	dixLookupPrivate(&(pScreen)->devPrivates, fbGetScreenPrivateKey()))
 #endif
 
 /* private field of GC */
@@ -670,7 +666,7 @@ typedef struct {
 } FbGCPrivRec, *FbGCPrivPtr;
 
 #define fbGetGCPrivate(pGC)	((FbGCPrivPtr)\
-	(pGC)->devPrivates[fbGetGCPrivateIndex()].ptr)
+	dixLookupPrivate(&(pGC)->devPrivates, fbGetGCPrivateKey()))
 
 #define fbGetCompositeClip(pGC) ((pGC)->pCompositeClip)
 #define fbGetExpose(pGC)	((pGC)->fExpose)
@@ -682,7 +678,7 @@ typedef struct {
 #define fbGetWindowPixmap(d)	fbGetScreenPixmap(((DrawablePtr) (d))->pScreen)
 #else
 #define fbGetWindowPixmap(pWin)	((PixmapPtr)\
-	((WindowPtr) (pWin))->devPrivates[fbGetWinPrivateIndex()].ptr)
+    dixLookupPrivate(&((WindowPtr)(pWin))->devPrivates, fbGetWinPrivateKey()))
 #endif
 
 #ifdef ROOTLESS
@@ -835,7 +831,7 @@ fb24_32ModifyPixmapHeader (PixmapPtr   pPixmap,
  * fballpriv.c
  */
 Bool
-fbAllocatePrivates(ScreenPtr pScreen, int *pGCIndex);
+fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCIndex);
     
 /*
  * fbarc.c
diff --git a/fb/fballpriv.c b/fb/fballpriv.c
index 8efb8fa..68cb2e4 100644
--- a/fb/fballpriv.c
+++ b/fb/fballpriv.c
@@ -27,51 +27,33 @@
 #include "fb.h"
 
 #ifdef FB_SCREEN_PRIVATE
-int fbScreenPrivateIndex;
-int fbGetScreenPrivateIndex(void)
+static DevPrivateKey fbScreenPrivateKey = &fbScreenPrivateKey;
+DevPrivateKey fbGetScreenPrivateKey(void)
 {
-    return fbScreenPrivateIndex;
+    return fbScreenPrivateKey;
 }
 #endif
-int fbGCPrivateIndex;
-int fbGetGCPrivateIndex(void)
+static DevPrivateKey fbGCPrivateKey = &fbGCPrivateKey;
+DevPrivateKey fbGetGCPrivateKey(void)
 {
-    return fbGCPrivateIndex;
+    return fbGCPrivateKey;
 }
 #ifndef FB_NO_WINDOW_PIXMAPS
-int fbWinPrivateIndex;
-int fbGetWinPrivateIndex(void)
+static DevPrivateKey fbWinPrivateKey = &fbWinPrivateKey;
+DevPrivateKey fbGetWinPrivateKey(void)
 {
-    return fbWinPrivateIndex;
+    return fbWinPrivateKey;
 }
 #endif
-int fbGeneration;
 
 Bool
-fbAllocatePrivates(ScreenPtr pScreen, int *pGCIndex)
+fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
 {
-    if (fbGeneration != serverGeneration)
-    {
-	fbGCPrivateIndex = miAllocateGCPrivateIndex ();
-#ifndef FB_NO_WINDOW_PIXMAPS
-	fbWinPrivateIndex = AllocateWindowPrivateIndex();
-#endif
-#ifdef FB_SCREEN_PRIVATE
-	fbScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (fbScreenPrivateIndex == -1)
-	    return FALSE;
-#endif
-	
-	fbGeneration = serverGeneration;
-    }
-    if (pGCIndex)
-	*pGCIndex = fbGCPrivateIndex;
-    if (!AllocateGCPrivate(pScreen, fbGCPrivateIndex, sizeof(FbGCPrivRec)))
+    if (pGCKey)
+	*pGCKey = fbGCPrivateKey;
+    
+    if (!dixRequestPrivate(fbGCPrivateKey, sizeof(FbGCPrivRec)))
 	return FALSE;
-#ifndef FB_NO_WINDOW_PIXMAPS
-    if (!AllocateWindowPrivate(pScreen, fbWinPrivateIndex, 0))
-	return FALSE;
-#endif
 #ifdef FB_SCREEN_PRIVATE
     {
 	FbScreenPrivPtr	pScreenPriv;
@@ -79,7 +61,7 @@ fbAllocatePrivates(ScreenPtr pScreen, int *pGCIndex)
 	pScreenPriv = (FbScreenPrivPtr) xalloc (sizeof (FbScreenPrivRec));
 	if (!pScreenPriv)
 	    return FALSE;
-	pScreen->devPrivates[fbScreenPrivateIndex].ptr = (pointer) pScreenPriv;
+	dixSetPrivate(&pScreen->devPrivates, fbScreenPrivateKey, pScreenPriv);
     }
 #endif
     return TRUE;
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 5d7481e..0d3c240 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -33,12 +33,11 @@
 #include "fboverlay.h"
 #include "shmint.h"
 
-int	fbOverlayGeneration;
-int	fbOverlayScreenPrivateIndex = -1;
+static DevPrivateKey fbOverlayScreenPrivateKey = &fbOverlayScreenPrivateKey;
 
-int fbOverlayGetScreenPrivateIndex(void)
+DevPrivateKey fbOverlayGetScreenPrivateKey(void)
 {
-    return fbOverlayScreenPrivateIndex;
+    return fbOverlayScreenPrivateKey;
 }
 
 /*
@@ -65,7 +64,7 @@ fbOverlayCreateWindow(WindowPtr pWin)
 	pPixmap = pScrPriv->layer[i].u.run.pixmap;
 	if (pWin->drawable.depth == pPixmap->drawable.depth)
 	{
-	    pWin->devPrivates[fbWinPrivateIndex].ptr = (pointer) pPixmap;
+	    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(), pPixmap);
 	    /*
 	     * Make sure layer keys are written correctly by
 	     * having non-root layers set to full while the
@@ -108,7 +107,7 @@ fbOverlayWindowLayer(WindowPtr pWin)
     int                 i;
 
     for (i = 0; i < pScrPriv->nlayers; i++)
-	if (pWin->devPrivates[fbWinPrivateIndex].ptr ==
+	if (dixLookupPrivate(&pWin->devPrivates, fbGetWinPrivateKey()) ==
 	    (pointer) pScrPriv->layer[i].u.run.pixmap)
 	    return i;
     return 0;
@@ -358,12 +357,6 @@ fbOverlayFinishScreenInit(ScreenPtr	pScreen,
     VisualID	defaultVisual;
     FbOverlayScrPrivPtr	pScrPriv;
 
-    if (fbOverlayGeneration != serverGeneration)
-    {
-	fbOverlayScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	fbOverlayGeneration = serverGeneration;
-    }
-
     pScrPriv = xalloc (sizeof (FbOverlayScrPrivRec));
     if (!pScrPriv)
 	return FALSE;
@@ -433,7 +426,7 @@ fbOverlayFinishScreenInit(ScreenPtr	pScreen,
     pScrPriv->layer[1].u.init.width = width2;
     pScrPriv->layer[1].u.init.depth = depth2;
     
-    pScreen->devPrivates[fbOverlayScreenPrivateIndex].ptr = (pointer) pScrPriv;
+    dixSetPrivate(&pScreen->devPrivates, fbOverlayScreenPrivateKey, pScrPriv);
     
     /* overwrite miCloseScreen with our own */
     pScreen->CloseScreen = fbOverlayCloseScreen;
diff --git a/fb/fboverlay.h b/fb/fboverlay.h
index af0acb8..85a28ec 100644
--- a/fb/fboverlay.h
+++ b/fb/fboverlay.h
@@ -25,9 +25,9 @@
 #ifndef _FBOVERLAY_H_
 #define _FBOVERLAY_H_
 
-extern int	fbOverlayGeneration;
-extern int	fbOverlayScreenPrivateIndex; /* XXX should be static */
-extern int	fbOverlayGetScreenPrivateIndex(void);
+#include "privates.h"
+
+extern DevPrivateKey fbOverlayGetScreenPrivateKey(void);
 
 #ifndef FB_OVERLAY_MAX
 #define FB_OVERLAY_MAX	2
@@ -58,8 +58,7 @@ typedef struct _fbOverlayScrPriv {
 } FbOverlayScrPrivRec, *FbOverlayScrPrivPtr;
 
 #define fbOverlayGetScrPriv(s) \
-    ((fbOverlayGetScreenPrivateIndex() != -1) ? \
-     (s)->devPrivates[fbOverlayGetScreenPrivateIndex()].ptr : NULL)
+    dixLookupPrivate(&(s)->devPrivates, fbOverlayGetScreenPrivateKey())
 Bool
 fbOverlayCreateWindow(WindowPtr pWin);
 
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index 2b77c4f..cd8cbcd 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -96,7 +96,7 @@ fbDestroyPixmap (PixmapPtr pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
-    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+    dixFreePrivates(pPixmap->devPrivates);
     xfree(pPixmap);
     return TRUE;
 }
diff --git a/fb/fbpseudocolor.c b/fb/fbpseudocolor.c
index 271e981..1b9b18a 100644
--- a/fb/fbpseudocolor.c
+++ b/fb/fbpseudocolor.c
@@ -125,13 +125,11 @@ typedef struct {
 } xxScrPrivRec, *xxScrPrivPtr;
 
 #define xxGetScrPriv(s)	((xxScrPrivPtr) \
-				 (xxScrPrivateIndex != -1) \
-                          ? (s)->devPrivates[xxScrPrivateIndex].ptr\
-				: NULL)
+    dixLookupPrivate(&(s)->devPrivates, xxScrPrivateKey))
 #define xxScrPriv(s)     xxScrPrivPtr pScrPriv = xxGetScrPriv(s)
 
 #define xxGetCmapPriv(s) ((xxCmapPrivPtr) \
-                          (s)->devPrivates[xxColormapPrivateIndex].ptr)
+    dixLookupPrivate(&(s)->devPrivates, xxColormapPrivateKey))
 #define xxCmapPriv(s)    xxCmapPrivPtr pCmapPriv = xxGetCmapPriv(s);
 
 typedef struct _xxGCPriv {
@@ -140,13 +138,12 @@ typedef struct _xxGCPriv {
 } xxGCPrivRec, *xxGCPrivPtr;
 
 #define xxGetGCPriv(pGC) ((xxGCPrivPtr) \
-				      (pGC)->devPrivates[xxGCPrivateIndex].ptr)
+    dixLookupPrivate(&(pGC)->devPrivates, xxGCPrivateKey))
 #define xxGCPriv(pGC)   xxGCPrivPtr  pGCPriv = xxGetGCPriv(pGC)
 
-int xxScrPrivateIndex = -1;
-int xxGCPrivateIndex;
-int xxColormapPrivateIndex = -1;
-int xxGeneration;
+static DevPrivateKey xxScrPrivateKey = &xxScrPrivateKey;
+static DevPrivateKey xxGCPrivateKey = &xxGCPrivateKey;
+static DevPrivateKey xxColormapPrivateKey = &xxColormapPrivateKey;
 
 
 #define wrap(priv,real,mem,func) {\
@@ -356,26 +353,20 @@ xxMyVisual(ScreenPtr pScreen, VisualID vid)
 }
 
 static Bool
-xxInitColormapDummy(ColormapPtr pmap, int index)
-{
-    return TRUE;
-}
-
-static Bool
 xxInitColormapPrivate(ColormapPtr pmap)
 {
     xxScrPriv(pmap->pScreen);
     xxCmapPrivPtr	pCmapPriv;
     pointer		cmap;
 
-    pmap->devPrivates[xxColormapPrivateIndex].ptr = (pointer) -1;
+    dixSetPrivate(&pmap->devPrivates, xxColormapPrivateKey, (pointer) -1);
     
     if (xxMyVisual(pmap->pScreen,pmap->pVisual->vid)) {
 	DBG("CreateColormap\n");
 	pCmapPriv = (xxCmapPrivPtr) xalloc (sizeof (xxCmapPrivRec));
 	if (!pCmapPriv)
 	    return FALSE;
-	pmap->devPrivates[xxColormapPrivateIndex].ptr = (pointer) pCmapPriv;
+	dixSetPrivate(&pmap->devPrivates, xxColormapPrivateKey, pCmapPriv);
 	cmap = xalloc(sizeof (CARD32) * (1 << pScrPriv->myDepth));
 	if (!cmap)
 	return FALSE;
@@ -677,7 +668,7 @@ xxCreateWindow(WindowPtr pWin)
     
     DBG("CreateWindow\n");
 
-    pWin->devPrivates[fbWinPrivateIndex].ptr = (pointer) pScrPriv->pPixmap;
+    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(), pScrPriv->pPixmap);
     PRINT_RECTS(pScrPriv->region);
 	if (!pWin->parent) {
 	REGION_EMPTY (pWin->drawable.pScreen, &pScrPriv->region);
@@ -746,9 +737,10 @@ xxCopyWindow(WindowPtr	pWin,
     xxPickMyWindows(pWin,&rgn);
 
     unwrap (pScrPriv, pScreen, CopyWindow);
-    pWin->devPrivates[fbWinPrivateIndex].ptr = fbGetScreenPixmap(pScreen);
+    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(),
+		  fbGetScreenPixmap(pScreen));
     pScreen->CopyWindow(pWin, ptOldOrg, prgnSrc);
-    pWin->devPrivates[fbWinPrivateIndex].ptr = pPixmap;
+    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(), pPixmap);
     wrap(pScrPriv, pScreen, CopyWindow, xxCopyWindow);
 
     REGION_INTERSECT(pScreen,&rgn,&rgn,&rgn_new);
@@ -1098,21 +1090,7 @@ xxSetup(ScreenPtr pScreen, int myDepth, int baseDepth, char* addr, xxSyncFunc sy
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
 
-    if (xxGeneration != serverGeneration) {
-	xxScrPrivateIndex = AllocateScreenPrivateIndex ();
-	if (xxScrPrivateIndex == -1)
-	    return FALSE;
-	xxColormapPrivateIndex
-	    = AllocateColormapPrivateIndex (xxInitColormapDummy);
-	if (xxColormapPrivateIndex == -1)
-	    return FALSE;
-	xxGCPrivateIndex = AllocateGCPrivateIndex ();
-	if (xxGCPrivateIndex == -1)
-	    return FALSE;
-	xxGeneration = serverGeneration;
-    }
-
-    if (!AllocateGCPrivate (pScreen, xxGCPrivateIndex, sizeof (xxGCPrivRec)))
+    if (!dixRequestPrivate(xxGCPrivateKey, sizeof (xxGCPrivRec)))
 	return FALSE;
 
     pScrPriv = (xxScrPrivPtr) xalloc (sizeof (xxScrPrivRec));
@@ -1190,7 +1168,7 @@ xxSetup(ScreenPtr pScreen, int myDepth, int baseDepth, char* addr, xxSyncFunc sy
     }
 #endif
     pScrPriv->addr = addr;
-    pScreen->devPrivates[xxScrPrivateIndex].ptr = (pointer) pScrPriv;
+    dixSetPrivate(&pScreen->devPrivates, xxScrPrivateKey, pScrPriv);
 
     pDefMap = (ColormapPtr) LookupIDByType(pScreen->defColormap, RT_COLORMAP);
     if (!xxInitColormapPrivate(pDefMap))
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 661268c..c99ba08 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -38,7 +38,7 @@ fbCloseScreen (int index, ScreenPtr pScreen)
     xfree (pScreen->visuals);
     xfree (pScreen->devPrivate);
 #ifdef FB_SCREEN_PRIVATE
-    xfree (pScreen->devPrivates[fbScreenPrivateIndex].ptr);
+    xfree (dixLookupPrivate(&pScreen->devPrivates, fbGetScreenPrivateKey()));
 #endif
     return TRUE;
 }
@@ -93,7 +93,7 @@ _fbSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap)
 #ifdef FB_NO_WINDOW_PIXMAPS
     FatalError ("Attempted to set window pixmap without fb support\n");
 #else
-    pWindow->devPrivates[fbWinPrivateIndex].ptr = (pointer) pPixmap;
+    dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(), pPixmap);
 #endif
 }
 
@@ -107,7 +107,7 @@ fbSetupScreen(ScreenPtr	pScreen,
 	      int	width,		/* pixel width of frame buffer */
 	      int	bpp)		/* bits per pixel for screen */
 {
-    if (!fbAllocatePrivates(pScreen, (int *) 0))
+    if (!fbAllocatePrivates(pScreen, NULL))
 	return FALSE;
     pScreen->defColormap = FakeClientID(0);
     /* let CreateDefColormap do whatever it wants for pixels */ 
diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index 144f083..594cc61 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -32,8 +32,8 @@ Bool
 fbCreateWindow(WindowPtr pWin)
 {
 #ifndef FB_NO_WINDOW_PIXMAPS
-    pWin->devPrivates[fbWinPrivateIndex].ptr = 
-	(pointer) fbGetScreenPixmap(pWin->drawable.pScreen);
+    dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(),
+		  fbGetScreenPixmap(pWin->drawable.pScreen));
 #endif
 #ifdef FB_SCREEN_PRIVATE
     if (pWin->drawable.bitsPerPixel == 32)
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 5ea9092..a6296fb 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -84,14 +84,14 @@
 #define fbFixCoordModePrevious wfbFixCoordModePrevious
 #define fbGCFuncs wfbGCFuncs
 #define fbGCOps wfbGCOps
-#define fbGCPrivateIndex wfbGCPrivateIndex
+#define fbGCPrivateKey wfbGCPrivateKey
 #define fbGeneration wfbGeneration
-#define fbGetGCPrivateIndex wfbGetGCPrivateIndex
+#define fbGetGCPrivateKey wfbGetGCPrivateKey
 #define fbGetImage wfbGetImage
-#define fbGetScreenPrivateIndex wfbGetScreenPrivateIndex
+#define fbGetScreenPrivateKey wfbGetScreenPrivateKey
 #define fbGetSpans wfbGetSpans
 #define _fbGetWindowPixmap _wfbGetWindowPixmap
-#define fbGetWinPrivateIndex wfbGetWinPrivateIndex
+#define fbGetWinPrivateKey wfbGetWinPrivateKey
 #define fbGlyph16 wfbGlyph16
 #define fbGlyph24 wfbGlyph24
 #define fbGlyph32 wfbGlyph32
@@ -117,10 +117,10 @@
 #define fbOverlayCreateWindow wfbOverlayCreateWindow
 #define fbOverlayFinishScreenInit wfbOverlayFinishScreenInit
 #define fbOverlayGeneration wfbOverlayGeneration
-#define fbOverlayGetScreenPrivateIndex wfbOverlayGetScreenPrivateIndex
+#define fbOverlayGetScreenPrivateKey wfbOverlayGetScreenPrivateKey
 #define fbOverlayPaintKey wfbOverlayPaintKey
 #define fbOverlayPaintWindow wfbOverlayPaintWindow
-#define fbOverlayScreenPrivateIndex wfbOverlayScreenPrivateIndex
+#define fbOverlayScreenPrivateKey wfbOverlayScreenPrivateKey
 #define fbOverlaySetupScreen wfbOverlaySetupScreen
 #define fbOverlayUpdateLayerRegion wfbOverlayUpdateLayerRegion
 #define fbOverlayWindowExposures wfbOverlayWindowExposures
@@ -160,7 +160,7 @@
 #define fbResolveColor wfbResolveColor
 #define fbRestoreAreas wfbRestoreAreas
 #define fbSaveAreas wfbSaveAreas
-#define fbScreenPrivateIndex wfbScreenPrivateIndex
+#define fbScreenPrivateKey wfbScreenPrivateKey
 #define fbSegment wfbSegment
 #define fbSelectBres wfbSelectBres
 #define fbSetSpans wfbSetSpans
@@ -185,14 +185,14 @@
 #define fbUnrealizeFont wfbUnrealizeFont
 #define fbValidateGC wfbValidateGC
 #define fbWalkCompositeRegion wfbWalkCompositeRegion
-#define fbWinPrivateIndex wfbWinPrivateIndex
+#define fbWinPrivateKey wfbWinPrivateKey
 #define fbZeroLine wfbZeroLine
 #define fbZeroSegment wfbZeroSegment
 #define free_pixman_pict wfb_free_pixman_pict
 #define image_from_pict wfb_image_from_pict
-#define xxScrPrivateIndex wfbxxScrPrivateIndex
-#define xxGCPrivateIndex wfbxxGCPrivateIndex
-#define xxColormapPrivateIndex wfbxxColormapPrivateIndex
+#define xxScrPrivateKey wfbxxScrPrivateKey
+#define xxGCPrivateKey wfbxxGCPrivateKey
+#define xxColormapPrivateKey wfbxxColormapPrivateKey
 #define xxGeneration wfbxxGeneration
 #define xxPrintVisuals wfbxxPrintVisuals
 #define xxGCFuncs wfbxxGCFuncs
diff --git a/hw/darwin/darwin.h b/hw/darwin/darwin.h
index fc4a58a..70101ec 100644
--- a/hw/darwin/darwin.h
+++ b/hw/darwin/darwin.h
@@ -88,8 +88,8 @@ void DarwinModeBell(int volume, DeviceIntPtr pDevice, pointer ctrl, int class);
 #define kern_assert(x) { if ((x) != KERN_SUCCESS) \
     FatalError("assert failed on line %d of %s with kernel return 0x%x!\n", \
                 __LINE__, __FILE__, x); }
-#define SCREEN_PRIV(pScreen) \
-    ((DarwinFramebufferPtr)pScreen->devPrivates[darwinScreenIndex].ptr)
+#define SCREEN_PRIV(pScreen) ((DarwinFramebufferPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, darwinScreenKey))
 
 
 #define MIN_KEYCODE XkbMinLegalKeyCode     // unfortunately, this isn't 0...
@@ -98,7 +98,7 @@ void DarwinModeBell(int volume, DeviceIntPtr pDevice, pointer ctrl, int class);
 /*
  * Global variables from darwin.c
  */
-extern int              darwinScreenIndex; // index into pScreen.devPrivates
+extern DevPrivateKey    darwinScreenKey; // index into pScreen.devPrivates
 extern int              darwinScreensFound;
 extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
diff --git a/hw/darwin/iokit/xfIOKit.h b/hw/darwin/iokit/xfIOKit.h
index 27d27bc..7d9a487 100644
--- a/hw/darwin/iokit/xfIOKit.h
+++ b/hw/darwin/iokit/xfIOKit.h
@@ -45,10 +45,10 @@ typedef struct {
     unsigned char      *shadowPtr;
 } XFIOKitScreenRec, *XFIOKitScreenPtr;
 
-#define XFIOKIT_SCREEN_PRIV(pScreen) \
-    ((XFIOKitScreenPtr)pScreen->devPrivates[xfIOKitScreenIndex].ptr)
+#define XFIOKIT_SCREEN_PRIV(pScreen) ((XFIOKitScreenPtr) \
+    dixLookupPrivate(&pScreen->devPrivates, xfIOKitScreenKey))
 
-extern int xfIOKitScreenIndex; // index into pScreen.devPrivates
+extern DevPrivateKey xfIOKitScreenKey; // index into pScreen.devPrivates
 extern io_connect_t xfIOKitInputConnect;
 
 Bool XFIOKitInitCursor(ScreenPtr pScreen);
diff --git a/hw/darwin/iokit/xfIOKitCursor.c b/hw/darwin/iokit/xfIOKitCursor.c
index 8388513..2247101 100644
--- a/hw/darwin/iokit/xfIOKitCursor.c
+++ b/hw/darwin/iokit/xfIOKitCursor.c
@@ -73,8 +73,8 @@
 #include <assert.h>
 #define DUMP_DARWIN_CURSOR FALSE
 
-#define CURSOR_PRIV(pScreen) \
-    ((XFIOKitCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
+#define CURSOR_PRIV(pScreen) ((XFIOKitCursorScreenPtr) \
+    dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
 
 // The cursors format are documented in IOFramebufferShared.h.
 #define RGBto34WithGamma(red, green, blue)  \
@@ -99,8 +99,7 @@ typedef struct {
     ColormapPtr             pInstalledMap;
 } XFIOKitCursorScreenRec, *XFIOKitCursorScreenPtr;
 
-static int darwinCursorScreenIndex = -1;
-static unsigned long darwinCursorGeneration = 0;
+static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKey;
 
 /*
 ===========================================================================
@@ -679,17 +678,10 @@ XFIOKitInitCursor(
         return FALSE;
     }
 
-    // allocate private storage for this screen's hardware cursor info
-    if (darwinCursorGeneration != serverGeneration) {
-        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-        darwinCursorGeneration = serverGeneration; 	
-    }
-
     ScreenPriv = xcalloc( 1, sizeof(XFIOKitCursorScreenRec) );
     if (!ScreenPriv) return FALSE;
 
-    pScreen->devPrivates[darwinCursorScreenIndex].ptr = (pointer) ScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, darwinCursorScreenKey, ScreenPriv);
 
     // check if a hardware cursor is supported
     if (!iokitScreen->cursorShmem->hardwareCursorCapable) {
@@ -722,7 +714,7 @@ XFIOKitInitCursor(
 
     // initialize hardware cursor handling
     PointPriv = (miPointerScreenPtr)
-                    pScreen->devPrivates[miPointerScreenIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
     ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
     PointPriv->spriteFuncs = &darwinSpriteFuncsRec; 
diff --git a/hw/darwin/quartz/fullscreen/fullscreen.c b/hw/darwin/quartz/fullscreen/fullscreen.c
index 02f6e89..ee16e55 100644
--- a/hw/darwin/quartz/fullscreen/fullscreen.c
+++ b/hw/darwin/quartz/fullscreen/fullscreen.c
@@ -49,18 +49,17 @@ typedef struct {
 } FSScreenRec, *FSScreenPtr;
 
 #define FULLSCREEN_PRIV(pScreen) \
-    ((FSScreenPtr)pScreen->devPrivates[fsScreenIndex].ptr)
+    ((FSScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, fsScreenKey))
 
-static int                  fsScreenIndex;
+static DevPrivateKey        fsScreenKey = &fsScreenKey;
 static CGDirectDisplayID   *quartzDisplayList = NULL;
 static int                  quartzNumScreens = 0;
 static FSScreenPtr          quartzScreens[MAXSCREENS];
 
-static int                  darwinCmapPrivateIndex = -1;
-static unsigned long        darwinCmapGeneration = 0;
+static DevPrivateKey        darwinCmapPrivateKey = &darwinCmapPrivateKey;
 
-#define CMAP_PRIV(pCmap) \
-    ((CGDirectPaletteRef) (pCmap)->devPrivates[darwinCmapPrivateIndex].ptr)
+#define CMAP_PRIV(pCmap) ((CGDirectPaletteRef) \
+    dixLookupPrivate(&(pCmap)->devPrivates, darwinCmapPrivateKey))
 
 /*
  =============================================================================
@@ -95,16 +94,6 @@ FSCreateColormap(
 {
     CGDirectPaletteRef  pallete;
 
-    // Allocate private storage for the hardware dependent colormap info.
-    if (darwinCmapGeneration != serverGeneration) {
-        if ((darwinCmapPrivateIndex =
-                AllocateColormapPrivateIndex(FSInitCmapPrivates)) < 0)
-        {
-            return FALSE;
-        }
-        darwinCmapGeneration = serverGeneration;
-    }
-
     pallete = CGPaletteCreateDefaultColorPalette();
     if (!pallete) return FALSE;
 
@@ -283,17 +272,10 @@ static void FSResumeScreen(
  */
 static void FSDisplayInit(void)
 {
-    static unsigned long generation = 0;
     CGDisplayCount quartzDisplayCount = 0;
 
     ErrorF("Display mode: Full screen Quartz -- Direct Display\n");
 
-    // Allocate private storage for each screen's mode specific info
-    if (generation != serverGeneration) {
-        fsScreenIndex = AllocateScreenPrivateIndex();
-        generation = serverGeneration;
-    }
-
     // Find all the CoreGraphics displays
     CGGetActiveDisplayList(0, NULL, &quartzDisplayCount);
     quartzDisplayList = xalloc(quartzDisplayCount * sizeof(CGDirectDisplayID));
diff --git a/hw/darwin/quartz/fullscreen/quartzCursor.c b/hw/darwin/quartz/fullscreen/quartzCursor.c
index 77fa008..bee83b8 100644
--- a/hw/darwin/quartz/fullscreen/quartzCursor.c
+++ b/hw/darwin/quartz/fullscreen/quartzCursor.c
@@ -56,8 +56,7 @@ typedef struct {
     miPointerSpriteFuncPtr  spriteFuncs;
 } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
 
-static int darwinCursorScreenIndex = -1;
-static unsigned long darwinCursorGeneration = 0;
+static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKey;
 static CursorPtr quartzLatentCursor = NULL;
 static QD_Cursor gQDArrow; // QuickDraw arrow cursor
 
@@ -66,8 +65,8 @@ static CCrsrHandle currentCursor = NULL;
 static pthread_mutex_t cursorMutex;
 static pthread_cond_t cursorCondition;
 
-#define CURSOR_PRIV(pScreen) \
-    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
+#define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, darwinCursorScreenKey))
 
 #define HIDE_QD_CURSOR(pScreen, visible)                                \
     if (visible) {                                                      \
@@ -592,13 +591,6 @@ QuartzInitCursor(
         return FALSE;
     }
 
-    // allocate private storage for this screen's QuickDraw cursor info
-    if (darwinCursorGeneration != serverGeneration) {
-        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-        darwinCursorGeneration = serverGeneration;
-    }
-
     ScreenPriv = xcalloc( 1, sizeof(QuartzCursorScreenRec) );
     if (!ScreenPriv) return FALSE;
 
@@ -611,7 +603,7 @@ QuartzInitCursor(
     // initialize QuickDraw cursor handling
     GetQDGlobalsArrow(&gQDArrow);
     PointPriv = (miPointerScreenPtr)
-                    pScreen->devPrivates[miPointerScreenIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
     ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
     PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
diff --git a/hw/darwin/quartz/quartz.c b/hw/darwin/quartz/quartz.c
index 038b21e..eac7652 100644
--- a/hw/darwin/quartz/quartz.c
+++ b/hw/darwin/quartz/quartz.c
@@ -62,7 +62,7 @@ int                     quartzUseAGL = 1;
 int                     quartzEnableKeyEquivalents = 1;
 int                     quartzServerVisible = TRUE;
 int                     quartzServerQuitting = FALSE;
-int                     quartzScreenIndex = 0;
+DevPrivateKey           quartzScreenKey = &quartzScreenKey;
 int                     aquaMenuBarHeight = 0;
 int                     noPseudoramiXExtension = TRUE;
 QuartzModeProcsPtr      quartzProcs = NULL;
@@ -121,14 +121,6 @@ void DarwinModeInitOutput(
     int argc,
     char **argv )
 {
-    static unsigned long generation = 0;
-
-    // Allocate private storage for each screen's Quartz specific info
-    if (generation != serverGeneration) {
-        quartzScreenIndex = AllocateScreenPrivateIndex();
-        generation = serverGeneration;
-    }
-
     if (serverGeneration == 0) {
         QuartzAudioInit();
     }
diff --git a/hw/darwin/quartz/quartzCommon.h b/hw/darwin/quartz/quartzCommon.h
index f5dff66..5e199d3 100644
--- a/hw/darwin/quartz/quartzCommon.h
+++ b/hw/darwin/quartz/quartzCommon.h
@@ -58,7 +58,7 @@ typedef struct {
 } QuartzScreenRec, *QuartzScreenPtr;
 
 #define QUARTZ_PRIV(pScreen) \
-    ((QuartzScreenPtr)pScreen->devPrivates[quartzScreenIndex].ptr)
+    ((QuartzScreenPtr)dixLookupPrivate(&pScreen->devPrivates, quartzScreenKey))
 
 // Data stored at startup for Cocoa front end
 extern int              quartzEventWriteFD;
@@ -73,7 +73,7 @@ extern int              quartzEnableKeyEquivalents;
 // Other shared data
 extern int              quartzServerVisible;
 extern int              quartzServerQuitting;
-extern int              quartzScreenIndex;
+extern DevPrivateKey    quartzScreenKey;
 extern int              aquaMenuBarHeight;
 
 // Name of GLX bundle for native OpenGL
diff --git a/hw/darwin/quartz/quartzCursor.c b/hw/darwin/quartz/quartzCursor.c
index 6ed6a76..a121ce1 100644
--- a/hw/darwin/quartz/quartzCursor.c
+++ b/hw/darwin/quartz/quartzCursor.c
@@ -57,8 +57,7 @@ typedef struct {
     miPointerSpriteFuncPtr  spriteFuncs;
 } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
 
-static int darwinCursorScreenIndex = -1;
-static unsigned long darwinCursorGeneration = 0;
+static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKey;
 static CursorPtr quartzLatentCursor = NULL;
 static QD_Cursor gQDArrow; // QuickDraw arrow cursor
 
@@ -67,8 +66,8 @@ static CCrsrHandle currentCursor = NULL;
 static pthread_mutex_t cursorMutex;
 static pthread_cond_t cursorCondition;
 
-#define CURSOR_PRIV(pScreen) \
-    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
+#define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
+    dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
 
 #define HIDE_QD_CURSOR(pScreen, visible)                                \
     if (visible) {                                                      \
@@ -595,13 +594,6 @@ QuartzInitCursor(
         return FALSE;
     }
 
-    // allocate private storage for this screen's QuickDraw cursor info
-    if (darwinCursorGeneration != serverGeneration) {
-        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-        darwinCursorGeneration = serverGeneration;
-    }
-
     ScreenPriv = xcalloc( 1, sizeof(QuartzCursorScreenRec) );
     if (!ScreenPriv) return FALSE;
 
@@ -614,7 +606,7 @@ QuartzInitCursor(
     // initialize QuickDraw cursor handling
     GetQDGlobalsArrow(&gQDArrow);
     PointPriv = (miPointerScreenPtr)
-                    pScreen->devPrivates[miPointerScreenIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
     ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
     PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
diff --git a/hw/darwin/quartz/xpr/dri.c b/hw/darwin/quartz/xpr/dri.c
index 08ee382..8c6ed99 100644
--- a/hw/darwin/quartz/xpr/dri.c
+++ b/hw/darwin/quartz/xpr/dri.c
@@ -65,9 +65,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <AvailabilityMacros.h>
 
-static int DRIScreenPrivIndex = -1;
-static int DRIWindowPrivIndex = -1;
-static int DRIPixmapPrivIndex = -1;
+static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKey;
+static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKey;
+static DevPrivateKey DRIPixmapPrivKey = &DRIPixmapPrivKey;
 
 static RESTYPE DRIDrawablePrivResType;
 
@@ -179,11 +179,11 @@ DRIScreenInit(ScreenPtr pScreen)
 
     pDRIPriv = (DRIScreenPrivPtr) xcalloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
-        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
         return FALSE;
     }
 
-    pScreen->devPrivates[DRIScreenPrivIndex].ptr = (pointer) pDRIPriv;
+    dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, pDRIPriv);
     pDRIPriv->directRenderingSupport = TRUE;
     pDRIPriv->nrWindows = 0;
 
@@ -214,13 +214,6 @@ DRIFinishScreenInit(ScreenPtr pScreen)
 {
     DRIScreenPrivPtr  pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
-    /* Allocate zero sized private area for each window. Should a window
-     * become a DRI window, we'll hang a DRIWindowPrivateRec off of this
-     * private index.
-     */
-    if (!AllocateWindowPrivate(pScreen, DRIWindowPrivIndex, 0))
-        return FALSE;
-
     /* Wrap DRI support */
     pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
     pScreen->ValidateTree = DRIValidateTree;
@@ -249,31 +242,13 @@ DRICloseScreen(ScreenPtr pScreen)
 
     if (pDRIPriv && pDRIPriv->directRenderingSupport) {
         xfree(pDRIPriv);
-        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
     }
 }
 
 Bool
 DRIExtensionInit(void)
 {
-    static unsigned long DRIGeneration = 0;
-
-    if (DRIGeneration != serverGeneration) {
-        if ((DRIScreenPrivIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-        DRIGeneration = serverGeneration;
-    }
-
-    /*
-     * Allocate a window private index with a zero sized private area for
-     * each window, then should a window become a DRI window, we'll hang
-     * a DRIWindowPrivateRec off of this private index. Do same for pixmaps.
-     */
-    if ((DRIWindowPrivIndex = AllocateWindowPrivateIndex()) < 0)
-        return FALSE;
-    if ((DRIPixmapPrivIndex = AllocatePixmapPrivateIndex()) < 0)
-        return FALSE;
-
     DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete);
 
     return TRUE;
@@ -417,7 +392,8 @@ DRICreateSurface(ScreenPtr pScreen, Drawable id,
             }
 
             /* save private off of preallocated index */
-            pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv;
+	    dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey,
+			  pDRIDrawablePriv);
         }
     }
 
@@ -450,7 +426,8 @@ DRICreateSurface(ScreenPtr pScreen, Drawable id,
             }
 
             /* save private off of preallocated index */
-            pPix->devPrivates[DRIPixmapPrivIndex].ptr = (pointer)pDRIDrawablePriv;
+	    dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey,
+			  pDRIDrawablePriv);
         }
     }
 #endif
@@ -577,9 +554,9 @@ DRIDrawablePrivDelete(pointer pResource, XID id)
     xfree(pDRIDrawablePriv);
 
     if (pDrawable->type == DRAWABLE_WINDOW) {
-        pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
+	dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL);
     } else if (pDrawable->type == DRAWABLE_PIXMAP) {
-        pPix->devPrivates[DRIPixmapPrivIndex].ptr = NULL;
+	dixSetPrivate(&pPix->devPrivates, DRIPixmapPrivKey, NULL);
     }
 
     --pDRIPriv->nrWindows;
diff --git a/hw/darwin/quartz/xpr/dristruct.h b/hw/darwin/quartz/xpr/dristruct.h
index 9a3d01c..19d78a9 100644
--- a/hw/darwin/quartz/xpr/dristruct.h
+++ b/hw/darwin/quartz/xpr/dristruct.h
@@ -40,15 +40,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #define DRI_MAX_DRAWABLES 256
 
-#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) \
-    ((DRIWindowPrivIndex < 0) ? \
-     NULL : \
-     ((DRIDrawablePrivPtr)((pWin)->devPrivates[DRIWindowPrivIndex].ptr)))
+#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) ((DRIDrawablePrivPtr) \
+    dixLookupPrivate(&(pWin)->devPrivates, DRIWindowPrivKey))
 
-#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) \
-    ((DRIPixmapPrivIndex < 0) ? \
-     NULL : \
-     ((DRIDrawablePrivPtr)((pPix)->devPrivates[DRIPixmapPrivIndex].ptr)))
+#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) ((DRIDrawablePrivPtr) \
+    dixLookupPrivate(&(pPix)->devPrivates, DRIPixmapPrivKey))
 
 typedef struct _DRIDrawablePrivRec
 {
@@ -61,13 +57,12 @@ typedef struct _DRIDrawablePrivRec
     x_list          *notifiers;     /* list of (FUN . DATA) */
 } DRIDrawablePrivRec, *DRIDrawablePrivPtr;
 
-#define DRI_SCREEN_PRIV(pScreen) \
-    ((DRIScreenPrivIndex < 0) ? \
-     NULL : \
-     ((DRIScreenPrivPtr)((pScreen)->devPrivates[DRIScreenPrivIndex].ptr)))
+#define DRI_SCREEN_PRIV(pScreen) ((DRIScreenPrivPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, DRIScreenPrivKey))
 
 #define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \
-    (screenInfo.screens[screenIndex]->devPrivates[DRIScreenPrivIndex].ptr))
+    dixLookupPrivate(&screenInfo.screens[screenIndex]->devPrivates, \
+		     DRIScreenPrivKey))
 
 
 typedef struct _DRIScreenPrivRec
diff --git a/hw/darwin/quartz/xpr/xprCursor.c b/hw/darwin/quartz/xpr/xprCursor.c
index e7f23b7..c0516e8 100644
--- a/hw/darwin/quartz/xpr/xprCursor.c
+++ b/hw/darwin/quartz/xpr/xprCursor.c
@@ -53,11 +53,10 @@ typedef struct {
     miPointerSpriteFuncPtr  spriteFuncs;
 } QuartzCursorScreenRec, *QuartzCursorScreenPtr;
 
-static int darwinCursorScreenIndex = -1;
-static unsigned long darwinCursorGeneration = 0;
+static DevPrivateKey darwinCursorScreenKey = &darwinCursorScreenKey;
 
-#define CURSOR_PRIV(pScreen) \
-    ((QuartzCursorScreenPtr)pScreen->devPrivates[darwinCursorScreenIndex].ptr)
+#define CURSOR_PRIV(pScreen) ((QuartzCursorScreenPtr) \
+    dixLookupPrivate(&pScreen->devPrivates, darwinCursorScreenKey))
 
 
 static Bool
@@ -360,15 +359,6 @@ QuartzInitCursor(ScreenPtr pScreen)
     if (!miDCInitialize(pScreen, &quartzScreenFuncsRec))
         return FALSE;
 
-    /* allocate private storage for this screen's QuickDraw cursor info */
-    if (darwinCursorGeneration != serverGeneration)
-    {
-        if ((darwinCursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
-            return FALSE;
-
-        darwinCursorGeneration = serverGeneration;
-    }
-
     ScreenPriv = xcalloc(1, sizeof(QuartzCursorScreenRec));
     if (ScreenPriv == NULL)
         return FALSE;
@@ -379,7 +369,8 @@ QuartzInitCursor(ScreenPtr pScreen)
     ScreenPriv->QueryBestSize = pScreen->QueryBestSize;
     pScreen->QueryBestSize = QuartzCursorQueryBestSize;
 
-    PointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr;
+    PointPriv = (miPointerScreenPtr)
+	dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
     ScreenPriv->spriteFuncs = PointPriv->spriteFuncs;
     PointPriv->spriteFuncs = &quartzSpriteFuncsRec;
diff --git a/hw/dmx/dmxcmap.c b/hw/dmx/dmxcmap.c
index 949d7d6..4aa586a 100644
--- a/hw/dmx/dmxcmap.c
+++ b/hw/dmx/dmxcmap.c
@@ -46,24 +46,10 @@
 
 #include "micmap.h"
 
-static int dmxInitColormapPrivateFunc(ColormapPtr pColormap, int index)
-{
-    return TRUE;
-}
-
 static Bool dmxAllocateColormapPrivates(ColormapPtr pColormap)
 {
-    static unsigned long dmxColormapGeneration;
     dmxColormapPrivPtr   pCmapPriv;
 
-    if (dmxColormapGeneration != serverGeneration) {
-	if ((dmxColormapPrivateIndex
-	     = AllocateColormapPrivateIndex(dmxInitColormapPrivateFunc)) < 0)
-	    return FALSE;
-
-	dmxColormapGeneration = serverGeneration;
-    }
-
     pCmapPriv = (dmxColormapPrivPtr)xalloc(sizeof(*pCmapPriv));
     if (!pCmapPriv)
 	return FALSE;
diff --git a/hw/dmx/dmxcmap.h b/hw/dmx/dmxcmap.h
index 228f866..f968f86 100644
--- a/hw/dmx/dmxcmap.h
+++ b/hw/dmx/dmxcmap.h
@@ -56,15 +56,14 @@ extern Bool dmxBECreateColormap(ColormapPtr pColormap);
 extern Bool dmxBEFreeColormap(ColormapPtr pColormap);
 
 /** Private index.  \see dmxcmap.c \see dmxscrinit.c \see dmxwindow.c */
-extern int dmxColormapPrivateIndex;
+extern DevPrivateKey dmxColormapPrivateKey;
 
 /** Set colormap private structure. */
 #define DMX_SET_COLORMAP_PRIV(_pCMap, _pCMapPriv)			\
-    (_pCMap)->devPrivates[dmxColormapPrivateIndex].ptr			\
-	= (pointer)(_pCMapPriv);
+    dixSetPrivate(&(_pCMap)->devPrivates, dmxColormapPrivateKey, _pCMapPriv)
 
 /** Get colormap private structure. */
-#define DMX_GET_COLORMAP_PRIV(_pCMap)					\
-    (dmxColormapPrivPtr)(_pCMap)->devPrivates[dmxColormapPrivateIndex].ptr
+#define DMX_GET_COLORMAP_PRIV(_pCMap) (dmxColormapPrivPtr)		\
+    dixLookupPrivate(&(_pCMap)->devPrivates, dmxColormapPrivateKey)
 
 #endif /* DMXCMAP_H */
diff --git a/hw/dmx/dmxdpms.c b/hw/dmx/dmxdpms.c
index ea0d66c..8c745a6 100644
--- a/hw/dmx/dmxdpms.c
+++ b/hw/dmx/dmxdpms.c
@@ -177,7 +177,7 @@ void dmxDPMSWakeup(void)
     if (screenIsSaved == SCREEN_SAVER_ON)
         SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 #ifdef DPMSExtension
-    if (DPMSPowerLevel) DPMSSet(0);
+    if (DPMSPowerLevel) DPMSSet(serverClient, 0);
 #endif
 }
 
@@ -190,11 +190,11 @@ Bool DPMSSupported(void)
 }
 
 /** This is used by clients (e.g., xset) to set the DPMS level. */
-void DPMSSet(int level)
+int DPMSSet(ClientPtr client, int level)
 {
     int i;
 
-    if (!dpmsSupported) return;
+    if (!dpmsSupported) return Success;
 
     if (level < 0) level = DPMSModeOn;
     if (level > 3) level = DPMSModeOff;
@@ -208,5 +208,6 @@ void DPMSSet(int level)
 	    dmxSync(dmxScreen, FALSE);
 	}
     }
+    return Success;
 }
 #endif
diff --git a/hw/dmx/dmxgc.c b/hw/dmx/dmxgc.c
index 981f64d..ce1730c 100644
--- a/hw/dmx/dmxgc.c
+++ b/hw/dmx/dmxgc.c
@@ -82,13 +82,9 @@ static GCOps dmxGCOps = {
     dmxPushPixels
 };
 
-/** Initialize the GC on \a pScreen, which currently involves allocating
- *  the GC private associated with this screen. */
+/** Initialize the GC on \a pScreen */
 Bool dmxInitGC(ScreenPtr pScreen)
 {
-    if (!AllocateGCPrivate(pScreen, dmxGCPrivateIndex, sizeof(dmxGCPrivRec)))
-	return FALSE;
-
     return TRUE;
 }
 
diff --git a/hw/dmx/dmxgc.h b/hw/dmx/dmxgc.h
index 3d49f67..2da3ba8 100644
--- a/hw/dmx/dmxgc.h
+++ b/hw/dmx/dmxgc.h
@@ -64,11 +64,11 @@ extern void dmxBECreateGC(ScreenPtr pScreen, GCPtr pGC);
 extern Bool dmxBEFreeGC(GCPtr pGC);
 
 /** Private index.  \see dmxgc.c \see dmxscrinit.c */
-extern int dmxGCPrivateIndex;
+extern DevPrivateKey dmxGCPrivateKey;
 
 /** Get private. */
 #define DMX_GET_GC_PRIV(_pGC)						\
-    (dmxGCPrivPtr)(_pGC)->devPrivates[dmxGCPrivateIndex].ptr
+    (dmxGCPrivPtr)dixLookupPrivate(&(_pGC)->devPrivates, dmxGCPrivateKey)
 
 #define DMX_GC_FUNC_PROLOGUE(_pGC)					\
 do {									\
diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
index 478542a..f2110b5 100644
--- a/hw/dmx/dmxpict.c
+++ b/hw/dmx/dmxpict.c
@@ -144,8 +144,7 @@ Bool dmxPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     if (!miPictureInit(pScreen, formats, nformats))
 	return FALSE;
 
-    if (!AllocatePicturePrivate(pScreen, dmxPictPrivateIndex,
-				sizeof(dmxPictPrivRec)))
+    if (!dixRequestPrivate(dmxPictPrivateKey, sizeof(dmxPictPrivRec)))
 	return FALSE;
 
     ps = GetPictureScreen(pScreen);
diff --git a/hw/dmx/dmxpict.h b/hw/dmx/dmxpict.h
index c178ef3..a81eb7d 100644
--- a/hw/dmx/dmxpict.h
+++ b/hw/dmx/dmxpict.h
@@ -116,19 +116,19 @@ extern Bool dmxBEFreeGlyphSet(ScreenPtr pScreen, GlyphSetPtr glyphSet);
 extern int dmxBECreatePicture(PicturePtr pPicture);
 extern Bool dmxBEFreePicture(PicturePtr pPicture);
 
-extern int dmxPictPrivateIndex;		/**< Index for picture private data */
-extern int dmxGlyphSetPrivateIndex;	/**< Index for glyphset private data */
+extern DevPrivateKey dmxPictPrivateKey;	/**< Index for picture private data */
+extern DevPrivateKey dmxGlyphSetPrivateKey; /**< Index for glyphset private data */
 
 
 /** Get the picture private data given a picture pointer */
 #define DMX_GET_PICT_PRIV(_pPict)					\
-    (dmxPictPrivPtr)(_pPict)->devPrivates[dmxPictPrivateIndex].ptr
+    (dmxPictPrivPtr)dixLookupPrivate(&(_pPict)->devPrivates, dmxPictPrivateKey)
 
 /** Set the glyphset private data given a glyphset pointer */
 #define DMX_SET_GLYPH_PRIV(_pGlyph, _pPriv)				\
-    GlyphSetSetPrivate((_pGlyph), dmxGlyphSetPrivateIndex, (_pPriv))
+    GlyphSetSetPrivate((_pGlyph), dmxGlyphSetPrivateKey, (_pPriv))
 /** Get the glyphset private data given a glyphset pointer */
 #define DMX_GET_GLYPH_PRIV(_pGlyph)					\
-    (dmxGlyphPrivPtr)GlyphSetGetPrivate((_pGlyph), dmxGlyphSetPrivateIndex)
+    (dmxGlyphPrivPtr)GlyphSetGetPrivate((_pGlyph), dmxGlyphSetPrivateKey)
 
 #endif /* DMXPICT_H */
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index 323ae60..f8d0126 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -49,8 +49,7 @@
 /** Initialize a private area in \a pScreen for pixmap information. */
 Bool dmxInitPixmap(ScreenPtr pScreen)
 {
-    if (!AllocatePixmapPrivate(pScreen, dmxPixPrivateIndex,
-			       sizeof(dmxPixPrivRec)))
+    if (!dixRequestPrivate(dmxPixPrivateKey, sizeof(dmxPixPrivRec)))
 	return FALSE;
 
     return TRUE;
@@ -173,7 +172,7 @@ Bool dmxDestroyPixmap(PixmapPtr pPixmap)
 	    dmxSync(dmxScreen, FALSE);
 	}
     }
-    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+    dixFreePrivates(pPixmap->devPrivates);
     xfree(pPixmap);
 
 #if 0
diff --git a/hw/dmx/dmxpixmap.h b/hw/dmx/dmxpixmap.h
index 4ecd10f..3cfd99e 100644
--- a/hw/dmx/dmxpixmap.h
+++ b/hw/dmx/dmxpixmap.h
@@ -57,10 +57,10 @@ extern void      dmxBECreatePixmap(PixmapPtr pPixmap);
 extern Bool      dmxBEFreePixmap(PixmapPtr pPixmap);
 
 /** Private index.  \see dmxpicmap.h \see dmxscrinit.c */
-extern int dmxPixPrivateIndex;
+extern DevPrivateKey dmxPixPrivateKey;
 
 /** Get pixmap private pointer. */
 #define DMX_GET_PIXMAP_PRIV(_pPix)					\
-    (dmxPixPrivPtr)(_pPix)->devPrivates[dmxPixPrivateIndex].ptr
+    (dmxPixPrivPtr)dixLookupPrivate(&(_pPix)->devPrivates, dmxPixPrivateKey)
 
 #endif /* DMXPIXMAP_H */
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index 8ae448a..9b15bb3 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -67,15 +67,15 @@ static Bool dmxSaveScreen(ScreenPtr pScreen, int what);
 static unsigned long dmxGeneration;
 static unsigned long *dmxCursorGeneration;
 
-int dmxGCPrivateIndex;          /**< Private index for GCs       */
-int dmxWinPrivateIndex;         /**< Private index for Windows   */
-int dmxPixPrivateIndex;         /**< Private index for Pixmaps   */
+DevPrivateKey dmxGCPrivateKey = &dmxGCPrivateKey; /**< Private index for GCs       */
+DevPrivateKey dmxWinPrivateKey = &dmxWinPrivateKey; /**< Private index for Windows   */
+DevPrivateKey dmxPixPrivateKey = &dmxPixPrivateKey; /**< Private index for Pixmaps   */
 int dmxFontPrivateIndex;        /**< Private index for Fonts     */
-int dmxScreenPrivateIndex;      /**< Private index for Screens   */
-int dmxColormapPrivateIndex;    /**< Private index for Colormaps */
+DevPrivateKey dmxScreenPrivateKey = &dmxScreenPrivateKey; /**< Private index for Screens   */
+DevPrivateKey dmxColormapPrivateKey = &dmxColormapPrivateKey; /**< Private index for Colormaps */
 #ifdef RENDER
-int dmxPictPrivateIndex;        /**< Private index for Picts     */
-int dmxGlyphSetPrivateIndex;    /**< Private index for GlyphSets */
+DevPrivateKey dmxPictPrivateKey = &dmxPictPrivateKey; /**< Private index for Picts     */
+DevPrivateKey dmxGlyphSetPrivateKey = &dmxGlyphSetPrivateKey; /**< Private index for GlyphSets */
 #endif
 
 /** Initialize the parts of screen \a idx that require access to the
@@ -208,43 +208,11 @@ Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[])
     int                   i, j;
 
     if (dmxGeneration != serverGeneration) {
-#ifdef RENDER
-	/* Allocate picture private index */
-	dmxPictPrivateIndex = AllocatePicturePrivateIndex();
-	if (dmxPictPrivateIndex == -1)
-	    return FALSE;
-
-	/* Allocate glyph set private index */
-	dmxGlyphSetPrivateIndex = AllocateGlyphSetPrivateIndex();
-	if (dmxGlyphSetPrivateIndex == -1)
-	    return FALSE;
-#endif
-
-	/* Allocate GC private index */
-	dmxGCPrivateIndex = AllocateGCPrivateIndex();
-	if (dmxGCPrivateIndex == -1)
-	    return FALSE;
-
-	/* Allocate window private index */
-	dmxWinPrivateIndex = AllocateWindowPrivateIndex();
-	if (dmxWinPrivateIndex == -1)
-	    return FALSE;
-
-	/* Allocate pixmap private index */
-	dmxPixPrivateIndex = AllocatePixmapPrivateIndex();
-	if (dmxPixPrivateIndex == -1)
-	    return FALSE;
-
 	/* Allocate font private index */
 	dmxFontPrivateIndex = AllocateFontPrivateIndex();
 	if (dmxFontPrivateIndex == -1)
 	    return FALSE;
 
-        /* Allocate screen private index */
-        dmxScreenPrivateIndex = AllocateScreenPrivateIndex();
-        if (dmxScreenPrivateIndex == -1)
-            return FALSE;
-
 	dmxGeneration = serverGeneration;
     }
 
diff --git a/hw/dmx/dmxscrinit.h b/hw/dmx/dmxscrinit.h
index 46a0a00..a464235 100644
--- a/hw/dmx/dmxscrinit.h
+++ b/hw/dmx/dmxscrinit.h
@@ -41,7 +41,7 @@
 #include "scrnintstr.h"
 
 /** Private index.  \see dmxscrrinit.c \see input/dmxconcole.c */
-extern int dmxScreenPrivateIndex;
+extern DevPrivateKey dmxScreenPrivateKey;
 
 extern Bool dmxScreenInit(int idx, ScreenPtr pScreen, int argc, char *argv[]);
 
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index b66f2a3..fa6b9a2 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -64,8 +64,7 @@ static void dmxDoSetShape(WindowPtr pWindow);
 /** Initialize the private area for the window functions. */
 Bool dmxInitWindow(ScreenPtr pScreen)
 {
-    if (!AllocateWindowPrivate(pScreen, dmxWinPrivateIndex,
-			       sizeof(dmxWinPrivRec)))
+    if (!dixRequestPrivate(dmxWinPrivateKey, sizeof(dmxWinPrivRec)))
 	return FALSE;
 
     return TRUE;
diff --git a/hw/dmx/dmxwindow.h b/hw/dmx/dmxwindow.h
index f976c79..1a98433 100644
--- a/hw/dmx/dmxwindow.h
+++ b/hw/dmx/dmxwindow.h
@@ -107,11 +107,11 @@ extern void dmxSetShape(WindowPtr pWindow);
 #endif
 
 /** Private index.  \see dmxwindow.c \see dmxscrinit.c */
-extern int dmxWinPrivateIndex;
+extern DevPrivateKey dmxWinPrivateKey;
 
 /** Get window private pointer. */
-#define DMX_GET_WINDOW_PRIV(_pWin)					\
-    ((dmxWinPrivPtr)(_pWin)->devPrivates[dmxWinPrivateIndex].ptr)
+#define DMX_GET_WINDOW_PRIV(_pWin) ((dmxWinPrivPtr) \
+    dixLookupPrivate(&(_pWin)->devPrivates, dmxWinPrivateKey))
 
 /* All of these macros are only used in dmxwindow.c */
 #define DMX_WINDOW_FUNC_PROLOGUE(_pGC)					\
diff --git a/hw/dmx/input/dmxconsole.c b/hw/dmx/input/dmxconsole.c
index cc820a2..b2a2ec3 100644
--- a/hw/dmx/input/dmxconsole.c
+++ b/hw/dmx/input/dmxconsole.c
@@ -612,7 +612,8 @@ static Bool dmxCloseConsoleScreen(int idx, ScreenPtr pScreen)
 {
     myPrivate *priv, *last;
 
-    for (last = priv = pScreen->devPrivates[dmxScreenPrivateIndex].ptr;
+    for (last = priv = (myPrivate *)dixLookupPrivate(&pScreen->devPrivates,
+						     dmxScreenPrivateKey);
          priv;
          priv = priv->next) dmxCloseConsole(last = priv);
     
@@ -846,13 +847,15 @@ void dmxConsoleInit(DevicePtr pDev)
 
     dmxConsoleDraw(priv, 1, 1);
 
-    if (screenInfo.screens[0]->devPrivates[dmxScreenPrivateIndex].ptr)
-        priv->next = (screenInfo.screens[0]
-                      ->devPrivates[dmxScreenPrivateIndex].ptr);
+    if (dixLookupPrivate(&screenInfo.screens[0]->devPrivates,
+			 dmxScreenPrivateKey))
+        priv->next = dixLookupPrivate(&screenInfo.screens[0]->devPrivates,
+				      dmxScreenPrivateKey);
     else 
         DMX_WRAP(CloseScreen, dmxCloseConsoleScreen,
                  priv, screenInfo.screens[0]);
-    screenInfo.screens[0]->devPrivates[dmxScreenPrivateIndex].ptr = priv;
+    dixSetPrivate(&screenInfo.screens[0]->devPrivates, dmxScreenPrivateKey,
+		  priv);
 }
 
 /** Fill in the \a info structure for the specified \a pDev.  Only used
diff --git a/hw/kdrive/savage/s3draw.c b/hw/kdrive/savage/s3draw.c
index 258dbcf..39cc256 100644
--- a/hw/kdrive/savage/s3draw.c
+++ b/hw/kdrive/savage/s3draw.c
@@ -78,9 +78,8 @@ short s3alu[16] = {
 #define PixTransStore(t)	*pix_trans = (t)
 #endif
 
-int	s3GCPrivateIndex;
-int	s3WindowPrivateIndex;
-int	s3Generation;
+DevPrivateKey s3GCPrivateKey = &s3GCPrivateKey;
+DevPrivateKey s3WindowPrivateKey = &s3WindowPrivateKey;
 
 /*
   s3DoBitBlt
@@ -2182,7 +2181,7 @@ s3CreateWindow (WindowPtr pWin)
     KdScreenPriv(pWin->drawable.pScreen);
     s3ScreenInfo(pScreenPriv);
     
-    pWin->devPrivates[s3WindowPrivateIndex].ptr = 0;
+    dixSetPrivate(&pWin->devPrivates, s3WindowPrivateKey, NULL);
     return KdCreateWindow (pWin);
 }
 
@@ -3095,15 +3094,7 @@ s3DrawInit (ScreenPtr pScreen)
     }
     else
     {
-	if (serverGeneration != s3Generation)
-	{
-	    s3GCPrivateIndex = AllocateGCPrivateIndex ();
-	    s3WindowPrivateIndex = AllocateWindowPrivateIndex ();
-	    s3Generation = serverGeneration;
-	}
-	if (!AllocateWindowPrivate(pScreen, s3WindowPrivateIndex, 0))
-	    return FALSE;
-	if (!AllocateGCPrivate(pScreen, s3GCPrivateIndex, sizeof (s3PrivGCRec)))
+	if (!dixRequestPrivate(s3GCPrivateKey, sizeof (s3PrivGCRec)))
 	    return FALSE;
 	pScreen->CreateGC = s3CreateGC;
 	pScreen->CreateWindow = s3CreateWindow;
diff --git a/hw/kdrive/savage/s3draw.h b/hw/kdrive/savage/s3draw.h
index 0689043..eab8e39 100644
--- a/hw/kdrive/savage/s3draw.h
+++ b/hw/kdrive/savage/s3draw.h
@@ -24,8 +24,8 @@
 #ifndef _S3DRAW_H_
 #define _S3DRAW_H_
 
-extern int  s3GCPrivateIndex;
-extern int  s3WindowPrivateIndex;
+extern DevPrivateKey s3GCPrivateKey;
+extern DevPrivateKey s3WindowPrivateKey;
 
 typedef struct _s3Pattern {
     S3PatternCache    	*cache;
@@ -42,16 +42,16 @@ typedef struct _s3PrivGC {
     s3PatternPtr    pPattern;	    /* pattern */
 } s3PrivGCRec, *s3PrivGCPtr;
 
-#define s3GetGCPrivate(g)	    ((s3PrivGCPtr) \
-			    (g)->devPrivates[s3GCPrivateIndex].ptr)
+#define s3GetGCPrivate(g) ((s3PrivGCPtr) \
+    dixLookupPrivate(&(g)->devPrivates, s3GCPrivateKey))
 
-#define s3GCPrivate(g)	    s3PrivGCPtr s3Priv = s3GetGCPrivate(g)
+#define s3GCPrivate(g)    s3PrivGCPtr s3Priv = s3GetGCPrivate(g)
 
-#define s3GetWindowPrivate(w)    ((s3PatternPtr) \
-			    (w)->devPrivates[s3WindowPrivateIndex].ptr)
+#define s3GetWindowPrivate(w) ((s3PatternPtr) \
+    dixLookupPrivate(&(w)->devPrivates, s3WindowPrivateKey))
 
-#define s3SetWindowPrivate(w,p) (\
-	    (w)->devPrivates[s3WindowPrivateIndex].ptr = (pointer) p)
+#define s3SetWindowPrivate(w,p) \
+    dixSetPrivate(&(w)->devPrivates, s3WindowPrivateKey, p)
 
 void	_s3LoadPattern (ScreenPtr pScreen, int fb, s3PatternPtr pPattern);
 
diff --git a/hw/kdrive/src/kaa.c b/hw/kdrive/src/kaa.c
index c9805dd..da618be 100644
--- a/hw/kdrive/src/kaa.c
+++ b/hw/kdrive/src/kaa.c
@@ -42,9 +42,8 @@
 #define DBG_PIXMAP(a)
 #endif
  
-int kaaGeneration;
-int kaaScreenPrivateIndex;
-int kaaPixmapPrivateIndex;
+DevPrivateKey kaaScreenPrivateKey = &kaaScreenPrivateKey;
+DevPrivateKey kaaPixmapPrivateKey = &kaaPixmapPrivateKey;
 
 #define KAA_PIXMAP_SCORE_MOVE_IN    10
 #define KAA_PIXMAP_SCORE_MAX	    20
@@ -1066,13 +1065,6 @@ kaaDrawInit (ScreenPtr		pScreen,
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
     
-    if (kaaGeneration != serverGeneration)
-    {
-	kaaScreenPrivateIndex = AllocateScreenPrivateIndex();
-	kaaPixmapPrivateIndex = AllocatePixmapPrivateIndex();
-	kaaGeneration = serverGeneration;
-    }
-
     pKaaScr = xalloc (sizeof (KaaScreenPrivRec));
 
     if (!pKaaScr)
@@ -1080,7 +1072,7 @@ kaaDrawInit (ScreenPtr		pScreen,
     
     pKaaScr->info = pScreenInfo;
     
-    pScreen->devPrivates[kaaScreenPrivateIndex].ptr = (pointer) pKaaScr;
+    dixSetPrivate(&pScreen->devPrivates, kaaScreenPrivateKey, pKaaScr);
     
     /*
      * Hook up asynchronous drawing
@@ -1106,17 +1098,11 @@ kaaDrawInit (ScreenPtr		pScreen,
     if ((pKaaScr->info->flags & KAA_OFFSCREEN_PIXMAPS) &&
 	screen->off_screen_base < screen->memory_size)
     {
-	if (!AllocatePixmapPrivate(pScreen, kaaPixmapPrivateIndex,
-				   sizeof (KaaPixmapPrivRec)))
+	if (!dixRequestPrivate(kaaPixmapPrivateKey, sizeof (KaaPixmapPrivRec)))
 	    return FALSE;
 	pScreen->CreatePixmap = kaaCreatePixmap;
 	pScreen->DestroyPixmap = kaaDestroyPixmap;
     }
-    else
-    {
-	if (!AllocatePixmapPrivate(pScreen, kaaPixmapPrivateIndex, 0))
-	    return FALSE;
-    }
 
     return TRUE;
 }
diff --git a/hw/kdrive/src/kaa.h b/hw/kdrive/src/kaa.h
index db890a7..90b963b 100644
--- a/hw/kdrive/src/kaa.h
+++ b/hw/kdrive/src/kaa.h
@@ -27,11 +27,14 @@
 
 #include "picturestr.h"
 
-#define KaaGetScreenPriv(s)	((KaaScreenPrivPtr)(s)->devPrivates[kaaScreenPrivateIndex].ptr)
+#define KaaGetScreenPriv(s) ((KaaScreenPrivPtr) \
+    dixLookupPrivate(&(s)->devPrivates, kaaScreenPrivateKey))
 #define KaaScreenPriv(s)	KaaScreenPrivPtr    pKaaScr = KaaGetScreenPriv(s)
 
-#define KaaGetPixmapPriv(p)	((KaaPixmapPrivPtr)(p)->devPrivates[kaaPixmapPrivateIndex].ptr)
-#define KaaSetPixmapPriv(p,a)	((p)->devPrivates[kaaPixmapPrivateIndex].ptr = (pointer) (a))
+#define KaaGetPixmapPriv(p) ((KaaPixmapPrivPtr) \
+    dixLookupPrivate(&(p)->devPrivates, kaaPixmapPrivateKey))
+#define KaaSetPixmapPriv(p,a) \
+    dixSetPrivate(&(p)->devPrivates, kaaPixmapPrivateKey, a)
 #define KaaPixmapPriv(p)	KaaPixmapPrivPtr pKaaPixmap = KaaGetPixmapPriv(p)
 
 typedef struct {
@@ -46,8 +49,8 @@ typedef struct {
     Bool	    dirty;
 } KaaPixmapPrivRec, *KaaPixmapPrivPtr;
 
-extern int kaaScreenPrivateIndex;
-extern int kaaPixmapPrivateIndex;
+extern DevPrivateKey kaaScreenPrivateKey;
+extern DevPrivateKey kaaPixmapPrivateKey;
 
 
 void
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 2da008d..d6646f0 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -498,7 +498,7 @@ typedef struct _KaaScreenInfo {
     (PixmapWidthPaddingInfo[d].padRoundUp+1)))
 #endif
 
-extern int		kdScreenPrivateIndex;
+extern DevPrivateKey	kdScreenPrivateKey;
 extern unsigned long	kdGeneration;
 extern Bool		kdEnabled;
 extern Bool		kdSwitchPending;
@@ -510,9 +510,9 @@ extern char		*kdSwitchCmd;
 extern KdOsFuncs	*kdOsFuncs;
 
 #define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \
-				  (pScreen)->devPrivates[kdScreenPrivateIndex].ptr)
-#define KdSetScreenPriv(pScreen,v) ((pScreen)->devPrivates[kdScreenPrivateIndex].ptr = \
-				    (pointer) v)
+    dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey))
+#define KdSetScreenPriv(pScreen,v) \
+    dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v)
 #define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen)
 
 /* kaa.c */
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index b8fbd73..fa50686 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -104,23 +104,22 @@ static void KdXVClipNotify(WindowPtr pWin, int dx, int dy);
 static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr*, int);
 
 
-int KdXVWindowIndex = -1;
-int KdXvScreenIndex = -1;
-static unsigned long KdXVGeneration = 0;
+DevPrivateKey KdXVWindowKey = &KdXVWindowKey;
+DevPrivateKey KdXvScreenKey = &KdXvScreenKey;
 static unsigned long PortResource = 0;
 
-int (*XvGetScreenIndexProc)(void) = XvGetScreenIndex;
+int (*XvGetScreenKeyProc)(void) = XvGetScreenKey;
 unsigned long (*XvGetRTPortProc)(void) = XvGetRTPort;
 int (*XvScreenInitProc)(ScreenPtr) = XvScreenInit;
 
-#define GET_XV_SCREEN(pScreen) \
-	((XvScreenPtr)((pScreen)->devPrivates[KdXvScreenIndex].ptr))
+#define GET_XV_SCREEN(pScreen) ((XvScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, KdXvScreenKey))
 
 #define GET_KDXV_SCREEN(pScreen) \
   	((KdXVScreenPtr)(GET_XV_SCREEN(pScreen)->devPriv.ptr))
 
-#define GET_KDXV_WINDOW(pWin) \
-	((KdXVWindowPtr)((pWin)->devPrivates[KdXVWindowIndex].ptr))
+#define GET_KDXV_WINDOW(pWin) ((KdXVWindowPtr) \
+    dixLookupPrivate(&(pWin)->devPrivates, KdXVWindowKey))
 
 static KdXVInitGenericAdaptorPtr *GenDrivers = NULL;
 static int NumGenDrivers = 0;
@@ -192,21 +191,12 @@ KdXVScreenInit(
 
 /*   fprintf(stderr,"KdXVScreenInit initializing %d adaptors\n",num); */
 
-  if(KdXVGeneration != serverGeneration) {
-	if((KdXVWindowIndex = AllocateWindowPrivateIndex()) < 0)
-	    return FALSE;
-	KdXVGeneration = serverGeneration;
-  }
-
-  if(!AllocateWindowPrivate(pScreen,KdXVWindowIndex,0))
-        return FALSE;
-
-  if(!XvGetScreenIndexProc || !XvGetRTPortProc || !XvScreenInitProc)
+  if(!XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
 	return FALSE;  
 
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
-  KdXvScreenIndex = (*XvGetScreenIndexProc)();
+  KdXvScreenIndex = (*XvGetScreenKeyProc)();
   PortResource = (*XvGetRTPortProc)();
 
   pxvs = GET_XV_SCREEN(pScreen);
@@ -938,7 +928,7 @@ KdXVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 	if(!winPriv) return BadAlloc;
 	winPriv->PortRec = portPriv;
 	winPriv->next = PrivRoot;
-	pWin->devPrivates[KdXVWindowIndex].ptr = (pointer)winPriv;
+	dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv);
    }   
    return Success;
 }
@@ -956,8 +946,7 @@ KdXVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 	    if(prevPriv) 
 		prevPriv->next = winPriv->next;
 	    else 
-		pWin->devPrivates[KdXVWindowIndex].ptr = 
-					(pointer)winPriv->next;
+		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv->next);
 	    xfree(winPriv);
 	    break;
 	}
@@ -981,7 +970,8 @@ KdXVCreateWindow(WindowPtr pWin)
   ret = (*pScreen->CreateWindow)(pWin);
   pScreen->CreateWindow = KdXVCreateWindow;
 
-  if(ret) pWin->devPrivates[KdXVWindowIndex].ptr = NULL;
+  if (ret)
+      dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, NULL);
 
   return ret;
 }
@@ -1010,7 +1000,7 @@ KdXVDestroyWindow(WindowPtr pWin)
      xfree(tmp);
   }
 
-  pWin->devPrivates[KdXVWindowIndex].ptr = NULL;
+  dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, NULL);
 
   pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
   ret = (*pScreen->DestroyWindow)(pWin);
@@ -1067,8 +1057,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
 	    pPriv->pDraw = NULL;
 
 	    if(!pPrev) 
-	       pWin->devPrivates[KdXVWindowIndex].ptr = 		
-						(pointer)(WinPriv->next);
+		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, WinPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
 	    tmp = WinPriv;
@@ -1117,8 +1106,7 @@ KdXVClipNotify(WindowPtr pWin, int dx, int dy)
 	    pPriv->pDraw = NULL;
 
 	    if(!pPrev) 
-	       pWin->devPrivates[KdXVWindowIndex].ptr = 		
-						(pointer)(WinPriv->next);
+		dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
 	    tmp = WinPriv;
diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index 69d619e..f8febc5 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -57,9 +57,9 @@
 /* General parameters */
 extern int xf86DoConfigure;
 extern Bool xf86DoConfigurePass1;
-extern int xf86ScreenIndex;		/* Index into pScreen.devPrivates */
-extern int xf86CreateRootWindowIndex;	/* Index into pScreen.devPrivates */
-extern int xf86PixmapIndex;
+extern DevPrivateKey xf86ScreenKey;
+extern DevPrivateKey xf86CreateRootWindowKey;
+extern DevPrivateKey xf86PixmapKey;
 extern ScrnInfoPtr *xf86Screens;	/* List of pointers to ScrnInfoRecs */
 extern const unsigned char byte_reversed[256];
 extern ScrnInfoPtr xf86CurrentScreen;
@@ -72,8 +72,8 @@ extern Bool sbusSlotClaimed;
 extern confDRIRec xf86ConfigDRI;
 extern Bool xf86inSuspend;
 
-#define XF86SCRNINFO(p) ((ScrnInfoPtr)((p)->devPrivates[xf86ScreenIndex].ptr))
-
+#define XF86SCRNINFO(p) ((ScrnInfoPtr)dixLookupPrivate(&(p)->devPrivates, \
+						       xf86ScreenKey))
 #define XF86FLIP_PIXELS() \
 	do { \
 	    if (xf86GetFlipPixels()) { \
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
index 9474ec8..68f538f 100644
--- a/hw/xfree86/common/xf86DGA.c
+++ b/hw/xfree86/common/xf86DGA.c
@@ -49,8 +49,7 @@
 
 #include "mi.h"
 
-static unsigned long DGAGeneration = 0;
-static int DGAScreenIndex = -1;
+static DevPrivateKey DGAScreenKey = NULL;
 static int mieq_installed = 0;
 
 static Bool DGACloseScreen(int i, ScreenPtr pScreen);
@@ -68,8 +67,8 @@ DGACopyModeInfo(
 
 _X_EXPORT int *XDGAEventBase = NULL;
 
-#define DGA_GET_SCREEN_PRIV(pScreen) \
-	((DGAScreenPtr)((pScreen)->devPrivates[DGAScreenIndex].ptr))
+#define DGA_GET_SCREEN_PRIV(pScreen) ((DGAScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, DGAScreenKey))
 
 
 typedef struct _FakedVisualList{
@@ -116,11 +115,7 @@ DGAInit(
     if(!modes || num <= 0)
 	return FALSE;
 
-    if(DGAGeneration != serverGeneration) {
-	if((DGAScreenIndex = AllocateScreenPrivateIndex()) < 0)
-	    return FALSE;
-	DGAGeneration = serverGeneration;
-    }
+    DGAScreenKey = &DGAScreenKey;
 
     if(!(pScreenPriv = (DGAScreenPtr)xalloc(sizeof(DGAScreenRec))))
 	return FALSE;
@@ -148,7 +143,7 @@ DGAInit(
 	    modes[i].flags &= ~DGA_PIXMAP_AVAILABLE;
 #endif
 
-    pScreen->devPrivates[DGAScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, DGAScreenKey, pScreenPriv);
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = DGACloseScreen;
     pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
@@ -176,7 +171,7 @@ DGAReInitModes(
     int i;
 
     /* No DGA? Ignore call (but don't make it look like it failed) */
-    if(DGAScreenIndex < 0)
+    if(DGAScreenKey == NULL)
 	return TRUE;
 	
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
@@ -350,7 +345,7 @@ xf86SetDGAMode(
    DGAModePtr pMode = NULL;
 
    /* First check if DGAInit was successful on this screen */
-   if (DGAScreenIndex < 0)
+   if (DGAScreenKey == NULL)
 	return BadValue;
    pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
    if (!pScreenPriv)
@@ -485,7 +480,7 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
    DGAModePtr   pMode;
    PixmapPtr    pPix;
 
-   if(DGAScreenIndex < 0)
+   if(DGAScreenKey == NULL)
 	return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -535,11 +530,12 @@ DGAChangePixmapMode(int index, int *x, int *y, int mode)
 _X_EXPORT Bool
 DGAAvailable(int index) 
 {
-   if(DGAScreenIndex < 0)
+   if(DGAScreenKey == NULL)
 	return FALSE;
    
-   if (!xf86NoSharedResources(((ScrnInfoPtr)screenInfo.screens[index]->
-			 devPrivates[xf86ScreenIndex].ptr)->scrnIndex,MEM))
+   if (!xf86NoSharedResources(((ScrnInfoPtr)dixLookupPrivate(
+				   &screenInfo.screens[index]->devPrivates,
+				   xf86ScreenKey))->scrnIndex, MEM))
        return FALSE;
    
    if(DGA_GET_SCREEN_PRIV(screenInfo.screens[index]))
@@ -553,7 +549,7 @@ DGAActive(int index)
 {
    DGAScreenPtr pScreenPriv;
 
-   if(DGAScreenIndex < 0)
+   if(DGAScreenKey == NULL)
 	return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -574,7 +570,7 @@ DGAShutdown()
     ScrnInfoPtr pScrn;
     int i;
 
-    if(DGAScreenIndex < 0)
+    if(DGAScreenKey == NULL)
 	return;
 
     for(i = 0; i < screenInfo.numScreens; i++) {
@@ -904,7 +900,7 @@ DGAVTSwitch(void)
 
        /* Alternatively, this could send events to DGA clients */
 
-       if(DGAScreenIndex >= 0) {
+       if(DGAScreenKey) {
 	   DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
 
 	   if(pScreenPriv && pScreenPriv->current)
@@ -921,7 +917,7 @@ DGAStealKeyEvent(int index, int key_code, int is_down)
    DGAScreenPtr pScreenPriv;
    dgaEvent    de;
     
-   if(DGAScreenIndex < 0) /* no DGA */
+   if(DGAScreenKey == NULL) /* no DGA */
         return FALSE;
 
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -945,7 +941,7 @@ DGAStealMotionEvent(int index, int dx, int dy)
    DGAScreenPtr pScreenPriv;
     dgaEvent    de;
 
-   if(DGAScreenIndex < 0) /* no DGA */
+   if(DGAScreenKey == NULL) /* no DGA */
         return FALSE;
     
    pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -980,7 +976,7 @@ DGAStealButtonEvent(int index, int button, int is_down)
     DGAScreenPtr pScreenPriv;
     dgaEvent de;
 
-    if (DGAScreenIndex < 0)
+    if (DGAScreenKey == NULL)
         return FALSE;
     
     pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]);
@@ -1006,7 +1002,7 @@ Bool
 DGAIsDgaEvent (xEvent *e)
 {
     int	    coreEquiv;
-    if (DGAScreenIndex < 0 || XDGAEventBase == 0)
+    if (DGAScreenKey == NULL || XDGAEventBase == 0)
 	return FALSE;
     coreEquiv = e->u.u.type - *XDGAEventBase;
     if (KeyPress <= coreEquiv && coreEquiv <= MotionNotify)
@@ -1275,7 +1271,7 @@ DGAHandleEvent(int screen_num, xEvent *event, DeviceIntPtr device, int nevents)
     int		    coreEquiv;
 
     /* no DGA */
-    if (DGAScreenIndex < 0 || XDGAEventBase == 0)
+    if (DGAScreenKey == NULL || XDGAEventBase == 0)
 	return;
     pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen);
     
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index a4ae67e..536d38e 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -47,8 +47,7 @@
 
 
 #ifdef DPMSExtension
-static int DPMSGeneration = 0;
-static int DPMSIndex = -1;
+static DevPrivateKey DPMSKey = NULL;
 static Bool DPMSClose(int i, ScreenPtr pScreen);
 static int DPMSCount = 0;
 #endif
@@ -62,18 +61,15 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
     DPMSPtr pDPMS;
     pointer DPMSOpt;
 
-    if (serverGeneration != DPMSGeneration) {
-	if ((DPMSIndex = AllocateScreenPrivateIndex()) < 0)
-	    return FALSE;
-	DPMSGeneration = serverGeneration;
-    }
+    DPMSKey = &DPMSKey;
 
     if (DPMSDisabledSwitch)
 	DPMSEnabled = FALSE;
-    if (!(pScreen->devPrivates[DPMSIndex].ptr = xcalloc(sizeof(DPMSRec), 1)))
+    if (!dixSetPrivate(&pScreen->devPrivates, DPMSKey,
+		       xcalloc(sizeof(DPMSRec), 1)))
 	return FALSE;
 
-    pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
+    pDPMS = (DPMSPtr)dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
     pScrn->DPMSSet = set;
     pDPMS->Flags = flags;
     DPMSOpt = xf86FindOption(pScrn->options, "dpms");
@@ -110,10 +106,10 @@ DPMSClose(int i, ScreenPtr pScreen)
     DPMSPtr pDPMS;
 
     /* This shouldn't happen */
-    if (DPMSIndex < 0)
+    if (DPMSKey == NULL)
 	return FALSE;
 
-    pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
+    pDPMS = (DPMSPtr)dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
 
     /* This shouldn't happen */
     if (!pDPMS)
@@ -132,9 +128,9 @@ DPMSClose(int i, ScreenPtr pScreen)
     }
     
     xfree((pointer)pDPMS);
-    pScreen->devPrivates[DPMSIndex].ptr = NULL;
+    dixSetPrivate(&pScreen->devPrivates, DPMSKey, NULL);
     if (--DPMSCount == 0)
-	DPMSIndex = -1;
+	DPMSKey = NULL;
     return pScreen->CloseScreen(i, pScreen);
 }
 
@@ -153,7 +149,7 @@ DPMSSet(ClientPtr client, int level)
 
     DPMSPowerLevel = level;
 
-    if (DPMSIndex < 0)
+    if (DPMSKey == NULL)
 	return Success;
 
     if (level != DPMSModeOn) {
@@ -165,7 +161,8 @@ DPMSSet(ClientPtr client, int level)
     /* For each screen, set the DPMS level */
     for (i = 0; i < xf86NumScreens; i++) {
     	pScrn = xf86Screens[i];
-	pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
+	pDPMS = (DPMSPtr)dixLookupPrivate(&screenInfo.screens[i]->devPrivates,
+					  DPMSKey);
 	if (pDPMS && pScrn->DPMSSet && pDPMS->Enabled && pScrn->vtSema) { 
 	    xf86EnableAccess(pScrn);
 	    pScrn->DPMSSet(pScrn, level, 0);
@@ -186,14 +183,15 @@ DPMSSupported(void)
     DPMSPtr pDPMS;
     ScrnInfoPtr pScrn;
 
-    if (DPMSIndex < 0) {
+    if (DPMSKey == NULL) {
 	return FALSE;
     }
 
     /* For each screen, check if DPMS is supported */
     for (i = 0; i < xf86NumScreens; i++) {
     	pScrn = xf86Screens[i];
-	pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
+	pDPMS = (DPMSPtr)dixLookupPrivate(&screenInfo.screens[i]->devPrivates,
+					  DPMSKey);
 	if (pDPMS && pScrn->DPMSSet)
 	    return TRUE;
     }
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 7dc45b7..4b51056 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -46,10 +46,12 @@
 
 /* Globals that video drivers may access */
 
-_X_EXPORT int xf86ScreenIndex = -1;	/* Index of ScrnInfo in pScreen.devPrivates */
-int xf86CreateRootWindowIndex = -1;	/* Index into pScreen.devPrivates */
+/* Index into pScreen.devPrivates */
+DevPrivateKey xf86CreateRootWindowKey = &xf86CreateRootWindowKey;
+/* Index of ScrnInfo in pScreen.devPrivates */
+_X_EXPORT DevPrivateKey xf86ScreenKey = &xf86ScreenKey;
+_X_EXPORT DevPrivateKey xf86PixmapKey = &xf86PixmapKey;
 _X_EXPORT ScrnInfoPtr *xf86Screens = NULL;	/* List of ScrnInfos */
-_X_EXPORT int xf86PixmapIndex = 0;
 _X_EXPORT const unsigned char byte_reversed[256] =
 {
     0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 90f744c..06af74f 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -139,8 +139,8 @@ xf86CreateRootWindow(WindowPtr pWin)
   int err = Success;
   ScreenPtr pScreen = pWin->drawable.pScreen;
   RootWinPropPtr pProp;
-  CreateWindowProcPtr CreateWindow =
-    (CreateWindowProcPtr)(pScreen->devPrivates[xf86CreateRootWindowIndex].ptr);
+  CreateWindowProcPtr CreateWindow = (CreateWindowProcPtr)
+      dixLookupPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey);
 
 #ifdef DEBUG
   ErrorF("xf86CreateRootWindow(%p)\n", pWin);
@@ -156,7 +156,7 @@ xf86CreateRootWindow(WindowPtr pWin)
 
   /* Unhook this function ... */
   pScreen->CreateWindow = CreateWindow;
-  pScreen->devPrivates[xf86CreateRootWindowIndex].ptr = NULL;
+  dixSetPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey, NULL);
 
   /* ... and call the previous CreateWindow fuction, if any */
   if (NULL!=pScreen->CreateWindow) {
@@ -476,7 +476,6 @@ void
 InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 {
   int                    i, j, k, scr_index;
-  static unsigned long   generation = 0;
   char                   **modulelist;
   pointer                *optionlist;
   screenLayoutPtr	 layout;
@@ -487,14 +486,6 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
   
   xf86Initialising = TRUE;
 
-  /* Do this early? */
-  if (generation != serverGeneration) {
-      xf86ScreenIndex = AllocateScreenPrivateIndex();
-      xf86CreateRootWindowIndex = AllocateScreenPrivateIndex();
-      xf86PixmapIndex = AllocatePixmapPrivateIndex();
-      generation = serverGeneration;
-  }
-
   if (serverGeneration == 1) {
 
     pScreenInfo->numScreens = 0;
@@ -1060,8 +1051,8 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 	 * Hook in our ScrnInfoRec, and initialise some other pScreen
 	 * fields.
 	 */
-	screenInfo.screens[scr_index]->devPrivates[xf86ScreenIndex].ptr
-	  = (pointer)xf86Screens[i];
+	dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates,
+		      xf86ScreenKey, xf86Screens[i]);
 	xf86Screens[i]->pScreen = screenInfo.screens[scr_index];
 	/* The driver should set this, but make sure it is set anyway */
 	xf86Screens[i]->vtSema = TRUE;
@@ -1077,8 +1068,9 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
 	     i, xf86Screens[i]->pScreen->CreateWindow );
 #endif
 
-      screenInfo.screens[scr_index]->devPrivates[xf86CreateRootWindowIndex].ptr
-	= (void*)(xf86Screens[i]->pScreen->CreateWindow);
+      dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates,
+		    xf86CreateRootWindowKey,
+		    xf86Screens[i]->pScreen->CreateWindow);
       xf86Screens[i]->pScreen->CreateWindow = xf86CreateRootWindow;
 
 #ifdef RENDER
diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c
index 288d721..4432ad9 100644
--- a/hw/xfree86/common/xf86RandR.c
+++ b/hw/xfree86/common/xf86RandR.c
@@ -45,10 +45,9 @@ typedef struct _xf86RandRInfo {
     Rotation			    rotation;
 } XF86RandRInfoRec, *XF86RandRInfoPtr;
 
-static int	    xf86RandRIndex = -1;
-static int	    xf86RandRGeneration;
+static DevPrivateKey xf86RandRKey = NULL;
 
-#define XF86RANDRINFO(p)    ((XF86RandRInfoPtr) (p)->devPrivates[xf86RandRIndex].ptr)
+#define XF86RANDRINFO(p) ((XF86RandRInfoPtr)dixLookupPrivate(&(p)->devPrivates, xf86RandRKey))
 
 static int
 xf86RandRModeRefresh (DisplayModePtr mode)
@@ -338,14 +337,14 @@ xf86RandRCloseScreen (int index, ScreenPtr pScreen)
     scrp->currentMode = scrp->modes;
     pScreen->CloseScreen = randrp->CloseScreen;
     xfree (randrp);
-    pScreen->devPrivates[xf86RandRIndex].ptr = 0;
+    dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, NULL);
     return (*pScreen->CloseScreen) (index, pScreen);
 }
 
 _X_EXPORT Rotation
 xf86GetRotation(ScreenPtr pScreen)
 {
-    if (xf86RandRIndex == -1)
+    if (xf86RandRKey == NULL)
        return RR_Rotate_0;
 
     return XF86RANDRINFO(pScreen)->rotation;
@@ -359,7 +358,7 @@ xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen,
 {
     XF86RandRInfoPtr randrp;
 
-    if (xf86RandRIndex == -1)
+    if (xf86RandRKey == NULL)
 	return FALSE;
 
     randrp = XF86RANDRINFO(pScreen);
@@ -401,11 +400,8 @@ xf86RandRInit (ScreenPtr    pScreen)
     if (!noPanoramiXExtension)
 	return TRUE;
 #endif
-    if (xf86RandRGeneration != serverGeneration)
-    {
-	xf86RandRIndex = AllocateScreenPrivateIndex();
-	xf86RandRGeneration = serverGeneration;
-    }
+
+    xf86RandRKey = &xf86RandRKey;
 
     randrp = xalloc (sizeof (XF86RandRInfoRec));
     if (!randrp)
@@ -433,7 +429,7 @@ xf86RandRInit (ScreenPtr    pScreen)
 
     randrp->rotation = RR_Rotate_0;
 
-    pScreen->devPrivates[xf86RandRIndex].ptr = randrp;
+    dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, randrp);
     return TRUE;
 }
 
diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index fb91513..763e5c5 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -47,12 +47,11 @@
 #include "vidmodeproc.h"
 #include "xf86cmap.h"
 
-static int VidModeGeneration = 0;
-static int VidModeIndex = -1;
+static DevPrivateKey VidModeKey = NULL;
 static int VidModeCount = 0;
 static Bool VidModeClose(int i, ScreenPtr pScreen);
 
-#define VMPTR(p) ((VidModePtr)(p)->devPrivates[VidModeIndex].ptr)
+#define VMPTR(p) ((VidModePtr)dixLookupPrivate(&(p)->devPrivates, VidModeKey))
 
 #endif
 
@@ -75,15 +74,10 @@ VidModeExtensionInit(ScreenPtr pScreen)
 	return FALSE;
     }
 
-    if (serverGeneration != VidModeGeneration) {
-	if ((VidModeIndex = AllocateScreenPrivateIndex()) < 0) {
-	    DEBUG_P("AllocateScreenPrivateIndex() failed");
-	    return FALSE;
-	}
-	VidModeGeneration = serverGeneration;
-    }
+    VidModeKey = &VidModeKey;
 
-    if (!(pScreen->devPrivates[VidModeIndex].ptr = xcalloc(sizeof(VidModeRec), 1))) {
+    if (!dixSetPrivate(&pScreen->devPrivates, VidModeKey,
+		       xcalloc(sizeof(VidModeRec), 1))) {
 	DEBUG_P("xcalloc failed");
 	return FALSE;
     }
@@ -118,10 +112,9 @@ VidModeClose(int i, ScreenPtr pScreen)
     pScreen->CloseScreen = pVidMode->CloseScreen;
 
     if (--VidModeCount == 0) {
-	if (pScreen->devPrivates[VidModeIndex].ptr)
-	  xfree(pScreen->devPrivates[VidModeIndex].ptr);
-	pScreen->devPrivates[VidModeIndex].ptr = NULL;
-	VidModeIndex = -1;
+	xfree(dixLookupPrivate(&pScreen->devPrivates, VidModeKey));
+	dixSetPrivate(&pScreen->devPrivates, VidModeKey, NULL);
+	VidModeKey = NULL;
     }
     return pScreen->CloseScreen(i, pScreen);
 }
@@ -134,8 +127,8 @@ VidModeAvailable(int scrnIndex)
 
     DEBUG_P("VidModeAvailable");
 
-    if (VidModeIndex < 0) {
-	DEBUG_P("VidModeIndex < 0");
+    if (VidModeKey == NULL) {
+	DEBUG_P("VidModeKey == NULL");
 	return FALSE;
     }
  
diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index ea6a26d..764647e 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -60,7 +60,7 @@
 #include "xf86cmap.h"
 
 #define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
-   ((CMapScreenPtr) (pScreen)->devPrivates[CMapScreenIndex].ptr)->field)
+    ((CMapScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, CMapScreenKey))->field)
 #define SCREEN_EPILOGUE(pScreen, field, wrapper)\
     ((pScreen)->field = wrapper)
 
@@ -102,9 +102,8 @@ typedef struct {
   int		overscan;
 } CMapColormapRec, *CMapColormapPtr;
 
-static unsigned long CMapGeneration = 0;
-static int CMapScreenIndex = -1;
-static int CMapColormapIndex = -1;
+static DevPrivateKey CMapScreenKey = NULL;
+static DevPrivateKey CMapColormapKey = &CMapColormapKey;
 
 static void CMapInstallColormap(ColormapPtr);
 static void CMapStoreColors(ColormapPtr, int, xColorItem *);
@@ -119,7 +118,6 @@ static int  CMapChangeGamma(int, Gamma);
 
 static void ComputeGamma(CMapScreenPtr);
 static Bool CMapAllocateColormapPrivate(ColormapPtr);
-static Bool CMapInitDefMap(ColormapPtr,int);
 static void CMapRefreshColors(ColormapPtr, int, int*);
 static void CMapSetOverscan(ColormapPtr, int, int *);
 static void CMapReinstallMap(ColormapPtr);
@@ -145,13 +143,7 @@ _X_EXPORT Bool xf86HandleColormaps(
     if(!maxColors || !sigRGBbits || !loadPalette)
 	return FALSE;
 
-    if(CMapGeneration != serverGeneration) {
-	if(((CMapScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
-	   ((CMapColormapIndex = AllocateColormapPrivateIndex(
-					CMapInitDefMap)) < 0))
-		return FALSE;
-	CMapGeneration = serverGeneration;
-    }
+    CMapScreenKey = &CMapScreenKey;
 
     elements = 1 << sigRGBbits;
 
@@ -169,7 +161,7 @@ _X_EXPORT Bool xf86HandleColormaps(
 	return FALSE;     
     }
 
-    pScreen->devPrivates[CMapScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, CMapScreenKey, pScreenPriv);
      
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreenPriv->CreateColormap = pScreen->CreateColormap;
@@ -225,12 +217,6 @@ _X_EXPORT Bool xf86HandleColormaps(
     return TRUE;
 }
 
-static Bool 
-CMapInitDefMap(ColormapPtr cmap, int index)
-{
-    return TRUE;
-}
-
 
 /**** Screen functions ****/
 
@@ -254,8 +240,8 @@ CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
 static Bool
 CMapAllocateColormapPrivate(ColormapPtr pmap)
 {
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pmap->pScreen->devPrivates, CMapScreenKey);
     CMapColormapPtr pColPriv;
     CMapLinkPtr pLink;
     int numColors;
@@ -274,7 +260,7 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
 	return FALSE;
     }	
 
-    pmap->devPrivates[CMapColormapIndex].ptr = (pointer)pColPriv;
+    dixSetPrivate(&pmap->devPrivates, CMapColormapKey, pColPriv);
  
     pColPriv->numColors = numColors;
     pColPriv->colors = colors;
@@ -296,8 +282,8 @@ static Bool
 CMapCreateColormap (ColormapPtr pmap)
 {
     ScreenPtr pScreen = pmap->pScreen;
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
     Bool ret = FALSE;
 
     pScreen->CreateColormap = pScreenPriv->CreateColormap;
@@ -314,10 +300,10 @@ static void
 CMapDestroyColormap (ColormapPtr cmap)
 {
     ScreenPtr pScreen = cmap->pScreen;
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
-    CMapColormapPtr pColPriv = 
-	(CMapColormapPtr) cmap->devPrivates[CMapColormapIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
+    CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
+	&cmap->devPrivates, CMapColormapKey);
     CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps;
 
     if(pColPriv) {
@@ -356,8 +342,8 @@ CMapStoreColors(
 ){
     ScreenPtr 	pScreen = pmap->pScreen;
     VisualPtr	pVisual = pmap->pVisual;
-    CMapScreenPtr pScreenPriv = 
-        	(CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
     int 	*indices = pScreenPriv->PreAllocIndices;
     int		num = ndef;
 
@@ -373,8 +359,8 @@ CMapStoreColors(
 	return;
 
     if(pVisual->class == DirectColor) {
-	CMapColormapPtr pColPriv = 
-	   (CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+	CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
+	    &pmap->devPrivates, CMapColormapKey);
 	int i;
 
 	if (CMapColormapUseMax(pVisual, pScreenPriv)) {
@@ -431,8 +417,8 @@ CMapInstallColormap(ColormapPtr pmap)
 {
     ScreenPtr 	  pScreen = pmap->pScreen;
     int		  index = pScreen->myNum;
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
 
     if (pmap == miInstalledMaps[index])
 	return;
@@ -462,8 +448,8 @@ static Bool
 CMapEnterVT(int index, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
 
     if((*pScreenPriv->EnterVT)(index, flags)) {
 	if(miInstalledMaps[index])
@@ -478,8 +464,8 @@ static Bool
 CMapSwitchMode(int index, DisplayModePtr mode, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
 
     if((*pScreenPriv->SwitchMode)(index, mode, flags)) {
 	if(miInstalledMaps[index])
@@ -494,8 +480,8 @@ static int
 CMapSetDGAMode(int index, int num, DGADevicePtr dev)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
     int ret;
 
     ret = (*pScreenPriv->SetDGAMode)(index, num, dev);
@@ -516,10 +502,10 @@ CMapSetDGAMode(int index, int num, DGADevicePtr dev)
 static void
 CMapReinstallMap(ColormapPtr pmap)
 {
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
-    CMapColormapPtr cmapPriv = 
-	(CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pmap->pScreen->devPrivates, CMapScreenKey);
+    CMapColormapPtr cmapPriv = (CMapColormapPtr)dixLookupPrivate(
+	&pmap->devPrivates, CMapColormapKey);
     ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
     int i = cmapPriv->numColors;
     int *indices = pScreenPriv->PreAllocIndices;
@@ -547,10 +533,10 @@ CMapReinstallMap(ColormapPtr pmap)
 static void 
 CMapRefreshColors(ColormapPtr pmap, int defs, int* indices)
 {
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
-    CMapColormapPtr pColPriv = 
-	(CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pmap->pScreen->devPrivates, CMapScreenKey);
+    CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
+	&pmap->devPrivates, CMapColormapKey);
     VisualPtr pVisual = pmap->pVisual;
     ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
     int numColors, i;
@@ -681,10 +667,10 @@ CMapCompareColors(LOCO *color1, LOCO *color2)
 static void
 CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
 {
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pmap->pScreen->devPrivates[CMapScreenIndex].ptr;
-    CMapColormapPtr pColPriv = 
-	(CMapColormapPtr) pmap->devPrivates[CMapColormapIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pmap->pScreen->devPrivates, CMapScreenKey);
+    CMapColormapPtr pColPriv = (CMapColormapPtr)dixLookupPrivate(
+	&pmap->devPrivates, CMapColormapKey);
     ScrnInfoPtr pScrn = xf86Screens[pmap->pScreen->myNum];
     VisualPtr pVisual = pmap->pVisual;
     int i;
@@ -819,8 +805,8 @@ CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
 static void
 CMapUnwrapScreen(ScreenPtr pScreen)
 {
-    CMapScreenPtr pScreenPriv = 
-        (CMapScreenPtr) pScreen->devPrivates[CMapScreenIndex].ptr;
+    CMapScreenPtr pScreenPriv = (CMapScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, CMapScreenKey);
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
@@ -904,10 +890,11 @@ CMapChangeGamma(
     CMapLinkPtr pLink;
         
     /* Is this sufficient checking ? */
-    if(CMapScreenIndex == -1)
+    if(CMapScreenKey == NULL)
 	return BadImplementation;
 
-    pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+    pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  CMapScreenKey);
     if(!pScreenPriv)
 	return BadImplementation;
  
@@ -925,8 +912,8 @@ CMapChangeGamma(
     /* mark all colormaps on this screen */
     pLink = pScreenPriv->maps;
     while(pLink) {
-    	pColPriv = 
-	 (CMapColormapPtr) pLink->cmap->devPrivates[CMapColormapIndex].ptr;
+    	pColPriv = (CMapColormapPtr)dixLookupPrivate(&pLink->cmap->devPrivates,
+						     CMapColormapKey);
 	pColPriv->recalculate = TRUE;
 	pLink = pLink->next;
     }
@@ -997,10 +984,11 @@ xf86ChangeGammaRamp(
     CMapScreenPtr pScreenPriv;
     CMapLinkPtr pLink;
 
-    if(CMapScreenIndex == -1)
+    if(CMapScreenKey == NULL)
         return BadImplementation;
 
-    pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+    pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  CMapScreenKey);
     if(!pScreenPriv)
         return BadImplementation;
 
@@ -1012,8 +1000,8 @@ xf86ChangeGammaRamp(
     /* mark all colormaps on this screen */
     pLink = pScreenPriv->maps;
     while(pLink) {
-        pColPriv =
-         (CMapColormapPtr) pLink->cmap->devPrivates[CMapColormapIndex].ptr;
+    	pColPriv = (CMapColormapPtr)dixLookupPrivate(&pLink->cmap->devPrivates,
+						     CMapColormapKey);
         pColPriv->recalculate = TRUE;
         pLink = pLink->next;
     }
@@ -1056,9 +1044,10 @@ xf86GetGammaRampSize(ScreenPtr pScreen)
 {
     CMapScreenPtr pScreenPriv;
 
-    if(CMapScreenIndex == -1) return 0;
+    if(CMapScreenKey == NULL) return 0;
 
-    pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+    pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  CMapScreenKey);
     if(!pScreenPriv) return 0;
 
     return pScreenPriv->gammaElements;
@@ -1076,10 +1065,11 @@ xf86GetGammaRamp(
     LOCO *entry;
     int shift, sigbits;
 
-    if(CMapScreenIndex == -1) 
+    if(CMapScreenKey == NULL) 
 	return BadImplementation;
 
-    pScreenPriv = (CMapScreenPtr)pScreen->devPrivates[CMapScreenIndex].ptr;
+    pScreenPriv = (CMapScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  CMapScreenKey);
     if(!pScreenPriv) 
 	return BadImplementation;
 
diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c
index 537d53d..9fd2e6c 100644
--- a/hw/xfree86/common/xf86fbman.c
+++ b/hw/xfree86/common/xf86fbman.c
@@ -42,21 +42,15 @@
 #define DEBUG
 */
 
-static int xf86FBMangerIndex = -1;
-static unsigned long xf86ManagerGeneration = 0;
+static DevPrivateKey xf86FBManagerKey = NULL;
 
 _X_EXPORT Bool xf86RegisterOffscreenManager(
     ScreenPtr pScreen, 
     FBManagerFuncsPtr funcs
 ){
 
-   if(xf86ManagerGeneration != serverGeneration) {
-	if((xf86FBMangerIndex = AllocateScreenPrivateIndex()) < 0)
-		return FALSE;
-	xf86ManagerGeneration = serverGeneration;
-   }
-
-   pScreen->devPrivates[xf86FBMangerIndex].ptr = (pointer)funcs;
+   xf86FBManagerKey = &xf86FBManagerKey;
+   dixSetPrivate(&pScreen->devPrivates, xf86FBManagerKey, funcs);
 
    return TRUE;
 }
@@ -65,9 +59,9 @@ _X_EXPORT Bool xf86RegisterOffscreenManager(
 _X_EXPORT Bool
 xf86FBManagerRunning(ScreenPtr pScreen)
 {
-    if(xf86FBMangerIndex < 0) 
+    if(xf86FBManagerKey == NULL) 
 	return FALSE;
-    if(!pScreen->devPrivates[xf86FBMangerIndex].ptr) 
+    if(!dixLookupPrivate(&pScreen->devPrivates, xf86FBManagerKey))
 	return FALSE;
 
     return TRUE;
@@ -81,9 +75,10 @@ xf86RegisterFreeBoxCallback(
 ){
    FBManagerFuncsPtr funcs;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return FALSE;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
 	return FALSE;
 
    return (*funcs->RegisterFreeBoxCallback)(pScreen, FreeBoxCallback, devPriv);
@@ -101,9 +96,10 @@ xf86AllocateOffscreenArea(
 ){
    FBManagerFuncsPtr funcs;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return NULL;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
 	return NULL;
 
    return (*funcs->AllocateOffscreenArea)(
@@ -122,9 +118,10 @@ xf86AllocateOffscreenLinear(
 ){
    FBManagerFuncsPtr funcs;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return NULL;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
 	return NULL;
 
    return (*funcs->AllocateOffscreenLinear)(
@@ -139,10 +136,10 @@ xf86FreeOffscreenArea(FBAreaPtr area)
 
    if(!area) return;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return;
-   if(!(funcs = 
-	(FBManagerFuncsPtr)area->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
+	    &area->pScreen->devPrivates, xf86FBManagerKey)))
 	return;
 
    (*funcs->FreeOffscreenArea)(area);
@@ -158,10 +155,10 @@ xf86FreeOffscreenLinear(FBLinearPtr linear)
 
    if(!linear) return;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return;
-   if(!(funcs = 
-	(FBManagerFuncsPtr)linear->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
+	    &linear->pScreen->devPrivates, xf86FBManagerKey)))
 	return;
 
    (*funcs->FreeOffscreenLinear)(linear);
@@ -179,10 +176,10 @@ xf86ResizeOffscreenArea(
 
    if(!resize) return FALSE;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return FALSE;
-   if(!(funcs = 
-	(FBManagerFuncsPtr)resize->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
+	    &resize->pScreen->devPrivates, xf86FBManagerKey)))
 	return FALSE;
 
    return (*funcs->ResizeOffscreenArea)(resize, w, h);
@@ -197,10 +194,10 @@ xf86ResizeOffscreenLinear(
 
    if(!resize) return FALSE;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return FALSE;
-   if(!(funcs = 
-	(FBManagerFuncsPtr)resize->pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(
+	    &resize->pScreen->devPrivates, xf86FBManagerKey)))
 	return FALSE;
 
    return (*funcs->ResizeOffscreenLinear)(resize, size);
@@ -220,9 +217,10 @@ xf86QueryLargestOffscreenArea(
    *w = 0;
    *h = 0;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return FALSE;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
 	return FALSE;
 
    return (*funcs->QueryLargestOffscreenArea)(
@@ -240,9 +238,10 @@ xf86QueryLargestOffscreenLinear(
 
    *size = 0;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return FALSE;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
 	return FALSE;
 
    return (*funcs->QueryLargestOffscreenLinear)(
@@ -255,9 +254,10 @@ xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
 {
    FBManagerFuncsPtr funcs;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
 	return FALSE;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
 	return FALSE;
 
    return (*funcs->PurgeOffscreenAreas)(pScreen);
@@ -269,8 +269,7 @@ xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
 
 \************************************************************/ 
 
-static unsigned long xf86FBGeneration = 0;
-static int xf86FBScreenIndex = -1;
+static DevPrivateKey xf86FBScreenKey = &xf86FBScreenKey;
 
 typedef struct _FBLink {
   FBArea area;
@@ -320,8 +319,8 @@ localRegisterFreeBoxCallback(
    FreeBoxCallbackProcPtr *newCallbacks;
    DevUnion *newPrivates; 
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    newCallbacks = xrealloc( offman->FreeBoxesUpdateCallback, 
 		sizeof(FreeBoxCallbackProcPtr) * (offman->NumCallbacks + 1));
 
@@ -446,8 +445,8 @@ localAllocateOffscreenArea(
    FBManagerPtr offman;
    FBAreaPtr area = NULL;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    if((area = AllocateArea(offman, w, h, gran, moveCB, removeCB, privData)))
 	SendCallFreeBoxCallbacks(offman);
 
@@ -464,8 +463,8 @@ localFreeOffscreenArea(FBAreaPtr area)
    ScreenPtr pScreen;
 
    pScreen = area->pScreen;
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-       
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    pLink = offman->UsedAreas;
    if(!pLink) return;  
  
@@ -505,8 +504,8 @@ localResizeOffscreenArea(
    FBLinkPtr pLink, newLink, pLinkPrev = NULL;
 
    pScreen = resize->pScreen;
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    /* find this link */
    if(!(pLink = offman->UsedAreas))
 	return FALSE;  
@@ -625,8 +624,8 @@ localQueryLargestOffscreenArea(
     if((preferences < 0) || (preferences > 3))
 	return FALSE;	
 
-    offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+    offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					    xf86FBScreenKey);
     if(severity < 0) severity = 0;
     if(severity > 2) severity = 2;
 
@@ -731,8 +730,8 @@ localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen)
    RegionRec FreedRegion;
    Bool anyUsed = FALSE;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-       
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    pLink = offman->UsedAreas;
    if(!pLink) return TRUE;  
  
@@ -780,8 +779,8 @@ LinearRemoveCBWrapper(FBAreaPtr area)
    FBLinearLinkPtr pLink, pLinkPrev = NULL;
    ScreenPtr pScreen = area->pScreen;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-       
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    pLink = offman->LinearAreas;
    if(!pLink) return;  
  
@@ -911,7 +910,8 @@ localAllocateOffscreenLinear(
    BoxPtr extents;
    int w, h, pitch;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
 
    /* Try to allocate from linear memory first...... */
 #ifdef DEBUG
@@ -991,8 +991,8 @@ localFreeOffscreenLinear(FBLinearPtr linear)
    FBLinearLinkPtr pLink, pLinkPrev = NULL;
    ScreenPtr pScreen = linear->pScreen;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    pLink = offman->LinearAreas;
    if(!pLink) return;  
  
@@ -1049,8 +1049,8 @@ localResizeOffscreenLinear(FBLinearPtr resize, int length)
    FBLinearLinkPtr pLink;
    ScreenPtr pScreen = resize->pScreen;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-       
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    pLink = offman->LinearAreas;
    if(!pLink) return FALSE;  
  
@@ -1099,7 +1099,8 @@ localQueryLargestOffscreenLinear(
     int priority
 )
 {
-    FBManagerPtr offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+    FBManagerPtr offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+							 xf86FBScreenKey);
     FBLinearLinkPtr pLink;
     FBLinearLinkPtr pLinkRet;
 
@@ -1130,7 +1131,8 @@ localQueryLargestOffscreenLinear(
 	    FBManagerPtr offman;
 	    BoxPtr extents;
 
-	    offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
+	    offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBScreenKey);
 	    extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
 	    if((extents->x2 - extents->x1) == w)
 	    	*size = w * h;
@@ -1162,9 +1164,8 @@ xf86FBCloseScreen (int i, ScreenPtr pScreen)
 {
    FBLinkPtr pLink, tmp;
    FBLinearLinkPtr pLinearLink, tmp2;
-   FBManagerPtr offman = 
-	(FBManagerPtr) pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   FBManagerPtr offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+							xf86FBScreenKey);
    
    pScreen->CloseScreen = offman->CloseScreen;
 
@@ -1188,7 +1189,7 @@ xf86FBCloseScreen (int i, ScreenPtr pScreen)
    xfree(offman->FreeBoxesUpdateCallback);
    xfree(offman->devPrivates);
    xfree(offman);
-   pScreen->devPrivates[xf86FBScreenIndex].ptr = NULL;
+   dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, NULL);
 
    return (*pScreen->CloseScreen) (i, pScreen);
 }
@@ -1332,19 +1333,13 @@ xf86InitFBManagerRegion(
    if(REGION_NIL(FullRegion))
 	return FALSE;
 
-   if(xf86FBGeneration != serverGeneration) {
-	if((xf86FBScreenIndex = AllocateScreenPrivateIndex()) < 0)
-		return FALSE;
-	xf86FBGeneration = serverGeneration;
-   }
-
    if(!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs))
 	return FALSE;
 
    offman = xalloc(sizeof(FBManager));
    if(!offman) return FALSE;
 
-   pScreen->devPrivates[xf86FBScreenIndex].ptr = (pointer)offman;
+   dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, offman);
 
    offman->CloseScreen = pScreen->CloseScreen;
    pScreen->CloseScreen = xf86FBCloseScreen;
@@ -1380,11 +1375,11 @@ xf86InitFBManagerLinear(
 	return FALSE;
 
    /* we expect people to have called the Area setup first for pixmap cache */
-   if (!pScreen->devPrivates[xf86FBScreenIndex].ptr)
+   if (!dixLookupPrivate(&pScreen->devPrivates, xf86FBScreenKey))
 	return FALSE;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    offman->LinearAreas = xalloc(sizeof(FBLinearLink));
    if (!offman->LinearAreas)
 	return FALSE;
@@ -1424,13 +1419,14 @@ xf86AllocateLinearOffscreenArea (
    BoxPtr extents;
    int w, h;
 
-   if(xf86FBMangerIndex < 0) 
+   if(xf86FBManagerKey == NULL) 
         return NULL;
-   if(!(funcs = (FBManagerFuncsPtr)pScreen->devPrivates[xf86FBMangerIndex].ptr))
+   if(!(funcs = (FBManagerFuncsPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    xf86FBManagerKey)))
         return NULL;
 
-   offman = pScreen->devPrivates[xf86FBScreenIndex].ptr;
-
+   offman = (FBManagerPtr)dixLookupPrivate(&pScreen->devPrivates,
+					   xf86FBScreenKey);
    extents = REGION_EXTENTS(pScreen, offman->InitialBoxes);
    w = extents->x2 - extents->x1;
 
diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c
index 2e06ffa..4ec099a 100644
--- a/hw/xfree86/common/xf86sbusBus.c
+++ b/hw/xfree86/common/xf86sbusBus.c
@@ -602,8 +602,7 @@ xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp)
     pScrn->virtualY = psdp->height;
 }
 
-static int sbusPaletteIndex = -1;
-static unsigned long sbusPaletteGeneration = 0;
+static DevPrivateKey sbusPaletteKey = &sbusPaletteKey;
 typedef struct _sbusCmap {
     sbusDevicePtr psdp;
     CloseScreenProcPtr CloseScreen;
@@ -613,7 +612,8 @@ typedef struct _sbusCmap {
     unsigned char origBlue[16];
 } sbusCmapRec, *sbusCmapPtr;
 
-#define SBUSCMAPPTR(pScreen) ((sbusCmapPtr)((pScreen)->devPrivates[sbusPaletteIndex].ptr))
+#define SBUSCMAPPTR(pScreen) ((sbusCmapPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, sbusPaletteKey))
 
 static void
 xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
@@ -673,13 +673,8 @@ xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp)
     struct fbcmap fbcmap;
     unsigned char data[2];
 
-    if(sbusPaletteGeneration != serverGeneration) {
-	if((sbusPaletteIndex = AllocateScreenPrivateIndex()) < 0)
-	    return FALSE;
-	sbusPaletteGeneration = serverGeneration;
-    }
     cmap = xnfcalloc(1, sizeof(sbusCmapRec));
-    pScreen->devPrivates[sbusPaletteIndex].ptr = cmap;
+    dixSetPrivate(&pScreen->devPrivates, sbusPaletteKey, cmap);
     cmap->psdp = psdp;
     fbcmap.index = 0;
     fbcmap.count = 16;
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 70a9469..f972b1f 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -110,23 +110,22 @@ static void xf86XVAdjustFrame(int index, int x, int y, int flags);
 static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int);
 
 
-static int XF86XVWindowIndex = -1;
-int XF86XvScreenIndex = -1;
-static unsigned long XF86XVGeneration = 0;
+static DevPrivateKey XF86XVWindowKey = &XF86XVWindowKey;
+DevPrivateKey XF86XvScreenKey;
 static unsigned long PortResource = 0;
 
-int (*XvGetScreenIndexProc)(void) = NULL;
+DevPrivateKey (*XvGetScreenKeyProc)(void) = NULL;
 unsigned long (*XvGetRTPortProc)(void) = NULL;
 int (*XvScreenInitProc)(ScreenPtr) = NULL;
 
 #define GET_XV_SCREEN(pScreen) \
-	((XvScreenPtr)((pScreen)->devPrivates[XF86XvScreenIndex].ptr))
+    ((XvScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XF86XvScreenKey))
 
 #define GET_XF86XV_SCREEN(pScreen) \
-	((XF86XVScreenPtr)(GET_XV_SCREEN(pScreen)->devPriv.ptr))
+    ((XF86XVScreenPtr)(GET_XV_SCREEN(pScreen)->devPriv.ptr))
 
 #define GET_XF86XV_WINDOW(pWin) \
-	((XF86XVWindowPtr)((pWin)->devPrivates[XF86XVWindowIndex].ptr))
+    ((XF86XVWindowPtr)dixLookupPrivate(&(pWin)->devPrivates, XF86XVWindowKey))
 
 static xf86XVInitGenericAdaptorPtr *GenDrivers = NULL;
 static int NumGenDrivers = 0;
@@ -233,21 +232,12 @@ xf86XVScreenInit(
   XvScreenPtr pxvs;
 
   if(num <= 0 ||
-     !XvGetScreenIndexProc || !XvGetRTPortProc || !XvScreenInitProc)
-	return FALSE;
-
-  if(XF86XVGeneration != serverGeneration) {
-	if((XF86XVWindowIndex = AllocateWindowPrivateIndex()) < 0)
-	    return FALSE;
-	XF86XVGeneration = serverGeneration;
-  }
-
-  if(!AllocateWindowPrivate(pScreen,XF86XVWindowIndex,0))
+     !XvGetScreenKeyProc || !XvGetRTPortProc || !XvScreenInitProc)
 	return FALSE;
 
   if(Success != (*XvScreenInitProc)(pScreen)) return FALSE;
 
-  XF86XvScreenIndex = (*XvGetScreenIndexProc)();
+  XF86XvScreenKey = (*XvGetScreenKeyProc)();
   PortResource = (*XvGetRTPortProc)();
 
   pxvs = GET_XV_SCREEN(pScreen);
@@ -977,7 +967,7 @@ xf86XVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 	memset(winPriv, 0, sizeof(XF86XVWindowRec));
 	winPriv->PortRec = portPriv;
 	winPriv->next = PrivRoot;
-	pWin->devPrivates[XF86XVWindowIndex].ptr = (pointer)winPriv;
+	dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, winPriv);
    }
 
    portPriv->pDraw = (DrawablePtr)pWin;
@@ -998,8 +988,8 @@ xf86XVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 	    if(prevPriv)
 		prevPriv->next = winPriv->next;
 	    else
-		pWin->devPrivates[XF86XVWindowIndex].ptr =
-					(pointer)winPriv->next;
+		dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey,
+			      winPriv->next);
 	    xfree(winPriv);
 	    break;
 	}
@@ -1037,7 +1027,7 @@ xf86XVDestroyWindow(WindowPtr pWin)
      xfree(tmp);
   }
 
-  pWin->devPrivates[XF86XVWindowIndex].ptr = NULL;
+  dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, NULL);
 
   pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
   ret = (*pScreen->DestroyWindow)(pWin);
@@ -1094,8 +1084,8 @@ xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
 	    pPriv->pDraw = NULL;
 
 	    if(!pPrev)
-	       pWin->devPrivates[XF86XVWindowIndex].ptr =
-						(pointer)(WinPriv->next);
+		dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey,
+			      WinPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
 	    tmp = WinPriv;
@@ -1146,8 +1136,8 @@ xf86XVClipNotify(WindowPtr pWin, int dx, int dy)
 	    pPriv->pDraw = NULL;
 
 	    if(!pPrev)
-	       pWin->devPrivates[XF86XVWindowIndex].ptr =
-						(pointer)(WinPriv->next);
+		dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey,
+			      WinPriv->next);
 	    else
 	       pPrev->next = WinPriv->next;
 	    tmp = WinPriv;
diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c
index f8ff0be..05267a2 100644
--- a/hw/xfree86/common/xf86xvmc.c
+++ b/hw/xfree86/common/xf86xvmc.c
@@ -56,11 +56,10 @@ typedef struct {
   XvMCAdaptorPtr dixinfo;
 } xf86XvMCScreenRec, *xf86XvMCScreenPtr;
 
-static unsigned long XF86XvMCGeneration = 0;
-static int XF86XvMCScreenIndex = -1;
+static DevPrivateKey XF86XvMCScreenKey = &XF86XvMCScreenKey;
 
-#define XF86XVMC_GET_PRIVATE(pScreen) \
-   (xf86XvMCScreenPtr)((pScreen)->devPrivates[XF86XvMCScreenIndex].ptr)
+#define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey)
 
 
 static int 
@@ -164,19 +163,12 @@ _X_EXPORT Bool xf86XvMCScreenInit(
 {
    XvMCAdaptorPtr pAdapt;
    xf86XvMCScreenPtr pScreenPriv;
-   XvScreenPtr pxvs = 
-	(XvScreenPtr)(pScreen->devPrivates[XF86XvScreenIndex].ptr);
-
+   XvScreenPtr pxvs = (XvScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						    XF86XvScreenKey);
    int i, j;
 
    if(!XvMCScreenInitProc) return FALSE;
 
-   if(XF86XvMCGeneration != serverGeneration) {
-	if((XF86XvMCScreenIndex = AllocateScreenPrivateIndex()) < 0)
-	   return FALSE;
-	XF86XvMCGeneration = serverGeneration;
-   }
-
    if(!(pAdapt = xalloc(sizeof(XvMCAdaptorRec) * num_adaptors)))
 	return FALSE;
 
@@ -185,7 +177,7 @@ _X_EXPORT Bool xf86XvMCScreenInit(
 	return FALSE;
    }
 
-   pScreen->devPrivates[XF86XvMCScreenIndex].ptr = (pointer)pScreenPriv; 
+   dixSetPrivate(&pScreen->devPrivates, XF86XvMCScreenKey, pScreenPriv);
 
    pScreenPriv->CloseScreen = pScreen->CloseScreen;
    pScreen->CloseScreen = xf86XvMCCloseScreen;
diff --git a/hw/xfree86/common/xf86xvpriv.h b/hw/xfree86/common/xf86xvpriv.h
index e716c9c..4200dac 100644
--- a/hw/xfree86/common/xf86xvpriv.h
+++ b/hw/xfree86/common/xf86xvpriv.h
@@ -30,10 +30,11 @@
 #define _XF86XVPRIV_H_
 
 #include "xf86xv.h"
+#include "privates.h"
 
 /*** These are DDX layer privates ***/
 
-extern int XF86XvScreenIndex;
+extern DevPrivateKey XF86XvScreenKey;
 
 typedef struct {
    DestroyWindowProcPtr		DestroyWindow;
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index fa95308..295e05e 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -62,8 +62,7 @@ unsigned char DGAReqCode = 0;
 int DGAErrorBase;
 int DGAEventBase;
 
-static int DGAGeneration = 0;
-static int DGAClientPrivateIndex;
+static DevPrivateKey DGAClientPrivateKey = &DGAClientPrivateKey;
 static int DGACallbackRefCount = 0;
 
 /* This holds the client's version information */
@@ -72,7 +71,11 @@ typedef struct {
     int		minor;
 } DGAPrivRec, *DGAPrivPtr;
 
-#define DGAPRIV(c) ((c)->devPrivates[DGAClientPrivateIndex].ptr)
+#define DGA_GETPRIV(c) ((DGAPrivPtr) \
+    dixLookupPrivate(&(c)->devPrivates, DGAClientPrivateKey))
+#define DGA_SETPRIV(c,p) \
+    dixSetPrivate(&(c)->devPrivates, DGAClientPrivateKey, p)
+
 
 void
 XFree86DGAExtensionInit(INITARGS)
@@ -97,23 +100,6 @@ XFree86DGAExtensionInit(INITARGS)
 	for (i = KeyPress; i <= MotionNotify; i++)
 	    SetCriticalEvent (DGAEventBase + i);
     }
-
-    /*
-     * Allocate a client private index to hold the client's version
-     * information.
-     */
-    if (DGAGeneration != serverGeneration) {
-	DGAClientPrivateIndex = AllocateClientPrivateIndex();
-	/*
-	 * Allocate 0 length, and use the private to hold a pointer to
-	 * our DGAPrivRec.
-	 */
-	if (!AllocateClientPrivate(DGAClientPrivateIndex, 0)) {
-	    ErrorF("XFree86DGAExtensionInit: AllocateClientPrivate failed\n");
-	    return;
-	}
-	DGAGeneration = serverGeneration;
-    }
 }
 
 
@@ -590,12 +576,12 @@ ProcXDGASetClientVersion(ClientPtr client)
     DGAPrivPtr pPriv;
 
     REQUEST_SIZE_MATCH(xXDGASetClientVersionReq);
-    if ((pPriv = DGAPRIV(client)) == NULL) {
+    if ((pPriv = DGA_GETPRIV(client)) == NULL) {
 	pPriv = xalloc(sizeof(DGAPrivRec));
 	/* XXX Need to look into freeing this */
 	if (!pPriv)
 	    return BadAlloc;
-	DGAPRIV(client) = pPriv;
+	DGA_SETPRIV(client, pPriv);
     }
     pPriv->major = stuff->major;
     pPriv->minor = stuff->minor;
diff --git a/hw/xfree86/dixmods/extmod/xf86misc.c b/hw/xfree86/dixmods/extmod/xf86misc.c
index 3a6f83e..66278a2 100644
--- a/hw/xfree86/dixmods/extmod/xf86misc.c
+++ b/hw/xfree86/dixmods/extmod/xf86misc.c
@@ -41,8 +41,7 @@
 #endif
 
 static int miscErrorBase;
-static int MiscGeneration = 0;
-static int MiscClientPrivateIndex;
+static DevPrivateKey MiscClientPrivateKey = &MiscClientPrivateKey;
 
 /* This holds the client's version information */
 typedef struct {
@@ -50,7 +49,10 @@ typedef struct {
     int		minor;
 } MiscPrivRec, *MiscPrivPtr;
 
-#define MPRIV(c) ((c)->devPrivates[MiscClientPrivateIndex].ptr)
+#define M_GETPRIV(c) ((MiscPrivPtr) \
+    dixLookupPrivate(&(c)->devPrivates, MiscClientPrivateKey))
+#define M_SETPRIV(c,p) \
+    dixSetPrivate(&(c)->devPrivates, MiscClientPrivateKey, p)
 
 static void XF86MiscResetProc(
     ExtensionEntry* /* extEntry */
@@ -61,7 +63,7 @@ ClientVersion(ClientPtr client, int *major, int *minor)
 {
     MiscPrivPtr pPriv;
 
-    pPriv = MPRIV(client);
+    pPriv = M_GETPRIV(client);
     if (!pPriv) {
 	if (major) *major = 0;
 	if (minor) *minor = 0;
@@ -123,24 +125,6 @@ XFree86MiscExtensionInit(void)
     if (!xf86GetModInDevEnabled())
 	return;
 
-    /*
-     * Allocate a client private index to hold the client's version
-     * information.
-     */
-    if (MiscGeneration != serverGeneration) {
-	MiscClientPrivateIndex = AllocateClientPrivateIndex();
-	/*
-	 * Allocate 0 length, and use the private to hold a pointer to our
-	 * MiscPrivRec.
-	 */
-	if (!AllocateClientPrivate(MiscClientPrivateIndex, 0)) {
-	    ErrorF("XFree86MiscExtensionInit: "
-		   "AllocateClientPrivate failed\n");
-	    return;
-	}
-	MiscGeneration = serverGeneration;
-    }
-    
     if (
 	(extEntry = AddExtension(XF86MISCNAME,
 				XF86MiscNumberEvents,
@@ -205,7 +189,9 @@ ProcXF86MiscSetSaver(client)
     if (stuff->screen > screenInfo.numScreens)
 	return BadValue;
 
-    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    vptr = (ScrnInfoPtr)
+	dixLookupPrivate(&screenInfo.screens[stuff->screen]->devPrivates,
+			 xf86ScreenKey);
 
     REQUEST_SIZE_MATCH(xXF86MiscSetSaverReq);
 
@@ -233,7 +219,9 @@ ProcXF86MiscGetSaver(client)
     if (stuff->screen > screenInfo.numScreens)
 	return BadValue;
 
-    vptr = (ScrnInfoPtr) screenInfo.screens[stuff->screen]->devPrivates[xf86ScreenIndex].ptr;
+    vptr = (ScrnInfoPtr)
+	dixLookupPrivate(&screenInfo.screens[stuff->screen]->devPrivates,
+			 xf86ScreenKey);
 
     REQUEST_SIZE_MATCH(xXF86MiscGetSaverReq);
     rep.type = X_Reply;
@@ -497,11 +485,11 @@ ProcXF86MiscSetClientVersion(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xXF86MiscSetClientVersionReq);
 
-    if ((pPriv = MPRIV(client)) == NULL) {
+    if ((pPriv = M_GETPRIV(client)) == NULL) {
 	pPriv = xalloc(sizeof(MiscPrivRec));
 	if (!pPriv)
 	    return BadAlloc;
-	MPRIV(client) = pPriv;
+	M_SETPRIV(client, pPriv);
     }
     if (xf86GetVerbosity() > 1) 
 	    ErrorF("SetClientVersion: %i %i\n",stuff->major,stuff->minor);
diff --git a/hw/xfree86/dixmods/extmod/xf86vmode.c b/hw/xfree86/dixmods/extmod/xf86vmode.c
index 44ec9f1..fa32848 100644
--- a/hw/xfree86/dixmods/extmod/xf86vmode.c
+++ b/hw/xfree86/dixmods/extmod/xf86vmode.c
@@ -52,8 +52,7 @@ from Kaleb S. KEITHLEY
 #define DEFAULT_XF86VIDMODE_VERBOSITY	3
 
 static int VidModeErrorBase;
-static int VidModeGeneration = 0;
-static int VidModeClientPrivateIndex;
+static DevPrivateKey VidModeClientPrivateKey = &VidModeClientPrivateKey;
 
 /* This holds the client's version information */
 typedef struct {
@@ -61,7 +60,10 @@ typedef struct {
     int		minor;
 } VidModePrivRec, *VidModePrivPtr;
 
-#define VMPRIV(c) ((c)->devPrivates[VidModeClientPrivateIndex].ptr)
+#define VM_GETPRIV(c) ((VidModePrivPtr) \
+    dixLookupPrivate(&(c)->devPrivates, VidModeClientPrivateKey))
+#define VM_SETPRIV(c,p) \
+    dixSetPrivate(&(c)->devPrivates, VidModeClientPrivateKey, p)
 
 static void XF86VidModeResetProc(
     ExtensionEntry* /* extEntry */
@@ -145,10 +147,12 @@ typedef struct _XF86VidModeScreenPrivate {
     Bool		hasWindow;
 } XF86VidModeScreenPrivateRec, *XF86VidModeScreenPrivatePtr;
    
-static int ScreenPrivateIndex;
+static DevPrivateKey ScreenPrivateKey = &ScreenPrivateKey;
 
-#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr)(s)->devPrivates[ScreenPrivateIndex].ptr)
-#define SetScreenPrivate(s,v) ((s)->devPrivates[ScreenPrivateIndex].ptr = (pointer) v);
+#define GetScreenPrivate(s) ((ScreenSaverScreenPrivatePtr) \
+    dixLookupPrivate(&(s)->devPrivates, ScreenPrivateKey))
+#define SetScreenPrivate(s,v) \
+    dixSetPrivate(&(s)->devPrivates, ScreenPrivateKey, v)
 #define SetupScreen(s)  ScreenSaverScreenPrivatePtr pPriv = GetScreenPrivate(s)
 
 #define New(t)  (xalloc (sizeof (t)))
@@ -172,7 +176,6 @@ XFree86VidModeExtensionInit(void)
 
 #ifdef XF86VIDMODE_EVENTS
     EventType = CreateNewResourceType(XF86VidModeFreeEvents);
-    ScreenPrivateIndex = AllocateScreenPrivateIndex ();
 #endif
 
     for(i = 0; i < screenInfo.numScreens; i++) {
@@ -187,27 +190,9 @@ XFree86VidModeExtensionInit(void)
     if (!enabled)
 	return;
 
-    /*
-     * Allocate a client private index to hold the client's version
-     * information.
-     */
-    if (VidModeGeneration != serverGeneration) {
-	VidModeClientPrivateIndex = AllocateClientPrivateIndex();
-	/*
-	 * Allocate 0 length, and use the private to hold a pointer to our
-	 * VidModePrivRec.
-	 */
-	if (!AllocateClientPrivate(VidModeClientPrivateIndex, 0)) {
-	    ErrorF("XFree86VidModeExtensionInit: "
-		   "AllocateClientPrivate failed\n");
-	    return;
-	}
-	VidModeGeneration = serverGeneration;
-    }
-
     if (
 #ifdef XF86VIDMODE_EVENTS
-        EventType && ScreenPrivateIndex != -1 &&
+        EventType &&
 #endif
 	(extEntry = AddExtension(XF86VIDMODENAME,
 				XF86VidModeNumberEvents,
@@ -239,7 +224,7 @@ ClientMajorVersion(ClientPtr client)
 {
     VidModePrivPtr pPriv;
 
-    pPriv = VMPRIV(client);
+    pPriv = VM_GETPRIV(client);
     if (!pPriv)
 	return 0;
     else
@@ -1682,11 +1667,11 @@ ProcXF86VidModeSetClientVersion(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xXF86VidModeSetClientVersionReq);
 
-    if ((pPriv = VMPRIV(client)) == NULL) {
+    if ((pPriv = VM_GETPRIV(client)) == NULL) {
 	pPriv = xalloc(sizeof(VidModePrivRec));
 	if (!pPriv)
 	    return BadAlloc;
-	VMPRIV(client) = pPriv;
+	VM_SETPRIV(client, pPriv);
     }
     pPriv->major = stuff->major;
     pPriv->minor = stuff->minor;
diff --git a/hw/xfree86/dixmods/extmod/xvmod.c b/hw/xfree86/dixmods/extmod/xvmod.c
index 7c1450c..6b3f114 100644
--- a/hw/xfree86/dixmods/extmod/xvmod.c
+++ b/hw/xfree86/dixmods/extmod/xvmod.c
@@ -16,7 +16,7 @@ void
 XvRegister()
 {
     XvScreenInitProc = XvScreenInit;
-    XvGetScreenIndexProc = XvGetScreenIndex;
+    XvGetScreenKeyProc = XvGetScreenKey;
     XvGetRTPortProc = XvGetRTPort;
     XvMCScreenInitProc = XvMCScreenInit;
 }
diff --git a/hw/xfree86/dixmods/extmod/xvmodproc.h b/hw/xfree86/dixmods/extmod/xvmodproc.h
index 81356a1..b39c915 100644
--- a/hw/xfree86/dixmods/extmod/xvmodproc.h
+++ b/hw/xfree86/dixmods/extmod/xvmodproc.h
@@ -5,7 +5,7 @@
 
 #include "xvmcext.h"
 
-extern int (*XvGetScreenIndexProc)(void);
+extern DevPrivateKey (*XvGetScreenKeyProc)(void);
 extern unsigned long (*XvGetRTPortProc)(void);
 extern int (*XvScreenInitProc)(ScreenPtr);
 extern int (*XvMCScreenInitProc)(ScreenPtr, int, XvMCAdaptorPtr);
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index d1bbfcd..84c0508 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -79,8 +79,8 @@ extern Bool noPanoramiXExtension;
 #endif
 
 static int DRIEntPrivIndex = -1;
-static int DRIScreenPrivIndex = -1;
-static int DRIWindowPrivIndex = -1;
+static DevPrivateKey DRIScreenPrivKey = &DRIScreenPrivKey;
+static DevPrivateKey DRIWindowPrivKey = &DRIWindowPrivKey;
 static unsigned long DRIGeneration = 0;
 static unsigned int DRIDrawableValidationStamp = 0;
 
@@ -343,20 +343,18 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
 
     pDRIEntPriv = DRI_ENT_PRIV(pScrn);
 
-    if (DRIGeneration != serverGeneration) {
-	if ((DRIScreenPrivIndex = AllocateScreenPrivateIndex()) < 0)
-	    return FALSE;
+    DRIScreenPrivKey = &DRIScreenPrivKey;
+    if (DRIGeneration != serverGeneration)
 	DRIGeneration = serverGeneration;
-    }
 
     pDRIPriv = (DRIScreenPrivPtr) xcalloc(1, sizeof(DRIScreenPrivRec));
     if (!pDRIPriv) {
-        pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
-        DRIScreenPrivIndex = -1;
+	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
+        DRIScreenPrivKey = NULL;
         return FALSE;
     }
 
-    pScreen->devPrivates[DRIScreenPrivIndex].ptr = (pointer) pDRIPriv;
+    dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, pDRIPriv);
     pDRIPriv->drmFD = pDRIEntPriv->drmFD;
     pDRIPriv->directRenderingSupport = TRUE;
     pDRIPriv->pDriverInfo = pDRIInfo;
@@ -381,7 +379,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
 		       &pDRIPriv->hSAREA) < 0)
 	{
 	    pDRIPriv->directRenderingSupport = FALSE;
-	    pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+	    dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
 	    drmClose(pDRIPriv->drmFD);
 	    DRIDrvMsg(pScreen->myNum, X_INFO,
 		      "[drm] drmAddMap failed\n");
@@ -398,7 +396,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
 		    (drmAddressPtr)(&pDRIPriv->pSAREA)) < 0)
 	{
 	    pDRIPriv->directRenderingSupport = FALSE;
-	    pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+	    dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
 	    drmClose(pDRIPriv->drmFD);
 	    DRIDrvMsg(pScreen->myNum, X_INFO,
 		      "[drm] drmMap failed\n");
@@ -428,7 +426,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
 		       &pDRIPriv->pDriverInfo->hFrameBuffer) < 0)
 	    {
 		pDRIPriv->directRenderingSupport = FALSE;
-		pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
+		dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
 		drmUnmap(pDRIPriv->pSAREA, pDRIPriv->pDriverInfo->SAREASize);
 		drmClose(pDRIPriv->drmFD);
 		DRIDrvMsg(pScreen->myNum, X_INFO,
@@ -744,8 +742,8 @@ DRICloseScreen(ScreenPtr pScreen)
 	}
 
 	xfree(pDRIPriv);
-	pScreen->devPrivates[DRIScreenPrivIndex].ptr = NULL;
-	DRIScreenPrivIndex = -1;
+	dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
+	DRIScreenPrivKey = NULL;
     }
 }
 
@@ -772,30 +770,13 @@ drmServerInfo DRIDRMServerInfo =  {
 Bool
 DRIExtensionInit(void)
 {
-    int		    	i;
-    ScreenPtr		pScreen;
-
-    if (DRIScreenPrivIndex < 0 || DRIGeneration != serverGeneration) {
+    if (!DRIScreenPrivKey || DRIGeneration != serverGeneration) {
 	return FALSE;
     }
 
-    /* Allocate a window private index with a zero sized private area for
-     * each window, then should a window become a DRI window, we'll hang
-     * a DRIWindowPrivateRec off of this private index.
-     */
-    if ((DRIWindowPrivIndex = AllocateWindowPrivateIndex()) < 0)
-	return FALSE;
-
     DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete);
     DRIContextPrivResType = CreateNewResourceType(DRIContextPrivDelete);
 
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	pScreen = screenInfo.screens[i];
-	if (!AllocateWindowPrivate(pScreen, DRIWindowPrivIndex, 0))
-	    return FALSE;
-    }
-
     RegisterBlockAndWakeupHandlers(DRIBlockHandler, DRIWakeupHandler, NULL);
 
     return TRUE;
@@ -1302,9 +1283,8 @@ DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
 	    pDRIDrawablePriv->nrects = REGION_NUM_RECTS(&pWin->clipList);
 
 	    /* save private off of preallocated index */
-	    pWin->devPrivates[DRIWindowPrivIndex].ptr =
-						(pointer)pDRIDrawablePriv;
-
+	    dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey,
+			  pDRIDrawablePriv);
 	    pDRIPriv->nrWindows++;
 
 	    if (pDRIDrawablePriv->nrects)
@@ -1362,7 +1342,7 @@ DRIDrawablePrivDestroy(WindowPtr pWin)
     drmDestroyDrawable(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable);
 
     xfree(pDRIDrawablePriv);
-    pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL;
+    dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL);
 }
 
 static Bool
diff --git a/hw/xfree86/dri/dristruct.h b/hw/xfree86/dri/dristruct.h
index c3b0aee..ae970d8 100644
--- a/hw/xfree86/dri/dristruct.h
+++ b/hw/xfree86/dri/dristruct.h
@@ -37,15 +37,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86drm.h"
 
 
-#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) \
-    ((DRIWindowPrivIndex < 0) ? \
-     NULL : \
-     ((DRIDrawablePrivPtr)((pWin)->devPrivates[DRIWindowPrivIndex].ptr)))
-
-#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) \
-    ((DRIPixmapPrivIndex < 0) ? \
-     NULL : \
-     ((DRIDrawablePrivPtr)((pPix)->devPrivates[DRIWindowPrivIndex].ptr)))
+#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) ((DRIDrawablePrivPtr) \
+    dixLookupPrivate(&(pWin)->devPrivates, DRIWindowPrivKey))
+#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) ((DRIDrawablePrivPtr) \
+    dixLookupPrivate(&(pPix)->devPrivates, DRIWindowPrivKey))
 
 typedef struct _DRIDrawablePrivRec
 {
@@ -65,13 +60,12 @@ struct _DRIContextPrivRec
     void**     		pContextStore;
 };
 
-#define DRI_SCREEN_PRIV(pScreen) \
-    ((DRIScreenPrivIndex < 0) ? \
-     NULL : \
-     ((DRIScreenPrivPtr)((pScreen)->devPrivates[DRIScreenPrivIndex].ptr)))
+#define DRI_SCREEN_PRIV(pScreen) ((DRIScreenPrivPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, DRIScreenPrivKey))
 
 #define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \
-    (screenInfo.screens[screenIndex]->devPrivates[DRIScreenPrivIndex].ptr))
+    dixLookupPrivate(&screenInfo.screens[screenIndex]->devPrivates, \
+		     DRIScreenPrivKey))
 
 #define DRI_ENT_PRIV(pScrn)  \
     ((DRIEntPrivIndex < 0) ? \
diff --git a/hw/xfree86/exa/examodule.c b/hw/xfree86/exa/examodule.c
index 4dce58f..aac3294 100644
--- a/hw/xfree86/exa/examodule.c
+++ b/hw/xfree86/exa/examodule.c
@@ -42,8 +42,7 @@ typedef struct _ExaXorgScreenPrivRec {
     OptionInfoPtr		 options;
 } ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr;
 
-static int exaXorgServerGeneration;
-static int exaXorgScreenPrivateIndex;
+static DevPrivateKey exaXorgScreenPrivateKey = &exaXorgScreenPrivateKey;
 
 typedef enum {
     EXAOPT_MIGRATION_HEURISTIC,
@@ -69,8 +68,8 @@ static Bool
 exaXorgCloseScreen (int i, ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen);
-    ExaXorgScreenPrivPtr pScreenPriv =
-	pScreen->devPrivates[exaXorgScreenPrivateIndex].ptr;
+    ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr)
+	dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey);
 
     pScreen->CloseScreen = pScreenPriv->SavedCloseScreen;
 
@@ -86,8 +85,8 @@ static void
 exaXorgEnableDisableFBAccess (int index, Bool enable)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    ExaXorgScreenPrivPtr pScreenPriv =
-	pScreen->devPrivates[exaXorgScreenPrivateIndex].ptr;
+    ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr)
+	dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey);
 
     if (!enable)
 	exaEnableDisableFBAccess (index, enable);
@@ -111,11 +110,6 @@ exaDDXDriverInit(ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     ExaXorgScreenPrivPtr pScreenPriv;
 
-    if (exaXorgServerGeneration != serverGeneration) {
-	exaXorgScreenPrivateIndex = AllocateScreenPrivateIndex();
-	exaXorgServerGeneration = serverGeneration;
-    }
-
     pScreenPriv = xcalloc (1, sizeof(ExaXorgScreenPrivRec));
     if (pScreenPriv == NULL)
 	return;
@@ -166,7 +160,7 @@ exaDDXDriverInit(ScreenPtr pScreen)
 	pExaScr->info->DownloadFromScreen = NULL;
     }
 
-    pScreen->devPrivates[exaXorgScreenPrivateIndex].ptr = pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey, pScreenPriv);
 
     pScreenPriv->SavedEnableDisableFBAccess = pScrn->EnableDisableFBAccess;
     pScrn->EnableDisableFBAccess = exaXorgEnableDisableFBAccess;
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 1af076b..4b3b66a 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -238,7 +238,7 @@ _X_HIDDEN void *dixLookupTab[] = {
 #ifdef XV
     /* XXX These are exported from the DDX, not DIX. */
     SYMVAR(XvScreenInitProc)
-    SYMVAR(XvGetScreenIndexProc)
+    SYMVAR(XvGetScreenKeyProc)
     SYMVAR(XvGetRTPortProc)
     SYMVAR(XvMCScreenInitProc)
 #endif
@@ -270,20 +270,6 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(dixFreePrivates)
     SYMFUNC(dixRegisterPrivateOffset)
     SYMFUNC(dixLookupPrivateOffset)
-    SYMFUNC(AllocateExtensionPrivate)
-    SYMFUNC(AllocateExtensionPrivateIndex)
-    SYMFUNC(AllocateClientPrivate)
-    SYMFUNC(AllocateClientPrivateIndex)
-    SYMFUNC(AllocateGCPrivate)
-    SYMFUNC(AllocateGCPrivateIndex)
-    SYMFUNC(AllocateWindowPrivate)
-    SYMFUNC(AllocateWindowPrivateIndex)
-    SYMFUNC(AllocateScreenPrivateIndex)
-    SYMFUNC(AllocateColormapPrivateIndex)
-    SYMFUNC(AllocateDevicePrivateIndex)
-    SYMFUNC(AllocateDevicePrivate)
-    SYMFUNC(AllocatePixmapPrivateIndex)
-    SYMFUNC(AllocatePixmapPrivate)
     /* resource.c */
     SYMFUNC(AddResource)
     SYMFUNC(ChangeResourceValue)
@@ -521,7 +507,7 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(PictureTransformPoint3d)
     SYMFUNC(PictureGetSubpixelOrder)
     SYMFUNC(PictureSetSubpixelOrder)
-    SYMVAR(PictureScreenPrivateIndex)
+    SYMVAR(PictureScreenPrivateKey)
     /* mipict.c */
     SYMFUNC(miPictureInit)
     SYMFUNC(miComputeCompositeRegion)
diff --git a/hw/xfree86/loader/misym.c b/hw/xfree86/loader/misym.c
index 78ae10e..e87d354 100644
--- a/hw/xfree86/loader/misym.c
+++ b/hw/xfree86/loader/misym.c
@@ -200,9 +200,9 @@ _X_HIDDEN void *miLookupTab[] = {
     SYMFUNC(miOverlaySetRootClip)
     SYMVAR(miEmptyBox)
     SYMVAR(miEmptyData)
-    SYMVAR(miZeroLineScreenIndex)
+    SYMVAR(miZeroLineScreenKey)
     SYMVAR(miSpritePointerFuncs)
-    SYMVAR(miPointerScreenIndex)
+    SYMVAR(miPointerScreenKey)
     SYMVAR(miInstalledMaps)
     SYMVAR(miInitVisualsProc)
 #ifdef RENDER
diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c
index 9b8dac8..7beef31 100644
--- a/hw/xfree86/loader/xf86sym.c
+++ b/hw/xfree86/loader/xf86sym.c
@@ -1099,8 +1099,8 @@ _X_HIDDEN void *xfree86LookupTab[] = {
     SYMVAR(xf86HUGE_VAL)
 
     /* General variables (from xf86.h) */
-    SYMVAR(xf86ScreenIndex)
-    SYMVAR(xf86PixmapIndex)
+    SYMVAR(xf86ScreenKey)
+    SYMVAR(xf86PixmapKey)
     SYMVAR(xf86Screens)
     SYMVAR(byte_reversed)
     SYMVAR(xf86inSuspend)
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index 38435c9..d58cc70 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -59,11 +59,11 @@ static Bool xf86RandR12Init12 (ScreenPtr pScreen);
 static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen);
 #endif
 
-static int	    xf86RandR12Index;
-static int	    xf86RandR12Generation;
+static int xf86RandR12Generation;
+static DevPrivateKey xf86RandR12Key = &xf86RandR12Key;
 
-#define XF86RANDRINFO(p) \
-	((XF86RandRInfoPtr)(p)->devPrivates[xf86RandR12Index].ptr)
+#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \
+    dixLookupPrivate(&(p)->devPrivates, xf86RandR12Key))
 
 static int
 xf86RandR12ModeRefresh (DisplayModePtr mode)
@@ -482,10 +482,7 @@ xf86RandR12Init (ScreenPtr pScreen)
 	return TRUE;
 #endif
     if (xf86RandR12Generation != serverGeneration)
-    {
-	xf86RandR12Index = AllocateScreenPrivateIndex();
 	xf86RandR12Generation = serverGeneration;
-    }
 
     randrp = xalloc (sizeof (XF86RandRInfoRec));
     if (!randrp)
@@ -511,7 +508,7 @@ xf86RandR12Init (ScreenPtr pScreen)
 
     randrp->maxX = randrp->maxY = 0;
 
-    pScreen->devPrivates[xf86RandR12Index].ptr = randrp;
+    dixSetPrivate(&pScreen->devPrivates, xf86RandR12Key, randrp);
 
 #if RANDR_12_INTERFACE
     if (!xf86RandR12Init12 (pScreen))
diff --git a/hw/xfree86/os-support/solaris/sun_mouse.c b/hw/xfree86/os-support/solaris/sun_mouse.c
index aa509d0..b1b7797 100644
--- a/hw/xfree86/os-support/solaris/sun_mouse.c
+++ b/hw/xfree86/os-support/solaris/sun_mouse.c
@@ -121,8 +121,11 @@ static void vuidMouseSendScreenSize(ScreenPtr pScreen, VuidMsePtr pVuidMse);
 static void vuidMouseAdjustFrame(int index, int x, int y, int flags);
 
 static int vuidMouseGeneration = 0;
-static int vuidMouseScreenIndex;
-#define vuidMouseScreenPrivate(s) ((s)->devPrivates[vuidMouseScreenIndex].ptr)
+static DevPrivateKey vuidMouseScreenKey = &vuidMouseScreenKey;
+#define vuidGetMouseScreenPrivate(s) ((VuidMsePtr) \
+    dixLookupPrivate(&(s)->devPrivates, vuidMouseScreenKey))
+#define vuidSetMouseScreenPrivate(s,p) \
+    dixSetPrivate(&(s)->devPrivates, vuidMouseScreenKey, p)
 #endif /* HAVE_ABSOLUTE_MOUSE_SCALING */
 
 static inline
@@ -455,7 +458,7 @@ static void vuidMouseAdjustFrame(int index, int x, int y, int flags)
       ScrnInfoPtr	pScrn = xf86Screens[index];
       ScreenPtr		pScreen = pScrn->pScreen;
       xf86AdjustFrameProc *wrappedAdjustFrame 
-	  = (xf86AdjustFrameProc *) vuidMouseScreenPrivate(pScreen);
+	  = (xf86AdjustFrameProc *) vuidMouseGetScreenPrivate(pScreen);
       VuidMsePtr	m;
 
       if(wrappedAdjustFrame) {
@@ -496,15 +499,12 @@ vuidMouseProc(DeviceIntPtr pPointer, int what)
     case DEVICE_INIT:
 #ifdef HAVE_ABSOLUTE_MOUSE_SCALING
 	if (vuidMouseGeneration != serverGeneration) {
-	    if ((vuidMouseScreenIndex = AllocateScreenPrivateIndex()) >= 0) {
 		for (i = 0; i < screenInfo.numScreens; i++) {
 		    ScreenPtr pScreen = screenInfo.screens[i];
 		    ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen);
-		    vuidMouseScreenPrivate(pScreen)
-			= (pointer) pScrn->AdjustFrame;
+		    vuidMouseSetScreenPrivate(pScreen, pScrn->AdjustFrame);
 		    pScrn->AdjustFrame = vuidMouseAdjustFrame;
 		}
-	    }
 	    vuidMouseGeneration = serverGeneration;
 	}
 #endif    	
diff --git a/hw/xfree86/rac/xf86RAC.c b/hw/xfree86/rac/xf86RAC.c
index 8492cdb..5302a86 100644
--- a/hw/xfree86/rac/xf86RAC.c
+++ b/hw/xfree86/rac/xf86RAC.c
@@ -39,9 +39,8 @@
                                   pScreen->x = y;}
 #define UNWRAP_SCREEN(x)    pScreen->x = pScreenPriv->x
 
-#define SCREEN_PROLOG(x) \
-            pScreen->x = \
-             ((RACScreenPtr) (pScreen)->devPrivates[RACScreenIndex].ptr)->x
+#define SCREEN_PROLOG(x) pScreen->x = ((RACScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, RACScreenKey))->x
 #define SCREEN_EPILOG(x,y) pScreen->x = y;
 
 #define WRAP_PICT_COND(x,y,cond) if (ps)\
@@ -50,9 +49,8 @@
 					ps->x = y;}
 #define UNWRAP_PICT(x) 	if (ps) {ps->x = pScreenPriv->x;}
 
-#define PICTURE_PROLOGUE(field) \
-	ps->field = \
-	((RACScreenPtr) (pScreen)->devPrivates[RACScreenIndex].ptr)->field
+#define PICTURE_PROLOGUE(field) ps->field = \
+	((RACScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, RACScreenKey))->field
 #define PICTURE_EPILOGUE(field, wrap) \
 	ps->field = wrap
 
@@ -65,9 +63,9 @@
 #define UNWRAP_SCREEN_INFO(x)    pScrn->x = pScreenPriv->x
 
 #define SPRITE_PROLOG     miPointerScreenPtr PointPriv = \
-(miPointerScreenPtr)pScreen->devPrivates[miPointerScreenIndex].ptr;\
-                               RACScreenPtr pScreenPriv = \
-((RACScreenPtr) (pScreen)->devPrivates[RACScreenIndex].ptr);\
+    (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); \
+    RACScreenPtr pScreenPriv = \
+    ((RACScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, RACScreenKey));\
 			PointPriv->spriteFuncs = pScreenPriv->miSprite;
 #define SPRITE_EPILOG pScreenPriv->miSprite = PointPriv->spriteFuncs;\
 	              PointPriv->spriteFuncs  = &RACSpriteFuncs;
@@ -82,7 +80,7 @@
                            (x)->ops = &RACGCOps;\
                          (x)->funcs = &RACGCFuncs;
 #define GC_UNWRAP(x)\
-           RACGCPtr  pGCPriv = (RACGCPtr) (x)->devPrivates[RACGCIndex].ptr;\
+    RACGCPtr  pGCPriv = (RACGCPtr)dixLookupPrivate(&(x)->devPrivates, RACGCKey);\
                     (x)->ops = pGCPriv->wrapOps;\
 	          (x)->funcs = pGCPriv->wrapFuncs;
 
@@ -255,9 +253,8 @@ static miPointerSpriteFuncRec RACSpriteFuncs = {
     RACSpriteMoveCursor
 };
 
-static int RACScreenIndex = -1;
-static int RACGCIndex = -1;
-static unsigned long RACGeneration = 0;
+static DevPrivateKey RACScreenKey = &RACScreenKey;
+static DevPrivateKey RACGCKey = &RACGCKey;
 
 
 Bool 
@@ -271,24 +268,17 @@ xf86RACInit(ScreenPtr pScreen, unsigned int flag)
 #endif
 
     pScrn = xf86Screens[pScreen->myNum];
-    PointPriv = (miPointerScreenPtr)pScreen->devPrivates[miPointerScreenIndex].ptr;
-
+    PointPriv = (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						     miPointerScreenKey);
     DPRINT_S("RACInit",pScreen->myNum);
-    if (RACGeneration != serverGeneration) {
-	if (	((RACScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
-		((RACGCIndex = AllocateGCPrivateIndex()) < 0))
-	    return FALSE;
-
-	RACGeneration = serverGeneration;
-    }
 
-    if (!AllocateGCPrivate(pScreen, RACGCIndex, sizeof(RACGCRec)))
+    if (!dixRequestPrivate(RACGCKey, sizeof(RACGCRec)))
 	return FALSE;
 
     if (!(pScreenPriv = xalloc(sizeof(RACScreenRec))))
 	return FALSE;
 
-    pScreen->devPrivates[RACScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, RACScreenKey, pScreenPriv);
     
     WRAP_SCREEN(CloseScreen, RACCloseScreen);
     WRAP_SCREEN(SaveScreen, RACSaveScreen);
@@ -327,10 +317,10 @@ static Bool
 RACCloseScreen (int i, ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    RACScreenPtr pScreenPriv = 
-	(RACScreenPtr) pScreen->devPrivates[RACScreenIndex].ptr;
-    miPointerScreenPtr PointPriv
-	= (miPointerScreenPtr)pScreen->devPrivates[miPointerScreenIndex].ptr;
+    RACScreenPtr pScreenPriv = (RACScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, RACScreenKey);
+    miPointerScreenPtr PointPriv = (miPointerScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, miPointerScreenKey);
 #ifdef RENDER
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
@@ -620,8 +610,8 @@ static void
 RACAdjustFrame(int index, int x, int y, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    RACScreenPtr pScreenPriv =
-	(RACScreenPtr) pScreen->devPrivates[RACScreenIndex].ptr;
+    RACScreenPtr pScreenPriv = (RACScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, RACScreenKey);
 
     DPRINT_S("RACAdjustFrame",index);
     xf86EnableAccess(xf86Screens[index]);
@@ -633,8 +623,8 @@ static Bool
 RACSwitchMode(int index, DisplayModePtr mode, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    RACScreenPtr pScreenPriv =
-	(RACScreenPtr) pScreen->devPrivates[RACScreenIndex].ptr;
+    RACScreenPtr pScreenPriv = (RACScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, RACScreenKey);
 
     DPRINT_S("RACSwitchMode",index);
     xf86EnableAccess(xf86Screens[index]);
@@ -646,8 +636,8 @@ static Bool
 RACEnterVT(int index, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    RACScreenPtr pScreenPriv =
-	(RACScreenPtr) pScreen->devPrivates[RACScreenIndex].ptr;
+    RACScreenPtr pScreenPriv = (RACScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, RACScreenKey);
 
     DPRINT_S("RACEnterVT",index);
     xf86EnableAccess(xf86Screens[index]);
@@ -659,8 +649,8 @@ static void
 RACLeaveVT(int index, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    RACScreenPtr pScreenPriv =
-	(RACScreenPtr) pScreen->devPrivates[RACScreenIndex].ptr;
+    RACScreenPtr pScreenPriv = (RACScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, RACScreenKey);
 
     DPRINT_S("RACLeaveVT",index);
     xf86EnableAccess(xf86Screens[index]);
@@ -672,8 +662,8 @@ static void
 RACFreeScreen(int index, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    RACScreenPtr pScreenPriv =
-	(RACScreenPtr) pScreen->devPrivates[RACScreenIndex].ptr;
+    RACScreenPtr pScreenPriv = (RACScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, RACScreenKey);
 
     DPRINT_S("RACFreeScreen",index);
     xf86EnableAccess(xf86Screens[index]);
@@ -685,7 +675,7 @@ static Bool
 RACCreateGC(GCPtr pGC)
 {
     ScreenPtr    pScreen = pGC->pScreen;
-    RACGCPtr     pGCPriv = (RACGCPtr) (pGC)->devPrivates[RACGCIndex].ptr;
+    RACGCPtr pGCPriv = (RACGCPtr)dixLookupPrivate(&pGC->devPrivates, RACGCKey);
     Bool         ret;
 
     DPRINT_S("RACCreateGC",pScreen->myNum);
diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c
index 4578076..1c2d6a8 100644
--- a/hw/xfree86/ramdac/xf86Cursor.c
+++ b/hw/xfree86/ramdac/xf86Cursor.c
@@ -8,8 +8,7 @@
 #include "colormapst.h"
 #include "cursorstr.h"
 
-int xf86CursorScreenIndex = -1;
-static unsigned long xf86CursorGeneration = 0;
+DevPrivateKey xf86CursorScreenKey = &xf86CursorScreenKey;
 
 /* sprite functions */
 
@@ -48,12 +47,6 @@ xf86InitCursor(
     xf86CursorScreenPtr ScreenPriv;
     miPointerScreenPtr PointPriv;
 
-    if (xf86CursorGeneration != serverGeneration) {
-	if ((xf86CursorScreenIndex = AllocateScreenPrivateIndex()) < 0)
-	    return FALSE;
-	xf86CursorGeneration = serverGeneration;
-    }
-
     if (!xf86InitHardwareCursor(pScreen, infoPtr))
 	return FALSE;
 
@@ -61,7 +54,7 @@ xf86InitCursor(
     if (!ScreenPriv)
 	return FALSE;
 
-    pScreen->devPrivates[xf86CursorScreenIndex].ptr = ScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, xf86CursorScreenKey, ScreenPriv);
 
     ScreenPriv->SWCursor = TRUE;
     ScreenPriv->isUp = FALSE;
@@ -84,7 +77,7 @@ xf86InitCursor(
 	ScreenPriv->PalettedCursor = TRUE;
     }
 
-    PointPriv = pScreen->devPrivates[miPointerScreenIndex].ptr;
+    PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
 
     ScreenPriv->showTransparent = PointPriv->showTransparent;
     if (infoPtr->Flags & HARDWARE_CURSOR_SHOW_TRANSPARENT)
@@ -113,10 +106,10 @@ static Bool
 xf86CursorCloseScreen(int i, ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    miPointerScreenPtr PointPriv =
-	pScreen->devPrivates[miPointerScreenIndex].ptr;
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    miPointerScreenPtr PointPriv = (miPointerScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, miPointerScreenKey);
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (ScreenPriv->isUp && pScrn->vtSema)
 	xf86SetCursor(pScreen, NullCursor, ScreenPriv->x, ScreenPriv->y);
@@ -146,8 +139,8 @@ xf86CursorQueryBestSize(
    unsigned short *height,
    ScreenPtr pScreen)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (class == CursorShape) {
 	if(*width > ScreenPriv->CursorInfoPtr->MaxWidth)
@@ -161,8 +154,8 @@ xf86CursorQueryBestSize(
 static void
 xf86CursorInstallColormap(ColormapPtr pMap)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pMap->pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pMap->pScreen->devPrivates, xf86CursorScreenKey);
 
     ScreenPriv->pInstalledMap = pMap;
 
@@ -175,8 +168,8 @@ xf86CursorRecolorCursor(
     CursorPtr pCurs,
     Bool displayed)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (!displayed)
 	return;
@@ -195,8 +188,8 @@ xf86CursorEnableDisableFBAccess(
     Bool enable)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (!enable && ScreenPriv->CurrentCursor != NullCursor) {
 	CursorPtr   currentCursor = ScreenPriv->CurrentCursor;
@@ -226,10 +219,10 @@ xf86CursorSwitchMode(int index, DisplayModePtr mode, int flags)
 {
     Bool ret;
     ScreenPtr pScreen = screenInfo.screens[index];
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
-    miPointerScreenPtr PointPriv =
-	pScreen->devPrivates[miPointerScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
+    miPointerScreenPtr PointPriv = (miPointerScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, miPointerScreenKey);
 
     if (ScreenPriv->isUp) {
 	xf86SetCursor(pScreen, NullCursor, ScreenPriv->x, ScreenPriv->y);
@@ -254,8 +247,8 @@ xf86CursorSwitchMode(int index, DisplayModePtr mode, int flags)
 static Bool
 xf86CursorRealizeCursor(ScreenPtr pScreen, CursorPtr pCurs)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (pCurs->refcnt <= 1)
 	pCurs->devPriv[pScreen->myNum] = NULL;
@@ -266,8 +259,8 @@ xf86CursorRealizeCursor(ScreenPtr pScreen, CursorPtr pCurs)
 static Bool
 xf86CursorUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCurs)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (pCurs->refcnt <= 1) {
 	xfree(pCurs->devPriv[pScreen->myNum]);
@@ -280,8 +273,8 @@ xf86CursorUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCurs)
 static void
 xf86CursorSetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
     xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr;
     miPointerScreenPtr PointPriv;
 
@@ -306,8 +299,8 @@ xf86CursorSetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
     ScreenPriv->HotX = pCurs->bits->xhot;
     ScreenPriv->HotY = pCurs->bits->yhot;
 
-    PointPriv = pScreen->devPrivates[miPointerScreenIndex].ptr;
-
+    PointPriv = (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						     miPointerScreenKey);
     if (infoPtr->pScrn->vtSema && (ScreenPriv->ForceHWCursorCount || ((
 #ifdef ARGB_CURSOR
 	pCurs->bits->argb && infoPtr->UseHWCursorARGB &&
@@ -351,8 +344,8 @@ xf86CursorSetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
 static void
 xf86CursorMoveCursor(ScreenPtr pScreen, int x, int y)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     ScreenPriv->x = x;
     ScreenPriv->y = y;
@@ -369,8 +362,8 @@ xf86CursorMoveCursor(ScreenPtr pScreen, int x, int y)
 void
 xf86ForceHWCursor (ScreenPtr pScreen, Bool on)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
 
     if (on)
     {
diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h
index 472e2b0..f82be2e 100644
--- a/hw/xfree86/ramdac/xf86CursorPriv.h
+++ b/hw/xfree86/ramdac/xf86CursorPriv.h
@@ -45,6 +45,6 @@ Bool xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr);
 
 CARD32 xf86ReverseBitOrder(CARD32 data);
 
-extern int xf86CursorScreenIndex;
+extern DevPrivateKey xf86CursorScreenKey;
 
 #endif /* _XF86CURSORPRIV_H */
diff --git a/hw/xfree86/ramdac/xf86HWCurs.c b/hw/xfree86/ramdac/xf86HWCurs.c
index 91caea0..0a753be 100644
--- a/hw/xfree86/ramdac/xf86HWCurs.c
+++ b/hw/xfree86/ramdac/xf86HWCurs.c
@@ -113,8 +113,8 @@ xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr)
 void
 xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
     xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr;
     unsigned char *bits;
 
@@ -157,8 +157,8 @@ xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y)
 void
 xf86SetTransparentCursor(ScreenPtr pScreen)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
     xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr;
 
     if (!ScreenPriv->transparentData)
@@ -178,8 +178,8 @@ xf86SetTransparentCursor(ScreenPtr pScreen)
 void
 xf86MoveCursor(ScreenPtr pScreen, int x, int y)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
     xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr;
 
     x -= infoPtr->pScrn->frameX0 + ScreenPriv->HotX;
@@ -191,8 +191,8 @@ xf86MoveCursor(ScreenPtr pScreen, int x, int y)
 void
 xf86RecolorCursor(ScreenPtr pScreen, CursorPtr pCurs, Bool displayed)
 {
-    xf86CursorScreenPtr ScreenPriv =
-	pScreen->devPrivates[xf86CursorScreenIndex].ptr;
+    xf86CursorScreenPtr ScreenPriv = (xf86CursorScreenPtr)dixLookupPrivate(
+	&pScreen->devPrivates, xf86CursorScreenKey);
     xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr;
 
 #ifdef ARGB_CURSOR
diff --git a/hw/xfree86/shadowfb/shadow.c b/hw/xfree86/shadowfb/shadow.c
index c1b6ed1..ba6e3a8 100644
--- a/hw/xfree86/shadowfb/shadow.c
+++ b/hw/xfree86/shadowfb/shadow.c
@@ -101,14 +101,13 @@ typedef struct {
 } ShadowGCRec, *ShadowGCPtr;
 
 
-static int ShadowScreenIndex = -1;
-static int ShadowGCIndex = -1;
-static unsigned long ShadowGeneration = 0;
+static DevPrivateKey ShadowScreenKey = &ShadowScreenKey;
+static DevPrivateKey ShadowGCKey = &ShadowGCKey;
 
 #define GET_SCREEN_PRIVATE(pScreen) \
-	(ShadowScreenPtr)((pScreen)->devPrivates[ShadowScreenIndex].ptr)
+    (ShadowScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, ShadowScreenKey)
 #define GET_GC_PRIVATE(pGC) \
-	(ShadowGCPtr)((pGC)->devPrivates[ShadowGCIndex].ptr)
+    (ShadowGCPtr)dixLookupPrivate(&(pGC)->devPrivates, ShadowGCKey);
 
 #define SHADOW_GC_FUNC_PROLOGUE(pGC)\
     ShadowGCPtr pGCPriv = GET_GC_PRIVATE(pGC);\
@@ -179,20 +178,13 @@ ShadowFBInit2 (
 
     if(!preRefreshArea && !postRefreshArea) return FALSE;
     
-    if (ShadowGeneration != serverGeneration) {
-	if(((ShadowScreenIndex = AllocateScreenPrivateIndex ()) < 0) ||
-	   ((ShadowGCIndex = AllocateGCPrivateIndex()) < 0))
-	    return FALSE;
-	ShadowGeneration = serverGeneration;
-    }
-
-    if(!AllocateGCPrivate(pScreen, ShadowGCIndex, sizeof(ShadowGCRec)))
+    if(!dixRequestPrivate(ShadowGCKey, sizeof(ShadowGCRec)))
 	return FALSE;
 
     if(!(pPriv = (ShadowScreenPtr)xalloc(sizeof(ShadowScreenRec))))
 	return FALSE;
 
-    pScreen->devPrivates[ShadowScreenIndex].ptr = (pointer)pPriv;  
+    dixSetPrivate(&pScreen->devPrivates, ShadowScreenKey, pPriv);
 
     pPriv->pScrn = pScrn;
     pPriv->preRefresh = preRefreshArea;
diff --git a/hw/xfree86/xaa/xaaDashLine.c b/hw/xfree86/xaa/xaaDashLine.c
index 1a4732b..63233e0 100644
--- a/hw/xfree86/xaa/xaaDashLine.c
+++ b/hw/xfree86/xaa/xaaDashLine.c
@@ -35,7 +35,8 @@ XAAPolyLinesDashed(
 #endif
 ){
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAGCPtr   pGCPriv = (XAAGCPtr) (pGC)->devPrivates[XAAGetGCIndex()].ptr;
+    XAAGCPtr   pGCPriv = (XAAGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						    XAAGetGCKey());
     BoxPtr pboxInit = REGION_RECTS(pGC->pCompositeClip);
     int nboxInit = REGION_NUM_RECTS(pGC->pCompositeClip);
     unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
diff --git a/hw/xfree86/xaa/xaaGC.c b/hw/xfree86/xaa/xaaGC.c
index f3434c9..65a482f 100644
--- a/hw/xfree86/xaa/xaaGC.c
+++ b/hw/xfree86/xaa/xaaGC.c
@@ -38,7 +38,8 @@ Bool
 XAACreateGC(GCPtr pGC)
 {
     ScreenPtr    pScreen = pGC->pScreen;
-    XAAGCPtr     pGCPriv = (XAAGCPtr)(pGC->devPrivates[XAAGetGCIndex()].ptr);
+    XAAGCPtr     pGCPriv = (XAAGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						      XAAGetGCKey());
     Bool         ret;
 
     XAA_SCREEN_PROLOGUE(pScreen,CreateGC);
diff --git a/hw/xfree86/xaa/xaaGCmisc.c b/hw/xfree86/xaa/xaaGCmisc.c
index a7a3f40..5823cc0 100644
--- a/hw/xfree86/xaa/xaaGCmisc.c
+++ b/hw/xfree86/xaa/xaaGCmisc.c
@@ -305,7 +305,8 @@ XAAValidatePolylines(
    DrawablePtr   pDraw )
 {
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-   XAAGCPtr   pGCPriv = (XAAGCPtr) (pGC)->devPrivates[XAAGetGCIndex()].ptr;
+   XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						 XAAGetGCKey());
 
    if(pGC->lineStyle == LineSolid) changes &= ~GCDashList;
    if(!changes) return;
diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c
index 93f6995..614ecf7 100644
--- a/hw/xfree86/xaa/xaaInit.c
+++ b/hw/xfree86/xaa/xaaInit.c
@@ -38,22 +38,20 @@ static int  XAASetDGAMode(int index, int num, DGADevicePtr devRet);
 static void XAAEnableDisableFBAccess (int index, Bool enable);
 static Bool XAAChangeWindowAttributes (WindowPtr pWin, unsigned long mask);
 
-static int XAAScreenIndex = -1;
-static int XAAGCIndex = -1;
-static int XAAPixmapIndex = -1;
+static DevPrivateKey XAAScreenKey = &XAAScreenKey;
+static DevPrivateKey XAAGCKey = &XAAGCKey;
+static DevPrivateKey XAAPixmapKey = &XAAPixmapKey;
 
-static unsigned long XAAGeneration = 0;
-
-int XAAGetScreenIndex(void) {
-    return XAAScreenIndex;
+DevPrivateKey XAAGetScreenKey(void) {
+    return XAAScreenKey;
 }
 
-int XAAGetGCIndex(void) {
-    return XAAGCIndex;
+DevPrivateKey XAAGetGCKey(void) {
+    return XAAGCKey;
 }
 
-int XAAGetPixmapIndex(void) {
-    return XAAPixmapIndex;
+DevPrivateKey XAAGetPixmapKey(void) {
+    return XAAPixmapKey;
 }
 
 /* temp kludge */
@@ -103,25 +101,16 @@ XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
     if (!infoRec)
 	return TRUE;
     
-    if (XAAGeneration != serverGeneration) {
-	if (	((XAAScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
-		((XAAGCIndex = AllocateGCPrivateIndex()) < 0) ||
-		((XAAPixmapIndex = AllocatePixmapPrivateIndex()) < 0))
-		return FALSE;
-
-	XAAGeneration = serverGeneration;
-    }
-
-    if (!AllocateGCPrivate(pScreen, XAAGCIndex, sizeof(XAAGCRec)))
+    if (!dixRequestPrivate(XAAGCKey, sizeof(XAAGCRec)))
 	return FALSE;
 
-    if (!AllocatePixmapPrivate(pScreen, XAAPixmapIndex, sizeof(XAAPixmapRec)))
+    if (!dixRequestPrivate(XAAPixmapKey, sizeof(XAAPixmapRec)))
 	return FALSE;
 
     if (!(pScreenPriv = xalloc(sizeof(XAAScreenRec))))
 	return FALSE;
 
-    pScreen->devPrivates[XAAScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, XAAScreenKey, pScreenPriv);
 
     if(!xf86FBManagerRunning(pScreen))
 	infoRec->Flags &= ~(PIXMAP_CACHE | OFFSCREEN_PIXMAPS);
@@ -226,7 +215,7 @@ XAACloseScreen (int i, ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     XAAScreenPtr pScreenPriv = 
-	(XAAScreenPtr) pScreen->devPrivates[XAAScreenIndex].ptr;
+	(XAAScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
 
     pScrn->EnterVT = pScreenPriv->EnterVT; 
     pScrn->LeaveVT = pScreenPriv->LeaveVT; 
@@ -524,7 +513,7 @@ XAAEnterVT(int index, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
     XAAScreenPtr pScreenPriv = 
-	(XAAScreenPtr) pScreen->devPrivates[XAAScreenIndex].ptr;
+	(XAAScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
 
     return((*pScreenPriv->EnterVT)(index, flags));
 }
@@ -534,7 +523,7 @@ XAALeaveVT(int index, int flags)
 {
     ScreenPtr pScreen = screenInfo.screens[index];
     XAAScreenPtr pScreenPriv = 
-	(XAAScreenPtr) pScreen->devPrivates[XAAScreenIndex].ptr;
+	(XAAScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
     XAAInfoRecPtr infoRec = pScreenPriv->AccelInfoRec;
 
     if(infoRec->NeedToSync) {
@@ -557,7 +546,7 @@ XAASetDGAMode(int index, int num, DGADevicePtr devRet)
     ScreenPtr pScreen = screenInfo.screens[index];
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAScreenPtr pScreenPriv = 
-	(XAAScreenPtr) pScreen->devPrivates[XAAScreenIndex].ptr;
+	(XAAScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
     int ret;
 
     if (!num && infoRec->dgaSaves) { /* restore old pixmap cache state */
@@ -619,7 +608,7 @@ XAAEnableDisableFBAccess (int index, Bool enable)
     ScreenPtr pScreen = screenInfo.screens[index];
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAScreenPtr pScreenPriv = 
-	(XAAScreenPtr) pScreen->devPrivates[XAAScreenIndex].ptr;
+	(XAAScreenPtr)dixLookupPrivate(&pScreen->devPrivates, XAAScreenKey);
 
     if(!enable) {
 	if((infoRec->Flags & OFFSCREEN_PIXMAPS) && (infoRec->OffscreenPixmaps))
diff --git a/hw/xfree86/xaa/xaaLineMisc.c b/hw/xfree86/xaa/xaaLineMisc.c
index 537b08b..cefb59a 100644
--- a/hw/xfree86/xaa/xaaLineMisc.c
+++ b/hw/xfree86/xaa/xaaLineMisc.c
@@ -64,7 +64,8 @@ void
 XAAComputeDash(GCPtr pGC)
 {
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
-    XAAGCPtr   pGCPriv = (XAAGCPtr) (pGC)->devPrivates[XAAGetGCIndex()].ptr;
+    XAAGCPtr   pGCPriv = (XAAGCPtr)dixLookupPrivate(&pGC->devPrivates,
+						    XAAGetGCKey());
     Bool EvenDash = (pGC->numInDashList & 0x01) ? FALSE : TRUE;
     int PatternLength = 0;
     unsigned char* DashPtr = (unsigned char*)pGC->dash;
diff --git a/hw/xfree86/xaa/xaaOverlayDF.c b/hw/xfree86/xaa/xaaOverlayDF.c
index 5897e32..77c9cb1 100644
--- a/hw/xfree86/xaa/xaaOverlayDF.c
+++ b/hw/xfree86/xaa/xaaOverlayDF.c
@@ -152,11 +152,10 @@ typedef struct {
    int (*TiledFillChooser)(GCPtr);
 } XAAOverlayRec, *XAAOverlayPtr;
 
-static int XAAOverlayIndex = -1;
-static unsigned long XAAOverlayGeneration = 0;
+static DevPrivateKey XAAOverlayKey = &XAAOverlayKey;
 
 #define GET_OVERLAY_PRIV(pScreen) \
-    ((XAAOverlayPtr)((pScreen)->devPrivates[XAAOverlayIndex].ptr))
+    (XAAOverlayPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAOverlayKey)
 
 #define SWITCH_DEPTH(d) \
    if(pOverPriv->currentDepth != d) { \
@@ -174,18 +173,10 @@ XAAInitDualFramebufferOverlay(
     XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCREEN(pScreen);
     XAAOverlayPtr pOverPriv;
 
-    if (XAAOverlayGeneration != serverGeneration) {
-	if((XAAOverlayIndex = AllocateScreenPrivateIndex()) < 0)
-		return FALSE;
-
-	XAAOverlayGeneration = serverGeneration;
-    }
-   
-
     if(!(pOverPriv = xalloc(sizeof(XAAOverlayRec))))
 	return FALSE;
 
-    pScreen->devPrivates[XAAOverlayIndex].ptr = (pointer)pOverPriv;
+    dixSetPrivate(&pScreen->devPrivates, XAAOverlayKey, pOverPriv);
 
     pOverPriv->pScrn = pScrn;
     pOverPriv->callback = callback;
diff --git a/hw/xfree86/xaa/xaaStateChange.c b/hw/xfree86/xaa/xaaStateChange.c
index 711f779..39ad046 100644
--- a/hw/xfree86/xaa/xaaStateChange.c
+++ b/hw/xfree86/xaa/xaaStateChange.c
@@ -276,18 +276,17 @@ typedef struct _XAAStateWrapRec {
 #endif
 } XAAStateWrapRec, *XAAStateWrapPtr;
 
-static int XAAStateIndex = -1;
-static unsigned long XAAStateGeneration = 0;
+static DevPrivateKey XAAStateKey = &XAAStateKey;
 
 /* Wrap functions start here */
 #define GET_STATEPRIV_GC(pGC)   XAAStateWrapPtr pStatePriv =\
-(XAAStateWrapPtr)(pGC->pScreen->devPrivates[XAAStateIndex].ptr)
+(XAAStateWrapPtr)dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAStateKey)
 
 #define GET_STATEPRIV_SCREEN(pScreen)   XAAStateWrapPtr pStatePriv =\
-(XAAStateWrapPtr)(pScreen->devPrivates[XAAStateIndex].ptr)
+(XAAStateWrapPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAStateKey)
 
 #define GET_STATEPRIV_PSCRN(pScrn)   XAAStateWrapPtr pStatePriv =\
-(XAAStateWrapPtr)(pScrn->pScreen->devPrivates[XAAStateIndex].ptr)
+(XAAStateWrapPtr)dixLookupPrivate(&(pScrn)->pScreen->devPrivates, XAAStateKey)
 
 #define STATE_CHECK_SP(pStatePriv) {\
 	ScrnInfoPtr pScrn = pStatePriv->pScrn;\
@@ -1526,12 +1525,8 @@ XAAInitStateWrap(ScreenPtr pScreen, XAAInfoRecPtr infoRec)
    XAAStateWrapPtr pStatePriv;
    int i = 0;
    
-   if (XAAStateGeneration != serverGeneration) {
-      if((XAAStateIndex = AllocateScreenPrivateIndex()) < 0) return FALSE;
-      XAAStateGeneration = serverGeneration;
-   }
    if(!(pStatePriv = xalloc(sizeof(XAAStateWrapRec)))) return FALSE;
-   pScreen->devPrivates[XAAStateIndex].ptr = (pointer)pStatePriv;   
+   dixSetPrivate(&pScreen->devPrivates, XAAStateKey, pStatePriv);
    pStatePriv->RestoreAccelState = infoRec->RestoreAccelState;
    pStatePriv->pScrn = pScrn;
    
diff --git a/hw/xfree86/xaa/xaaWrapper.c b/hw/xfree86/xaa/xaaWrapper.c
index 6d8107b..642ef8c 100644
--- a/hw/xfree86/xaa/xaaWrapper.c
+++ b/hw/xfree86/xaa/xaaWrapper.c
@@ -90,10 +90,8 @@ typedef struct {
     int depth;
 } xaaWrapperScrPrivRec, *xaaWrapperScrPrivPtr;
 
-#define xaaWrapperGetScrPriv(s)	((xaaWrapperScrPrivPtr)( \
-				 (xaaWrapperScrPrivateIndex != -1) \
-                          ? (s)->devPrivates[xaaWrapperScrPrivateIndex].ptr\
-				: NULL))
+#define xaaWrapperGetScrPriv(s)	((xaaWrapperScrPrivPtr) \
+    dixLookupPrivate(&(s)->devPrivates, xaaWrapperScrPrivateKey))
 #define xaaWrapperScrPriv(s)     xaaWrapperScrPrivPtr pScrPriv = xaaWrapperGetScrPriv(s)
 
 #define wrap(priv,real,mem,func) {\
@@ -131,13 +129,12 @@ typedef struct _xaaWrapperGCPriv {
 } xaaWrapperGCPrivRec, *xaaWrapperGCPrivPtr;
 
 #define xaaWrapperGetGCPriv(pGC) ((xaaWrapperGCPrivPtr) \
-				      (pGC)->devPrivates[xaaWrapperGCPrivateIndex].ptr)
+    dixLookupPrivate(&(pGC)->devPrivates, xaaWrapperGCPrivateKey))
 #define xaaWrapperGCPriv(pGC)   xaaWrapperGCPrivPtr  pGCPriv = xaaWrapperGetGCPriv(pGC)
 
 
-static int xaaWrapperScrPrivateIndex = -1;
-static int xaaWrapperGCPrivateIndex = -1;
-static int xaaWrapperGeneration = -1;
+static DevPrivateKey xaaWrapperScrPrivateKey = &xaaWrapperScrPrivateKey;
+static DevPrivateKey xaaWrapperGCPrivateKey = &xaaWrapperGCPrivateKey;
 
 static Bool
 xaaWrapperCreateScreenResources(ScreenPtr pScreen)
@@ -305,18 +302,8 @@ xaaSetupWrapper(ScreenPtr pScreen, XAAInfoRecPtr infoPtr, int depth, SyncFunc *f
 #ifdef RENDER
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
-    if (xaaWrapperGeneration != serverGeneration) {
-	xaaWrapperScrPrivateIndex = AllocateScreenPrivateIndex ();
-	if (xaaWrapperScrPrivateIndex == -1)
-	    return FALSE;
-	xaaWrapperGCPrivateIndex = AllocateGCPrivateIndex ();
-	if (xaaWrapperGCPrivateIndex == -1)
-	    return FALSE;
-	xaaWrapperGeneration = serverGeneration;
-    }
 
-    if (!AllocateGCPrivate (pScreen, xaaWrapperGCPrivateIndex,
-			    sizeof (xaaWrapperGCPrivRec)))
+    if (!dixRequestPrivate(xaaWrapperGCPrivateKey, sizeof(xaaWrapperGCPrivRec)))
 	return FALSE;
 
     pScrPriv = (xaaWrapperScrPrivPtr) xalloc (sizeof (xaaWrapperScrPrivRec));
@@ -370,7 +357,7 @@ xaaSetupWrapper(ScreenPtr pScreen, XAAInfoRecPtr infoPtr, int depth, SyncFunc *f
     }
 #endif
     pScrPriv->depth = depth;
-    pScreen->devPrivates[xaaWrapperScrPrivateIndex].ptr = (pointer) pScrPriv;
+    dixSetPrivate(&pScreen->devPrivates, xaaWrapperScrPrivateKey, pScrPriv);
 
     *func = XAASync;
     
@@ -521,8 +508,8 @@ xaaWrapperGlyphs (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
 void
 XAASync(ScreenPtr pScreen)
 {
-    XAAScreenPtr pScreenPriv = 
-	(XAAScreenPtr) pScreen->devPrivates[XAAGetScreenIndex()].ptr;
+    XAAScreenPtr pScreenPriv = (XAAScreenPtr)
+	dixLookupPrivate(&pScreen->devPrivates, XAAGetScreenKey());
     XAAInfoRecPtr infoRec = pScreenPriv->AccelInfoRec;
 
     if(infoRec->NeedToSync) {
diff --git a/hw/xfree86/xaa/xaalocal.h b/hw/xfree86/xaa/xaalocal.h
index 3ddea24..1e536c1 100644
--- a/hw/xfree86/xaa/xaalocal.h
+++ b/hw/xfree86/xaa/xaalocal.h
@@ -1639,9 +1639,9 @@ XAAGetPixelFromRGBA (
 extern GCOps XAAFallbackOps;
 extern GCOps *XAAGetFallbackOps(void);
 extern GCFuncs XAAGCFuncs;
-extern int XAAGetScreenIndex(void);
-extern int XAAGetGCIndex(void);
-extern int XAAGetPixmapIndex(void);
+extern DevPrivateKey XAAGetScreenKey(void);
+extern DevPrivateKey XAAGetGCKey(void);
+extern DevPrivateKey XAAGetPixmapKey(void);
 
 extern unsigned int XAAShiftMasks[32];
 
@@ -1650,28 +1650,28 @@ extern unsigned int byte_expand3[256], byte_reversed_expand3[256];
 CARD32 XAAReverseBitOrder(CARD32 data);
 
 #define GET_XAASCREENPTR_FROM_SCREEN(pScreen)\
-	(pScreen)->devPrivates[XAAGetScreenIndex()].ptr
+    dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey())
 
 #define GET_XAASCREENPTR_FROM_GC(pGC)\
-	(pGC)->pScreen->devPrivates[XAAGetScreenIndex()].ptr
+    dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAGetScreenKey())
 
 #define GET_XAASCREENPTR_FROM_DRAWABLE(pDraw)\
-	(pDraw)->pScreen->devPrivates[XAAGetScreenIndex()].ptr
+    dixLookupPrivate(&(pDraw)->pScreen->devPrivates, XAAGetScreenKey())
 
 #define GET_XAAINFORECPTR_FROM_SCREEN(pScreen)\
-   ((XAAScreenPtr)((pScreen)->devPrivates[XAAGetScreenIndex()].ptr))->AccelInfoRec
+((XAAScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey()))->AccelInfoRec
 
 #define GET_XAAINFORECPTR_FROM_GC(pGC)\
-((XAAScreenPtr)((pGC)->pScreen->devPrivates[XAAGetScreenIndex()].ptr))->AccelInfoRec
+((XAAScreenPtr)dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec
 
 #define GET_XAAINFORECPTR_FROM_DRAWABLE(pDraw)\
-((XAAScreenPtr)((pDraw)->pScreen->devPrivates[XAAGetScreenIndex()].ptr))->AccelInfoRec
+((XAAScreenPtr)dixLookupPrivate(&(pDraw)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec
 
 #define GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn)\
-((XAAScreenPtr)((pScrn)->pScreen->devPrivates[XAAGetScreenIndex()].ptr))->AccelInfoRec
+((XAAScreenPtr)dixLookupPrivate(&(pScrn)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec
 
 #define XAA_GET_PIXMAP_PRIVATE(pix)\
-	(XAAPixmapPtr)((pix)->devPrivates[XAAGetPixmapIndex()].ptr)
+    (XAAPixmapPtr)dixLookupPrivate(&(pix)->devPrivates, XAAGetPixmapKey())
 
 #define CHECK_RGB_EQUAL(c) (!((((c) >> 8) ^ (c)) & 0xffff))
 
diff --git a/hw/xfree86/xaa/xaawrap.h b/hw/xfree86/xaa/xaawrap.h
index 32c17a6..38c97d7 100644
--- a/hw/xfree86/xaa/xaawrap.h
+++ b/hw/xfree86/xaa/xaawrap.h
@@ -1,14 +1,14 @@
 
 #define XAA_SCREEN_PROLOGUE(pScreen, field)\
   ((pScreen)->field = \
-   ((XAAScreenPtr) (pScreen)->devPrivates[XAAGetScreenIndex()].ptr)->field)
+   ((XAAScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey()))->field)
 
 #define XAA_SCREEN_EPILOGUE(pScreen, field, wrapper)\
     ((pScreen)->field = wrapper)
 
 
 #define XAA_GC_FUNC_PROLOGUE(pGC)\
-    XAAGCPtr   pGCPriv = (XAAGCPtr) (pGC)->devPrivates[XAAGetGCIndex()].ptr;\
+    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
     (pGC)->funcs = pGCPriv->wrapFuncs;\
     if(pGCPriv->flags)\
 	(pGC)->ops = pGCPriv->wrapOps
@@ -24,13 +24,13 @@
 
 
 #define XAA_GC_OP_PROLOGUE(pGC)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)(pGC->devPrivates[XAAGetGCIndex()].ptr);\
+    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
     GCFuncs *oldFuncs = pGC->funcs;\
     pGC->funcs = pGCPriv->wrapFuncs;\
     pGC->ops = pGCPriv->wrapOps
 
 #define XAA_GC_OP_PROLOGUE_WITH_RETURN(pGC)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)(pGC->devPrivates[XAAGetGCIndex()].ptr);\
+    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
     GCFuncs *oldFuncs = pGC->funcs;\
     if(!REGION_NUM_RECTS(pGC->pCompositeClip)) return; \
     pGC->funcs = pGCPriv->wrapFuncs;\
@@ -44,7 +44,7 @@
 
 
 #define XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw)\
-    XAAGCPtr pGCPriv = (XAAGCPtr)(pGC->devPrivates[XAAGetGCIndex()].ptr);\
+    XAAGCPtr pGCPriv = (XAAGCPtr)dixLookupPrivate(&(pGC)->devPrivates, XAAGetGCKey()); \
     XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE((PixmapPtr)(pDraw));\
     GCFuncs *oldFuncs = pGC->funcs;\
     pGC->funcs = pGCPriv->wrapFuncs;\
@@ -64,7 +64,7 @@
 #ifdef RENDER
 #define XAA_RENDER_PROLOGUE(pScreen,field)\
     (GetPictureScreen(pScreen)->field = \
-     ((XAAScreenPtr) (pScreen)->devPrivates[XAAGetScreenIndex()].ptr)->field)
+     ((XAAScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XAAGetScreenKey()))->field)
 
 #define XAA_RENDER_EPILOGUE(pScreen, field, wrapper)\
     (GetPictureScreen(pScreen)->field = wrapper)
@@ -74,7 +74,7 @@
 
 #define SYNC_CHECK(pGC) {\
      XAAInfoRecPtr infoRec =\
-((XAAScreenPtr)((pGC)->pScreen->devPrivates[XAAGetScreenIndex()].ptr))->AccelInfoRec;\
+((XAAScreenPtr)dixLookupPrivate(&(pGC)->pScreen->devPrivates, XAAGetScreenKey()))->AccelInfoRec;	\
     if(infoRec->NeedToSync) {\
 	(*infoRec->Sync)(infoRec->pScrn);\
 	infoRec->NeedToSync = FALSE;\
diff --git a/hw/xfree86/xf4bpp/mfbfillarc.c b/hw/xfree86/xf4bpp/mfbfillarc.c
index d5b5372..89aeadd 100644
--- a/hw/xfree86/xf4bpp/mfbfillarc.c
+++ b/hw/xfree86/xf4bpp/mfbfillarc.c
@@ -253,7 +253,8 @@ xf4bppPolyFillArcSolid
     mfbPrivGC *priv;
     int rop;
 
-    priv = (mfbPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr;
+    priv = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					 mfbGetGCPrivateKey());
     rop = priv->rop;
     if ((rop == RROP_NOP) || !(pGC->planemask & 1))
 #else
diff --git a/hw/xfree86/xf4bpp/mfbimggblt.c b/hw/xfree86/xf4bpp/mfbimggblt.c
index bf53f4c..711a16e 100644
--- a/hw/xfree86/xf4bpp/mfbimggblt.c
+++ b/hw/xfree86/xf4bpp/mfbimggblt.c
@@ -149,7 +149,8 @@ xf4bppImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
        backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
 
 
-       pPrivGC = pGC->devPrivates[mfbGetGCPrivateIndex()].ptr;
+       pPrivGC = (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					       mfbGetGCPrivateKey());
        oldfillStyle = pPrivGC->colorRrop.fillStyle; /* GJA */
        oldfg = pPrivGC->colorRrop.fgPixel; /* GJA */
        oldalu = pPrivGC->colorRrop.alu; /* GJA */
diff --git a/hw/xfree86/xf4bpp/mfbzerarc.c b/hw/xfree86/xf4bpp/mfbzerarc.c
index c7a8c4d..61fc7b1 100644
--- a/hw/xfree86/xf4bpp/mfbzerarc.c
+++ b/hw/xfree86/xf4bpp/mfbzerarc.c
@@ -108,7 +108,8 @@ v16ZeroArcSS
     int pmask;
     register int *paddr;
 
-    if (((mfbPrivGC *)(pGC->devPrivates[mfbGetGCPrivateIndex()].ptr))->rop ==
+    if (((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+				       mfbGetGCPrivateKey()))->rop ==
 	RROP_BLACK)
 	pixel = 0;
     else
diff --git a/hw/xfree86/xf4bpp/ppcArea.c b/hw/xfree86/xf4bpp/ppcArea.c
index e956962..df7856a 100644
--- a/hw/xfree86/xf4bpp/ppcArea.c
+++ b/hw/xfree86/xf4bpp/ppcArea.c
@@ -49,7 +49,7 @@ int alu ;
 unsigned long int fg, bg, pm ;
 int xSrc, ySrc ;
 PixmapPtr pPixmap ;
-ppcPrivGC *pPrivGC = pGC->devPrivates[mfbGetGCPrivateIndex()].ptr;
+ppcPrivGC *pPrivGC = dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey());
 
 TRACE( ( "xf4bppFillArea(0x%x,%d,0x%x,0x%x)\n", pWin, nboxes, pBox, pGC ) ) ;
 
diff --git a/hw/xfree86/xf4bpp/ppcGC.c b/hw/xfree86/xf4bpp/ppcGC.c
index b59dab3..ca3c5e9 100644
--- a/hw/xfree86/xf4bpp/ppcGC.c
+++ b/hw/xfree86/xf4bpp/ppcGC.c
@@ -183,7 +183,7 @@ register GCPtr pGC ;
          * a pointer to a ppcPrivGC in its slot.
          */
 	*pPriv = vgaPrototypeGCPriv;
-	(pGC->devPrivates[mfbGetGCPrivateIndex()].ptr) = (pointer) pPriv;
+	dixSetPrivate(&pGC->devPrivates, mfbGetGCPrivateKey(), pPriv);
 
 	/* Set the vgaGCOps */
 	*pOps = vgaGCOps;
@@ -209,7 +209,7 @@ xf4bppDestroyGC( pGC )
     if ( pGC->freeCompClip && pGC->pCompositeClip )
 	REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
     if(pGC->ops->devPrivate.val) xfree( pGC->ops );
-    xfree( pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
+    xfree(dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()));
     return ;
 }
 
@@ -220,7 +220,7 @@ ppcChangePixmapGC
 	register Mask changes
 )
 {
-register ppcPrivGCPtr devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
+register ppcPrivGCPtr devPriv = (ppcPrivGCPtr)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey());
 register unsigned long int idx ; /* used for stepping through bitfields */
 
 #define LOWBIT( x ) ( x & - x ) /* Two's complement */
@@ -298,8 +298,8 @@ xf4bppValidateGC( pGC, changes, pDrawable )
     register ppcPrivGCPtr devPriv ;
     WindowPtr pWin ;
 
-    devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
-
+    devPriv = (ppcPrivGCPtr)dixLookupPrivate(&pGC->devPrivates,
+					     mfbGetGCPrivateKey());
     if ( pDrawable->type != devPriv->lastDrawableType ) {
 	devPriv->lastDrawableType = pDrawable->type ;
 	xf4bppChangeGCtype( pGC, devPriv ) ;
diff --git a/hw/xfree86/xf4bpp/ppcIO.c b/hw/xfree86/xf4bpp/ppcIO.c
index 8d726e7..bd20218 100644
--- a/hw/xfree86/xf4bpp/ppcIO.c
+++ b/hw/xfree86/xf4bpp/ppcIO.c
@@ -219,7 +219,7 @@ xf4bppScreenInit( pScreen, pbits, virtx, virty, dpix, dpiy, width )
   pScreen-> ResolveColor = xf4bppResolveColor;
   mfbFillInScreen(pScreen);
 
-  if (!mfbAllocatePrivates(pScreen, (int*)NULL, (int*)NULL))
+  if (!mfbAllocatePrivates(pScreen, NULL, NULL))
 	return FALSE;
 
   if (!miScreenInit(pScreen, pbits, virtx, virty, dpix, dpiy, width,
diff --git a/hw/xfree86/xf4bpp/ppcPixFS.c b/hw/xfree86/xf4bpp/ppcPixFS.c
index f24168b..91b7532 100644
--- a/hw/xfree86/xf4bpp/ppcPixFS.c
+++ b/hw/xfree86/xf4bpp/ppcPixFS.c
@@ -124,7 +124,7 @@ xf4bppSolidPixmapFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()))->colorRrop.alu ) == GXnoop )
 	return ;
 
     n = nInit * miFindMaxBand(pGC->pCompositeClip) ;
@@ -142,8 +142,8 @@ xf4bppSolidPixmapFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
     n = miClipSpans( pGC->pCompositeClip, pptInit, pwidthInit, nInit,
 	ppt, pwidth, fSorted ) ;
 
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
-    fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.fgPixel ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
+    fg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.fgPixel ;
     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
 
     for ( ; n-- ; ppt++, pwidth++ ) {
@@ -258,14 +258,14 @@ int fSorted ;
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     SETSPANPTRS( nInit, n, pwidthInit, pwidthFree, pptInit,
 		pptFree, pwidth, ppt, fSorted ) ;
 
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
-    fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.fgPixel ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
+    fg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.fgPixel ;
 
     pTile = pGC->stipple ;
     tlwidth = pTile->devKind ;
@@ -356,15 +356,15 @@ int fSorted ;
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     SETSPANPTRS( nInit, n, pwidthInit, pwidthFree, pptInit,
 		 pptFree, pwidth, ppt, fSorted ) ;
 
-    fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.fgPixel ;
-    bg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.bgPixel ;
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
+    fg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.fgPixel ;
+    bg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.bgPixel ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
 
     pTile = pGC->stipple ;
@@ -459,14 +459,14 @@ int fSorted ;
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     SETSPANPTRS( nInit, n, pwidthInit, pwidthFree, pptInit,
 		 pptFree, pwidth, ppt, fSorted ) ;
 
     /* the following code is for 8 bits per pixel addressable memory only */
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
     pTile = pGC->tile.pixmap ;
     tileWidth = pTile->drawable.width ;
diff --git a/hw/xfree86/xf4bpp/ppcPixmap.c b/hw/xfree86/xf4bpp/ppcPixmap.c
index ec181cf..2079e2e 100644
--- a/hw/xfree86/xf4bpp/ppcPixmap.c
+++ b/hw/xfree86/xf4bpp/ppcPixmap.c
@@ -137,6 +137,7 @@ xf4bppCopyPixmap(pSrc)
     pDst = xalloc(sizeof(PixmapRec) + size);
     if (!pDst)
 	return NullPixmap;
+    pDst->devPrivates = NULL;
     pDst->drawable = pSrc->drawable;
     pDst->drawable.id = 0;
     pDst->drawable.serialNumber = NEXT_SERIAL_NUMBER;
diff --git a/hw/xfree86/xf4bpp/ppcPntWin.c b/hw/xfree86/xf4bpp/ppcPntWin.c
index 5d7a07e..482b34b 100644
--- a/hw/xfree86/xf4bpp/ppcPntWin.c
+++ b/hw/xfree86/xf4bpp/ppcPntWin.c
@@ -100,7 +100,7 @@ xf4bppPaintWindow(pWin, pRegion, what)
 {
 
     register mfbPrivWin	*pPrivWin;
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbGetWindowPrivateIndex()].ptr);
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates, mfbGetWindowPrivateKey());
 
     TRACE(("xf4bppPaintWindow( pWin= 0x%x, pRegion= 0x%x, what= %d )\n",
 							pWin,pRegion,what));
diff --git a/hw/xfree86/xf4bpp/ppcPolyPnt.c b/hw/xfree86/xf4bpp/ppcPolyPnt.c
index 1d69055..c61fd6d 100644
--- a/hw/xfree86/xf4bpp/ppcPolyPnt.c
+++ b/hw/xfree86/xf4bpp/ppcPolyPnt.c
@@ -102,7 +102,7 @@ if ( pDrawable->type == DRAWABLE_PIXMAP ) {
 	return ;
 }
 
-devPriv = (ppcPrivGC *) ( pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
+devPriv = (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey());
 if ( ( alu = devPriv->colorRrop.alu ) == GXnoop )
 	return ;
 
diff --git a/hw/xfree86/xf4bpp/ppcWinFS.c b/hw/xfree86/xf4bpp/ppcWinFS.c
index e19ce0d..982bf42 100644
--- a/hw/xfree86/xf4bpp/ppcWinFS.c
+++ b/hw/xfree86/xf4bpp/ppcWinFS.c
@@ -96,7 +96,7 @@ xf4bppSolidWindowFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     n = nInit * miFindMaxBand( pGC->pCompositeClip ) ;
@@ -114,8 +114,8 @@ xf4bppSolidWindowFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
     n = miClipSpans( pGC->pCompositeClip, pptInit, pwidthInit, nInit,
 	ppt, pwidth, fSorted ) ;
 
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
-    fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.fgPixel ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
+    fg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.fgPixel ;
 
     for ( ; n-- ; ppt++, pwidth++ )
 	if ( *pwidth )
@@ -163,14 +163,14 @@ int fSorted ;
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     SETSPANPTRS( nInit, n, pwidthInit, pwidthFree, pptInit,
 		 pptFree, pwidth, ppt, fSorted ) ;
 
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
-    fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.fgPixel ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
+    fg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.fgPixel ;
 
     xSrc = pGC->patOrg.x + pDrawable->x ;
     ySrc = pGC->patOrg.y + pDrawable->y ;
@@ -215,15 +215,15 @@ int fSorted ;
 	return ;
     }
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     SETSPANPTRS( nInit, n, pwidthInit, pwidthFree, pptInit,
 		 pptFree, pwidth, ppt, fSorted ) ;
 
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
-    fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.fgPixel ;
-    bg = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.bgPixel ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
+    fg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.fgPixel ;
+    bg = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.bgPixel ;
 
     xSrc = pGC->patOrg.x + pDrawable->x ;
     ySrc = pGC->patOrg.y + pDrawable->y ;
@@ -260,7 +260,7 @@ int fSorted ;
     TRACE( ( "xf4bppTileWindowFS(pDrawable=0x%x,pGC=0x%x,nInit=%d,pptInit=0x%x,pwidthInit=0x%x,fSorted=%d)\n",
 	    pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted ) ) ;
 
-    if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.alu ) == GXnoop )
+    if ( ( alu = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.alu ) == GXnoop )
 	return ;
 
     SETSPANPTRS( nInit, n, pwidthInit, pwidthFree, pptInit,
@@ -268,7 +268,7 @@ int fSorted ;
 
     xSrc = pGC->patOrg.x + pDrawable->x ;
     ySrc = pGC->patOrg.y + pDrawable->y ;
-    pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGetGCPrivateIndex()].ptr )->colorRrop.planemask ;
+    pm = ( (ppcPrivGC *)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey()) )->colorRrop.planemask ;
 
     for ( ; n-- ; ppt++, pwidth++ )
 	    xf4bppTileRect( (WindowPtr)pDrawable, pGC->tile.pixmap, alu, pm,
diff --git a/hw/xfree86/xf4bpp/ppcWindow.c b/hw/xfree86/xf4bpp/ppcWindow.c
index 01768d9..0554667 100644
--- a/hw/xfree86/xf4bpp/ppcWindow.c
+++ b/hw/xfree86/xf4bpp/ppcWindow.c
@@ -218,7 +218,7 @@ register WindowPtr pWin ;
 
     TRACE(("xf4bppCreateWindowForXYhardware (pWin= 0x%x)\n", pWin));
 
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbGetWindowPrivateIndex()].ptr);
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates, mfbGetWindowPrivateKey());
     pPrivWin->pRotatedBorder = NullPixmap;
     pPrivWin->pRotatedBackground = NullPixmap;
     pPrivWin->fastBackground = 0;
diff --git a/hw/xfree86/xf4bpp/vgaGC.c b/hw/xfree86/xf4bpp/vgaGC.c
index 5a86040..6495e56 100644
--- a/hw/xfree86/xf4bpp/vgaGC.c
+++ b/hw/xfree86/xf4bpp/vgaGC.c
@@ -107,7 +107,7 @@ xf4bppChangeWindowGC( pGC, changes )
 register GC *pGC ;
 register Mask changes ;
 {
-register ppcPrivGCPtr devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGetGCPrivateIndex()].ptr) ;
+register ppcPrivGCPtr devPriv = (ppcPrivGCPtr)dixLookupPrivate(&pGC->devPrivates, mfbGetGCPrivateKey());
 register unsigned long int idx ; /* used for stepping through bitfields */
 
 #define LOWBIT( x ) ( x & - x ) /* Two's complement */
diff --git a/hw/xfree86/xf8_32bpp/cfb8_32.h b/hw/xfree86/xf8_32bpp/cfb8_32.h
index 31028a3..281e5f2 100644
--- a/hw/xfree86/xf8_32bpp/cfb8_32.h
+++ b/hw/xfree86/xf8_32bpp/cfb8_32.h
@@ -22,10 +22,8 @@ typedef struct {
 } cfb8_32ScreenRec, *cfb8_32ScreenPtr;
 
 
-extern int cfb8_32GCPrivateIndex;	/* XXX */
-extern int cfb8_32GetGCPrivateIndex(void);
-extern int cfb8_32ScreenPrivateIndex;	/* XXX */
-extern int cfb8_32GetScreenPrivateIndex(void);
+extern DevPrivateKey cfb8_32GetGCPrivateKey(void);
+extern DevPrivateKey cfb8_32GetScreenPrivateKey(void);
 
 RegionPtr
 cfb8_32CopyArea(
@@ -198,11 +196,11 @@ cfb8_32ChangeWindowAttributes(
 );
 
 
-#define CFB8_32_GET_GC_PRIVATE(pGC)\
-   (cfb8_32GCPtr)((pGC)->devPrivates[cfb8_32GetGCPrivateIndex()].ptr)
+#define CFB8_32_GET_GC_PRIVATE(pGC) ((cfb8_32GCPtr) \
+    dixLookupPrivate(&(pGC)->devPrivates, cfb8_32GetGCPrivateKey()))
 
-#define CFB8_32_GET_SCREEN_PRIVATE(pScreen)\
-   (cfb8_32ScreenPtr)((pScreen)->devPrivates[cfb8_32GetScreenPrivateIndex()].ptr)
+#define CFB8_32_GET_SCREEN_PRIVATE(pScreen) ((cfb8_32ScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, cfb8_32GetScreenPrivateKey()))
 
 Bool xf86Overlay8Plus32Init (ScreenPtr pScreen);
 
diff --git a/hw/xfree86/xf8_32bpp/cfbscrinit.c b/hw/xfree86/xf8_32bpp/cfbscrinit.c
index 29dc669..fffd8d3 100644
--- a/hw/xfree86/xf8_32bpp/cfbscrinit.c
+++ b/hw/xfree86/xf8_32bpp/cfbscrinit.c
@@ -31,42 +31,41 @@
 /* CAUTION:  We require that cfb8 and cfb32 were NOT 
 	compiled with CFB_NEED_SCREEN_PRIVATE */
 
-int cfb8_32GCPrivateIndex;
-int cfb8_32GetGCPrivateIndex(void) { return cfb8_32GCPrivateIndex; }
-int cfb8_32ScreenPrivateIndex;
-int cfb8_32GetScreenPrivateIndex(void) { return cfb8_32ScreenPrivateIndex; }
-static unsigned long cfb8_32Generation = 0;
+static DevPrivateKey cfb8_32GCPrivateKey = &cfb8_32GCPrivateKey;
+DevPrivateKey cfb8_32GetGCPrivateKey(void)
+{
+    return cfb8_32GCPrivateKey;
+}
+
+static DevPrivateKey cfb8_32ScreenPrivateKey = &cfb8_32ScreenPrivateKey;
+DevPrivateKey cfb8_32GetScreenPrivateKey(void)
+{
+    return cfb8_32ScreenPrivateKey;
+}
 
 static Bool
 cfb8_32AllocatePrivates(ScreenPtr pScreen)
 {
    cfb8_32ScreenPtr pScreenPriv;
 
-   if(cfb8_32Generation != serverGeneration) {
-	if(((cfb8_32GCPrivateIndex = AllocateGCPrivateIndex()) < 0) ||
-	    ((cfb8_32ScreenPrivateIndex = AllocateScreenPrivateIndex()) < 0))
-	    return FALSE;
-	cfb8_32Generation = serverGeneration;
-   }
-
    if (!(pScreenPriv = xalloc(sizeof(cfb8_32ScreenRec))))
         return FALSE;
 
-   pScreen->devPrivates[cfb8_32ScreenPrivateIndex].ptr = (pointer)pScreenPriv;
+   dixSetPrivate(&pScreen->devPrivates, cfb8_32ScreenPrivateKey, pScreenPriv);
    
    
    /* All cfb will have the same GC and Window private indicies */
-   if(!mfbAllocatePrivates(pScreen,&cfbWindowPrivateIndex, &cfbGCPrivateIndex))
+   if(!mfbAllocatePrivates(pScreen, &cfbWindowPrivateKey, &cfbGCPrivateKey))
 	return FALSE;
 
    /* The cfb indicies are the mfb indicies. Reallocating them resizes them */ 
-   if(!AllocateWindowPrivate(pScreen,cfbWindowPrivateIndex,sizeof(cfbPrivWin)))
+   if(!dixRequestPrivate(cfbWindowPrivateKey, sizeof(cfbPrivWin)))
 	return FALSE;
 
-   if(!AllocateGCPrivate(pScreen, cfbGCPrivateIndex, sizeof(cfbPrivGC)))
+   if(!dixRequestPrivate(cfbGCPrivateKey, sizeof(cfbPrivGC)))
         return FALSE;
 
-   if(!AllocateGCPrivate(pScreen, cfb8_32GCPrivateIndex, sizeof(cfb8_32GCRec)))
+   if(!dixRequestPrivate(cfb8_32GCPrivateKey, sizeof(cfb8_32GCRec)))
         return FALSE;
 
    return TRUE;
@@ -166,7 +165,7 @@ cfb8_32CloseScreen (int i, ScreenPtr pScreen)
 	xfree(pScreenPriv->visualData);
 
     xfree((pointer) pScreenPriv);
-    pScreen->devPrivates[cfb8_32ScreenPrivateIndex].ptr = NULL;
+    dixSetPrivate(&pScreen->devPrivates, cfb8_32ScreenPrivateKey, NULL);
 
     return(cfb32CloseScreen(i, pScreen));
 }
diff --git a/hw/xfree86/xf8_32bpp/xf86overlay.c b/hw/xfree86/xf8_32bpp/xf86overlay.c
index c5585ca..bab014b 100644
--- a/hw/xfree86/xf8_32bpp/xf86overlay.c
+++ b/hw/xfree86/xf8_32bpp/xf86overlay.c
@@ -180,23 +180,22 @@ typedef struct {
 } OverlayPixmapRec, *OverlayPixmapPtr;
 
 
-static int OverlayScreenIndex = -1;
-static int OverlayGCIndex = -1;
-static int OverlayPixmapIndex = -1;
-static unsigned long OverlayGeneration = 0;
+static DevPrivateKey OverlayScreenKey = &OverlayScreenKey;
+static DevPrivateKey OverlayGCKey = &OverlayGCKey;
+static DevPrivateKey OverlayPixmapKey = &OverlayPixmapKey;
 
 /** Macros **/
 
 #define TILE_EXISTS(pGC) (!(pGC)->tileIsPixel && (pGC)->tile.pixmap)
 
-#define OVERLAY_GET_PIXMAP_PRIVATE(pPix) \
-    (OverlayPixmapPtr)((pPix)->devPrivates[OverlayPixmapIndex].ptr)
+#define OVERLAY_GET_PIXMAP_PRIVATE(pPix) ((OverlayPixmapPtr) \
+    dixLookupPrivate(&(pPix)->devPrivates, OverlayPixmapKey))
 
-#define OVERLAY_GET_SCREEN_PRIVATE(pScreen) \
-    (OverlayScreenPtr)((pScreen)->devPrivates[OverlayScreenIndex].ptr)
+#define OVERLAY_GET_SCREEN_PRIVATE(pScreen) ((OverlayScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, OverlayScreenKey))
 
-#define OVERLAY_GET_GC_PRIVATE(pGC) \
-    (OverlayGCPtr)((pGC)->devPrivates[OverlayGCIndex].ptr)
+#define OVERLAY_GET_GC_PRIVATE(pGC) ((OverlayGCPtr) \
+    dixLookupPrivate(&(pGC)->devPrivates, OverlayGCKey))
 
 #define OVERLAY_GC_FUNC_PROLOGUE(pGC)\
     OverlayGCPtr pGCPriv = OVERLAY_GET_GC_PRIVATE(pGC);\
@@ -258,26 +257,16 @@ xf86Overlay8Plus32Init (ScreenPtr pScreen)
 {
     OverlayScreenPtr pScreenPriv;
 
-    if(OverlayGeneration != serverGeneration) {
-	if(((OverlayScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
-	   ((OverlayGCIndex = AllocateGCPrivateIndex()) < 0) ||
-	   ((OverlayPixmapIndex = AllocatePixmapPrivateIndex()) < 0))
-		return FALSE;
-
-	OverlayGeneration = serverGeneration;
-    }
-
-    if (!AllocateGCPrivate(pScreen, OverlayGCIndex, sizeof(OverlayGCRec)))
+    if (!dixRequestPrivate(OverlayGCKey, sizeof(OverlayGCRec)))
 	return FALSE;
 
-    if (!AllocatePixmapPrivate(pScreen, OverlayPixmapIndex, 
-						sizeof(OverlayPixmapRec)))
+    if (!dixRequestPrivate(OverlayPixmapKey, sizeof(OverlayPixmapRec)))
 	return FALSE;
 
     if (!(pScreenPriv = xalloc(sizeof(OverlayScreenRec))))
 	return FALSE;
 
-    pScreen->devPrivates[OverlayScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, OverlayScreenKey, pScreenPriv);
 
     pScreenPriv->CreateGC = pScreen->CreateGC;
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
diff --git a/hw/xgl/egl/xegl.c b/hw/xgl/egl/xegl.c
index c671dbe..1cf615b 100644
--- a/hw/xgl/egl/xegl.c
+++ b/hw/xgl/egl/xegl.c
@@ -42,14 +42,13 @@
 #define XEGL_DEFAULT_SCREEN_WIDTH  800
 #define XEGL_DEFAULT_SCREEN_HEIGHT 600
 
-int xeglScreenGeneration = -1;
-int xeglScreenPrivateIndex;
+DevPrivateKey xeglScreenPrivateKey = &xeglScreenPrivateKey;
 
-#define XEGL_GET_SCREEN_PRIV(pScreen)				         \
-    ((xeglScreenPtr) (pScreen)->devPrivates[xeglScreenPrivateIndex].ptr)
+#define XEGL_GET_SCREEN_PRIV(pScreen) ((xeglScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, xeglScreenPrivateKey))
 
-#define XEGL_SET_SCREEN_PRIV(pScreen, v)			       \
-    ((pScreen)->devPrivates[xeglScreenPrivateIndex].ptr = (pointer) v)
+#define XEGL_SET_SCREEN_PRIV(pScreen, v) \
+    dixSetPrivate(&(pScreen)->devPrivates, xeglScreenPrivateKey, v)
 
 #define XEGL_SCREEN_PRIV(pScreen)			       \
     xeglScreenPtr pScreenPriv = XEGL_GET_SCREEN_PRIV (pScreen)
@@ -66,15 +65,6 @@ xeglAllocatePrivates (ScreenPtr pScreen)
 {
     xeglScreenPtr pScreenPriv;
 
-    if (xeglScreenGeneration != serverGeneration)
-    {
-	xeglScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (xeglScreenPrivateIndex < 0)
-	    return FALSE;
-
-	xeglScreenGeneration = serverGeneration;
-    }
-
     pScreenPriv = xalloc (sizeof (xeglScreenRec));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/hw/xgl/egl/xegl.h b/hw/xgl/egl/xegl.h
index be9b48c..0a07397 100644
--- a/hw/xgl/egl/xegl.h
+++ b/hw/xgl/egl/xegl.h
@@ -109,7 +109,7 @@ extern KdMouseInfo     *kdMouseInfo;
 extern KdOsFuncs       *kdOsFuncs;
 extern Bool	       kdDontZap;
 extern Bool	       kdDisableZaphod;
-extern int	       xeglScreenPrivateIndex;
+extern DevPrivateKey   xeglScreenPrivateKey;
 extern KdMouseFuncs    LinuxEvdevMouseFuncs;
 extern KdKeyboardFuncs LinuxEvdevKeyboardFuncs;
 
@@ -117,8 +117,8 @@ extern KdKeyboardFuncs LinuxEvdevKeyboardFuncs;
     (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270)
 #define RR_Reflect_All (RR_Reflect_X | RR_Reflect_Y)
 
-#define KdGetScreenPriv(pScreen)					   \
-    ((xeglScreenPtr) ((pScreen)->devPrivates[xeglScreenPrivateIndex].ptr))
+#define KdGetScreenPriv(pScreen) ((xeglScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, xeglScreenPrivateKey))
 #define KdScreenPriv(pScreen)				  \
     xeglScreenPtr pScreenPriv = KdGetScreenPriv (pScreen)
 
diff --git a/hw/xgl/glx/xglx.c b/hw/xgl/glx/xglx.c
index 92974f0..657afc0 100644
--- a/hw/xgl/glx/xglx.c
+++ b/hw/xgl/glx/xglx.c
@@ -105,14 +105,13 @@ typedef struct _xglxScreen {
     CloseScreenProcPtr CloseScreen;
 } xglxScreenRec, *xglxScreenPtr;
 
-int xglxScreenGeneration = -1;
-int xglxScreenPrivateIndex;
+DevPrivateKey xglxScreenPrivateKey = &xglxScreenPrivateKey;
 
-#define XGLX_GET_SCREEN_PRIV(pScreen)				         \
-    ((xglxScreenPtr) (pScreen)->devPrivates[xglxScreenPrivateIndex].ptr)
+#define XGLX_GET_SCREEN_PRIV(pScreen) ((xglxScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, xglxScreenPrivateKey))
 
-#define XGLX_SET_SCREEN_PRIV(pScreen, v)			       \
-    ((pScreen)->devPrivates[xglxScreenPrivateIndex].ptr = (pointer) v)
+#define XGLX_SET_SCREEN_PRIV(pScreen, v) \
+    dixSetPrivate(&(pScreen)->devPrivates, xglxScreenPrivateKey, v)
 
 #define XGLX_SCREEN_PRIV(pScreen)			       \
     xglxScreenPtr pScreenPriv = XGLX_GET_SCREEN_PRIV (pScreen)
@@ -148,15 +147,6 @@ xglxAllocatePrivates (ScreenPtr pScreen)
 {
     xglxScreenPtr pScreenPriv;
 
-    if (xglxScreenGeneration != serverGeneration)
-    {
-	xglxScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (xglxScreenPrivateIndex < 0)
-	    return FALSE;
-
-	xglxScreenGeneration = serverGeneration;
-    }
-
     pScreenPriv = xalloc (sizeof (xglxScreenRec));
     if (!pScreenPriv)
 	return FALSE;
diff --git a/hw/xgl/xgl.h b/hw/xgl/xgl.h
index 5710bbf..ea28ea1 100644
--- a/hw/xgl/xgl.h
+++ b/hw/xgl/xgl.h
@@ -224,10 +224,11 @@ typedef struct _xglGlyph {
     xglAreaPtr pArea;
 } xglGlyphRec, *xglGlyphPtr;
 
-extern int xglGlyphPrivateIndex;
+extern DevPrivateKey xglGlyphPrivateKey;
 
 #define XGL_GET_GLYPH_PRIV(pScreen, pGlyph) ((xglGlyphPtr)		     \
-    (GetGlyphPrivatesForScreen (pGlyph, pScreen))[xglGlyphPrivateIndex].ptr)
+    dixLookupPrivate(GetGlyphPrivatesForScreen (pGlyph, pScreen),	     \
+    					        xglGlyphPrivateKey))
 
 #define XGL_GLYPH_PRIV(pScreen, pGlyph)				  \
     xglGlyphPtr pGlyphPriv = XGL_GET_GLYPH_PRIV (pScreen, pGlyph)
@@ -295,13 +296,13 @@ typedef struct _xglScreen {
 #endif
 } xglScreenRec, *xglScreenPtr;
 
-extern int xglScreenPrivateIndex;
+extern DevPrivateKey xglScreenPrivateKey;
 
-#define XGL_GET_SCREEN_PRIV(pScreen)				       \
-    ((xglScreenPtr) (pScreen)->devPrivates[xglScreenPrivateIndex].ptr)
+#define XGL_GET_SCREEN_PRIV(pScreen) ((xglScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, xglScreenPrivateKey))
 
-#define XGL_SET_SCREEN_PRIV(pScreen, v)				      \
-    ((pScreen)->devPrivates[xglScreenPrivateIndex].ptr = (pointer) v)
+#define XGL_SET_SCREEN_PRIV(pScreen, v) \
+    dixSetPrivate(&(pScreen)->devPrivates, xglScreenPrivateKey, v)
 
 #define XGL_SCREEN_PRIV(pScreen)			     \
     xglScreenPtr pScreenPriv = XGL_GET_SCREEN_PRIV (pScreen)
@@ -336,10 +337,10 @@ typedef struct _xglGC {
     GCOpsPtr	      ops;
 } xglGCRec, *xglGCPtr;
 
-extern int xglGCPrivateIndex;
+extern DevPrivateKey xglGCPrivateKey;
 
-#define XGL_GET_GC_PRIV(pGC)				   \
-    ((xglGCPtr) (pGC)->devPrivates[xglGCPrivateIndex].ptr)
+#define XGL_GET_GC_PRIV(pGC) ((xglGCPtr) \
+    dixLookupPrivate(&(pGC)->devPrivates, xglGCPrivateKey))
 
 #define XGL_GC_PRIV(pGC)		     \
     xglGCPtr pGCPriv = XGL_GET_GC_PRIV (pGC)
@@ -396,10 +397,10 @@ typedef struct _xglPixmap {
 
 } xglPixmapRec, *xglPixmapPtr;
 
-extern int xglPixmapPrivateIndex;
+extern DevPrivateKey xglPixmapPrivateKey;
 
-#define XGL_GET_PIXMAP_PRIV(pPixmap)				       \
-    ((xglPixmapPtr) (pPixmap)->devPrivates[xglPixmapPrivateIndex].ptr)
+#define XGL_GET_PIXMAP_PRIV(pPixmap) ((xglPixmapPtr) \
+    dixLookupPrivate(&(pPixmap)->devPrivates, xglPixmapPrivateKey))
 
 #define XGL_PIXMAP_PRIV(pPixmap)			     \
     xglPixmapPtr pPixmapPriv = XGL_GET_PIXMAP_PRIV (pPixmap)
@@ -411,10 +412,10 @@ typedef struct _xglWin {
     PixmapPtr    pPixmap;
 } xglWinRec, *xglWinPtr;
 
-extern int xglWinPrivateIndex;
+extern DevPrivateKey xglWinPrivateKey;
 
-#define XGL_GET_WINDOW_PRIV(pWin)			      \
-    ((xglWinPtr) (pWin)->devPrivates[xglWinPrivateIndex].ptr)
+#define XGL_GET_WINDOW_PRIV(pWin) ((xglWinPtr) \
+    dixLookupPrivate(&(pWin)->devPrivates, xglWinPrivateKey))
 
 #define XGL_WINDOW_PRIV(pWin)			    \
     xglWinPtr pWinPriv = XGL_GET_WINDOW_PRIV (pWin)
diff --git a/hw/xgl/xglpixmap.c b/hw/xgl/xglpixmap.c
index 166c33e..59ed00a 100644
--- a/hw/xgl/xglpixmap.c
+++ b/hw/xgl/xglpixmap.c
@@ -310,7 +310,7 @@ xglDestroyPixmap (PixmapPtr pPixmap)
 
     xglFiniPixmap (pPixmap);
 
-    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+    dixFreePrivates(pPixmap->devPrivates);
     xfree (pPixmap);
 
     return TRUE;
diff --git a/hw/xgl/xglxv.c b/hw/xgl/xglxv.c
index aaa66c7..bfa16e3 100644
--- a/hw/xgl/xglxv.c
+++ b/hw/xgl/xglxv.c
@@ -35,11 +35,11 @@
 #include <X11/extensions/Xv.h>
 #include <X11/extensions/Xvproto.h>
 
-static unsigned int  xglXvScreenIndex = 0;
+static DevPrivateKey xglXvScreenKey;
 static unsigned long portResource = 0;
 
-#define XGL_GET_XV_SCREEN(pScreen)				   \
-    ((XvScreenPtr) ((pScreen)->devPrivates[xglXvScreenIndex].ptr))
+#define XGL_GET_XV_SCREEN(pScreen) ((XvScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, xglXvScreenKey))
 
 #define XGL_XV_SCREEN(pScreen)				\
     XvScreenPtr pXvScreen = XGL_GET_XV_SCREEN (pScreen)
@@ -591,7 +591,7 @@ xglXvScreenInit (ScreenPtr pScreen)
     if (status != Success)
 	return FALSE;
 
-    xglXvScreenIndex = XvGetScreenIndex ();
+    xglXvScreenKey = XvGetScreenKey ();
     portResource = XvGetRTPort ();
 
     pXvScreen = XGL_GET_XV_SCREEN (pScreen);
diff --git a/hw/xnest/GC.c b/hw/xnest/GC.c
index a52ce1f..06e6e02 100644
--- a/hw/xnest/GC.c
+++ b/hw/xnest/GC.c
@@ -35,7 +35,7 @@ is" without express or implied warranty.
 #include "XNFont.h"
 #include "Color.h"
 
-int xnestGCPrivateIndex;
+DevPrivateKey xnestGCPrivateKey = &xnestGCPrivateKey;
 
 static GCFuncs xnestFuncs = {
   xnestValidateGC,
diff --git a/hw/xnest/Init.c b/hw/xnest/Init.c
index 5bf0300..324cf96 100644
--- a/hw/xnest/Init.c
+++ b/hw/xnest/Init.c
@@ -74,8 +74,6 @@ InitOutput(ScreenInfo *screenInfo, int argc, char *argv[])
 	break;
       }
   
-  xnestWindowPrivateIndex = AllocateWindowPrivateIndex();
-  xnestGCPrivateIndex = AllocateGCPrivateIndex();
   xnestFontPrivateIndex = AllocateFontPrivateIndex();
   
   if (!xnestNumScreens) xnestNumScreens = 1;
diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index c4b8aa6..c9c662a 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -33,7 +33,7 @@ is" without express or implied warranty.
 #include "Screen.h"
 #include "XNPixmap.h"
 
-int xnestPixmapPrivateIndex;	    
+DevPrivateKey xnestPixmapPrivateKey = &xnestPixmapPrivateKey;
 
 PixmapPtr
 xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth)
@@ -56,8 +56,8 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth)
   pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
   pPixmap->refcnt = 1;
   pPixmap->devKind = PixmapBytePad(width, depth);
-  pPixmap->devPrivates[xnestPixmapPrivateIndex].ptr =
-      (pointer)((char *)pPixmap + pScreen->totalPixmapSize);
+  dixSetPrivate(&pPixmap->devPrivates, xnestPixmapPrivateKey,
+		(char *)pPixmap + pScreen->totalPixmapSize);
   if (width && height)
       xnestPixmapPriv(pPixmap)->pixmap = 
 	  XCreatePixmap(xnestDisplay, 
@@ -75,7 +75,7 @@ xnestDestroyPixmap(PixmapPtr pPixmap)
   if(--pPixmap->refcnt)
     return TRUE;
   XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
-  dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+  dixFreePrivates(pPixmap->devPrivates);
   xfree(pPixmap);
   return TRUE;
 }
diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c
index d08e482..f914549 100644
--- a/hw/xnest/Screen.c
+++ b/hw/xnest/Screen.c
@@ -49,8 +49,6 @@ Window xnestScreenSaverWindows[MAXSCREENS];
 extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
 #endif
 
-static int xnestScreenGeneration = -1;
-
 ScreenPtr
 xnestScreen(Window window)
 {
@@ -146,21 +144,13 @@ xnestOpenScreen(int index, ScreenPtr pScreen, int argc, char *argv[])
   VisualID defaultVisual;
   int rootDepth;
 
-  if (!(AllocateWindowPrivate(pScreen, xnestWindowPrivateIndex,
-			    sizeof(xnestPrivWin))  &&
-	  AllocateGCPrivate(pScreen, xnestGCPrivateIndex, 
-			    sizeof(xnestPrivGC)))) 
+  if (!dixRequestPrivate(xnestWindowPrivateKey, sizeof(xnestPrivWin)))
+      return False;
+  if (!dixRequestPrivate(xnestGCPrivateKey, sizeof(xnestPrivGC)))
     return False;
-
-  if (xnestScreenGeneration != serverGeneration) {
-      if ((xnestPixmapPrivateIndex = AllocatePixmapPrivateIndex()) < 0)
-	  return False;
-      xnestScreenGeneration = serverGeneration;
-  }
-  
-  if (!AllocatePixmapPrivate(pScreen,xnestPixmapPrivateIndex,
-			     sizeof (xnestPrivPixmap)))
+  if (!dixRequestPrivate(xnestPixmapPrivateKey, sizeof (xnestPrivPixmap)))
       return False;
+
   visuals = (VisualPtr)xalloc(xnestNumVisuals * sizeof(VisualRec));
   numVisuals = 0;
 
diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c
index f87a1ba..0955e61 100644
--- a/hw/xnest/Window.c
+++ b/hw/xnest/Window.c
@@ -39,7 +39,7 @@ is" without express or implied warranty.
 #include "Events.h"
 #include "Args.h"
 
-int xnestWindowPrivateIndex;
+DevPrivateKey xnestWindowPrivateKey = &xnestWindowPrivateKey;
 
 static int
 xnestFindWindowMatch(WindowPtr pWin, pointer ptr)
diff --git a/hw/xnest/XNGC.h b/hw/xnest/XNGC.h
index d3ac3df..19535fe 100644
--- a/hw/xnest/XNGC.h
+++ b/hw/xnest/XNGC.h
@@ -22,10 +22,10 @@ typedef struct {
   int nClipRects;
 } xnestPrivGC;
 
-extern int xnestGCPrivateIndex;
+extern DevPrivateKey xnestGCPrivateKey;
 
-#define xnestGCPriv(pGC) \
-  ((xnestPrivGC *)((pGC)->devPrivates[xnestGCPrivateIndex].ptr))
+#define xnestGCPriv(pGC) ((xnestPrivGC *) \
+    dixLookupPrivate(&(pGC)->devPrivates, xnestGCPrivateKey))
 
 #define xnestGC(pGC) (xnestGCPriv(pGC)->gc)
 
diff --git a/hw/xnest/XNPixmap.h b/hw/xnest/XNPixmap.h
index 6971b11..3b08339 100644
--- a/hw/xnest/XNPixmap.h
+++ b/hw/xnest/XNPixmap.h
@@ -15,14 +15,14 @@ is" without express or implied warranty.
 #ifndef XNESTPIXMAP_H
 #define XNESTPIXMAP_H
 
-extern int xnestPixmapPrivateIndex;
+extern DevPrivateKey xnestPixmapPrivateKey;
 
 typedef struct {
   Pixmap pixmap;
 } xnestPrivPixmap;
 
-#define xnestPixmapPriv(pPixmap) \
-  ((xnestPrivPixmap *)((pPixmap)->devPrivates[xnestPixmapPrivateIndex].ptr))
+#define xnestPixmapPriv(pPixmap) ((xnestPrivPixmap *) \
+    dixLookupPrivate(&(pPixmap)->devPrivates, xnestPixmapPrivateKey))
 
 #define xnestPixmap(pPixmap) (xnestPixmapPriv(pPixmap)->pixmap)
 
diff --git a/hw/xnest/XNWindow.h b/hw/xnest/XNWindow.h
index 21be5f5..1aaf4e1 100644
--- a/hw/xnest/XNWindow.h
+++ b/hw/xnest/XNWindow.h
@@ -35,10 +35,10 @@ typedef struct {
   Window window;
 } xnestWindowMatch;
 
-extern int xnestWindowPrivateIndex;
+extern DevPrivateKey xnestWindowPrivateKey;
 
-#define xnestWindowPriv(pWin) \
-  ((xnestPrivWin *)((pWin)->devPrivates[xnestWindowPrivateIndex].ptr))
+#define xnestWindowPriv(pWin) ((xnestPrivWin *) \
+    dixLookupPrivate(&(pWin)->devPrivates, xnestWindowPrivateKey))
 
 #define xnestWindow(pWin) (xnestWindowPriv(pWin)->window)
 
diff --git a/hw/xprint/attributes.c b/hw/xprint/attributes.c
index d8ee5ad..9756e28 100644
--- a/hw/xprint/attributes.c
+++ b/hw/xprint/attributes.c
@@ -124,7 +124,7 @@ SysAttrs systemAttributes;
  * attrCtxtPrivIndex hold the attribute store's context private index.
  * This index is allocated at the time the attribute store is initialized.
  */
-static int attrCtxtPrivIndex;
+static DevPrivateKey attrCtxtPrivKey = &attrCtxtPrivKey;
 
 /*
  * The ContextAttrs structure descibes the context private space reserved
@@ -521,8 +521,7 @@ XpBuildAttributeStore(
     {
 	if(attrList != (PrAttrPtr)NULL)
 	    FreeAttrList();
-        attrCtxtPrivIndex = XpAllocateContextPrivateIndex();
-        XpAllocateContextPrivate(attrCtxtPrivIndex, sizeof(ContextAttrs));
+	dixRequestPrivate(attrCtxtPrivKey, sizeof(ContextAttrs));
 	BuildSystemAttributes();
 
 	attrGeneration = serverGeneration;
@@ -592,7 +591,8 @@ XpInitAttributes(XpContextPtr pContext)
     PrAttrPtr pPrAttr = attrList;
 
     /* Initialize all the pointers to NULL */
-    pCtxtAttrs = (ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
+    pCtxtAttrs = (ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						  attrCtxtPrivKey);
     (void)memset((void *)pCtxtAttrs, 0, (size_t) sizeof(ContextAttrs));
 
     for(pPrAttr = attrList; pPrAttr != (PrAttrPtr)NULL; pPrAttr = pPrAttr->next)
@@ -612,8 +612,8 @@ XpDestroyAttributes(
 {
     ContextAttrPtr pCtxtAttrs;
 
-    pCtxtAttrs = (ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
-
+    pCtxtAttrs = (ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						  attrCtxtPrivKey);
     if(pCtxtAttrs->printerAttrs != (XrmDatabase)NULL)
 	XrmDestroyDatabase(pCtxtAttrs->printerAttrs);
     if(pCtxtAttrs->docAttrs != (XrmDatabase)NULL)
@@ -661,7 +661,8 @@ XpGetOneAttribute(
     }
     else
     {
-        pCtxtAttrs=(ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
+        pCtxtAttrs=(ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						    attrCtxtPrivKey);
         switch(class)
         {
 	    case XPPrinterAttr:
@@ -714,7 +715,8 @@ XpPutOneAttribute(
     XrmBinding bindings[1];
     XrmQuark quarks[2];
     
-    pCtxtAttrs = (ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
+    pCtxtAttrs = (ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						  attrCtxtPrivKey);
     switch(class)
     {
     case XPPrinterAttr:
@@ -900,7 +902,8 @@ XpGetAttributes(
 	db = systemAttributes.server;
     else
     {
-        pCtxtAttrs=(ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
+        pCtxtAttrs=(ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						    attrCtxtPrivKey);
         switch(class)
         {
 	    case XPServerAttr:
@@ -952,7 +955,8 @@ XpAugmentAttributes(
     db = XrmGetStringDatabase(attributes);
     if(db == (XrmDatabase)NULL) return BadAlloc;
 
-    pCtxtAttrs = (ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
+    pCtxtAttrs = (ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						  attrCtxtPrivKey);
     switch(class)
     {
 	case XPPrinterAttr:
@@ -988,7 +992,8 @@ XpSetAttributes(
     db = XrmGetStringDatabase(attributes);
     if(db == (XrmDatabase)NULL) return BadAlloc;
 
-    pCtxtAttrs=(ContextAttrPtr)pContext->devPrivates[attrCtxtPrivIndex].ptr;
+    pCtxtAttrs=(ContextAttrPtr)dixLookupPrivate(&pContext->devPrivates,
+						attrCtxtPrivKey);
     switch(class)
     {
 	case XPPrinterAttr:
diff --git a/hw/xprint/pcl/Pcl.h b/hw/xprint/pcl/Pcl.h
index 217e304..216353b 100644
--- a/hw/xprint/pcl/Pcl.h
+++ b/hw/xprint/pcl/Pcl.h
@@ -83,10 +83,10 @@ typedef char *XPointer;
 /******
  * externally visible variables from PclInit.c
  ******/
-extern int PclScreenPrivateIndex, PclWindowPrivateIndex;
-extern int PclContextPrivateIndex;
-extern int PclPixmapPrivateIndex;
-extern int PclGCPrivateIndex;
+extern DevPrivateKey PclScreenPrivateKey, PclWindowPrivateKey;
+extern DevPrivateKey PclContextPrivateKey;
+extern DevPrivateKey PclPixmapPrivateKey;
+extern DevPrivateKey PclGCPrivateKey;
 
 /******
  * externally visible variables from PclAttVal.c
diff --git a/hw/xprint/pcl/PclArc.c b/hw/xprint/pcl/PclArc.c
index 0d8289e..20d3f72 100644
--- a/hw/xprint/pcl/PclArc.c
+++ b/hw/xprint/pcl/PclArc.c
@@ -85,7 +85,7 @@ PclDoArc(
 
     pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     XpGetReproductionArea( pCon, &repro );
     
     /* 
diff --git a/hw/xprint/pcl/PclColor.c b/hw/xprint/pcl/PclColor.c
index 8b05da0..5e8ffa6 100644
--- a/hw/xprint/pcl/PclColor.c
+++ b/hw/xprint/pcl/PclColor.c
@@ -129,8 +129,8 @@ PclCreateColormap(ColormapPtr pColor)
     PclCmapToContexts *new;
     PclScreenPrivPtr sPriv;
 
-    sPriv = (PclScreenPrivPtr)pColor->pScreen
-      ->devPrivates[PclScreenPrivateIndex].ptr;
+    sPriv = (PclScreenPrivPtr)
+	dixLookupPrivate(&pColor->pScreen->devPrivates, PclScreenPrivateKey);
 
 	/*
 	 * Use existing code to initialize the values in the colormap
@@ -175,8 +175,8 @@ PclDestroyColormap(ColormapPtr pColor)
     /*
      * Find the colormap <-> contexts mapping 
      */
-    sPriv = (PclScreenPrivPtr)pColor->pScreen
-      ->devPrivates[PclScreenPrivateIndex].ptr;
+    sPriv = (PclScreenPrivPtr)
+	dixLookupPrivate(&pColor->pScreen->devPrivates, PclScreenPrivateKey);
     pCmap = sPriv->colormaps;
     while( pCmap )
       {
@@ -195,8 +195,8 @@ PclDestroyColormap(ColormapPtr pColor)
 	  con = pCmap->contexts;
 	  while( con )
 	    {
-		cPriv = con->context->devPrivates[PclContextPrivateIndex].ptr;
-
+		cPriv = dixLookupPrivate(&con->context->devPrivates,
+					 PclContextPrivateKey);
 		pPal = cPriv->palettes;
 		while( pPal )
 		  {
@@ -259,8 +259,8 @@ PclStoreColors(ColormapPtr pColor,
     char t[80];
     int i;
 
-    sPriv = (PclScreenPrivPtr)pColor->pScreen
-      ->devPrivates[PclScreenPrivateIndex].ptr;
+    sPriv = (PclScreenPrivPtr)
+	dixLookupPrivate(&pColor->pScreen->devPrivates, PclScreenPrivateKey);
     p = sPriv->colormaps;
     while( p )
       {
@@ -278,8 +278,8 @@ PclStoreColors(ColormapPtr pColor,
 		 * For each context, get the palette ID and update the
 		 * appropriate palette.
 		 */
-		cPriv = con->context
-		  ->devPrivates[PclContextPrivateIndex].ptr;
+		cPriv = dixLookupPrivate(&con->context->devPrivates,
+					 PclContextPrivateKey);
 		pMap = PclFindPaletteMap( cPriv, pColor, NULL );
 
 		/*
@@ -407,7 +407,8 @@ PclUpdateColormap(DrawablePtr pDrawable,
     unsigned short r, g, b, rr, gg, bb;
     int i;
 
-    cPriv = pCon->devPrivates[PclContextPrivateIndex].ptr;
+    cPriv = (PclContextPrivPtr)
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     
     c = wColormap( win );
     cmap = (ColormapPtr)LookupIDByType( c, RT_COLORMAP );
@@ -436,8 +437,9 @@ PclUpdateColormap(DrawablePtr pDrawable,
 	  /*
 	   * Add the colormap to the screen-level colormap<->context mapping.
 	   */
-	  sPriv = (PclScreenPrivPtr)cmap->pScreen
-	    ->devPrivates[PclScreenPrivateIndex].ptr;
+	  sPriv = (PclScreenPrivPtr)
+	      dixLookupPrivate(&cmap->pScreen->devPrivates,
+			       PclScreenPrivateKey);
 	  pCmap = sPriv->colormaps;
 	  while( pCmap && ( pCmap->colormapId != cmap->mid ) )
 		pCmap = pCmap->next;
diff --git a/hw/xprint/pcl/PclGC.c b/hw/xprint/pcl/PclGC.c
index ba82c56..e64e779 100644
--- a/hw/xprint/pcl/PclGC.c
+++ b/hw/xprint/pcl/PclGC.c
@@ -144,7 +144,8 @@ PclGetDrawablePrivateStuff(
 	    return FALSE;
 	  else
 	    {
-		cPriv = pCon->devPrivates[PclContextPrivateIndex].ptr;
+		cPriv = (PclContextPrivPtr)
+		    dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 		*gc = cPriv->lastGC;
 		*valid = cPriv->validGC;
 		*file = cPriv->pPageFile;
@@ -171,7 +172,8 @@ PclSetDrawablePrivateGC(
       {
 	case DRAWABLE_PIXMAP:
 	  pix = (PixmapPtr)pDrawable;
-	  pixPriv = pix->devPrivates[PclPixmapPrivateIndex].ptr;
+	  pixPriv = (PclPixmapPrivPtr)
+	      dixLookupPrivate(&pix->devPrivates, PclPixmapPrivateKey);
 	  
 	  pixPriv->lastGC = gc;
 	  pixPriv->validGC = 1;
@@ -179,8 +181,8 @@ PclSetDrawablePrivateGC(
 
 	case DRAWABLE_WINDOW:
 	  pCon = PclGetContextFromWindow( (WindowPtr)pDrawable );
-	  pPriv = ((PclContextPrivPtr)
-		   (pCon->devPrivates[PclContextPrivateIndex].ptr));
+	  pPriv = (PclContextPrivPtr)
+	      dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 	  
 	  pPriv->validGC = 1;
 	  pPriv->lastGC = gc;
@@ -316,13 +318,14 @@ PclUpdateDrawableGC(
     XpContextPtr pCon;
     PclContextPrivPtr cPriv;
     PclGCPrivPtr gcPriv = (PclGCPrivPtr)
-      (pGC->devPrivates[PclGCPrivateIndex].ptr);
+	dixLookupPrivate(&pGC->devPrivates, PclGCPrivateKey);
     
     if( !PclGetDrawablePrivateStuff( pDrawable, &dGC, &valid, outFile ) )
       return FALSE;
 
     pCon = PclGetContextFromWindow( (WindowPtr)pDrawable );
-    cPriv = pCon->devPrivates[PclContextPrivateIndex].ptr;
+    cPriv = (PclContextPrivPtr)
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     /*
      * Here's where we update the colormap.  Since there can be
diff --git a/hw/xprint/pcl/PclInit.c b/hw/xprint/pcl/PclInit.c
index 1832252..478a342 100644
--- a/hw/xprint/pcl/PclInit.c
+++ b/hw/xprint/pcl/PclInit.c
@@ -67,11 +67,11 @@ static void AllocatePclPrivates(ScreenPtr pScreen);
 static int PclInitContext(XpContextPtr pCon);
 static Bool PclDestroyContext(XpContextPtr pCon);
 
-int PclScreenPrivateIndex;
-int PclContextPrivateIndex;
-int PclPixmapPrivateIndex;
-int PclWindowPrivateIndex;
-int PclGCPrivateIndex;
+DevPrivateKey PclScreenPrivateKey = &PclScreenPrivateKey;
+DevPrivateKey PclContextPrivateKey = &PclContextPrivateKey;
+DevPrivateKey PclPixmapPrivateKey = &PclPixmapPrivateKey;
+DevPrivateKey PclWindowPrivateKey = &PclWindowPrivateKey;
+DevPrivateKey PclGCPrivateKey = &PclGCPrivateKey;
 
 #ifdef XP_PCL_COLOR
 /*
@@ -119,7 +119,8 @@ Bool
 PclCloseScreen(int index,
 	       ScreenPtr pScreen)
 {
-    PclScreenPrivPtr pPriv = pScreen->devPrivates[PclScreenPrivateIndex].ptr;
+    PclScreenPrivPtr pPriv = (PclScreenPrivPtr)
+	dixLookupPrivate(&pScreen->devPrivates, PclScreenPrivateKey);
 
     pScreen->CloseScreen = pPriv->CloseScreen;
     xfree( pPriv );
@@ -157,8 +158,8 @@ InitializePclDriver(
      */
     AllocatePclPrivates(pScreen);
    
-    pPriv =
-      (PclScreenPrivPtr)pScreen->devPrivates[PclScreenPrivateIndex].ptr;
+    pPriv = (PclScreenPrivPtr)
+	dixLookupPrivate(&pScreen->devPrivates, PclScreenPrivateKey);
 
     maxDim = MAX( pScreen->height, pScreen->width );
     xRes = pScreen->width / ( pScreen->mmWidth / 25.4 );
@@ -260,33 +261,13 @@ InitializePclDriver(
 static void
 AllocatePclPrivates(ScreenPtr pScreen)
 {
-    static unsigned long PclGeneration = 0;
+    dixRequestPrivate(PclWindowPrivateKey, sizeof( PclWindowPrivRec ) );
+    dixRequestPrivate(PclContextPrivateKey, sizeof( PclContextPrivRec ) );
+    dixRequestPrivate(PclGCPrivateKey, sizeof( PclGCPrivRec ) );
+    dixRequestPrivate(PclPixmapPrivateKey, sizeof( PclPixmapPrivRec ) );
 
-    if((unsigned long) PclGeneration != serverGeneration)
-    {
-        PclScreenPrivateIndex = AllocateScreenPrivateIndex();
-
-	PclWindowPrivateIndex = AllocateWindowPrivateIndex();
-	AllocateWindowPrivate( pScreen, PclWindowPrivateIndex,
-			       sizeof( PclWindowPrivRec ) );
-
-	PclContextPrivateIndex = XpAllocateContextPrivateIndex();
-	XpAllocateContextPrivate( PclContextPrivateIndex, 
-				  sizeof( PclContextPrivRec ) );
-
-	PclGCPrivateIndex = AllocateGCPrivateIndex();
-	AllocateGCPrivate( pScreen, PclGCPrivateIndex, 
-			   sizeof( PclGCPrivRec ) );
-
-	PclPixmapPrivateIndex = AllocatePixmapPrivateIndex();
-	AllocatePixmapPrivate( pScreen, PclPixmapPrivateIndex, 
-			       sizeof( PclPixmapPrivRec ) );
-	
-        PclGeneration = serverGeneration;
-    }
-
-    pScreen->devPrivates[PclScreenPrivateIndex].ptr = (pointer)xalloc(
-                sizeof(PclScreenPrivRec));
+    dixSetPrivate(&pScreen->devPrivates, PclScreenPrivateKey,
+		  xalloc(sizeof(PclScreenPrivRec)));
 }
 
 /*
@@ -349,8 +330,8 @@ PclInitContext(XpContextPtr pCon)
     /*
      * Set up the context privates
      */
-    pConPriv =
-      (PclContextPrivPtr)pCon->devPrivates[PclContextPrivateIndex].ptr;
+    pConPriv = (PclContextPrivPtr)
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     
     pConPriv->jobFileName = (char *)NULL;
     pConPriv->pageFileName = (char *)NULL;
@@ -483,7 +464,7 @@ static Bool
 PclDestroyContext(XpContextPtr pCon)
 {
     PclContextPrivPtr pConPriv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     PclPaletteMapPtr p, t;
     PclCmapToContexts *pCmap;
     ScreenPtr screen;
@@ -541,7 +522,8 @@ PclDestroyContext(XpContextPtr pCon)
      * Remove the context from the screen-level colormap<->contexts mappings
      */
     screen = screenInfo.screens[pCon->screenNum];
-    sPriv = (PclScreenPrivPtr)screen->devPrivates[PclScreenPrivateIndex].ptr;
+    sPriv = (PclScreenPrivPtr)
+	dixLookupPrivate(&screen->devPrivates, PclScreenPrivateKey);
     pCmap = sPriv->colormaps;
     while( pCmap )
       {
@@ -583,8 +565,8 @@ PclGetContextFromWindow(WindowPtr win)
     
     while( win )
       {
-	  pPriv =
-	    (PclWindowPrivPtr)win->devPrivates[PclWindowPrivateIndex].ptr;
+	  pPriv = (PclWindowPrivPtr)
+	      dixLookupPrivate(&win->devPrivates, PclWindowPrivateKey);
 	  if( pPriv->validContext )
 	    return pPriv->context;
       
diff --git a/hw/xprint/pcl/PclLine.c b/hw/xprint/pcl/PclLine.c
index 52a586d..68d55a5 100644
--- a/hw/xprint/pcl/PclLine.c
+++ b/hw/xprint/pcl/PclLine.c
@@ -107,7 +107,7 @@ PclPolyLine(
 
     pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     /*
      * Allocate the storage required to deal with the clipping
@@ -223,7 +223,7 @@ PclPolySegment(
 
     pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     /*
      * Allocate the storage for the temporary regions.
diff --git a/hw/xprint/pcl/PclPixel.c b/hw/xprint/pcl/PclPixel.c
index f41af27..d219838 100644
--- a/hw/xprint/pcl/PclPixel.c
+++ b/hw/xprint/pcl/PclPixel.c
@@ -125,13 +125,15 @@ PclPolyPoint( pDrawable, pGC, mode, nPoints, pPoints )
     if( pDrawable->type == DRAWABLE_WINDOW )
       {
 	  pCon = PclGetContextFromWindow( (WindowPtr)pDrawable );
-	  cPriv = pCon->devPrivates[PclContextPrivateIndex].ptr;
+	  cPriv = (PclContextPrivPtr)
+	      dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 	  cPriv->changeMask = GCLineWidth | GCLineStyle;
       }
     else
       {
-	  pPriv =
-	    ((PixmapPtr)pDrawable)->devPrivates[PclPixmapPrivateIndex].ptr;
+	  pPriv = (PclPixmapPrivPtr)
+	      dixLookupPrivate(&((PixmapPtr)pDrawable)->devPrivates,
+			       PclPixmapPrivateKey);
 	  pPriv->changeMask = GCLineWidth | GCLineStyle;
       }
 #endif
diff --git a/hw/xprint/pcl/PclPolygon.c b/hw/xprint/pcl/PclPolygon.c
index 9867758..7d95d64 100644
--- a/hw/xprint/pcl/PclPolygon.c
+++ b/hw/xprint/pcl/PclPolygon.c
@@ -76,7 +76,7 @@ PclPolyRectangle(
 
     pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     /*
      * Allocate the storage required to deal with the clipping
@@ -170,7 +170,7 @@ PclFillPolygon(
 
     pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     /*
      * Generate the PCL code to draw the filled polygon, by defining
@@ -283,7 +283,7 @@ PclPolyFillRect(
 
     pCon = PclGetContextFromWindow( (WindowPtr) pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     /*
      * Allocate the storage required to deal with the clipping
diff --git a/hw/xprint/pcl/PclPrint.c b/hw/xprint/pcl/PclPrint.c
index 176a002..ac8ea15 100644
--- a/hw/xprint/pcl/PclPrint.c
+++ b/hw/xprint/pcl/PclPrint.c
@@ -72,8 +72,8 @@ PclStartJob(
      Bool sendClientData,
      ClientPtr client)
 {
-    PclContextPrivPtr pConPriv = 
-      (PclContextPrivPtr)pCon->devPrivates[PclContextPrivateIndex].ptr;
+    PclContextPrivPtr pConPriv = (PclContextPrivPtr)
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     PclPaletteMap *pal;
     
     /*
@@ -130,7 +130,7 @@ PclEndJob(
      Bool cancel)
 {
     PclContextPrivPtr priv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
 #ifdef CCP_DEBUG
     FILE *xpoutput;
@@ -250,9 +250,9 @@ PclStartPage(
      WindowPtr pWin)
 {
     PclContextPrivPtr pConPriv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
-    PclWindowPrivPtr pWinPriv =
-      (PclWindowPrivPtr)pWin->devPrivates[PclWindowPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
+    PclWindowPrivPtr pWinPriv = (PclWindowPrivPtr)
+	dixLookupPrivate(&pWin->devPrivates, PclWindowPrivateKey);
     xRectangle repro;
     char t[80];
     XpOid orient, plex, tray, medium;
@@ -488,7 +488,7 @@ PclEndPage(
      WindowPtr pWin)
 {
     PclContextPrivPtr pConPriv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
 
     struct stat statBuf;
 
@@ -532,7 +532,7 @@ PclStartDoc(XpContextPtr pCon,
 	    XPDocumentType type)
 {
     PclContextPrivPtr pConPriv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     
 #ifndef XP_PCL_LJ3
     /*
@@ -592,7 +592,7 @@ PclDocumentData(
 {
     int type = 0;
     PclContextPrivPtr pPriv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     XpOidDocFmtList *formats;
     XpOidDocFmt *f;
     char t[80];
@@ -700,7 +700,7 @@ PclGetDocumentData(
      int maxBufferSize)
 {
     PclContextPrivPtr pPriv = (PclContextPrivPtr)
-      pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     
     pPriv->getDocClient = client;
     pPriv->getDocBufSize = maxBufferSize;
diff --git a/hw/xprint/pcl/PclText.c b/hw/xprint/pcl/PclText.c
index 246c019..324de30 100644
--- a/hw/xprint/pcl/PclText.c
+++ b/hw/xprint/pcl/PclText.c
@@ -123,7 +123,7 @@ char font_type;
 
     pCon = PclGetContextFromWindow( (WindowPtr)pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     pSoftFontInfo = pConPriv->pSoftFontInfo;
     font_type = isInternal(pGC->font);
     if ( font_type == DOWNLOAD_FONT ) {
@@ -293,7 +293,7 @@ char font_type;
 
     pCon = PclGetContextFromWindow( (WindowPtr)pDrawable );
     pConPriv = (PclContextPrivPtr)
-			pCon->devPrivates[PclContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, PclContextPrivateKey);
     pSoftFontInfo = pConPriv->pSoftFontInfo;
 
     font_type = isInternal(pGC->font);
diff --git a/hw/xprint/pcl/PclWindow.c b/hw/xprint/pcl/PclWindow.c
index 80f4e91..997cfe4 100644
--- a/hw/xprint/pcl/PclWindow.c
+++ b/hw/xprint/pcl/PclWindow.c
@@ -97,9 +97,9 @@ PclCreateWindow(
     Bool status = Success;
     ScreenPtr pScreen = pWin->drawable.pScreen;
     PclScreenPrivPtr pScreenPriv = (PclScreenPrivPtr) 
-		     pScreen->devPrivates[PclScreenPrivateIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, PclScreenPrivateKey);
     PclWindowPrivPtr pWinPriv = (PclWindowPrivPtr)
-			 pWin->devPrivates[PclWindowPrivateIndex].ptr;
+	dixLookupPrivate(&pWin->devPrivates, PclWindowPrivateKey);
 
     /*
      * Initialize this window's private struct.
@@ -142,7 +142,8 @@ PclCreateWindow(
     /*
      * Invalidate the window's private print context.
      */
-    pPriv = (PclWindowPrivPtr)pWin->devPrivates[PclWindowPrivateIndex].ptr;
+    pPriv = (PclWindowPrivPtr)
+	dixLookupPrivate(&pWin->devPrivates, PclWindowPrivateKey);
     pPriv->validContext = 0;
     
     return TRUE;
diff --git a/hw/xprint/pcl/Pclmap.h b/hw/xprint/pcl/Pclmap.h
index ae88b5a..7972421 100644
--- a/hw/xprint/pcl/Pclmap.h
+++ b/hw/xprint/pcl/Pclmap.h
@@ -82,11 +82,11 @@ copyright holders.
 #define InitializePclDriver		CATNAME(Initialize, PclDriver)
 #define PclCloseScreen			PCLNAME(CloseScreen)
 #define PclGetContextFromWindow		PCLNAME(GetContextFromWindow)
-#define PclScreenPrivateIndex	PCLNAME(ScreenPrivateIndex)
-#define PclWindowPrivateIndex	PCLNAME(WindowPrivateIndex)
-#define PclContextPrivateIndex	PCLNAME(ContextPrivateIndex)
-#define PclPixmapPrivateIndex	PCLNAME(PixmapPrivateIndex)
-#define PclGCPrivateIndex	PCLNAME(GCPrivateIndex)
+#define PclScreenPrivateKey	PCLNAME(ScreenPrivateKey)
+#define PclWindowPrivateKey	PCLNAME(WindowPrivateKey)
+#define PclContextPrivateKey	PCLNAME(ContextPrivateKey)
+#define PclPixmapPrivateKey	PCLNAME(PixmapPrivateKey)
+#define PclGCPrivateKey		PCLNAME(GCPrivateKey)
 
 /* PclPrint.c */
 #define PclStartJob			PCLNAME(StartJob)
diff --git a/hw/xprint/ps/Ps.h b/hw/xprint/ps/Ps.h
index 3adad39..db1dd91 100644
--- a/hw/xprint/ps/Ps.h
+++ b/hw/xprint/ps/Ps.h
@@ -121,10 +121,10 @@ typedef char *XPointer;
  *  Public index variables from PsInit.c
  */
 
-extern int PsScreenPrivateIndex;
-extern int PsWindowPrivateIndex;
-extern int PsContextPrivateIndex;
-extern int PsPixmapPrivateIndex;
+extern DevPrivateKey PsScreenPrivateKey;
+extern DevPrivateKey PsWindowPrivateKey;
+extern DevPrivateKey PsContextPrivateKey;
+extern DevPrivateKey PsPixmapPrivateKey;
 extern XpValidatePoolsRec PsValidatePoolsRec;
 
 /*
diff --git a/hw/xprint/ps/PsGC.c b/hw/xprint/ps/PsGC.c
index 3ec07a7..19898c9 100644
--- a/hw/xprint/ps/PsGC.c
+++ b/hw/xprint/ps/PsGC.c
@@ -162,9 +162,11 @@ PsGetDrawablePrivateStuff(
         c = wColormap((WindowPtr)pDrawable);
         cmap = (ColormapPtr)LookupIDByType(c, RT_COLORMAP);
 
-        cPriv = pCon->devPrivates[PsContextPrivateIndex].ptr;
+        cPriv = (PsContextPrivPtr)
+	    dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
         sPriv = (PsScreenPrivPtr)
-                pDrawable->pScreen->devPrivates[PsScreenPrivateIndex].ptr;
+	    dixLookupPrivate(&pDrawable->pScreen->devPrivates,
+			     PsScreenPrivateKey);
         *gc     = cPriv->lastGC;
         *valid  = cPriv->validGC;
         *psOut  = cPriv->pPsOut;
@@ -189,7 +191,8 @@ PsGetPsContextPriv( DrawablePtr pDrawable )
       pCon = PsGetContextFromWindow((WindowPtr)pDrawable);
       if (pCon != NULL)
       {
-        return pCon->devPrivates[PsContextPrivateIndex].ptr;
+	  return (PsContextPrivPtr)
+	      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
       }
   }
   return NULL;
@@ -257,8 +260,9 @@ PsUpdateDrawableGC(
         PsOut_Offset(*psOut, pDrawable->x, pDrawable->y);
         PsOut_Clip(*psOut, pGC->clientClipType, (PsClipPtr)pGC->clientClip);
       }
-      cPriv = ( PsGetContextFromWindow( (WindowPtr)pDrawable ) )
-             ->devPrivates[PsContextPrivateIndex].ptr;
+      cPriv = (PsContextPrivPtr)dixLookupPrivate(
+	  &PsGetContextFromWindow((WindowPtr)pDrawable)->devPrivates,
+	  PsContextPrivateKey);
       break;
   }
   return TRUE;
diff --git a/hw/xprint/ps/PsInit.c b/hw/xprint/ps/PsInit.c
index 639908f..6c86fa2 100644
--- a/hw/xprint/ps/PsInit.c
+++ b/hw/xprint/ps/PsInit.c
@@ -97,10 +97,10 @@ static void AllocatePsPrivates(ScreenPtr pScreen);
 static int PsInitContext(XpContextPtr pCon);
 static int PsDestroyContext(XpContextPtr pCon);
 
-int PsScreenPrivateIndex;
-int PsContextPrivateIndex;
-int PsPixmapPrivateIndex;
-int PsWindowPrivateIndex;
+DevPrivateKey PsScreenPrivateKey = &PsScreenPrivateKey;
+DevPrivateKey PsContextPrivateKey = &PsContextPrivateKey;
+DevPrivateKey PsPixmapPrivateKey = &PsPixmapPrivateKey;
+DevPrivateKey PsWindowPrivateKey = &PsWindowPrivateKey;
 
 #ifdef GLXEXT
 extern void GlxWrapInitVisuals(miInitVisualsProcPtr *);
@@ -152,7 +152,8 @@ InitializePsDriver(ndx, pScreen, argc, argv)
   AllocatePsPrivates(pScreen);
 
 #if 0
-  pPriv = (PsScreenPrivPtr)pScreen->devPrivates[PsScreenPrivateIndex].ptr;
+  pPriv = (PsScreenPrivPtr)
+      dixLookupPrivate(&pScreen->devPrivates, PsScreenPrivateKey);
   pPriv->resDB = rmdb;
 #endif
 
@@ -476,28 +477,12 @@ InitializePsDriver(ndx, pScreen, argc, argv)
 static void
 AllocatePsPrivates(ScreenPtr pScreen)
 {
-  static unsigned long PsGeneration = 0;
+    dixRequestPrivate(PsWindowPrivateKey, sizeof(PsWindowPrivRec));
+    dixRequestPrivate(PsContextPrivateKey, sizeof(PsContextPrivRec));
+    dixRequestPrivate(PsPixmapPrivateKey, sizeof(PsPixmapPrivRec));
 
-  if((unsigned long)PsGeneration != serverGeneration)
-  {
-    PsScreenPrivateIndex = AllocateScreenPrivateIndex();
-
-    PsWindowPrivateIndex = AllocateWindowPrivateIndex();
-    AllocateWindowPrivate(pScreen, PsWindowPrivateIndex,
-                          sizeof(PsWindowPrivRec));
-
-    PsContextPrivateIndex = XpAllocateContextPrivateIndex();
-    XpAllocateContextPrivate(PsContextPrivateIndex, 
-                             sizeof(PsContextPrivRec));
-
-    PsPixmapPrivateIndex = AllocatePixmapPrivateIndex();
-    AllocatePixmapPrivate(pScreen, PsPixmapPrivateIndex,
-                          sizeof(PsPixmapPrivRec));
-
-    PsGeneration = serverGeneration;
-  }
-  pScreen->devPrivates[PsScreenPrivateIndex].ptr =
-           (pointer)xalloc(sizeof(PsScreenPrivRec));
+    dixSetPrivate(&pScreen->devPrivates, PsScreenPrivateKey,
+		  xalloc(sizeof(PsScreenPrivRec)));
 }
 
 /*
@@ -552,8 +537,8 @@ PsInitContext(pCon)
   /*
    * Set up the context privates
    */
-  pConPriv =
-      (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+  pConPriv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
 
   memset(pConPriv, 0, sizeof(PsContextPrivRec));
   pConPriv->jobFileName         = (char *)NULL;
@@ -622,8 +607,8 @@ static Bool
 PsDestroyContext(pCon)
   XpContextPtr pCon;
 {
-  PsContextPrivPtr pConPriv =
-      (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+  PsContextPrivPtr pConPriv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
     
   if( pConPriv->pJobFile!=(FILE *)NULL )
   {
@@ -655,7 +640,8 @@ PsGetContextFromWindow(win)
 
   while( win )
   {
-    pPriv = (PsWindowPrivPtr)win->devPrivates[PsWindowPrivateIndex].ptr;
+    pPriv = (PsWindowPrivPtr)
+	dixLookupPrivate(&win->devPrivates, PsWindowPrivateKey);
     if( pPriv->validContext ) return pPriv->context;
     win = win->parent;
   }
diff --git a/hw/xprint/ps/PsPixmap.c b/hw/xprint/ps/PsPixmap.c
index 220feab..1fa4e40 100644
--- a/hw/xprint/ps/PsPixmap.c
+++ b/hw/xprint/ps/PsPixmap.c
@@ -111,14 +111,11 @@ PsCreatePixmap(
   pPixmap->drawable.height       = height;
   pPixmap->devKind               = 0;
   pPixmap->refcnt                = 1;
-
-  pPixmap->devPrivates = (DevUnion *)xcalloc(1, sizeof(DevUnion));
-  if( !pPixmap->devPrivates )
-    { xfree(pPixmap); return NullPixmap; }
+  pPixmap->devPrivates		 = NULL;
 
   pPixmap->devPrivate.ptr = (PsPixmapPrivPtr)xcalloc(1, sizeof(PsPixmapPrivRec));
   if( !pPixmap->devPrivate.ptr )
-    { xfree(pPixmap->devPrivates); xfree(pPixmap); return NullPixmap; }
+    { xfree(pPixmap); return NullPixmap; }
   return pPixmap;
 }
 
@@ -201,7 +198,7 @@ PsDestroyPixmap(PixmapPtr pPixmap)
   PsScrubPixmap(pPixmap);
 
   xfree(priv);
-  dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+  dixFreePrivates(pPixmap->devPrivates);
   xfree(pPixmap);
   return TRUE;
 }
diff --git a/hw/xprint/ps/PsPrint.c b/hw/xprint/ps/PsPrint.c
index 4571c07..3866468 100644
--- a/hw/xprint/ps/PsPrint.c
+++ b/hw/xprint/ps/PsPrint.c
@@ -165,8 +165,8 @@ PsStartJob(
   Bool         sendClientData,
   ClientPtr    client)
 {
-  PsContextPrivPtr  pConPriv = 
-      (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+  PsContextPrivPtr  pConPriv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
 
   /* 
    * Create a temporary file to store the printer output.
@@ -191,8 +191,8 @@ PsEndJob(
   struct stat buffer;
   int error;
 
-  PsContextPrivPtr priv =
-    (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+  PsContextPrivPtr priv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
 
   if (cancel == True) {
     if (priv->getDocClient != (ClientPtr) NULL) {
@@ -291,10 +291,10 @@ PsStartPage(
 {
   int                iorient, iplex, icount, ires;
   unsigned short     iwd, iht;
-  PsContextPrivPtr   pConPriv =
-     (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
-  PsWindowPrivPtr    pWinPriv =
-     (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
+  PsContextPrivPtr   pConPriv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
+  PsWindowPrivPtr    pWinPriv = (PsWindowPrivPtr)
+      dixLookupPrivate(&pWin->devPrivates, PsWindowPrivateKey);
 
 /*
  * Put a pointer to the context in the window private structure
@@ -337,10 +337,10 @@ PsEndPage(
   XpContextPtr pCon,
   WindowPtr    pWin)
 {
-  PsWindowPrivPtr    pWinPriv =
-     (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
-  PsContextPrivPtr pConPriv =
-    (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+  PsWindowPrivPtr    pWinPriv = (PsWindowPrivPtr)
+      dixLookupPrivate(&pWin->devPrivates, PsWindowPrivateKey);
+  PsContextPrivPtr pConPriv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
 
   PsOut_EndPage(pConPriv->pPsOut);
 
@@ -366,8 +366,8 @@ PsStartDoc(XpContextPtr pCon, XPDocumentType type)
   int                iorient, iplex, icount, ires;
   unsigned short     iwd, iht;
   char              *title;
-  PsContextPrivPtr   pConPriv = 
-      (PsContextPrivPtr)pCon->devPrivates[PsContextPrivateIndex].ptr;
+  PsContextPrivPtr   pConPriv = (PsContextPrivPtr)
+      dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
 
   /* get job level attributes */ 
   title = XpGetOneAttribute(pCon, XPJobAttr, "job-name");
@@ -420,7 +420,8 @@ PsDocumentData(
         len_opt)
 	return BadValue;
 
-    cPriv = pCon->devPrivates[PsContextPrivateIndex].ptr;
+    cPriv = (PsContextPrivPtr)
+	dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
     psOut = cPriv->pPsOut;
 
     if (pDraw)
@@ -448,7 +449,7 @@ PsGetDocumentData(
   int          maxBufferSize)
 {
   PsContextPrivPtr pPriv = (PsContextPrivPtr)
-    pCon->devPrivates[PsContextPrivateIndex].ptr;
+    dixLookupPrivate(&pCon->devPrivates, PsContextPrivateKey);
 
   pPriv->getDocClient = client;
   pPriv->getDocBufSize = maxBufferSize;
diff --git a/hw/xprint/ps/PsWindow.c b/hw/xprint/ps/PsWindow.c
index 26075a8..d107e5c 100644
--- a/hw/xprint/ps/PsWindow.c
+++ b/hw/xprint/ps/PsWindow.c
@@ -123,9 +123,9 @@ PsCreateWindow(WindowPtr pWin)
     Bool status = Success;
     ScreenPtr pScreen = pWin->drawable.pScreen;
     PsScreenPrivPtr pScreenPriv = (PsScreenPrivPtr) 
-		     pScreen->devPrivates[PsScreenPrivateIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, PsScreenPrivateKey);
     PsWindowPrivPtr pWinPriv = (PsWindowPrivPtr)
-			 pWin->devPrivates[PsWindowPrivateIndex].ptr;
+	dixLookupPrivate(&pWin->devPrivates, PsWindowPrivateKey);
 
     /*
      * Initialize this window's private struct.
@@ -165,7 +165,8 @@ PsCreateWindow(WindowPtr pWin)
     return status;
 #endif
 
-  pPriv = (PsWindowPrivPtr)pWin->devPrivates[PsWindowPrivateIndex].ptr;
+  pPriv = (PsWindowPrivPtr)
+      dixLookupPrivate(&pWin->devPrivates, PsWindowPrivateKey);
   pPriv->validContext = 0;
 
   return TRUE;
diff --git a/hw/xprint/raster/Raster.c b/hw/xprint/raster/Raster.c
index 0286a18..dccef61 100644
--- a/hw/xprint/raster/Raster.c
+++ b/hw/xprint/raster/Raster.c
@@ -151,8 +151,8 @@ static int RasterReproducibleArea(XpContextPtr pCon,
 #define DOC_PCL		1
 #define DOC_RASTER	2
 
-static int RasterScreenPrivateIndex, RasterContextPrivateIndex;
-static int RasterGeneration = 0;
+static DevPrivateKey RasterScreenPrivateKey = &RasterScreenPrivateKey;
+static DevPrivateKey RasterContextPrivateKey = &RasterContextPrivateKey;
 static char RASTER_DRIV_NAME[] = "XP-RASTER";
 static int doc_type = DOC_RASTER;
 
@@ -205,7 +205,7 @@ InitializeRasterDriver(
     AllocateRasterPrivates(pScreen);
    
     pPriv = (RasterScreenPrivPtr)
-      pScreen->devPrivates[RasterScreenPrivateIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, RasterScreenPrivateKey);
 
     maxDim = MAX( pScreen->height, pScreen->width );
     numBytes = maxDim + BITMAP_SCANLINE_PAD - 1; /* pixels per row */
@@ -252,7 +252,7 @@ GetPropString(
      char *propName)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-      pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
     char *type;
     XrmValue val;
     struct stat status;
@@ -371,7 +371,7 @@ StartJob(
      ClientPtr client)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
 
     SetDocumentType( pCon );
 
@@ -488,7 +488,7 @@ EndJob(
      Bool cancel)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
 
     if( cancel == True )
     {
@@ -549,7 +549,7 @@ StartPage(
      WindowPtr pWin)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
 
     if(pConPriv->pPageFile != (FILE *)NULL)
     {
@@ -830,7 +830,7 @@ SendPage( XpContextPtr pCon )
 {
     struct stat statBuf;
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
 
     if(stat(pConPriv->pageFileName, &statBuf) < 0)
         return BadAlloc;
@@ -872,7 +872,7 @@ EndPage(
      WindowPtr pWin)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
     struct stat statBuf;
     char *rasterFileName = (char *)NULL, *pCommand = (char *)NULL;
     FILE *pRasterFile = (FILE *)NULL;
@@ -1068,7 +1068,7 @@ DocumentData(
      ClientPtr client)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
     char *preRasterStr = PRE_RASTER, *postRasterStr = POST_RASTER,
 	 *noRasterStr = NO_RASTER;
 
@@ -1135,7 +1135,7 @@ GetDocumentData(
     int maxBufferSize)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-			 pContext->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pContext->devPrivates, RasterContextPrivateKey);
 
     pConPriv->getDocClient = client;
     pConPriv->getDocBufSize = maxBufferSize;
@@ -1146,17 +1146,9 @@ static void
 AllocateRasterPrivates(
     ScreenPtr pScreen)
 {
-    if(RasterGeneration != serverGeneration)
-    {
-        RasterScreenPrivateIndex = AllocateScreenPrivateIndex();
-	RasterContextPrivateIndex = XpAllocateContextPrivateIndex();
-        XpAllocateContextPrivate( RasterContextPrivateIndex, 
-			     sizeof( RasterContextPrivRec ) );
-
-        RasterGeneration = serverGeneration;
-    }
-    pScreen->devPrivates[RasterScreenPrivateIndex].ptr = (pointer)Xalloc(
-                sizeof(RasterScreenPrivRec));
+    dixRequestPrivate(RasterContextPrivateKey, sizeof( RasterContextPrivRec ) );
+    dixSetPrivate(&pScreen->devPrivates, RasterScreenPrivateKey,
+		  Xalloc(sizeof(RasterScreenPrivRec)));
 }
 
 /*
@@ -1171,7 +1163,7 @@ RasterChangeWindowAttributes(
     Bool status = Success;
     ScreenPtr pScreen = pWin->drawable.pScreen;
     RasterScreenPrivPtr pScreenPriv = (RasterScreenPrivPtr) 
-		     pScreen->devPrivates[RasterScreenPrivateIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, RasterScreenPrivateKey);
 
     if(pWin->backingStore == NotUseful)
     {
@@ -1270,7 +1262,7 @@ RasterInitContext(
      * Set up the context privates
      */
     pConPriv = (RasterContextPrivPtr)
-      pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
     
     pConPriv->jobFileName = (char *)NULL;
     pConPriv->pageFileName = (char *)NULL;
@@ -1355,7 +1347,7 @@ RasterDestroyContext(
      XpContextPtr pCon)
 {
     RasterContextPrivPtr pConPriv = (RasterContextPrivPtr)
-      pCon->devPrivates[RasterContextPrivateIndex].ptr;
+	dixLookupPrivate(&pCon->devPrivates, RasterContextPrivateKey);
     
     /*
      * Clean up the temporary files
@@ -1477,7 +1469,7 @@ RasterCloseScreen(
 {
     Bool status = Success;
     RasterScreenPrivPtr pScreenPriv = (RasterScreenPrivPtr) 
-		     pScreen->devPrivates[RasterScreenPrivateIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, RasterScreenPrivateKey);
     
     /*
      * Call any wrapped CloseScreen proc.
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 09a9fb2..fad5e2b 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -631,11 +631,11 @@ extern DWORD			g_dwEvents;
 #ifdef HAS_DEVWINDOWS
 extern int			g_fdMessageQueue;
 #endif
-extern int			g_iScreenPrivateIndex;
-extern int			g_iCmapPrivateIndex;
-extern int			g_iGCPrivateIndex;
-extern int			g_iPixmapPrivateIndex;
-extern int			g_iWindowPrivateIndex;
+extern DevPrivateKey		g_iScreenPrivateKey;
+extern DevPrivateKey		g_iCmapPrivateKey;
+extern DevPrivateKey		g_iGCPrivateKey;
+extern DevPrivateKey		g_iPixmapPrivateKey;
+extern DevPrivateKey		g_iWindowPrivateKey;
 extern unsigned long		g_ulServerGeneration;
 extern CARD32			g_c32LastInputEventTime;
 extern DWORD			g_dwEnginesSupported;
@@ -661,11 +661,11 @@ extern FARPROC			g_fpTrackMouseEvent;
  * Screen privates macros
  */
 
-#define winGetScreenPriv(pScreen) \
-	((winPrivScreenPtr) (pScreen)->devPrivates[g_iScreenPrivateIndex].ptr)
+#define winGetScreenPriv(pScreen) ((winPrivScreenPtr) \
+    dixLookupPrivate(&(pScreen)->devPrivates, g_iScreenPrivateKey))
 
 #define winSetScreenPriv(pScreen,v) \
-	((pScreen)->devPrivates[g_iScreenPrivateIndex].ptr = (pointer) v)
+    dixSetPrivate(&(pScreen)->devPrivates, g_iScreenPrivateKey, v)
 
 #define winScreenPriv(pScreen) \
 	winPrivScreenPtr pScreenPriv = winGetScreenPriv(pScreen)
@@ -675,11 +675,11 @@ extern FARPROC			g_fpTrackMouseEvent;
  * Colormap privates macros
  */
 
-#define winGetCmapPriv(pCmap) \
-	((winPrivCmapPtr) (pCmap)->devPrivates[g_iCmapPrivateIndex].ptr)
+#define winGetCmapPriv(pCmap) ((winPrivCmapPtr) \
+    dixLookupPrivate(&(pCmap)->devPrivates, g_iCmapPrivateKey))
 
 #define winSetCmapPriv(pCmap,v) \
-	((pCmap)->devPrivates[g_iCmapPrivateIndex].ptr = (pointer) v)
+    dixSetPrivate(&(pCmap)->devPrivates, g_iCmapPrivateKey, v)
 
 #define winCmapPriv(pCmap) \
 	winPrivCmapPtr pCmapPriv = winGetCmapPriv(pCmap)
@@ -689,11 +689,11 @@ extern FARPROC			g_fpTrackMouseEvent;
  * GC privates macros
  */
 
-#define winGetGCPriv(pGC) \
-	((winPrivGCPtr) (pGC)->devPrivates[g_iGCPrivateIndex].ptr)
+#define winGetGCPriv(pGC) ((winPrivGCPtr) \
+    dixLookupPrivate(&(pGC)->devPrivates, g_iGCPrivateKey))
 
 #define winSetGCPriv(pGC,v) \
-	((pGC)->devPrivates[g_iGCPrivateIndex].ptr = (pointer) v)
+    dixSetPrivate(&(pGC)->devPrivates, g_iGCPrivateKey, v)
 
 #define winGCPriv(pGC) \
 	winPrivGCPtr pGCPriv = winGetGCPriv(pGC)
@@ -703,11 +703,11 @@ extern FARPROC			g_fpTrackMouseEvent;
  * Pixmap privates macros
  */
 
-#define winGetPixmapPriv(pPixmap) \
-	((winPrivPixmapPtr) (pPixmap)->devPrivates[g_iPixmapPrivateIndex].ptr)
+#define winGetPixmapPriv(pPixmap) ((winPrivPixmapPtr) \
+    dixLookupPrivate(&(pPixmap)->devPrivates, g_iPixmapPrivateKey))
 
 #define winSetPixmapPriv(pPixmap,v) \
-	((pPixmap)->devPrivates[g_iPixmapPrivateIndex].ptr = (pointer) v)
+    dixLookupPrivate(&(pPixmap)->devPrivates, g_iPixmapPrivateKey, v)
 
 #define winPixmapPriv(pPixmap) \
 	winPrivPixmapPtr pPixmapPriv = winGetPixmapPriv(pPixmap)
@@ -717,11 +717,11 @@ extern FARPROC			g_fpTrackMouseEvent;
  * Window privates macros
  */
 
-#define winGetWindowPriv(pWin) \
-	((winPrivWinPtr) (pWin)->devPrivates[g_iWindowPrivateIndex].ptr)
+#define winGetWindowPriv(pWin) ((winPrivWinPtr) \
+    dixLookupPrivate(&(pWin)->devPrivates, g_iWindowPrivateKey))
 
 #define winSetWindowPriv(pWin,v) \
-	((pWin)->devPrivates[g_iWindowPrivateIndex].ptr = (pointer) v)
+    dixLookupPrivate(&(pWin)->devPrivates, g_iWindowPrivateKey, v)
 
 #define winWindowPriv(pWin) \
 	winPrivWinPtr pWinPriv = winGetWindowPriv(pWin)
diff --git a/hw/xwin/winallpriv.c b/hw/xwin/winallpriv.c
index f4decfb..21ccd9b 100644
--- a/hw/xwin/winallpriv.c
+++ b/hw/xwin/winallpriv.c
@@ -57,12 +57,6 @@ winAllocatePrivates (ScreenPtr pScreen)
   /* We need a new slot for our privates if the screen gen has changed */
   if (g_ulServerGeneration != serverGeneration)
     {
-      /* Get an index that we can store our privates at */
-      g_iScreenPrivateIndex = AllocateScreenPrivateIndex ();
-      g_iGCPrivateIndex = AllocateGCPrivateIndex ();
-      g_iPixmapPrivateIndex = AllocatePixmapPrivateIndex ();
-      g_iWindowPrivateIndex = AllocateWindowPrivateIndex ();
-
       g_ulServerGeneration = serverGeneration;
     }
 
@@ -84,24 +78,21 @@ winAllocatePrivates (ScreenPtr pScreen)
   winSetScreenPriv (pScreen, pScreenPriv);
 
   /* Reserve GC memory for our privates */
-  if (!AllocateGCPrivate (pScreen, g_iGCPrivateIndex,
-			  sizeof (winPrivGCRec)))
+  if (!dixRequestPrivate(g_iGCPrivateKey, sizeof (winPrivGCRec)))
     {
       ErrorF ("winAllocatePrivates - AllocateGCPrivate () failed\n");
       return FALSE;
     }
 
   /* Reserve Pixmap memory for our privates */
-  if (!AllocatePixmapPrivate (pScreen, g_iPixmapPrivateIndex,
-			      sizeof (winPrivPixmapRec)))
+  if (!dixRequestPrivate(g_iPixmapPrivateKey, sizeof (winPrivPixmapRec)))
     {
       ErrorF ("winAllocatePrivates - AllocatePixmapPrivates () failed\n");
       return FALSE;
     }
 
   /* Reserve Window memory for our privates */
-  if (!AllocateWindowPrivate (pScreen, g_iWindowPrivateIndex,
-			      sizeof (winPrivWinRec)))
+  if (!dixRequestPrivate(g_iWindowPrivateKey, sizeof (winPrivWinRec)))
     {
       ErrorF ("winAllocatePrivates () - AllocateWindowPrivates () failed\n");
        return FALSE;
@@ -155,9 +146,6 @@ winAllocateCmapPrivates (ColormapPtr pCmap)
   /* Get a new privates index when the server generation changes */
   if (s_ulPrivateGeneration != serverGeneration)
     {
-      /* Get an index that we can store our privates at */
-      g_iCmapPrivateIndex = AllocateColormapPrivateIndex (winInitCmapPrivates);
-      
       /* Save the new server generation */
       s_ulPrivateGeneration = serverGeneration;
     }
diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c
index c1e619b..021b8b8 100644
--- a/hw/xwin/wincursor.c
+++ b/hw/xwin/wincursor.c
@@ -598,7 +598,8 @@ winInitCursor (ScreenPtr pScreen)
   pScreenPriv->cursor.QueryBestSize = pScreen->QueryBestSize;
   pScreen->QueryBestSize = winCursorQueryBestSize;
   
-  pPointPriv = (miPointerScreenPtr) pScreen->devPrivates[miPointerScreenIndex].ptr;
+  pPointPriv = (miPointerScreenPtr)
+      dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey);
   
   pScreenPriv->cursor.spriteFuncs = pPointPriv->spriteFuncs;
   pPointPriv->spriteFuncs = &winSpriteFuncsRec;
diff --git a/hw/xwin/winfillsp.c b/hw/xwin/winfillsp.c
index 7e39669..702f34f 100644
--- a/hw/xwin/winfillsp.c
+++ b/hw/xwin/winfillsp.c
@@ -35,15 +35,6 @@
 #include "win.h"
 
 
-/*
- * References to external symbols
- */
-
-extern int			g_iPixmapPrivateIndex;
-extern int			g_iGCPrivateIndex;
-extern int                      g_copyROP[];
-
-
 extern void ROP16(HDC hdc, int rop);
 
 #define TRANSLATE_COLOR(color)						\
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index af8190d..fddada3 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -44,11 +44,11 @@ int		g_iLastScreen = -1;
 #ifdef HAS_DEVWINDOWS
 int		g_fdMessageQueue = WIN_FD_INVALID;
 #endif
-int		g_iScreenPrivateIndex = -1;
-int		g_iCmapPrivateIndex = -1;
-int		g_iGCPrivateIndex = -1;
-int		g_iPixmapPrivateIndex = -1;
-int		g_iWindowPrivateIndex = -1;
+DevPrivateKey	g_iScreenPrivateKey = &g_iScreenPrivateKey;
+DevPrivateKey	g_iCmapPrivateKey = &g_iCmapPrivateKey;
+DevPrivateKey	g_iGCPrivateKey = &g_iGCPrivateKey;
+DevPrivateKey	g_iPixmapPrivateKey = &g_iPixmapPrivateKey;
+DevPrivateKey	g_iWindowPrivateKey = &g_iWindowPrivateKey;
 unsigned long	g_ulServerGeneration = 0;
 Bool		g_fInitializedDefaultScreens = FALSE;
 DWORD		g_dwEnginesSupported = 0;
diff --git a/hw/xwin/winmultiwindowwndproc.c b/hw/xwin/winmultiwindowwndproc.c
index 0a7579b..20ff9f7 100644
--- a/hw/xwin/winmultiwindowwndproc.c
+++ b/hw/xwin/winmultiwindowwndproc.c
@@ -365,7 +365,7 @@ winTopLevelWindowProc (HWND hwnd, UINT message,
       ErrorF ("\thenght %08X\n", pWin->drawable.height);
       ErrorF ("\tpScreen %08X\n", pWin->drawable.pScreen);
       ErrorF ("\tserialNumber %08X\n", pWin->drawable.serialNumber);
-      ErrorF ("g_iWindowPrivateIndex %d\n", g_iWindowPrivateIndex);
+      ErrorF ("g_iWindowPrivateKey %p\n", g_iWindowPrivateKey);
       ErrorF ("pWinPriv %08X\n", pWinPriv);
       ErrorF ("s_pScreenPriv %08X\n", s_pScreenPriv);
       ErrorF ("s_pScreenInfo %08X\n", s_pScreenInfo);
diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c
index baff60c..ffe7207 100644
--- a/hw/xwin/winpixmap.c
+++ b/hw/xwin/winpixmap.c
@@ -36,13 +36,6 @@
 
 
 /*
- * References to external symbols
- */
-
-extern int			g_iPixmapPrivateIndex;
-
-
-/*
  * Local prototypes
  */
 
diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c
index 52adba8..2038e6f 100644
--- a/hw/xwin/winscrinit.c
+++ b/hw/xwin/winscrinit.c
@@ -73,9 +73,6 @@ winMWExtWMProcs = {
  * References to external symbols
  */
 
-extern winScreenInfo		g_ScreenInfo[];
-extern miPointerScreenFuncRec	g_winPointerCursorFuncs;
-extern int			g_iScreenPrivateIndex;
 extern Bool                     g_fSoftwareCursor;
 
 
diff --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c
index 8a3faee..f894d6c 100644
--- a/hw/xwin/winsetsp.c
+++ b/hw/xwin/winsetsp.c
@@ -35,15 +35,6 @@
 #include "win.h"
 
 
-/*
- * References to external symbols
- */
-
-extern int			g_iPixmapPrivateIndex;
-extern int			g_iGCPrivateIndex;
-extern int                      g_copyROP[];
-
-
 /* See Porting Layer Definition - p. 55 */
 void
 winSetSpansNativeGDI (DrawablePtr	pDrawable,
diff --git a/include/colormapst.h b/include/colormapst.h
index c9d9514..f1fc8eb 100644
--- a/include/colormapst.h
+++ b/include/colormapst.h
@@ -52,6 +52,7 @@ SOFTWARE.
 
 #include "colormap.h"
 #include "screenint.h"
+#include "privates.h"
 
 /* Shared color -- the color is used by AllocColorPlanes */
 typedef struct
@@ -126,7 +127,7 @@ typedef struct _ColormapRec
     Entry 	*green;
     Entry	*blue;
     pointer	devPriv;
-    DevUnion	*devPrivates;	/* dynamic devPrivates added after devPriv
+    PrivateRec	*devPrivates;	/* dynamic devPrivates added after devPriv
 				   already existed - must keep devPriv */
 } ColormapRec;
 	      
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 01142a5..8d4d731 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -261,9 +261,6 @@
 /* Internal define for Xinerama */
 #undef PANORAMIX
 
-/* Support pixmap privates */
-#undef PIXPRIV
-
 /* Overall prefix */
 #undef PROJECTROOT
 
diff --git a/include/dix.h b/include/dix.h
index 05366ec..54629cd 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -496,12 +496,6 @@ void
 ScreenRestructured (ScreenPtr pScreen);
 #endif
 
-extern int AllocateClientPrivateIndex(void);
-
-extern Bool AllocateClientPrivate(
-    int /*index*/,
-    unsigned /*amount*/);
-
 extern int ffs(int i);
 
 /*
diff --git a/include/dixstruct.h b/include/dixstruct.h
index 2a3e696..7f14aba 100644
--- a/include/dixstruct.h
+++ b/include/dixstruct.h
@@ -29,6 +29,7 @@ SOFTWARE.
 #include "cursor.h"
 #include "gc.h"
 #include "pixmap.h"
+#include "privates.h"
 #include <X11/Xmd.h>
 
 /*
@@ -110,7 +111,7 @@ typedef struct _Client {
     Bool	big_requests;		/* supports large requests */
     int		priority;
     ClientState clientState;
-    DevUnion	*devPrivates;
+    PrivateRec	*devPrivates;
 #ifdef XKB
     unsigned short	xkbClientFlags;
     unsigned short	mapNotifyMask;
diff --git a/include/extension.h b/include/extension.h
index 27decc1..6e60817 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -58,12 +58,6 @@ extern Bool EnableDisableExtension(char *name, Bool enable);
 
 extern void EnableDisableExtensionError(char *name, Bool enable);
 
-extern int AllocateExtensionPrivateIndex(void);
-
-extern Bool AllocateExtensionPrivate(
-    int /*index*/,
-    unsigned /*amount*/);
-
 extern void InitExtensions(int argc, char **argv);
 
 extern void InitVisualWrap(void);
diff --git a/include/extnsionst.h b/include/extnsionst.h
index 58bf0a2..59acd0e 100644
--- a/include/extnsionst.h
+++ b/include/extnsionst.h
@@ -53,6 +53,7 @@ SOFTWARE.
 #include "screenint.h"
 #include "extension.h"
 #include "gc.h"
+#include "privates.h"
 
 typedef struct _ExtensionEntry {
     int index;
@@ -69,7 +70,7 @@ typedef struct _ExtensionEntry {
     pointer extPrivate;
     unsigned short (* MinorOpcode)(	/* called for errors */
 	ClientPtr /* client */);
-    DevUnion *devPrivates;
+    PrivateRec *devPrivates;
 } ExtensionEntry;
 
 /* 
diff --git a/include/gcstruct.h b/include/gcstruct.h
index 14f7478..8d9b055 100644
--- a/include/gcstruct.h
+++ b/include/gcstruct.h
@@ -56,6 +56,7 @@ SOFTWARE.
 #include "region.h"
 #include "pixmap.h"
 #include "screenint.h"
+#include "privates.h"
 #include <X11/Xprotostr.h>
 
 /*
@@ -308,7 +309,7 @@ typedef struct _GC {
     unsigned long       serialNumber;
     GCFuncs		*funcs;
     GCOps		*ops;
-    DevUnion		*devPrivates;
+    PrivateRec		*devPrivates;
     /*
      * The following were moved here from private storage to allow device-
      * independent access to them from screen wrappers.
diff --git a/include/input.h b/include/input.h
index 97a7856..4f9164a 100644
--- a/include/input.h
+++ b/include/input.h
@@ -158,9 +158,6 @@ typedef struct {
     unsigned char id;
 } LedCtrl;
 
-extern int AllocateDevicePrivateIndex(void);
-extern Bool AllocateDevicePrivate(DeviceIntPtr device, int index);
-
 extern KeybdCtrl	defaultKeyboardControl;
 extern PtrCtrl		defaultPointerControl;
 
diff --git a/include/inputstr.h b/include/inputstr.h
index 3398949..bb7f350 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -52,6 +52,7 @@ SOFTWARE.
 #include "input.h"
 #include "window.h"
 #include "dixstruct.h"
+#include "privates.h"
 
 #define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
 
@@ -62,7 +63,7 @@ SOFTWARE.
 
 #define EMASKSIZE	MAX_DEVICES
 
-extern int CoreDevicePrivatesIndex;
+extern DevPrivateKey CoreDevicePrivateKey;
 
 /* Kludge: OtherClients and InputClients must be compatible, see code */
 
@@ -327,7 +328,7 @@ typedef struct _DeviceIntRec {
     void                *pad0;
 #endif
     char                *config_info; /* used by the hotplug layer */
-    DevUnion		*devPrivates;
+    PrivateRec		*devPrivates;
     int			nPrivates;
     DeviceUnwrapProc    unwrapProc;
 } DeviceIntRec;
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 4594882..4162c66 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -47,27 +47,17 @@ SOFTWARE.
 
 #ifndef PIXMAPSTRUCT_H
 #define PIXMAPSTRUCT_H
-#include <X11/Xarch.h>
 #include "pixmap.h"
 #include "screenint.h"
 #include "regionstr.h"
-
-/*
- * The padN members are unfortunate ABI BC.  See fdo bug #6924.
- */
+#include "privates.h"
 
 typedef struct _Drawable {
     unsigned char	type;	/* DRAWABLE_<type> */
     unsigned char	class;	/* specific to type */
     unsigned char	depth;
     unsigned char	bitsPerPixel;
-#if defined(_XSERVER64)
-    XID			pad0;
-#endif
     XID			id;	/* resource id */
-#if defined(_XSERVER64)
-    XID			pad1;
-#endif
     short		x;	/* window: screen absolute, pixmap: 0 */
     short		y;	/* window: screen absolute, pixmap: 0 */
     unsigned short	width;
@@ -85,7 +75,7 @@ typedef struct _Pixmap {
     int			refcnt;
     int			devKind;
     DevUnion		devPrivate;
-    DevUnion		*devPrivates; /* real devPrivates like gcs & windows */
+    PrivateRec		*devPrivates;
 #ifdef COMPOSITE
     short		screen_x;
     short		screen_y;
diff --git a/include/privates.h b/include/privates.h
index e377b30..9539a29 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -28,13 +28,6 @@ typedef struct _Private {
 } PrivateRec;
 
 /*
- * Backwards compatibility macro.  Use to get the proper PrivateRec
- * reference from any of the structure types that supported the old
- * devPrivates mechanism.
- */
-#define DEVPRIV_PTR(foo) ((PrivateRec **)(&(foo)->devPrivates[0].ptr))
-
-/*
  * Request pre-allocated private space for your driver/module.
  * Calling this is not necessary if only a pointer by itself is needed.
  */
@@ -154,7 +147,4 @@ dixLookupPrivateOffset(RESTYPE type);
 extern int
 dixRegisterPrivateOffset(RESTYPE type, unsigned offset);
 
-/* Used by the legacy support, don't rely on this being here */
-#define PadToLong(w) ((((w) + sizeof(long)-1) / sizeof(long)) * sizeof(long))
-
 #endif /* PRIVATES_H */
diff --git a/include/screenint.h b/include/screenint.h
index bf8da44..6d074a3 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -55,22 +55,6 @@ typedef struct _Visual *VisualPtr;
 typedef struct _Depth  *DepthPtr;
 typedef struct _Screen *ScreenPtr;
 
-extern int AllocateScreenPrivateIndex(void);
-
-extern int AllocateWindowPrivateIndex(void);
-
-extern Bool AllocateWindowPrivate(
-    ScreenPtr /* pScreen */,
-    int /* index */,
-    unsigned /* amount */);
-
-extern int AllocateGCPrivateIndex(void);
-
-extern Bool AllocateGCPrivate(
-    ScreenPtr /* pScreen */,
-    int /* index */,
-    unsigned /* amount */);
-
 extern int AddScreen(
     Bool (* /*pfnInit*/)(
 	int /*index*/,
@@ -80,18 +64,6 @@ extern int AddScreen(
     int /*argc*/,
     char** /*argv*/);
 
-extern int AllocatePixmapPrivateIndex(void);
-
-extern Bool AllocatePixmapPrivate(
-    ScreenPtr /* pScreen */,
-    int /* index */,
-    unsigned /* amount */);
-
-
 typedef struct _ColormapRec *ColormapPtr;
-typedef int (*InitCmapPrivFunc)(ColormapPtr, int);
-
-extern int AllocateColormapPrivateIndex(
-    InitCmapPrivFunc /* initPrivFunc */);
 
 #endif /* SCREENINT_H */
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 110f4dc..a24c5f5 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -56,6 +56,7 @@ SOFTWARE.
 #include "validate.h"
 #include <X11/Xproto.h>
 #include "dix.h"
+#include "privates.h"
 
 typedef struct _PixmapFormat {
     unsigned char	depth;
@@ -449,12 +450,6 @@ typedef struct _Screen {
     pointer		devPrivate;
     short       	numVisuals;
     VisualPtr		visuals;
-    int			WindowPrivateLen;
-    unsigned		*WindowPrivateSizes;
-    unsigned		totalWindowSize;
-    int			GCPrivateLen;
-    unsigned		*GCPrivateSizes;
-    unsigned		totalGCSize;
 
     /* Random screen procedures */
 
@@ -546,7 +541,7 @@ typedef struct _Screen {
     pointer wakeupData;
 
     /* anybody can get a piece of this array */
-    DevUnion	*devPrivates;
+    PrivateRec	*devPrivates;
 
     CreateScreenResourcesProcPtr CreateScreenResources;
     ModifyPixmapHeaderProcPtr	ModifyPixmapHeader;
@@ -558,8 +553,6 @@ typedef struct _Screen {
 
     PixmapPtr pScratchPixmap;		/* scratch pixmap "pool" */
 
-    int			PixmapPrivateLen;
-    unsigned int		*PixmapPrivateSizes;
     unsigned int		totalPixmapSize;
 
     MarkWindowProcPtr		MarkWindow;
diff --git a/include/window.h b/include/window.h
index d5437a7..f85eceb 100644
--- a/include/window.h
+++ b/include/window.h
@@ -83,9 +83,6 @@ extern int WalkTree(
     VisitWindowProcPtr /*func*/,
     pointer /*data*/);
 
-extern WindowPtr AllocateWindow(
-    ScreenPtr /*pScreen*/);
-
 extern Bool CreateRootWindow(
     ScreenPtr /*pScreen*/);
 
diff --git a/include/windowstr.h b/include/windowstr.h
index 6d874ae..ca212ad 100644
--- a/include/windowstr.h
+++ b/include/windowstr.h
@@ -55,6 +55,7 @@ SOFTWARE.
 #include "property.h"
 #include "resource.h"	/* for ROOT_WINDOW_ID_BASE */
 #include "dix.h"
+#include "privates.h"
 #include "miscstruct.h"
 #include <X11/Xprotostr.h>
 #include "opaque.h"
@@ -159,7 +160,7 @@ typedef struct _Window {
 #ifdef COMPOSITE
     unsigned		redirectDraw:2;	/* rendering is redirected from here */
 #endif
-    DevUnion		*devPrivates;
+    PrivateRec		*devPrivates;
 } WindowRec;
 
 /*
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 5edee53..71ea115 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -246,7 +246,7 @@ typedef struct
 	device->public.realInputProc = oldprocs->realInputProc; \
 	device->unwrapProc = oldprocs->unwrapProc;
 
-#define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr) (dev)->devPrivates[xkbDevicePrivateIndex].ptr)
+#define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr)dixLookupPrivate(&(dev)->devPrivates, xkbDevicePrivateKey))
 
 /***====================================================================***/
 
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index b9643a2..97d53a2 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -57,9 +57,6 @@
 /* Solaris 8 or later? */
 #undef __SOL8__
 
-/* Whether to use pixmap privates */
-#undef PIXPRIV
-
 /* Define to 1 if you have the `walkcontext' function (used on Solaris for
    xorg_backtrace in hw/xfree86/common/xf86Events.c */
 #undef HAVE_WALKCONTEXT
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index c117dfa..4b9104d 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -70,9 +70,6 @@
 /* Internal define for Xinerama */
 #undef PANORAMIX
 
-/* Support pixmap privates */
-#undef PIXPRIV
-
 /* Support RANDR extension */
 #undef RANDR
 
diff --git a/mfb/mfb.h b/mfb/mfb.h
index 001f43e..42f3002 100644
--- a/mfb/mfb.h
+++ b/mfb/mfb.h
@@ -705,8 +705,8 @@ extern Bool mfbCloseScreen(
 
 extern Bool mfbAllocatePrivates(
     ScreenPtr /*pScreen*/,
-    int * /*pWinIndex*/,
-    int * /*pGCIndex*/
+    DevPrivateKey *pWinKey,
+    DevPrivateKey *pGCIndex
 );
 
 extern Bool mfbScreenInit(
@@ -891,14 +891,10 @@ typedef struct {
 typedef mfbPrivGC	*mfbPrivGCPtr;
 #endif
 
-/* XXX these should be static, but it breaks the ABI */
-extern int  mfbGCPrivateIndex;		/* index into GC private array */
-extern int  mfbGetGCPrivateIndex(void);
-extern int  mfbWindowPrivateIndex;	/* index into Window private array */
-extern int  mfbGetWindowPrivateIndex(void);
+extern DevPrivateKey mfbGetGCPrivateKey(void);
+extern DevPrivateKey mfbGetWindowPrivateKey(void);
 #ifdef PIXMAP_PER_WINDOW
-extern int  frameWindowPrivateIndex;	/* index into Window private array */
-extern int  frameGetWindowPrivateIndex(void);
+extern DevPrivateKey frameGetWindowPrivateKey(void);
 #endif
 
 #ifndef MFB_PROTOTYPES_ONLY
diff --git a/mfb/mfbbitblt.c b/mfb/mfbbitblt.c
index 270fd96..3efee45 100644
--- a/mfb/mfbbitblt.c
+++ b/mfb/mfbbitblt.c
@@ -397,8 +397,7 @@ int dstx, dsty;
  * must register a function for n-to-1 copy operations
  */
 
-static unsigned long	copyPlaneGeneration;
-static int		copyPlaneScreenIndex = -1;
+static DevPrivateKey copyPlaneScreenKey = &copyPlaneScreenKey;
 
 typedef RegionPtr (*CopyPlaneFuncPtr)(
     DrawablePtr         /* pSrcDrawable */,
@@ -417,14 +416,7 @@ mfbRegisterCopyPlaneProc (pScreen, proc)
     ScreenPtr	pScreen;
     CopyPlaneFuncPtr proc;
 {
-    if (copyPlaneGeneration != serverGeneration)
-    {
-	copyPlaneScreenIndex = AllocateScreenPrivateIndex();
-	if (copyPlaneScreenIndex < 0)
-	    return FALSE;
-	copyPlaneGeneration = serverGeneration;
-    }
-    pScreen->devPrivates[copyPlaneScreenIndex].fptr = (CopyPlaneFuncPtr)proc;
+    dixSetPrivate(&pScreen->devPrivates, copyPlaneScreenKey, proc);
     return TRUE;
 }
 
@@ -469,9 +461,9 @@ unsigned long plane;
 
     if (pSrcDrawable->depth != 1)
     {
-	if (copyPlaneScreenIndex >= 0 &&
-	    (copyPlane = (CopyPlaneFuncPtr)
-		pSrcDrawable->pScreen->devPrivates[copyPlaneScreenIndex].fptr)
+	if ((copyPlane = (CopyPlaneFuncPtr)
+	     dixLookupPrivate(&pSrcDrawable->pScreen->devPrivates,
+			      copyPlaneScreenKey))
 	    )
 	{
 	    return (*copyPlane) (pSrcDrawable, pDstDrawable,
diff --git a/mfb/mfbfillarc.c b/mfb/mfbfillarc.c
index 30ec00d..cbf47a0 100644
--- a/mfb/mfbfillarc.c
+++ b/mfb/mfbfillarc.c
@@ -289,7 +289,8 @@ mfbPolyFillArcSolid(pDraw, pGC, narcs, parcs)
     RegionPtr cclip;
     int rop;
 
-    priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    priv = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					 mfbGetGCPrivateKey());
     rop = priv->rop;
     if ((rop == RROP_NOP) || !(pGC->planemask & 1))
 	return;
diff --git a/mfb/mfbfillrct.c b/mfb/mfbfillrct.c
index f9209d0..506776b 100644
--- a/mfb/mfbfillrct.c
+++ b/mfb/mfbfillrct.c
@@ -96,7 +96,8 @@ mfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
     if (!(pGC->planemask & 1))
 	return;
 
-    priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    priv = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					 mfbGetGCPrivateKey());
     alu = priv->ropFillArea;
     pfn = priv->FillArea;
     ppix = pGC->pRotatedPixmap;
diff --git a/mfb/mfbfillsp.c b/mfb/mfbfillsp.c
index 112f532..e9be737 100644
--- a/mfb/mfbfillsp.c
+++ b/mfb/mfbfillsp.c
@@ -624,7 +624,8 @@ mfbTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
     if (pGC->fillStyle == FillTiled)
 	rop = pGC->alu;
     else
-	rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->ropOpStip;
+	rop = ((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					     mfbGetGCPrivateKey()))->ropOpStip;
 
     flip = 0;
     switch(rop)
@@ -769,7 +770,8 @@ mfbUnnaturalTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
     {
 	pTile = pGC->stipple;
 	tlwidth = pTile->devKind / PGSZB;
-	rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->ropOpStip;
+	rop = ((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					     mfbGetGCPrivateKey()))->ropOpStip;
     }
 
     xSrc = pDrawable->x;
@@ -926,7 +928,8 @@ mfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
 		    ppt, pwidth, fSorted);
 
     pTile = pGC->stipple;
-    rop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
+    rop = ((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					 mfbGetGCPrivateKey()))->rop;
     tlwidth = pTile->devKind / PGSZB;
     xSrc = pDrawable->x;
     ySrc = pDrawable->y;
diff --git a/mfb/mfbgc.c b/mfb/mfbgc.c
index c60e976..7492d7c 100644
--- a/mfb/mfbgc.c
+++ b/mfb/mfbgc.c
@@ -381,7 +381,8 @@ matchCommon (
 	FONTMINBOUNDS(pGC->font,leftSideBearing) > 32 ||
 	FONTMINBOUNDS(pGC->font,characterWidth) < 0)
 	return 0;
-    priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    priv = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					 mfbGetGCPrivateKey());
     for (i = 0; i < numberCommonOps; i++) {
 	cop = &mfbCommonOps[i];
 	if ((pGC->fgPixel & 1) != cop->fg)
@@ -420,7 +421,8 @@ mfbCreateGC(pGC)
     /* mfb wants to translate before scan convesion */
     pGC->miTranslate = 1;
 
-    pPriv = (mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr);
+    pPriv = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					  mfbGetGCPrivateKey());
     pPriv->rop = mfbReduceRop(pGC->alu, pGC->fgPixel);
     pGC->fExpose = TRUE;
     pGC->pRotatedPixmap = NullPixmap;
@@ -508,8 +510,8 @@ mfbValidateGC(pGC, changes, pDrawable)
     new_rotate = (oldOrg.x != pGC->lastWinOrg.x) ||
 		 (oldOrg.y != pGC->lastWinOrg.y);
 
-    devPriv = ((mfbPrivGCPtr) (pGC->devPrivates[mfbGCPrivateIndex].ptr));
-
+    devPriv = (mfbPrivGCPtr)dixLookupPrivate(&pGC->devPrivates,
+					     mfbGetGCPrivateKey());
     /*
 	if the client clip is different or moved OR
 	the subwindowMode has changed OR
diff --git a/mfb/mfbimggblt.c b/mfb/mfbimggblt.c
index e5c186b..2778b62 100644
--- a/mfb/mfbimggblt.c
+++ b/mfb/mfbimggblt.c
@@ -184,7 +184,8 @@ MFBIMAGEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
        but that is usually not a cheap thing to do.
     */
 
-    pPrivGC = pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    pPrivGC = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					    mfbGetGCPrivateKey());
     oldFillArea = pPrivGC->FillArea;
 
     if (pGC->bgPixel & 1)
diff --git a/mfb/mfbline.c b/mfb/mfbline.c
index 863a618..65baa5e 100644
--- a/mfb/mfbline.c
+++ b/mfb/mfbline.c
@@ -146,7 +146,8 @@ mfbLineSS (pDrawable, pGC, mode, npt, pptInit)
 	return;
 
     cclip = pGC->pCompositeClip;
-    alu = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
+    alu = ((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					 mfbGetGCPrivateKey()))->rop;
     pboxInit = REGION_RECTS(cclip);
     nboxInit = REGION_NUM_RECTS(cclip);
 
@@ -525,7 +526,8 @@ mfbLineSD( pDrawable, pGC, mode, npt, pptInit)
 	return;
 
     cclip = pGC->pCompositeClip;
-    fgrop = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop;
+    fgrop = ((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					   mfbGetGCPrivateKey()))->rop;
     pboxInit = REGION_RECTS(cclip);
     nboxInit = REGION_NUM_RECTS(cclip);
 
diff --git a/mfb/mfbpixmap.c b/mfb/mfbpixmap.c
index b13e3af..1f3f011 100644
--- a/mfb/mfbpixmap.c
+++ b/mfb/mfbpixmap.c
@@ -113,7 +113,7 @@ mfbDestroyPixmap(pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
-    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
+    dixFreePrivates(pPixmap->devPrivates);
     xfree(pPixmap);
     return TRUE;
 }
diff --git a/mfb/mfbpntwin.c b/mfb/mfbpntwin.c
index b18797a..725d6be 100644
--- a/mfb/mfbpntwin.c
+++ b/mfb/mfbpntwin.c
@@ -56,6 +56,7 @@ SOFTWARE.
 #include "regionstr.h"
 #include "pixmapstr.h"
 #include "scrnintstr.h"
+#include "privates.h"
 
 #include "mfb.h"
 #include "maskbits.h"
@@ -69,8 +70,8 @@ mfbPaintWindow(pWin, pRegion, what)
 {
     register mfbPrivWin	*pPrivWin;
 
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
-    
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      mfbGetWindowPrivateKey());
     switch (what) {
     case PW_BACKGROUND:
 	switch (pWin->backgroundState) {
diff --git a/mfb/mfbpolypnt.c b/mfb/mfbpolypnt.c
index 1c40451..146cfdc 100644
--- a/mfb/mfbpolypnt.c
+++ b/mfb/mfbpolypnt.c
@@ -88,7 +88,8 @@ mfbPolyPoint(pDrawable, pGC, mode, npt, pptInit)
     if (!(pGC->planemask & 1))
 	return;
 
-    pGCPriv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
+    pGCPriv = (mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+					    mfbGetGCPrivateKey());
     rop = pGCPriv->rop;
 
     mfbGetPixelWidthAndPointer(pDrawable, nlwidth, addrl);
diff --git a/mfb/mfbscrinit.c b/mfb/mfbscrinit.c
index 13ea5d3..515e9e3 100644
--- a/mfb/mfbscrinit.c
+++ b/mfb/mfbscrinit.c
@@ -68,13 +68,13 @@ SOFTWARE.
 #include "servermd.h"
 
 #ifdef PIXMAP_PER_WINDOW
-int frameWindowPrivateIndex;
-int frameGetWindowPrivateIndex(void) { return frameWindowPrivateIndex; }
+static DevPrivateKey frameWindowPrivateKey = &frameWindowPrivateKey;
+DevPrivateKey frameGetWindowPrivateKey(void) { return frameWindowPrivateKey; }
 #endif
-int mfbWindowPrivateIndex;
-int mfbGetWindowPrivateIndex(void) { return mfbWindowPrivateIndex; }
-int mfbGCPrivateIndex;
-int mfbGetGCPrivateIndex(void) { return mfbGCPrivateIndex; }
+static DevPrivateKey mfbWindowPrivateKey = &mfbWindowPrivateKey;
+DevPrivateKey mfbGetWindowPrivateKey(void) { return mfbWindowPrivateKey; }
+static DevPrivateKey mfbGCPrivateKey = &mfbGCPrivateKey;
+DevPrivateKey mfbGetGCPrivateKey(void) { return mfbGCPrivateKey; }
 static unsigned long mfbGeneration = 0;
 
 static VisualRec visual = {
@@ -90,30 +90,23 @@ static DepthRec depth = {
 };
 
 Bool
-mfbAllocatePrivates(pScreen, pWinIndex, pGCIndex)
-    ScreenPtr pScreen;
-    int *pWinIndex, *pGCIndex;
+mfbAllocatePrivates(ScreenPtr pScreen,
+		    DevPrivateKey *pWinIndex, DevPrivateKey *pGCIndex)
 {
     if (mfbGeneration != serverGeneration)
     {
-#ifdef PIXMAP_PER_WINDOW
-	frameWindowPrivateIndex = AllocateWindowPrivateIndex();
-#endif
-	mfbWindowPrivateIndex = AllocateWindowPrivateIndex();
-	mfbGCPrivateIndex = miAllocateGCPrivateIndex();
 	visual.vid = FakeClientID(0);
 	VID = visual.vid;
 	mfbGeneration = serverGeneration;
     }
     if (pWinIndex)
-	*pWinIndex = mfbWindowPrivateIndex;
+	*pWinIndex = mfbWindowPrivateKey;
     if (pGCIndex)
-	*pGCIndex = mfbGCPrivateIndex;
+	*pGCIndex = mfbGCPrivateKey;
     pScreen->GetWindowPixmap = mfbGetWindowPixmap;
     pScreen->SetWindowPixmap = mfbSetWindowPixmap;
-    return (AllocateWindowPrivate(pScreen, mfbWindowPrivateIndex,
-				  sizeof(mfbPrivWin)) &&
-	    AllocateGCPrivate(pScreen, mfbGCPrivateIndex, sizeof(mfbPrivGC)));
+    return (dixRequestPrivate(mfbWindowPrivateKey, sizeof(mfbPrivWin)) &&
+	    dixRequestPrivate(mfbGCPrivateKey, sizeof(mfbPrivGC)));
 }
 
 
@@ -126,7 +119,7 @@ mfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
     int dpix, dpiy;		/* dots per inch */
     int width;			/* pixel width of frame buffer */
 {
-    if 	(!mfbAllocatePrivates(pScreen, (int *)NULL, (int *)NULL))
+    if 	(!mfbAllocatePrivates(pScreen, NULL, NULL))
 	return FALSE;
     pScreen->defColormap = (Colormap) FakeClientID(0);
     /* whitePixel, blackPixel */
@@ -167,7 +160,8 @@ mfbGetWindowPixmap(pWin)
     WindowPtr pWin;
 {
 #ifdef PIXMAP_PER_WINDOW
-    return (PixmapPtr)(pWin->devPrivates[frameWindowPrivateIndex].ptr);
+    return (PixmapPtr)dixLookupPrivate(&pWin->devPrivates,
+				       frameWindowPrivateKey);
 #else
     ScreenPtr pScreen = pWin->drawable.pScreen;
 
@@ -181,7 +175,7 @@ mfbSetWindowPixmap(pWin, pPix)
     PixmapPtr pPix;
 {
 #ifdef PIXMAP_PER_WINDOW
-    pWin->devPrivates[frameWindowPrivateIndex].ptr = (pointer)pPix;
+    dixSetPrivate(&pWin->devPrivates, frameWindowPrivateKey, pPix);
 #else
     (* pWin->drawable.pScreen->SetScreenPixmap)(pPix);
 #endif
diff --git a/mfb/mfbwindow.c b/mfb/mfbwindow.c
index b138d58..c522b07 100644
--- a/mfb/mfbwindow.c
+++ b/mfb/mfbwindow.c
@@ -55,6 +55,7 @@ SOFTWARE.
 #include <X11/X.h>
 #include "scrnintstr.h"
 #include "windowstr.h"
+#include "privates.h"
 #include "mfb.h"
 #include "mistruct.h"
 #include "regionstr.h"
@@ -66,7 +67,8 @@ mfbCreateWindow(pWin)
 {
     register mfbPrivWin *pPrivWin;
 
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      mfbGetWindowPrivateKey());
     pPrivWin->pRotatedBorder = NullPixmap;
     pPrivWin->pRotatedBackground = NullPixmap;
     pPrivWin->fastBackground = FALSE;
@@ -83,8 +85,8 @@ mfbDestroyWindow(pWin)
 {
     register mfbPrivWin *pPrivWin;
 
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
-
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      mfbGetWindowPrivateKey());
     if (pPrivWin->pRotatedBorder)
 	(*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
     if (pPrivWin->pRotatedBackground)
@@ -116,7 +118,8 @@ mfbPositionWindow(pWin, x, y)
     register mfbPrivWin *pPrivWin;
     int	reset = 0;
 
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      mfbGetWindowPrivateKey());
     if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
     {
 	mfbXRotatePixmap(pPrivWin->pRotatedBackground,
@@ -227,7 +230,8 @@ mfbChangeWindowAttributes(pWin, mask)
     register mfbPrivWin *pPrivWin;
     WindowPtr	pBgWin;
 
-    pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
+    pPrivWin = (mfbPrivWin *)dixLookupPrivate(&pWin->devPrivates,
+					      mfbGetWindowPrivateKey());
     /*
      * When background state changes from ParentRelative and
      * we had previously rotated the fast border pixmap to match
diff --git a/mfb/mfbzerarc.c b/mfb/mfbzerarc.c
index 964e2f1..624e45f 100644
--- a/mfb/mfbzerarc.c
+++ b/mfb/mfbzerarc.c
@@ -92,7 +92,8 @@ mfbZeroArcSS(
     PixelType pmask;
     register PixelType *paddr;
 
-    if (((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->rop ==
+    if (((mfbPrivGC *)dixLookupPrivate(&pGC->devPrivates,
+				       mfbGetGCPrivateKey()))->rop ==
 	RROP_BLACK)
 	pixel = 0;
     else
diff --git a/mi/mi.h b/mi/mi.h
index c71c9b7..8d8f488 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -55,6 +55,7 @@ SOFTWARE.
 #include <X11/fonts/font.h>
 #include "input.h"
 #include "cursor.h"
+#include "privates.h"
 
 #define MiBits	CARD32
 
@@ -412,7 +413,7 @@ extern Bool miScreenInit(
     VisualPtr /*visuals*/
 );
 
-extern int miAllocateGCPrivateIndex(
+extern DevPrivateKey miAllocateGCPrivateIndex(
     void
 );
 
diff --git a/mi/mibank.c b/mi/mibank.c
index 00638a4..b52399c 100644
--- a/mi/mibank.c
+++ b/mi/mibank.c
@@ -177,15 +177,15 @@ typedef struct _miBankQueue
 #define ALLOCATE_LOCAL_ARRAY(atype, ntype) \
     (atype *)ALLOCATE_LOCAL((ntype) * sizeof(atype))
 
-static int           miBankScreenIndex;
-static int           miBankGCIndex;
+static DevPrivateKey miBankScreenKey = &miBankScreenKey;
+static DevPrivateKey miBankGCKey = &miBankGCKey;
 static unsigned long miBankGeneration = 0;
 
-#define BANK_SCRPRIVLVAL pScreen->devPrivates[miBankScreenIndex].ptr
+#define BANK_SCRPRIVLVAL dixLookupPrivate(&pScreen->devPrivates, miBankScreenKey)
 
 #define BANK_SCRPRIVATE ((miBankScreenPtr)(BANK_SCRPRIVLVAL))
 
-#define BANK_GCPRIVLVAL(pGC) (pGC)->devPrivates[miBankGCIndex].ptr
+#define BANK_GCPRIVLVAL(pGC) dixLookupPrivate(&(pGC)->devPrivates, miBankGCKey)
 
 #define BANK_GCPRIVATE(pGC) ((miBankGCPtr)(BANK_GCPRIVLVAL(pGC)))
 
@@ -2116,15 +2116,9 @@ miInitializeBanking(
     /* Private areas */
 
     if (miBankGeneration != serverGeneration)
-    {
-        if (((miBankScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
-            ((miBankGCIndex = AllocateGCPrivateIndex()) < 0))
-            return FALSE;
-
         miBankGeneration = serverGeneration;
-    }
 
-    if (!AllocateGCPrivate(pScreen, miBankGCIndex,
+    if (!dixRequestPrivate(miBankGCKey,
         (nBanks * sizeof(RegionPtr)) +
             (sizeof(miBankGCRec) - sizeof(RegionPtr))))
         return FALSE;
@@ -2273,7 +2267,7 @@ miInitializeBanking(
     SCREEN_WRAP(PaintWindowBorder,     miBankPaintWindow);
     SCREEN_WRAP(CopyWindow,            miBankCopyWindow);
 
-    BANK_SCRPRIVLVAL = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, miBankScreenKey, pScreenPriv);
 
     return TRUE;
 }
diff --git a/mi/midispcur.c b/mi/midispcur.c
index feb6c2f..8b78292 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -54,8 +54,7 @@ in this Software without prior written authorization from The Open Group.
 
 /* per-screen private data */
 
-static int	miDCScreenIndex;
-static unsigned long miDCGeneration = 0;
+static DevPrivateKey miDCScreenKey = &miDCScreenKey;
 
 static Bool	miDCCloseScreen(int index, ScreenPtr pScreen);
 
@@ -117,13 +116,6 @@ miDCInitialize (pScreen, screenFuncs)
 {
     miDCScreenPtr   pScreenPriv;
 
-    if (miDCGeneration != serverGeneration)
-    {
-	miDCScreenIndex = AllocateScreenPrivateIndex ();
-	if (miDCScreenIndex < 0)
-	    return FALSE;
-	miDCGeneration = serverGeneration;
-    }
     pScreenPriv = (miDCScreenPtr) xalloc (sizeof (miDCScreenRec));
     if (!pScreenPriv)
 	return FALSE;
@@ -149,7 +141,7 @@ miDCInitialize (pScreen, screenFuncs)
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = miDCCloseScreen;
     
-    pScreen->devPrivates[miDCScreenIndex].ptr = (pointer) pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, miDCScreenKey, pScreenPriv);
 
     if (!miSpriteInitialize (pScreen, &miDCFuncs, screenFuncs))
     {
@@ -170,7 +162,8 @@ miDCCloseScreen (index, pScreen)
 {
     miDCScreenPtr   pScreenPriv;
 
-    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  miDCScreenKey);
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     tossGC (pScreenPriv->pSourceGC);
     tossGC (pScreenPriv->pMaskGC);
@@ -475,7 +468,8 @@ miDCPutUpCursor (pScreen, pCursor, x, y, source, mask)
 	if (!pPriv)
 	    return FALSE;
     }
-    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  miDCScreenKey);
     pWin = WindowTable[pScreen->myNum];
 #ifdef ARGB_CURSOR
     if (pPriv->pPicture)
@@ -520,7 +514,8 @@ miDCSaveUnderCursor (pScreen, x, y, w, h)
     WindowPtr	    pWin;
     GCPtr	    pGC;
 
-    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  miDCScreenKey);
     pSave = pScreenPriv->pSave;
     pWin = WindowTable[pScreen->myNum];
     if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h)
@@ -552,7 +547,8 @@ miDCRestoreUnderCursor (pScreen, x, y, w, h)
     WindowPtr	    pWin;
     GCPtr	    pGC;
 
-    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  miDCScreenKey);
     pSave = pScreenPriv->pSave;
     pWin = WindowTable[pScreen->myNum];
     if (!pSave)
@@ -578,7 +574,8 @@ miDCChangeSave (pScreen, x, y, w, h, dx, dy)
     GCPtr	    pGC;
     int		    sourcex, sourcey, destx, desty, copyw, copyh;
 
-    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  miDCScreenKey);
     pSave = pScreenPriv->pSave;
     pWin = WindowTable[pScreen->myNum];
     /*
@@ -721,7 +718,8 @@ miDCMoveCursor (pScreen, pCursor, x, y, w, h, dx, dy, source, mask)
 	if (!pPriv)
 	    return FALSE;
     }
-    pScreenPriv = (miDCScreenPtr) pScreen->devPrivates[miDCScreenIndex].ptr;
+    pScreenPriv = (miDCScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						  miDCScreenKey);
     pWin = WindowTable[pScreen->myNum];
     pTemp = pScreenPriv->pTemp;
     if (!pTemp ||
diff --git a/mi/miline.h b/mi/miline.h
index b97b8cf..ffa4b27 100644
--- a/mi/miline.h
+++ b/mi/miline.h
@@ -119,9 +119,8 @@ extern void miSetZeroLineBias(
         t = y1;  y1 = y2;  y2 = t;\
 }
 
-#define miGetZeroLineBias(_pScreen) \
-    ((miZeroLineScreenIndex < 0) ? \
-     		0 : ((_pScreen)->devPrivates[miZeroLineScreenIndex].uval))
+#define miGetZeroLineBias(_pScreen) ((unsigned long) \
+    dixLookupPrivate(&(_pScreen)->devPrivates, miZeroLineScreenKey))
 
 #define CalcLineDeltas(_x1,_y1,_x2,_y2,_adx,_ady,_sx,_sy,_SX,_SY,_octant) \
     (_octant) = 0;				\
@@ -148,7 +147,7 @@ extern void miSetZeroLineBias(
 #define IsXDecreasingOctant(_octant)	((_octant) & XDECREASING)
 #define IsYDecreasingOctant(_octant)	((_octant) & YDECREASING)
 
-extern int miZeroLineScreenIndex;
+extern DevPrivateKey miZeroLineScreenKey;
 
 extern int miZeroClipLine(
     int /*xmin*/,
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index 1dbb85d..a1f32ad 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -10,6 +10,7 @@
 #include "mi.h"
 #include "gcstruct.h"
 #include "regionstr.h"
+#include "privates.h"
 #include "mivalidate.h"
 #include "mioverlay.h"
 #include "migc.h"
@@ -53,9 +54,8 @@ typedef struct {
    Bool				copyUnderlay;
 } miOverlayScreenRec, *miOverlayScreenPtr;
 
-static unsigned long miOverlayGeneration = 0;
-static int miOverlayWindowIndex = -1;
-static int miOverlayScreenIndex = -1;
+static DevPrivateKey miOverlayWindowKey = &miOverlayWindowKey;
+static DevPrivateKey miOverlayScreenKey = &miOverlayScreenKey;
 
 static void RebuildTree(WindowPtr);
 static Bool HasUnderlayChildren(WindowPtr);
@@ -85,10 +85,10 @@ static void miOverlaySetShape(WindowPtr);
 #endif
 static void miOverlayChangeBorderWidth(WindowPtr, unsigned int);
 
-#define MIOVERLAY_GET_SCREEN_PRIVATE(pScreen) \
-	((miOverlayScreenPtr)((pScreen)->devPrivates[miOverlayScreenIndex].ptr))
-#define MIOVERLAY_GET_WINDOW_PRIVATE(pWin) \
-	((miOverlayWindowPtr)((pWin)->devPrivates[miOverlayWindowIndex].ptr))
+#define MIOVERLAY_GET_SCREEN_PRIVATE(pScreen) ((miOverlayScreenPtr) \
+	dixLookupPrivate(&(pScreen)->devPrivates, miOverlayScreenKey))
+#define MIOVERLAY_GET_WINDOW_PRIVATE(pWin) ((miOverlayWindowPtr) \
+	dixLookupPrivate(&(pWin)->devPrivates, miOverlayWindowKey))
 #define MIOVERLAY_GET_WINDOW_TREE(pWin) \
 	(MIOVERLAY_GET_WINDOW_PRIVATE(pWin)->tree)
 
@@ -112,22 +112,13 @@ miInitOverlay(
 
     if(!inOverlayFunc || !transFunc) return FALSE;
 
-    if(miOverlayGeneration != serverGeneration) {
-	if(((miOverlayScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
-	   ((miOverlayWindowIndex = AllocateWindowPrivateIndex()) < 0))
-	    return FALSE;
-	
-	miOverlayGeneration = serverGeneration;
-    }
-
-    if(!AllocateWindowPrivate(pScreen, miOverlayWindowIndex,
-				sizeof(miOverlayWindowRec)))
+    if(!dixRequestPrivate(miOverlayWindowKey, sizeof(miOverlayWindowRec)))
 	return FALSE;
 
     if(!(pScreenPriv = xalloc(sizeof(miOverlayScreenRec))))
 	return FALSE;
 
-    pScreen->devPrivates[miOverlayScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, miOverlayScreenKey, pScreenPriv);
 
     pScreenPriv->InOverlay = inOverlayFunc;
     pScreenPriv->MakeTransparent = transFunc;
diff --git a/mi/mipointer.c b/mi/mipointer.c
index b86a26a..4d1db4f 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -41,10 +41,10 @@ in this Software without prior written authorization from The Open Group.
 # include   "dixstruct.h"
 # include   "inputstr.h"
 
-_X_EXPORT int miPointerScreenIndex;
-static unsigned long miPointerGeneration = 0;
+_X_EXPORT DevPrivateKey miPointerScreenKey = &miPointerScreenKey;
 
-#define GetScreenPrivate(s) ((miPointerScreenPtr) ((s)->devPrivates[miPointerScreenIndex].ptr))
+#define GetScreenPrivate(s) ((miPointerScreenPtr) \
+    dixLookupPrivate(&(s)->devPrivates, miPointerScreenKey))
 #define SetupScreen(s)	miPointerScreenPtr  pScreenPriv = GetScreenPrivate(s)
 
 /*
@@ -76,13 +76,6 @@ miPointerInitialize (pScreen, spriteFuncs, screenFuncs, waitForUpdate)
 {
     miPointerScreenPtr	pScreenPriv;
 
-    if (miPointerGeneration != serverGeneration)
-    {
-	miPointerScreenIndex = AllocateScreenPrivateIndex();
-	if (miPointerScreenIndex < 0)
-	    return FALSE;
-	miPointerGeneration = serverGeneration;
-    }
     pScreenPriv = (miPointerScreenPtr) xalloc (sizeof (miPointerScreenRec));
     if (!pScreenPriv)
 	return FALSE;
@@ -99,7 +92,7 @@ miPointerInitialize (pScreen, spriteFuncs, screenFuncs, waitForUpdate)
     pScreenPriv->showTransparent = FALSE;
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = miPointerCloseScreen;
-    pScreen->devPrivates[miPointerScreenIndex].ptr = (pointer) pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, miPointerScreenKey, pScreenPriv);
     /*
      * set up screen cursor method table
      */
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 1bce42c..e864fdd 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
 
 #include "cursor.h"
 #include "input.h"
+#include "privates.h"
 
 typedef struct _miPointerSpriteFuncRec {
     Bool	(*RealizeCursor)(
@@ -166,6 +167,6 @@ extern void miPointerSetPosition(
 extern void miPointerUpdateSprite(
     DeviceIntPtr pDev);
 
-extern int miPointerScreenIndex;
+extern DevPrivateKey miPointerScreenKey;
 
 #endif /* MIPOINTER_H */
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index cc40cbe..2dd8cd9 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -293,35 +293,22 @@ miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
     return miScreenDevPrivateInit(pScreen, width, pbits);
 }
 
-_X_EXPORT int
+static DevPrivateKey privateKey = &privateKey;
+
+_X_EXPORT DevPrivateKey
 miAllocateGCPrivateIndex()
 {
-    static int privateIndex = -1;
-    static unsigned long miGeneration = 0;
-
-    if (miGeneration != serverGeneration)
-    {
-	privateIndex = AllocateGCPrivateIndex();
-	miGeneration = serverGeneration;
-    }
-    return privateIndex;
+    return privateKey;
 }
 
-_X_EXPORT int miZeroLineScreenIndex;
-static unsigned int miZeroLineGeneration = 0;
+_X_EXPORT DevPrivateKey miZeroLineScreenKey;
 
 _X_EXPORT void
 miSetZeroLineBias(pScreen, bias)
     ScreenPtr pScreen;
     unsigned int bias;
 {
-    if (miZeroLineGeneration != serverGeneration)
-    {
-	miZeroLineScreenIndex = AllocateScreenPrivateIndex();
-	miZeroLineGeneration = serverGeneration;
-    }
-    if (miZeroLineScreenIndex >= 0)
-	pScreen->devPrivates[miZeroLineScreenIndex].uval = bias;
+    dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey, (pointer)bias);
 }
 
 _X_EXPORT PixmapPtr
diff --git a/mi/misprite.c b/mi/misprite.c
index 0b402fa..0af3368 100644
--- a/mi/misprite.c
+++ b/mi/misprite.c
@@ -67,8 +67,7 @@ in this Software without prior written authorization from The Open Group.
  * screen wrappers
  */
 
-static int  miSpriteScreenIndex;
-static unsigned long miSpriteGeneration = 0;
+static DevPrivateKey miSpriteScreenKey = &miSpriteScreenKey;
 
 static Bool	    miSpriteCloseScreen(int i, ScreenPtr pScreen);
 static void	    miSpriteGetImage(DrawablePtr pDrawable, int sx, int sy,
@@ -91,10 +90,9 @@ static void	    miSpriteStoreColors(ColormapPtr pMap, int ndef,
 
 static void	    miSpriteComputeSaved(ScreenPtr pScreen);
 
-#define SCREEN_PROLOGUE(pScreen, field)\
-  ((pScreen)->field = \
-   ((miSpriteScreenPtr) (pScreen)->devPrivates[miSpriteScreenIndex].ptr)->field)
-
+#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
+   ((miSpriteScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
+					miSpriteScreenKey))->field)
 #define SCREEN_EPILOGUE(pScreen, field)\
     ((pScreen)->field = miSprite##field)
 
@@ -128,8 +126,8 @@ miSpriteReportDamage (DamagePtr pDamage, RegionPtr pRegion, void *closure)
     ScreenPtr		    pScreen = closure;
     miSpriteScreenPtr	    pScreenPriv;
     
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-    
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     if (pScreenPriv->isUp &&
 	RECT_IN_REGION (pScreen, pRegion, &pScreenPriv->saved) != rgnOUT)
     {
@@ -156,14 +154,6 @@ miSpriteInitialize (pScreen, cursorFuncs, screenFuncs)
     if (!DamageSetup (pScreen))
 	return FALSE;
 
-    if (miSpriteGeneration != serverGeneration)
-    {
-	miSpriteScreenIndex = AllocateScreenPrivateIndex ();
-	if (miSpriteScreenIndex < 0)
-	    return FALSE;
-	miSpriteGeneration = serverGeneration;
-    }
-    
     pScreenPriv = (miSpriteScreenPtr) xalloc (sizeof (miSpriteScreenRec));
     if (!pScreenPriv)
 	return FALSE;
@@ -214,7 +204,7 @@ miSpriteInitialize (pScreen, cursorFuncs, screenFuncs)
     pScreenPriv->colors[MASK_COLOR].red = 0;
     pScreenPriv->colors[MASK_COLOR].green = 0;
     pScreenPriv->colors[MASK_COLOR].blue = 0;
-    pScreen->devPrivates[miSpriteScreenIndex].ptr = (pointer) pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, miSpriteScreenKey, pScreenPriv);
     
     pScreen->CloseScreen = miSpriteCloseScreen;
     pScreen->GetImage = miSpriteGetImage;
@@ -247,8 +237,8 @@ miSpriteCloseScreen (i, pScreen)
 {
     miSpriteScreenPtr   pScreenPriv;
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     pScreen->GetImage = pScreenPriv->GetImage;
     pScreen->GetSpans = pScreenPriv->GetSpans;
@@ -278,8 +268,8 @@ miSpriteGetImage (pDrawable, sx, sy, w, h, format, planemask, pdstLine)
     
     SCREEN_PROLOGUE (pScreen, GetImage);
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     if (pDrawable->type == DRAWABLE_WINDOW &&
         pScreenPriv->isUp &&
 	ORG_OVERLAP(&pScreenPriv->saved,pDrawable->x,pDrawable->y, sx, sy, w, h))
@@ -308,8 +298,8 @@ miSpriteGetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
     
     SCREEN_PROLOGUE (pScreen, GetSpans);
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     if (pDrawable->type == DRAWABLE_WINDOW && pScreenPriv->isUp)
     {
 	DDXPointPtr    	pts;
@@ -350,8 +340,8 @@ miSpriteSourceValidate (pDrawable, x, y, width, height)
     
     SCREEN_PROLOGUE (pScreen, SourceValidate);
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     if (pDrawable->type == DRAWABLE_WINDOW && pScreenPriv->isUp &&
 	ORG_OVERLAP(&pScreenPriv->saved, pDrawable->x, pDrawable->y,
 		    x, y, width, height))
@@ -374,7 +364,8 @@ miSpriteCopyWindow (WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     
     SCREEN_PROLOGUE (pScreen, CopyWindow);
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     /*
      * Damage will take care of destination check
      */
@@ -399,8 +390,8 @@ miSpriteBlockHandler (i, blockData, pTimeout, pReadmask)
     ScreenPtr		pScreen = screenInfo.screens[i];
     miSpriteScreenPtr	pPriv;
 
-    pPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						miSpriteScreenKey);
     SCREEN_PROLOGUE(pScreen, BlockHandler);
     
     (*pScreen->BlockHandler) (i, blockData, pTimeout, pReadmask);
@@ -421,8 +412,8 @@ miSpriteInstallColormap (pMap)
     ScreenPtr		pScreen = pMap->pScreen;
     miSpriteScreenPtr	pPriv;
 
-    pPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						miSpriteScreenKey);
     SCREEN_PROLOGUE(pScreen, InstallColormap);
     
     (*pScreen->InstallColormap) (pMap);
@@ -450,8 +441,8 @@ miSpriteStoreColors (pMap, ndef, pdef)
     int			updated;
     VisualPtr		pVisual;
 
-    pPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
-
+    pPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						miSpriteScreenKey);
     SCREEN_PROLOGUE(pScreen, StoreColors);
     
     (*pScreen->StoreColors) (pMap, ndef, pdef);
@@ -518,7 +509,7 @@ static void
 miSpriteFindColors (ScreenPtr pScreen)
 {
     miSpriteScreenPtr	pScreenPriv = (miSpriteScreenPtr)
-			    pScreen->devPrivates[miSpriteScreenIndex].ptr;
+	dixLookupPrivate(&pScreen->devPrivates, miSpriteScreenKey);
     CursorPtr		pCursor;
     xColorItem		*sourceColor, *maskColor;
 
@@ -562,7 +553,8 @@ miSpriteRealizeCursor (pScreen, pCursor)
 {
     miSpriteScreenPtr	pScreenPriv;
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     if (pCursor == pScreenPriv->pCursor)
 	pScreenPriv->checkPixels = TRUE;
     return (*pScreenPriv->funcs->RealizeCursor) (pScreen, pCursor);
@@ -575,7 +567,8 @@ miSpriteUnrealizeCursor (pScreen, pCursor)
 {
     miSpriteScreenPtr	pScreenPriv;
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     return (*pScreenPriv->funcs->UnrealizeCursor) (pScreen, pCursor);
 }
 
@@ -588,7 +581,8 @@ miSpriteSetCursor (pScreen, pCursor, x, y)
 {
     miSpriteScreenPtr	pScreenPriv;
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     if (!pCursor)
     {
     	pScreenPriv->shouldBeUp = FALSE;
@@ -688,7 +682,8 @@ miSpriteMoveCursor (pScreen, x, y)
 {
     miSpriteScreenPtr	pScreenPriv;
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     miSpriteSetCursor (pScreen, pScreenPriv->pCursor, x, y);
 }
 
@@ -703,7 +698,8 @@ miSpriteRemoveCursor (pScreen)
     miSpriteScreenPtr   pScreenPriv;
 
     DamageDrawInternal (pScreen, TRUE);
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     miSpriteIsUpFALSE (pScreen, pScreenPriv);
     pScreenPriv->pCacheWin = NullWindow;
     if (!(*pScreenPriv->funcs->RestoreUnderCursor) (pScreen,
@@ -732,7 +728,8 @@ miSpriteRestoreCursor (pScreen)
 
     DamageDrawInternal (pScreen, TRUE);
     miSpriteComputeSaved (pScreen);
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     pCursor = pScreenPriv->pCursor;
     x = pScreenPriv->x - (int)pCursor->bits->xhot;
     y = pScreenPriv->y - (int)pCursor->bits->yhot;
@@ -767,7 +764,8 @@ miSpriteComputeSaved (pScreen)
     int		    wpad, hpad;
     CursorPtr	    pCursor;
 
-    pScreenPriv = (miSpriteScreenPtr) pScreen->devPrivates[miSpriteScreenIndex].ptr;
+    pScreenPriv = (miSpriteScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						      miSpriteScreenKey);
     pCursor = pScreenPriv->pCursor;
     x = pScreenPriv->x - (int)pCursor->bits->xhot;
     y = pScreenPriv->y - (int)pCursor->bits->yhot;
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index b03f5e3..df4b121 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -43,13 +43,12 @@
 #define CW_ASSERT(x) do {} while (0)
 #endif
 
-int cwGCIndex;
-int cwScreenIndex;
-int cwWindowIndex;
+DevPrivateKey cwGCKey = &cwGCKey;
+DevPrivateKey cwScreenKey = &cwScreenKey;
+DevPrivateKey cwWindowKey = &cwWindowKey;
 #ifdef RENDER
-int cwPictureIndex;
+DevPrivateKey cwPictureKey = &cwPictureKey;
 #endif
-static unsigned long cwGeneration = 0;
 extern GCOps cwGCOps;
 
 static Bool
@@ -237,7 +236,7 @@ cwValidateGC(GCPtr pGC, unsigned long stateChanges, DrawablePtr pDrawable)
 static void
 cwChangeGC(GCPtr pGC, unsigned long mask)
 {
-    cwGCPtr	pPriv = (cwGCPtr)(pGC)->devPrivates[cwGCIndex].ptr;
+    cwGCPtr pPriv = (cwGCPtr)dixLookupPrivate(&pGC->devPrivates, cwGCKey);
 
     FUNC_PROLOGUE(pGC, pPriv);
 
@@ -249,7 +248,7 @@ cwChangeGC(GCPtr pGC, unsigned long mask)
 static void
 cwCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
 {
-    cwGCPtr	pPriv = (cwGCPtr)(pGCDst)->devPrivates[cwGCIndex].ptr;
+    cwGCPtr pPriv = (cwGCPtr)dixLookupPrivate(&pGCDst->devPrivates, cwGCKey);
 
     FUNC_PROLOGUE(pGCDst, pPriv);
 
@@ -261,7 +260,7 @@ cwCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
 static void
 cwDestroyGC(GCPtr pGC)
 {
-    cwGCPtr	pPriv = (cwGCPtr)(pGC)->devPrivates[cwGCIndex].ptr;
+    cwGCPtr pPriv = (cwGCPtr)dixLookupPrivate(&pGC->devPrivates, cwGCKey);
 
     FUNC_PROLOGUE(pGC, pPriv);
 
@@ -275,7 +274,7 @@ cwDestroyGC(GCPtr pGC)
 static void
 cwChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
 {
-    cwGCPtr	pPriv = (cwGCPtr)(pGC)->devPrivates[cwGCIndex].ptr;
+    cwGCPtr pPriv = (cwGCPtr)dixLookupPrivate(&pGC->devPrivates, cwGCKey);
 
     FUNC_PROLOGUE(pGC, pPriv);
 
@@ -287,7 +286,7 @@ cwChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects)
 static void
 cwCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
 {
-    cwGCPtr	pPriv = (cwGCPtr)(pgcDst)->devPrivates[cwGCIndex].ptr;
+    cwGCPtr pPriv = (cwGCPtr)dixLookupPrivate(&pgcDst->devPrivates, cwGCKey);
 
     FUNC_PROLOGUE(pgcDst, pPriv);
 
@@ -299,7 +298,7 @@ cwCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
 static void
 cwDestroyClip(GCPtr pGC)
 {
-    cwGCPtr	pPriv = (cwGCPtr)(pGC)->devPrivates[cwGCIndex].ptr;
+    cwGCPtr pPriv = (cwGCPtr)dixLookupPrivate(&pGC->devPrivates, cwGCKey);
 
     FUNC_PROLOGUE(pGC, pPriv);
 
@@ -621,34 +620,14 @@ miInitializeCompositeWrapper(ScreenPtr pScreen)
     Bool has_render = GetPictureScreenIfSet(pScreen) != NULL;
 #endif
 
-    if (cwGeneration != serverGeneration)
-    {
-	cwScreenIndex = AllocateScreenPrivateIndex();
-	if (cwScreenIndex < 0)
-	    return;
-	cwGCIndex = AllocateGCPrivateIndex();
-	cwWindowIndex = AllocateWindowPrivateIndex();
-#ifdef RENDER
-	if (has_render)
-	    cwPictureIndex = AllocatePicturePrivateIndex();
-#endif
-	cwGeneration = serverGeneration;
-    }
-    if (!AllocateGCPrivate(pScreen, cwGCIndex, sizeof(cwGCRec)))
-	return;
-    if (!AllocateWindowPrivate(pScreen, cwWindowIndex, 0))
+    if (!dixRequestPrivate(cwGCKey, sizeof(cwGCRec)))
 	return;
-#ifdef RENDER
-    if (has_render) {
-	if (!AllocatePicturePrivate(pScreen, cwPictureIndex, 0))
-	    return;
-    }
-#endif
+
     pScreenPriv = (cwScreenPtr)xalloc(sizeof(cwScreenRec));
     if (!pScreenPriv)
 	return;
 
-    pScreen->devPrivates[cwScreenIndex].ptr = (pointer)pScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, cwScreenKey, pScreenPriv);
     
     SCREEN_EPILOGUE(pScreen, CloseScreen, cwCloseScreen);
     SCREEN_EPILOGUE(pScreen, GetImage, cwGetImage);
@@ -675,8 +654,8 @@ cwCloseScreen (int i, ScreenPtr pScreen)
     PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
 #endif
 
-    pScreenPriv = (cwScreenPtr)pScreen->devPrivates[cwScreenIndex].ptr;
-
+    pScreenPriv = (cwScreenPtr)dixLookupPrivate(&pScreen->devPrivates,
+						cwScreenKey);
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     pScreen->GetImage = pScreenPriv->GetImage;
     pScreen->GetSpans = pScreenPriv->GetSpans;
diff --git a/miext/cw/cw.h b/miext/cw/cw.h
index 0d57b9b..45247d6 100644
--- a/miext/cw/cw.h
+++ b/miext/cw/cw.h
@@ -26,6 +26,7 @@
 
 #include "gcstruct.h"
 #include "picturestr.h"
+#include "privates.h"
 
 /*
  * One of these structures is allocated per GC that gets used with a window with
@@ -43,10 +44,10 @@ typedef struct {
     GCFuncs	    *wrapFuncs;	    /* wrapped funcs */
 } cwGCRec, *cwGCPtr;
 
-extern int cwGCIndex;
+extern DevPrivateKey cwGCKey;
 
-#define getCwGC(pGC)	((cwGCPtr)(pGC)->devPrivates[cwGCIndex].ptr)
-#define setCwGC(pGC,p)	((pGC)->devPrivates[cwGCIndex].ptr = (pointer) (p))
+#define getCwGC(pGC) ((cwGCPtr)dixLookupPrivate(&(pGC)->devPrivates, cwGCKey))
+#define setCwGC(pGC,p) dixSetPrivate(&(pGC)->devPrivates, cwGCKey, p)
 
 /*
  * One of these structures is allocated per Picture that gets used with a
@@ -59,17 +60,17 @@ typedef struct {
     unsigned long   stateChanges;
 } cwPictureRec, *cwPicturePtr;
 
-#define getCwPicture(pPicture)	\
-    (pPicture->pDrawable ? (cwPicturePtr)(pPicture)->devPrivates[cwPictureIndex].ptr : 0)
-#define setCwPicture(pPicture,p) ((pPicture)->devPrivates[cwPictureIndex].ptr = (pointer) (p))
+#define getCwPicture(pPicture) (pPicture->pDrawable ? \
+    (cwPicturePtr)dixLookupPrivate(&(pPicture)->devPrivates, cwPictureKey) : 0)
+#define setCwPicture(pPicture,p) dixSetPrivate(&(pPicture)->devPrivates, cwPictureKey, p)
 
-extern int  cwPictureIndex;
+extern DevPrivateKey cwPictureKey;
+extern DevPrivateKey cwWindowKey;
 
-extern int cwWindowIndex;
-
-#define cwWindowPrivate(pWindow)    ((pWindow)->devPrivates[cwWindowIndex].ptr)
+#define cwWindowPrivate(pWin) dixLookupPrivate(&(pWin)->devPrivates, cwWindowKey)
 #define getCwPixmap(pWindow)	    ((PixmapPtr) cwWindowPrivate(pWindow))
-#define setCwPixmap(pWindow,pPixmap) (cwWindowPrivate(pWindow) = (pointer) (pPixmap))
+#define setCwPixmap(pWindow,pPixmap) \
+    dixSetPrivate(&(pWindow)->devPrivates, cwWindowKey, pPixmap)
 
 #define cwDrawableIsRedirWindow(pDraw)					\
 	((pDraw)->type == DRAWABLE_WINDOW &&				\
@@ -112,10 +113,10 @@ typedef struct {
 #endif
 } cwScreenRec, *cwScreenPtr;
 
-extern int cwScreenIndex;
+extern DevPrivateKey cwScreenKey;
 
-#define getCwScreen(pScreen)	((cwScreenPtr)(pScreen)->devPrivates[cwScreenIndex].ptr)
-#define setCwScreen(pScreen,p)	((cwScreenPtr)(pScreen)->devPrivates[cwScreenIndex].ptr = (p))
+#define getCwScreen(pScreen) ((cwScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, cwScreenKey))
+#define setCwScreen(pScreen,p) dixSetPrivate(&(pScreen)->devPrivates, cwScreenKey, p)
 
 #define CW_OFFSET_XYPOINTS(ppt, npt) do { \
     DDXPointPtr _ppt = (DDXPointPtr)(ppt); \
diff --git a/miext/damage/damage.c b/miext/damage/damage.c
index 65314d8..b7f6fb5 100755
--- a/miext/damage/damage.c
+++ b/miext/damage/damage.c
@@ -65,16 +65,15 @@
 #define DAMAGE_DEBUG(x)
 #endif
 
-#define getPixmapDamageRef(pPixmap) \
-    ((DamagePtr *) &(pPixmap->devPrivates[damagePixPrivateIndex].ptr))
+#define getPixmapDamageRef(pPixmap) ((DamagePtr *) \
+    dixLookupPrivateAddr(&(pPixmap)->devPrivates, damagePixPrivateKey))
 
 #define pixmapDamage(pPixmap)		damagePixPriv(pPixmap)
 
-static int damageScrPrivateIndex;
-static int damagePixPrivateIndex;
-static int damageGCPrivateIndex;
-static int damageWinPrivateIndex;
-static int damageGeneration;
+static DevPrivateKey damageScrPrivateKey = &damageScrPrivateKey;
+static DevPrivateKey damagePixPrivateKey = &damagePixPrivateKey;
+static DevPrivateKey damageGCPrivateKey = &damageGCPrivateKey;
+static DevPrivateKey damageWinPrivateKey = &damageWinPrivateKey;
 
 static DamagePtr *
 getDrawableDamageRef (DrawablePtr pDrawable)
@@ -115,7 +114,7 @@ getDrawableDamageRef (DrawablePtr pDrawable)
 
 #define winDamageRef(pWindow) \
     DamagePtr	*pPrev = (DamagePtr *) \
-	    &(pWindow->devPrivates[damageWinPrivateIndex].ptr)
+	dixLookupPrivateAddr(&(pWindow)->devPrivates, damageWinPrivateKey)
 
 static void
 DamageReportDamage (DamagePtr pDamage, RegionPtr pDamageRegion)
@@ -1779,30 +1778,10 @@ DamageSetup (ScreenPtr pScreen)
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
 
-    if (damageGeneration != serverGeneration)
-    {
-	damageScrPrivateIndex = AllocateScreenPrivateIndex ();
-	if (damageScrPrivateIndex == -1)
-	    return FALSE;
-	damageGCPrivateIndex = AllocateGCPrivateIndex ();
-	if (damageGCPrivateIndex == -1)
-	    return FALSE;
-	damagePixPrivateIndex = AllocatePixmapPrivateIndex ();
-	if (damagePixPrivateIndex == -1)
-	    return FALSE;
-	damageWinPrivateIndex = AllocateWindowPrivateIndex ();
-	if (damageWinPrivateIndex == -1)
-	    return FALSE;
-	damageGeneration = serverGeneration;
-    }
-    if (pScreen->devPrivates[damageScrPrivateIndex].ptr)
+    if (dixLookupPrivate(&pScreen->devPrivates, damageScrPrivateKey))
 	return TRUE;
 
-    if (!AllocateGCPrivate (pScreen, damageGCPrivateIndex, sizeof (DamageGCPrivRec)))
-	return FALSE;
-    if (!AllocatePixmapPrivate (pScreen, damagePixPrivateIndex, 0))
-	return FALSE;
-    if (!AllocateWindowPrivate (pScreen, damageWinPrivateIndex, 0))
+    if (!dixRequestPrivate(damageGCPrivateKey, sizeof(DamageGCPrivRec)))
 	return FALSE;
 
     pScrPriv = (DamageScrPrivPtr) xalloc (sizeof (DamageScrPrivRec));
@@ -1827,7 +1806,7 @@ DamageSetup (ScreenPtr pScreen)
     }
 #endif
 
-    pScreen->devPrivates[damageScrPrivateIndex].ptr = (pointer) pScrPriv;
+    dixSetPrivate(&pScreen->devPrivates, damageScrPrivateKey, pScrPriv);
     return TRUE;
 }
 
diff --git a/miext/damage/damagestr.h b/miext/damage/damagestr.h
index 1e0efad..9f3dd66 100755
--- a/miext/damage/damagestr.h
+++ b/miext/damage/damagestr.h
@@ -29,6 +29,7 @@
 
 #include "damage.h"
 #include "gcstruct.h"
+#include "privates.h"
 #ifdef RENDER
 # include "picturestr.h"
 #endif
@@ -80,31 +81,31 @@ typedef struct _damageGCPriv {
 } DamageGCPrivRec, *DamageGCPrivPtr;
 
 /* XXX should move these into damage.c, damageScrPrivateIndex is static */
-#define damageGetScrPriv(pScr) \
-    ((DamageScrPrivPtr) (pScr)->devPrivates[damageScrPrivateIndex].ptr)
+#define damageGetScrPriv(pScr) ((DamageScrPrivPtr) \
+    dixLookupPrivate(&(pScr)->devPrivates, damageScrPrivateKey))
 
 #define damageScrPriv(pScr) \
     DamageScrPrivPtr    pScrPriv = damageGetScrPriv(pScr)
 
 #define damageGetPixPriv(pPix) \
-    ((DamagePtr) (pPix)->devPrivates[damagePixPrivateIndex].ptr)
+    dixLookupPrivate(&(pPix)->devPrivates, damagePixPrivateKey)
 
 #define damgeSetPixPriv(pPix,v) \
-    ((pPix)->devPrivates[damagePixPrivateIndex].ptr = (pointer ) (v))
+    dixSetPrivate(&(pPix)->devPrivates, damagePixPrivateKey, v)
 
 #define damagePixPriv(pPix) \
     DamagePtr	    pDamage = damageGetPixPriv(pPix)
 
 #define damageGetGCPriv(pGC) \
-    ((DamageGCPrivPtr) (pGC)->devPrivates[damageGCPrivateIndex].ptr)
+    dixLookupPrivate(&(pGC)->devPrivates, damageGCPrivateKey)
 
 #define damageGCPriv(pGC) \
     DamageGCPrivPtr  pGCPriv = damageGetGCPriv(pGC)
 
 #define damageGetWinPriv(pWin) \
-    ((DamagePtr) (pWin)->devPrivates[damageWinPrivateIndex].ptr)
+    ((DamagePtr)dixLookupPrivate(&(pWin)->devPrivates, damageWinPrivateKey))
 
 #define damageSetWinPriv(pWin,d) \
-    ((pWin)->devPrivates[damageWinPrivateIndex].ptr = (d))
+    dixSetPrivate(&(pWin)->devPrivates, damageWinPrivateKey, d)
 
 #endif /* _DAMAGESTR_H_ */
diff --git a/miext/rootless/accel/rlAccel.c b/miext/rootless/accel/rlAccel.c
index d62bee7..a144124 100644
--- a/miext/rootless/accel/rlAccel.c
+++ b/miext/rootless/accel/rlAccel.c
@@ -46,10 +46,10 @@ typedef struct _rlAccelScreenRec {
     CloseScreenProcPtr CloseScreen;
 } rlAccelScreenRec, *rlAccelScreenPtr;
 
-static int rlAccelScreenPrivateIndex = -1;
+static DevPrivateKey rlAccelScreenPrivateKey = &rlAccelScreenPrivateKey;
 
-#define RLACCELREC(pScreen) \
-   ((rlAccelScreenRec *)(pScreen)->devPrivates[rlAccelScreenPrivateIndex].ptr)
+#define RLACCELREC(pScreen) ((rlAccelScreenRec *) \
+    dixLookupPrivate(&(pScreen)->devPrivates, rlAccelScreenPrivateKey))
 
 /* This is mostly identical to fbGCOps. */
 static GCOps rlAccelOps = {
@@ -128,15 +128,8 @@ rlCloseScreen (int iScreen, ScreenPtr pScreen)
 Bool
 RootlessAccelInit(ScreenPtr pScreen)
 {
-    static unsigned long rlAccelGeneration = 0;
     rlAccelScreenRec *s;
 
-    if (rlAccelGeneration != serverGeneration) {
-        rlAccelScreenPrivateIndex = AllocateScreenPrivateIndex();
-        if (rlAccelScreenPrivateIndex == -1) return FALSE;
-        rlAccelGeneration = serverGeneration;
-    }
-
     s = xalloc(sizeof(rlAccelScreenRec));
     if (!s) return FALSE;
     RLACCELREC(pScreen) = s;
diff --git a/miext/rootless/rootlessCommon.h b/miext/rootless/rootlessCommon.h
index 3bf6af0..5ebe35e 100644
--- a/miext/rootless/rootlessCommon.h
+++ b/miext/rootless/rootlessCommon.h
@@ -52,9 +52,9 @@
 
 
 // Global variables
-extern int rootlessGCPrivateIndex;
-extern int rootlessScreenPrivateIndex;
-extern int rootlessWindowPrivateIndex;
+extern DevPrivateKey rootlessGCPrivateKey;
+extern DevPrivateKey rootlessScreenPrivateKey;
+extern DevPrivateKey rootlessWindowPrivateKey;
 
 
 // RootlessGCRec: private per-gc data
@@ -133,12 +133,17 @@ typedef struct _RootlessScreenRec {
 
 // Accessors for screen and window privates
 
-#define SCREENREC(pScreen) \
-   ((RootlessScreenRec *)(pScreen)->devPrivates[rootlessScreenPrivateIndex].ptr)
+#define SCREENREC(pScreen) ((RootlessScreenRec *) \
+    dixLookupPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey))
 
-#define WINREC(pWin) \
-    ((RootlessWindowRec *)(pWin)->devPrivates[rootlessWindowPrivateIndex].ptr)
+#define SETSCREENREC(pScreen, v) \
+    dixSetPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey, v)
 
+#define WINREC(pWin) ((RootlessWindowRec *) \
+    dixLookupPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey))
+
+#define SETWINREC(pWin, v) \
+    dixSetPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey, v)
 
 // Call a rootless implementation function.
 // Many rootless implementation functions are allowed to be NULL.
diff --git a/miext/rootless/rootlessGC.c b/miext/rootless/rootlessGC.c
index b26f52c..bf129ea 100644
--- a/miext/rootless/rootlessGC.c
+++ b/miext/rootless/rootlessGC.c
@@ -276,11 +276,11 @@ RootlessCreateGC(GCPtr pGC)
     Bool result;
 
     SCREEN_UNWRAP(pGC->pScreen, CreateGC);
-    s = (RootlessScreenRec *) pGC->pScreen->
-            devPrivates[rootlessScreenPrivateIndex].ptr;
+    s = SCREENREC(pGC->pScreen);
     result = s->CreateGC(pGC);
 
-    gcrec = (RootlessGCRec *) pGC->devPrivates[rootlessGCPrivateIndex].ptr;
+    gcrec = (RootlessGCRec *)
+	dixLookupPrivate(&pGC->devPrivates, rootlessGCPrivateKey);
     gcrec->originalOps = NULL; // don't wrap ops yet
     gcrec->originalFuncs = pGC->funcs;
     pGC->funcs = &rootlessGCFuncs;
@@ -302,7 +302,7 @@ RootlessCreateGC(GCPtr pGC)
 // does not assume ops have been wrapped
 #define GCFUNC_UNWRAP(pGC) \
     RootlessGCRec *gcrec = (RootlessGCRec *) \
-        (pGC)->devPrivates[rootlessGCPrivateIndex].ptr; \
+	dixLookupPrivate(&(pGC)->devPrivates, rootlessGCPrivateKey); \
     (pGC)->funcs = gcrec->originalFuncs; \
     if (gcrec->originalOps) { \
         (pGC)->ops = gcrec->originalOps; \
@@ -399,7 +399,7 @@ static void RootlessCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
 // assumes both funcs and ops are wrapped
 #define GCOP_UNWRAP(pGC) \
     RootlessGCRec *gcrec = (RootlessGCRec *) \
-        (pGC)->devPrivates[rootlessGCPrivateIndex].ptr; \
+        dixLookupPrivate(&(pGC)->devPrivates, rootlessGCPrivateKey); \
     GCFuncs *saveFuncs = pGC->funcs; \
     (pGC)->funcs = gcrec->originalFuncs; \
     (pGC)->ops = gcrec->originalOps;
diff --git a/miext/rootless/rootlessScreen.c b/miext/rootless/rootlessScreen.c
index 700de6e..f647893 100644
--- a/miext/rootless/rootlessScreen.c
+++ b/miext/rootless/rootlessScreen.c
@@ -61,9 +61,9 @@ extern int RootlessMiValidateTree(WindowPtr pRoot, WindowPtr pChild,
 extern Bool RootlessCreateGC(GCPtr pGC);
 
 // Initialize globals
-int rootlessGCPrivateIndex = -1;
-int rootlessScreenPrivateIndex = -1;
-int rootlessWindowPrivateIndex = -1;
+DevPrivateKey rootlessGCPrivateKey = &rootlessGCPrivateKey;
+DevPrivateKey rootlessScreenPrivateKey = &rootlessScreenPrivateKey;
+DevPrivateKey rootlessWindowPrivateKey = &rootlessWindowPrivateKey;
 
 
 /*
@@ -547,28 +547,14 @@ static Bool
 RootlessAllocatePrivates(ScreenPtr pScreen)
 {
     RootlessScreenRec *s;
-    static unsigned long rootlessGeneration = 0;
-
-    if (rootlessGeneration != serverGeneration) {
-        rootlessScreenPrivateIndex = AllocateScreenPrivateIndex();
-        if (rootlessScreenPrivateIndex == -1) return FALSE;
-        rootlessGCPrivateIndex = AllocateGCPrivateIndex();
-        if (rootlessGCPrivateIndex == -1) return FALSE;
-        rootlessWindowPrivateIndex = AllocateWindowPrivateIndex();
-        if (rootlessWindowPrivateIndex == -1) return FALSE;
-        rootlessGeneration = serverGeneration;
-    }
 
     // no allocation needed for screen privates
-    if (!AllocateGCPrivate(pScreen, rootlessGCPrivateIndex,
-                           sizeof(RootlessGCRec)))
-        return FALSE;
-    if (!AllocateWindowPrivate(pScreen, rootlessWindowPrivateIndex, 0))
+    if (!dixRequestPrivate(rootlessGCPrivateKey, sizeof(RootlessGCRec)))
         return FALSE;
 
     s = xalloc(sizeof(RootlessScreenRec));
     if (! s) return FALSE;
-    SCREENREC(pScreen) = s;
+    SETSCREENREC(pScreen, s);
 
     s->pixmap_data = NULL;
     s->pixmap_data_size = 0;
@@ -583,8 +569,7 @@ RootlessAllocatePrivates(ScreenPtr pScreen)
 static void
 RootlessWrap(ScreenPtr pScreen)
 {
-    RootlessScreenRec *s = (RootlessScreenRec*)
-            pScreen->devPrivates[rootlessScreenPrivateIndex].ptr;
+    RootlessScreenRec *s = SCREENREC(pScreen);
 
 #define WRAP(a) \
     if (pScreen->a) { \
@@ -650,8 +635,7 @@ Bool RootlessInit(ScreenPtr pScreen, RootlessFrameProcsPtr procs)
     if (!RootlessAllocatePrivates(pScreen))
         return FALSE;
 
-    s = (RootlessScreenRec*)
-        pScreen->devPrivates[rootlessScreenPrivateIndex].ptr;
+    s = SCREENREC(pScreen);
 
     s->imp = procs;
 
diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c
index 30b7daa..687748c 100644
--- a/miext/rootless/rootlessWindow.c
+++ b/miext/rootless/rootlessWindow.c
@@ -66,7 +66,7 @@ RootlessCreateWindow(WindowPtr pWin)
     Bool result;
     RegionRec saveRoot;
 
-    WINREC(pWin) = NULL;
+    SETWINREC(pWin, NULL);
 
     SCREEN_UNWRAP(pWin->drawable.pScreen, CreateWindow);
 
@@ -107,7 +107,7 @@ RootlessDestroyFrame(WindowPtr pWin, RootlessWindowPtr winRec)
 #endif
 
     xfree(winRec);
-    WINREC(pWin) = NULL;
+    SETWINREC(pWin, NULL);
 }
 
 
@@ -353,7 +353,7 @@ RootlessEnsureFrame(WindowPtr pWin)
     winRec->pixmap = NULL;
     winRec->wid = NULL;
 
-    WINREC(pWin) = winRec;
+    SETWINREC(pWin, winRec);
 
 #ifdef SHAPE
     // Set the frame's shape if the window is shaped
@@ -370,7 +370,7 @@ RootlessEnsureFrame(WindowPtr pWin)
     {
         RL_DEBUG_MSG("implementation failed to create frame!\n");
         xfree(winRec);
-        WINREC(pWin) = NULL;
+        SETWINREC(pWin, NULL);
         return NULL;
     }
 
@@ -1298,8 +1298,8 @@ RootlessReparentWindow(WindowPtr pWin, WindowPtr pPriorParent)
 
         /* Switch the frame record from one to the other. */
 
-        WINREC(pWin) = NULL;
-        WINREC(pTopWin) = winRec;
+        SETWINREC(pWin, NULL);
+        SETWINREC(pTopWin, winRec);
 
         RootlessInitializeFrame(pTopWin, winRec);
         RootlessReshapeFrame(pTopWin);
diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index f624216..74544b1 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -36,8 +36,7 @@
 #include    "gcstruct.h"
 #include    "shadow.h"
 
-int shadowScrPrivateIndex;
-int shadowGeneration;
+DevPrivateKey shadowScrPrivateKey = &shadowScrPrivateKey;
 
 #define wrap(priv, real, mem) {\
     priv->mem = real->mem; \
@@ -116,7 +115,8 @@ static void
 shadowReportFunc(DamagePtr pDamage, RegionPtr pRegion, void *closure)
 {
     ScreenPtr pScreen = closure;
-    shadowBufPtr pBuf = pScreen->devPrivates[shadowScrPrivateIndex].ptr;
+    shadowBufPtr pBuf = (shadowBufPtr)
+	dixLookupPrivate(&pScreen->devPrivates, shadowScrPrivateKey);
 
     /* Register the damaged region, use DamageReportNone below when we
      * want to break BC below... */
@@ -138,13 +138,6 @@ shadowSetup(ScreenPtr pScreen)
     if (!DamageSetup(pScreen))
 	return FALSE;
 
-    if (shadowGeneration != serverGeneration) {
-	shadowScrPrivateIndex = AllocateScreenPrivateIndex();
-	if (shadowScrPrivateIndex == -1)
-	    return FALSE;
-	shadowGeneration = serverGeneration;
-    }
-
     pBuf = (shadowBufPtr) xalloc(sizeof(shadowBufRec));
     if (!pBuf)
 	return FALSE;
@@ -175,7 +168,7 @@ shadowSetup(ScreenPtr pScreen)
     REGION_NULL(pScreen, &pBuf->damage); /* bc */
 #endif
 
-    pScreen->devPrivates[shadowScrPrivateIndex].ptr = (pointer) pBuf;
+    dixSetPrivate(&pScreen->devPrivates, shadowScrPrivateKey, pBuf);
     return TRUE;
 }
 
diff --git a/miext/shadow/shadow.h b/miext/shadow/shadow.h
index 8986809..2e45df2 100644
--- a/miext/shadow/shadow.h
+++ b/miext/shadow/shadow.h
@@ -74,9 +74,10 @@ typedef struct _shadowBuf {
 #define SHADOW_REFLECT_Y    32
 #define SHADOW_REFLECT_ALL  (SHADOW_REFLECT_X|SHADOW_REFLECT_Y)
 
-extern int shadowScrPrivateIndex;
+extern DevPrivateKey shadowScrPrivateKey;
 
-#define shadowGetBuf(pScr)  ((shadowBufPtr) (pScr)->devPrivates[shadowScrPrivateIndex].ptr)
+#define shadowGetBuf(pScr) ((shadowBufPtr) \
+    dixLookupPrivate(&(pScr)->devPrivates, shadowScrPrivateKey))
 #define shadowBuf(pScr)            shadowBufPtr pBuf = shadowGetBuf(pScr)
 #define shadowDamage(pBuf)  DamageRegion(pBuf->pDamage)    
 
diff --git a/randr/randr.c b/randr/randr.c
index 958f9c1..bc2b995 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -56,9 +56,9 @@ static int SProcRRDispatch (ClientPtr pClient);
 int	RREventBase;
 int	RRErrorBase;
 RESTYPE RRClientType, RREventType; /* resource types for event masks */
-int	RRClientPrivateIndex;
+DevPrivateKey RRClientPrivateKey = &RRClientPrivateKey;
 
-int	rrPrivIndex = -1;
+DevPrivateKey rrPrivKey = &rrPrivKey;
 
 static void
 RRClientCallback (CallbackListPtr	*list,
@@ -214,8 +214,6 @@ Bool RRInit (void)
     return TRUE;
 }
 
-static int RRScreenGeneration;
-
 Bool RRScreenInit(ScreenPtr pScreen)
 {
     rrScrPrivPtr   pScrPriv;
@@ -223,13 +221,6 @@ Bool RRScreenInit(ScreenPtr pScreen)
     if (!RRInit ())
 	return FALSE;
 
-    if (RRScreenGeneration != serverGeneration)
-    {
-	if ((rrPrivIndex = AllocateScreenPrivateIndex()) < 0)
-	    return FALSE;
-	RRScreenGeneration = serverGeneration;
-    }
-
     pScrPriv = (rrScrPrivPtr) xcalloc (1, sizeof (rrScrPrivRec));
     if (!pScrPriv)
 	return FALSE;
@@ -333,8 +324,7 @@ RRExtensionInit (void)
 
     if (RRNScreens == 0) return;
 
-    RRClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (RRClientPrivateIndex,
+    if (!dixRequestPrivate(RRClientPrivateKey,
 				sizeof (RRClientRec) +
 				screenInfo.numScreens * sizeof (RRTimesRec)))
 	return;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index bd19fe9..e8358bc 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -262,11 +262,11 @@ typedef struct _rrScrPriv {
 #endif
 } rrScrPrivRec, *rrScrPrivPtr;
 
-extern int rrPrivIndex;
+extern DevPrivateKey rrPrivKey;
 
-#define rrGetScrPriv(pScr)  ((rrScrPrivPtr) (pScr)->devPrivates[rrPrivIndex].ptr)
+#define rrGetScrPriv(pScr)  ((rrScrPrivPtr)dixLookupPrivate(&(pScr)->devPrivates, rrPrivKey))
 #define rrScrPriv(pScr)	rrScrPrivPtr    pScrPriv = rrGetScrPriv(pScr)
-#define SetRRScreen(s,p) ((s)->devPrivates[rrPrivIndex].ptr = (pointer) (p))
+#define SetRRScreen(s,p) dixSetPrivate(&(s)->devPrivates, rrPrivKey, p)
 
 /*
  * each window has a list of clients requesting
@@ -298,7 +298,7 @@ typedef struct _RRClient {
 } RRClientRec, *RRClientPtr;
 
 extern RESTYPE	RRClientType, RREventType; /* resource types for event masks */
-extern int	RRClientPrivateIndex;
+extern DevPrivateKey RRClientPrivateKey;
 extern RESTYPE	RRCrtcType, RRModeType, RROutputType;
 
 #define LookupOutput(client,id,a) ((RROutputPtr) \
@@ -311,7 +311,7 @@ extern RESTYPE	RRCrtcType, RRModeType, RROutputType;
 				 (SecurityLookupIDByType (client, id, \
 							  RRModeType, a)))
 
-#define GetRRClient(pClient)    ((RRClientPtr) (pClient)->devPrivates[RRClientPrivateIndex].ptr)
+#define GetRRClient(pClient)    ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey))
 #define rrClientPriv(pClient)	RRClientPtr pRRClient = GetRRClient(pClient)
 
 /* Initialize the extension */
diff --git a/record/record.c b/record/record.c
index 0ed8f84..2e65e67 100644
--- a/record/record.c
+++ b/record/record.c
@@ -164,13 +164,13 @@ typedef struct {
     ProcFunctionPtr recordVector[256]; 
 } RecordClientPrivateRec, *RecordClientPrivatePtr;
 
-static int RecordClientPrivateIndex;
+static DevPrivateKey RecordClientPrivateKey = &RecordClientPrivateKey;
 
 /*  RecordClientPrivatePtr RecordClientPrivate(ClientPtr)
  *  gets the client private of the given client.  Syntactic sugar.
  */
 #define RecordClientPrivate(_pClient) (RecordClientPrivatePtr) \
-    ((_pClient)->devPrivates[RecordClientPrivateIndex].ptr)
+    dixLookupPrivate(&(_pClient)->devPrivates, RecordClientPrivateKey)
 
 
 /***************************************************************************/
@@ -982,8 +982,8 @@ RecordInstallHooks(RecordClientsAndProtocolPtr pRCAP, XID oneclient)
 		    memcpy(pClientPriv->recordVector, pClient->requestVector, 
 			   sizeof (pClientPriv->recordVector));
 		    pClientPriv->originalVector = pClient->requestVector;
-		    pClient->devPrivates[RecordClientPrivateIndex].ptr =
-			(pointer)pClientPriv;
+		    dixSetPrivate(&pClient->devPrivates,
+				  RecordClientPrivateKey, pClientPriv);
 		    pClient->requestVector = pClientPriv->recordVector;
 		}
 		while ((pIter = RecordIterateSet(pRCAP->pRequestMajorOpSet,
@@ -1096,7 +1096,8 @@ RecordUninstallHooks(RecordClientsAndProtocolPtr pRCAP, XID oneclient)
 		if (!otherRCAPwantsProcVector)
 		{ /* nobody needs it, so free it */
 		    pClient->requestVector = pClientPriv->originalVector;
-		    pClient->devPrivates[RecordClientPrivateIndex].ptr = NULL;
+		    dixSetPrivate(&pClient->devPrivates,
+				  RecordClientPrivateKey, NULL);
 		    xfree(pClientPriv);
 		}
 	    } /* end if this RCAP specifies any requests */
@@ -2948,10 +2949,6 @@ RecordExtensionInit(void)
     if (!RTContext)
 	return;
 
-    RecordClientPrivateIndex = AllocateClientPrivateIndex();
-    if (!AllocateClientPrivate(RecordClientPrivateIndex, 0))
-	return;
-
     ppAllContexts = NULL;
     numContexts = numEnabledContexts = numEnabledRCAPs = 0;
 
diff --git a/render/animcur.c b/render/animcur.c
index 1f25e79..444d706 100644
--- a/render/animcur.c
+++ b/render/animcur.c
@@ -87,14 +87,14 @@ static CursorBits   animCursorBits = {
     empty, empty, 2, 1, 1, 0, 0, 1
 };
 
-static int AnimCurScreenPrivateIndex = -1;
 static int AnimCurGeneration;
+static DevPrivateKey AnimCurScreenPrivateKey = &AnimCurScreenPrivateKey;
 
 #define IsAnimCur(c)	    ((c)->bits == &animCursorBits)
 #define GetAnimCur(c)	    ((AnimCurPtr) ((c) + 1))
-#define GetAnimCurScreen(s) ((AnimCurScreenPtr) ((s)->devPrivates[AnimCurScreenPrivateIndex].ptr))
-#define GetAnimCurScreenIfSet(s) ((AnimCurScreenPrivateIndex != -1) ? GetAnimCurScreen(s) : NULL)
-#define SetAnimCurScreen(s,p) ((s)->devPrivates[AnimCurScreenPrivateIndex].ptr = (pointer) (p))
+#define GetAnimCurScreen(s) ((AnimCurScreenPtr)dixLookupPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey))
+#define GetAnimCurScreenIfSet(s) GetAnimCurScreen(s)
+#define SetAnimCurScreen(s,p) dixSetPrivate(&(s)->devPrivates, AnimCurScreenPrivateKey, p)
 
 #define Wrap(as,s,elt,func) (((as)->elt = (s)->elt), (s)->elt = func)
 #define Unwrap(as,s,elt)    ((s)->elt = (as)->elt)
@@ -128,8 +128,6 @@ AnimCurCloseScreen (int index, ScreenPtr pScreen)
     SetAnimCurScreen(pScreen,0);
     ret = (*pScreen->CloseScreen) (index, pScreen);
     xfree (as);
-    if (index == 0)
-	AnimCurScreenPrivateIndex = -1;
     return ret;
 }
 
@@ -324,9 +322,6 @@ AnimCurInit (ScreenPtr pScreen)
 
     if (AnimCurGeneration != serverGeneration)
     {
-	AnimCurScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (AnimCurScreenPrivateIndex < 0)
-	    return FALSE;
 	AnimCurGeneration = serverGeneration;
 	animCurState.pCursor = 0;
 	animCurState.pScreen = 0;
diff --git a/render/glyph.c b/render/glyph.c
index 583a52b..cb1534d 100644
--- a/render/glyph.c
+++ b/render/glyph.c
@@ -81,220 +81,18 @@ static const CARD8	glyphDepths[GlyphFormatNum] = { 1, 4, 8, 16, 32 };
 
 static GlyphHashRec	globalGlyphs[GlyphFormatNum];
 
-static int	globalTotalGlyphPrivateSize = 0;
-
-static int	glyphPrivateCount = 0;
-
-void
-ResetGlyphPrivates (void)
-{
-    glyphPrivateCount = 0;
-}
-
-int
-AllocateGlyphPrivateIndex (void)
-{
-    return glyphPrivateCount++;
-}
-
-Bool
-AllocateGlyphPrivate (ScreenPtr pScreen,
-		      int	index2,
-		      unsigned	amount)
-{
-    PictureScreenPtr ps;
-    unsigned	     oldamount;
-
-    ps = GetPictureScreenIfSet (pScreen);
-    if (!ps)
-	return FALSE;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof (DevUnion) - 1)) / sizeof (DevUnion)) *
-	sizeof (DevUnion);
-
-    if (index2 >= ps->glyphPrivateLen)
-    {
-	unsigned *nsizes;
-	nsizes = (unsigned *) xrealloc (ps->glyphPrivateSizes,
-					(index2 + 1) * sizeof (unsigned));
-	if (!nsizes)
-	    return FALSE;
-	
-	while (ps->glyphPrivateLen <= index2)
-	{
-	    nsizes[ps->glyphPrivateLen++] = 0;
-	    ps->totalGlyphPrivateSize += sizeof (DevUnion);
-	}
-	ps->glyphPrivateSizes = nsizes;
-    }
-    oldamount = ps->glyphPrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	ps->glyphPrivateSizes[index2] = amount;
-	ps->totalGlyphPrivateSize += (amount - oldamount);
-    }
-    ps->totalGlyphPrivateSize = BitmapBytePad (ps->totalGlyphPrivateSize * 8);
-    
-    return TRUE;
-}
-
 static void
-SetGlyphScreenPrivateOffsets (void)
+FreeGlyphPrivates (GlyphPtr glyph)
 {
-    PictureScreenPtr ps;
-    int		     offset = 0;
-    int		     i;
+    ScreenPtr pScreen;
+    int i;
 
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
-	if (ps && ps->totalGlyphPrivateSize)
-	{
-	    ps->glyphPrivateOffset = offset;
-	    offset += ps->totalGlyphPrivateSize / sizeof (DevUnion);
-	}
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	pScreen = screenInfo.screens[i];
+	dixFreePrivates(*GetGlyphPrivatesForScreen(glyph, pScreen));
     }
-}
 
-static void
-SetGlyphPrivatePointers (GlyphPtr glyph)
-{
-    PictureScreenPtr ps;
-    int		     i;
-    char	     *ptr;
-    DevUnion         *ppriv;
-    unsigned         *sizes;
-    unsigned         size;
-    int		     len;
-
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
-	if (ps && ps->totalGlyphPrivateSize)
-	{
-	    ppriv = glyph->devPrivates + ps->glyphPrivateOffset;
-	    sizes = ps->glyphPrivateSizes;
-	    ptr = (char *) (ppriv + ps->glyphPrivateLen);
-	    for (len = ps->glyphPrivateLen; --len >= 0; ppriv++, sizes++)
-	    {
-		if ((size = *sizes) != 0)
-		{
-		    ppriv->ptr = (pointer) ptr;
-		    ptr += size;
-		}
-		else
-		    ppriv->ptr = (pointer) 0;
-	    }
-	}
-    }
-}
-
-static Bool
-ReallocGlobalGlyphPrivate (GlyphPtr glyph)
-{
-    PictureScreenPtr ps;
-    DevUnion         *devPrivates;
-    char	     *ptr;
-    int		     i;
-
-    devPrivates = xalloc (globalTotalGlyphPrivateSize);
-    if (!devPrivates)
-	return FALSE;
-
-    ptr = (char *) devPrivates;
-    for (i = 0; i < screenInfo.numScreens; i++)
-    {
-	ps = GetPictureScreenIfSet (screenInfo.screens[i]);
-	if (ps && ps->totalGlyphPrivateSize)
-	{
-	    if (ps->glyphPrivateOffset != -1)
-	    {
-		memcpy (ptr, glyph->devPrivates + ps->glyphPrivateOffset,
-			ps->totalGlyphPrivateSize);
-	    }
-	    else if (ps->totalGlyphPrivateSize)
-	    {
-		memset (ptr, 0, ps->totalGlyphPrivateSize);
-	    }
-	    
-	    ptr += ps->totalGlyphPrivateSize;
-	}
-    }
-
-    if (glyph->devPrivates)
-	xfree (glyph->devPrivates);
-    
-    glyph->devPrivates = devPrivates;
-
-    return TRUE;
-}
-
-Bool
-GlyphInit (ScreenPtr pScreen)
-{
-    PictureScreenPtr ps = GetPictureScreen (pScreen);
-    
-    ps->totalGlyphPrivateSize = 0;
-    ps->glyphPrivateSizes = 0;
-    ps->glyphPrivateLen = 0;
-    ps->glyphPrivateOffset = -1;
-    
-    return TRUE;
-}
-
-Bool
-GlyphFinishInit (ScreenPtr pScreen)
-{
-    PictureScreenPtr ps = GetPictureScreen (pScreen);
-
-    if (ps->totalGlyphPrivateSize)
-    {
-	GlyphPtr glyph;
-	int	 fdepth, i;
-	
-	globalTotalGlyphPrivateSize += ps->totalGlyphPrivateSize;
-	
-	for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
-	{
-	    if (!globalGlyphs[fdepth].hashSet)
-		continue;
-		
-	    for (i = 0; i < globalGlyphs[fdepth].hashSet->size; i++)
-	    {
-		glyph = globalGlyphs[fdepth].table[i].glyph;
-		if (glyph && glyph != DeletedGlyph)
-		{
-		    if (!ReallocGlobalGlyphPrivate (glyph))
-			return FALSE;
-		}
-	    }
-	}
-
-	SetGlyphScreenPrivateOffsets ();
-
-	for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
-	{
-	    if (!globalGlyphs[fdepth].hashSet)
-		continue;
-		
-	    for (i = 0; i < globalGlyphs[fdepth].hashSet->size; i++)
-	    {
-		glyph = globalGlyphs[fdepth].table[i].glyph;
-		if (glyph && glyph != DeletedGlyph)
-		{
-		    SetGlyphPrivatePointers (glyph);
-			
-		    if (!(*ps->RealizeGlyph) (pScreen, glyph))
-			return FALSE;
-		}
-	    }
-	}
-    }
-    else
-	ps->glyphPrivateOffset = 0;
-    
-    return TRUE;
+    dixFreePrivates(glyph->devPrivates);
 }
 
 void
@@ -304,8 +102,6 @@ GlyphUninit (ScreenPtr pScreen)
     GlyphPtr	     glyph;
     int		     fdepth, i;
 
-    globalTotalGlyphPrivateSize -= ps->totalGlyphPrivateSize;
-
     for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
     {
 	if (!globalGlyphs[fdepth].hashSet)
@@ -317,43 +113,20 @@ GlyphUninit (ScreenPtr pScreen)
 	    if (glyph && glyph != DeletedGlyph)
 	    {
 		(*ps->UnrealizeGlyph) (pScreen, glyph);
-		
-		if (globalTotalGlyphPrivateSize)
-		{
-		    if (!ReallocGlobalGlyphPrivate (glyph))
-			return;
-		}
-		else
-		{
-		    if (glyph->devPrivates)
-			xfree (glyph->devPrivates);
-		    glyph->devPrivates = NULL;
-		}
+		FreeGlyphPrivates(glyph);
+		glyph->devPrivates = NULL;
 	    }
 	}
     }
 
-    if (globalTotalGlyphPrivateSize)
-	SetGlyphScreenPrivateOffsets ();
-
     for (fdepth = 0; fdepth < GlyphFormatNum; fdepth++)
     {
 	if (!globalGlyphs[fdepth].hashSet)
 	    continue;
 	
 	for (i = 0; i < globalGlyphs[fdepth].hashSet->size; i++)
-	{
 	    glyph = globalGlyphs[fdepth].table[i].glyph;    
-	    if (glyph && glyph != DeletedGlyph)
-	    {
-		if (globalTotalGlyphPrivateSize)
-		    SetGlyphPrivatePointers (glyph);
-	    }
-	}
     }
-
-    if (ps->glyphPrivateSizes)
-	xfree (ps->glyphPrivateSizes);
 }
 
 GlyphHashSetPtr
@@ -367,50 +140,6 @@ FindGlyphHashSet (CARD32 filled)
     return 0;
 }
 
-static int _GlyphSetPrivateAllocateIndex = 0;
-
-int
-AllocateGlyphSetPrivateIndex (void)
-{
-    return _GlyphSetPrivateAllocateIndex++;
-}
-
-void
-ResetGlyphSetPrivateIndex (void)
-{
-    _GlyphSetPrivateAllocateIndex = 0;
-}
-
-Bool
-_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr)
-{
-    pointer *new;
-
-    if (n > glyphSet->maxPrivate) {
-	if (glyphSet->devPrivates &&
-	    glyphSet->devPrivates != (pointer)(&glyphSet[1])) {
-	    new = (pointer *) xrealloc (glyphSet->devPrivates,
-					(n + 1) * sizeof (pointer));
-	    if (!new)
-		return FALSE;
-	} else {
-	    new = (pointer *) xalloc ((n + 1) * sizeof (pointer));
-	    if (!new)
-		return FALSE;
-	    if (glyphSet->devPrivates)
-		memcpy (new,
-			glyphSet->devPrivates,
-			(glyphSet->maxPrivate + 1) * sizeof (pointer));
-	}
-	glyphSet->devPrivates = new;
-	/* Zero out new, uninitialize privates */
-	while (++glyphSet->maxPrivate < n)
-	    glyphSet->devPrivates[glyphSet->maxPrivate] = (pointer)0;
-    }
-    glyphSet->devPrivates[n] = ptr;
-    return TRUE;
-}
-
 GlyphRefPtr
 FindGlyphRef (GlyphHashPtr hash, CARD32 signature, Bool match, GlyphPtr compare)
 {
@@ -539,8 +268,7 @@ FreeGlyph (GlyphPtr glyph, int format)
 		(*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
 	}
 	
-	if (glyph->devPrivates)
-	    xfree (glyph->devPrivates);
+	FreeGlyphPrivates(glyph);
 	xfree (glyph);
     }
 }
@@ -566,8 +294,7 @@ AddGlyph (GlyphSetPtr glyphSet, GlyphPtr glyph, Glyph id)
 	    if (ps)
 		(*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
 	}
-	if (glyph->devPrivates)
-	    xfree (glyph->devPrivates);
+	FreeGlyphPrivates(glyph);
 	xfree (glyph);
 	glyph = gr->glyph;
     }
@@ -634,16 +361,7 @@ AllocateGlyph (xGlyphInfo *gi, int fdepth)
     glyph->refcnt = 0;
     glyph->size = size + sizeof (xGlyphInfo);
     glyph->info = *gi;
-
-    if (globalTotalGlyphPrivateSize)
-    {
-	glyph->devPrivates = xalloc (globalTotalGlyphPrivateSize);
-	if (!glyph->devPrivates)
-	    return 0;
-
-	SetGlyphPrivatePointers (glyph);
-    } else
-	glyph->devPrivates = NULL;
+    glyph->devPrivates = NULL;
 
     for (i = 0; i < screenInfo.numScreens; i++)
     {
@@ -659,8 +377,7 @@ AllocateGlyph (xGlyphInfo *gi, int fdepth)
 			(*ps->UnrealizeGlyph) (screenInfo.screens[i], glyph);
 		}
 		
-		if (glyph->devPrivates)
-		    xfree (glyph->devPrivates);
+		FreeGlyphPrivates(glyph);
 		xfree (glyph);
 		return 0;
 	    }
@@ -744,15 +461,11 @@ AllocateGlyphSet (int fdepth, PictFormatPtr format)
 	    return FALSE;
     }
 
-    size = (sizeof (GlyphSetRec) +
-	    (sizeof (pointer) * _GlyphSetPrivateAllocateIndex));
+    size = sizeof (GlyphSetRec);
     glyphSet = xalloc (size);
     if (!glyphSet)
 	return FALSE;
     bzero((char *)glyphSet, size);
-    glyphSet->maxPrivate = _GlyphSetPrivateAllocateIndex - 1;
-    if (_GlyphSetPrivateAllocateIndex)
-	glyphSet->devPrivates = (pointer)(&glyphSet[1]);
 
     if (!AllocateGlyphHash (&glyphSet->hash, &glyphHashSets[0]))
     {
@@ -792,11 +505,7 @@ FreeGlyphSet (pointer	value,
 	else
 	    ResizeGlyphHash (&globalGlyphs[glyphSet->fdepth], 0, TRUE);
 	xfree (table);
-
-	if (glyphSet->devPrivates &&
-	    glyphSet->devPrivates != (pointer)(&glyphSet[1]))
-	    xfree(glyphSet->devPrivates);
-
+	dixFreePrivates(glyphSet->devPrivates);
 	xfree (glyphSet);
     }
     return Success;
diff --git a/render/glyphstr.h b/render/glyphstr.h
index 22150de..e89f34e 100644
--- a/render/glyphstr.h
+++ b/render/glyphstr.h
@@ -30,6 +30,7 @@
 #include "screenint.h"
 #include "regionstr.h"
 #include "miscstruct.h"
+#include "privates.h"
 
 #define GlyphFormat1	0
 #define GlyphFormat4	1
@@ -40,7 +41,7 @@
 
 typedef struct _Glyph {
     CARD32	refcnt;
-    DevUnion	*devPrivates;
+    PrivateRec	*devPrivates;
     CARD32	size;	/* info + bitmap */
     xGlyphInfo	info;
     /* bits follow */
@@ -71,18 +72,14 @@ typedef struct _GlyphSet {
     int		    fdepth;
     GlyphHashRec    hash;
     int             maxPrivate;
-    pointer         *devPrivates;
+    PrivateRec      *devPrivates;
 } GlyphSetRec, *GlyphSetPtr;
 
-#define GlyphSetGetPrivate(pGlyphSet,n)					\
-	((n) > (pGlyphSet)->maxPrivate ?				\
-	 (pointer) 0 :							\
-	 (pGlyphSet)->devPrivates[n])
+#define GlyphSetGetPrivate(pGlyphSet,k)					\
+    dixLookupPrivate(&(pGlyphSet)->devPrivates, k)
 
-#define GlyphSetSetPrivate(pGlyphSet,n,ptr)				\
-	((n) > (pGlyphSet)->maxPrivate ?				\
-	 _GlyphSetSetNewPrivate(pGlyphSet, n, ptr) :			\
-	 ((((pGlyphSet)->devPrivates[n] = (ptr)) != 0) || TRUE))
+#define GlyphSetSetPrivate(pGlyphSet,k,ptr)				\
+    dixSetPrivate(&(pGlyphSet)->devPrivates, k, ptr)
 
 typedef struct _GlyphList {
     INT16	    xOff;
@@ -94,32 +91,6 @@ typedef struct _GlyphList {
 GlyphHashSetPtr
 FindGlyphHashSet (CARD32 filled);
 
-int
-AllocateGlyphSetPrivateIndex (void);
-
-void
-ResetGlyphSetPrivateIndex (void);
-
-Bool
-_GlyphSetSetNewPrivate (GlyphSetPtr glyphSet, int n, pointer ptr);
-
-void
-ResetGlyphPrivates (void);
-
-int
-AllocateGlyphPrivateIndex (void);
-
-Bool
-AllocateGlyphPrivate (ScreenPtr pScreen,
-		      int	index2,
-		      unsigned	amount);
-
-Bool
-GlyphInit (ScreenPtr pScreen);
-
-Bool
-GlyphFinishInit (ScreenPtr pScreen);
-
 void
 GlyphUninit (ScreenPtr pScreen);
 
diff --git a/render/picture.c b/render/picture.c
index ede865f..bc2c3b5 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -41,65 +41,14 @@
 #include "servermd.h"
 #include "picturestr.h"
 
-_X_EXPORT int	PictureScreenPrivateIndex = -1;
-int		PictureWindowPrivateIndex;
+_X_EXPORT DevPrivateKey PictureScreenPrivateKey = &PictureScreenPrivateKey;
+DevPrivateKey	PictureWindowPrivateKey = &PictureWindowPrivateKey;
 static int	PictureGeneration;
 RESTYPE		PictureType;
 RESTYPE		PictFormatType;
 RESTYPE		GlyphSetType;
 int		PictureCmapPolicy = PictureCmapPolicyDefault;
 
-/* Picture Private machinery */
-
-static int picturePrivateCount;
-
-void
-ResetPicturePrivateIndex (void)
-{
-    picturePrivateCount = 0;
-}
-
-int
-AllocatePicturePrivateIndex (void)
-{
-    return picturePrivateCount++;
-}
-
-Bool
-AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount)
-{
-    PictureScreenPtr	ps = GetPictureScreen(pScreen);
-    unsigned int	oldamount;
-
-    /* Round up sizes for proper alignment */
-    amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
-
-    if (index2 >= ps->PicturePrivateLen)
-    {
-	unsigned int *nsizes;
-
-	nsizes = (unsigned int *)xrealloc(ps->PicturePrivateSizes,
-					  (index2 + 1) * sizeof(unsigned int));
-	if (!nsizes)
-	    return FALSE;
-	while (ps->PicturePrivateLen <= index2)
-	{
-	    nsizes[ps->PicturePrivateLen++] = 0;
-	    ps->totalPictureSize += sizeof(DevUnion);
-	}
-	ps->PicturePrivateSizes = nsizes;
-    }
-    oldamount = ps->PicturePrivateSizes[index2];
-    if (amount > oldamount)
-    {
-	ps->PicturePrivateSizes[index2] = amount;
-	ps->totalPictureSize += (amount - oldamount);
-    }
-
-    return TRUE;
-}
-
-
 Bool
 PictureDestroyWindow (WindowPtr pWindow)
 {
@@ -137,8 +86,6 @@ PictureCloseScreen (int index, ScreenPtr pScreen)
 	    (*ps->CloseIndexed) (pScreen, &ps->formats[n]);
     GlyphUninit (pScreen);
     SetPictureScreen(pScreen, 0);
-    if (ps->PicturePrivateSizes)
-	xfree (ps->PicturePrivateSizes);
     xfree (ps->formats);
     xfree (ps);
     return ret;
@@ -497,8 +444,6 @@ PictureFinishInit (void)
 
     for (s = 0; s < screenInfo.numScreens; s++)
     {
-	if (!GlyphFinishInit (screenInfo.screens[s]))
-	    return FALSE;
 	if (!PictureInitIndexedFormats (screenInfo.screens[s]))
 	    return FALSE;
 	(void) AnimCurInit (screenInfo.screens[s]);
@@ -637,10 +582,6 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 	GlyphSetType = CreateNewResourceType (FreeGlyphSet);
 	if (!GlyphSetType)
 	    return FALSE;
-	PictureScreenPrivateIndex = AllocateScreenPrivateIndex();
-	if (PictureScreenPrivateIndex < 0)
-	    return FALSE;
-	PictureWindowPrivateIndex = AllocateWindowPrivateIndex();
 	PictureGeneration = serverGeneration;
 #ifdef XResExtension
 	RegisterResourceName (PictureType, "PICTURE");
@@ -648,9 +589,6 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 	RegisterResourceName (GlyphSetType, "GLYPHSET");
 #endif
     }
-    if (!AllocateWindowPrivate (pScreen, PictureWindowPrivateIndex, 0))
-	return FALSE;
-    
     if (!formats)
     {
 	formats = PictureCreateDefaultFormats (pScreen, &nformats);
@@ -697,18 +635,7 @@ PictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats)
 	return FALSE;
     }
     SetPictureScreen(pScreen, ps);
-    if (!GlyphInit (pScreen))
-    {
-	SetPictureScreen(pScreen, 0);
-	xfree (formats);
-	xfree (ps);
-	return FALSE;
-    }
 
-    ps->totalPictureSize = sizeof (PictureRec);
-    ps->PicturePrivateSizes = 0;
-    ps->PicturePrivateLen = 0;
-    
     ps->formats = formats;
     ps->fallback = formats;
     ps->nformats = nformats;
@@ -774,37 +701,6 @@ SetPictureToDefaults (PicturePtr    pPicture)
 }
 
 PicturePtr
-AllocatePicture (ScreenPtr  pScreen)
-{
-    PictureScreenPtr	ps = GetPictureScreen(pScreen);
-    PicturePtr		pPicture;
-    char		*ptr;
-    DevUnion		*ppriv;
-    unsigned int    	*sizes;
-    unsigned int    	size;
-    int			i;
-
-    pPicture = (PicturePtr) xalloc (ps->totalPictureSize);
-    if (!pPicture)
-	return 0;
-    ppriv = (DevUnion *)(pPicture + 1);
-    pPicture->devPrivates = ppriv;
-    sizes = ps->PicturePrivateSizes;
-    ptr = (char *)(ppriv + ps->PicturePrivateLen);
-    for (i = ps->PicturePrivateLen; --i >= 0; ppriv++, sizes++)
-    {
-	if ( (size = *sizes) )
-	{
-	    ppriv->ptr = (pointer)ptr;
-	    ptr += size;
-	}
-	else
-	    ppriv->ptr = (pointer)NULL;
-    }
-    return pPicture;
-}
-
-PicturePtr
 CreatePicture (Picture		pid,
 	       DrawablePtr	pDrawable,
 	       PictFormatPtr	pFormat,
@@ -816,7 +712,7 @@ CreatePicture (Picture		pid,
     PicturePtr		pPicture;
     PictureScreenPtr	ps = GetPictureScreen(pDrawable->pScreen);
 
-    pPicture = AllocatePicture (pDrawable->pScreen);
+    pPicture = (PicturePtr)xalloc(sizeof(PictureRec));
     if (!pPicture)
     {
 	*error = BadAlloc;
@@ -827,6 +723,7 @@ CreatePicture (Picture		pid,
     pPicture->pDrawable = pDrawable;
     pPicture->pFormat = pFormat;
     pPicture->format = pFormat->format | (pDrawable->bitsPerPixel << 24);
+    pPicture->devPrivates = NULL;
     if (pDrawable->type == DRAWABLE_PIXMAP)
     {
 	++((PixmapPtr)pDrawable)->refcnt;
@@ -1607,7 +1504,8 @@ FreePicture (pointer	value,
                 WindowPtr	pWindow = (WindowPtr) pPicture->pDrawable;
                 PicturePtr	*pPrev;
 
-                for (pPrev = (PicturePtr *) &((pWindow)->devPrivates[PictureWindowPrivateIndex].ptr);
+                for (pPrev = (PicturePtr *)dixLookupPrivateAddr
+			 (&pWindow->devPrivates, PictureWindowPrivateKey);
                      *pPrev;
                      pPrev = &(*pPrev)->pNext)
                 {
@@ -1623,6 +1521,7 @@ FreePicture (pointer	value,
                 (*pScreen->DestroyPixmap) ((PixmapPtr)pPicture->pDrawable);
             }
         }
+	dixFreePrivates(pPicture->devPrivates);
 	xfree (pPicture);
     }
     return Success;
diff --git a/render/picturestr.h b/render/picturestr.h
index 005c588..aafe4e8 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -27,6 +27,7 @@
 #include "glyphstr.h"
 #include "scrnintstr.h"
 #include "resource.h"
+#include "privates.h"
 
 typedef struct _DirectFormat {
     CARD16	    red, redMask;
@@ -173,7 +174,7 @@ typedef struct _Picture {
 
     RegionPtr	    pCompositeClip;
 
-    DevUnion	    *devPrivates;
+    PrivateRec	    *devPrivates;
 
     PictTransform   *transform;
 
@@ -328,10 +329,6 @@ typedef void	(*UnrealizeGlyphProcPtr)    (ScreenPtr	    pScreen,
 					     GlyphPtr	    glyph);
 
 typedef struct _PictureScreen {
-    int				totalPictureSize;
-    unsigned int		*PicturePrivateSizes;
-    int				PicturePrivateLen;
-
     PictFormatPtr		formats;
     PictFormatPtr		fallback;
     int				nformats;
@@ -389,30 +386,25 @@ typedef struct _PictureScreen {
 
     AddTrapsProcPtr		AddTraps;
 
-    int			  	totalGlyphPrivateSize;
-    unsigned int	  	*glyphPrivateSizes;
-    int			  	glyphPrivateLen;
-    int			  	glyphPrivateOffset;
-
     RealizeGlyphProcPtr   	RealizeGlyph;
     UnrealizeGlyphProcPtr 	UnrealizeGlyph;
 
 } PictureScreenRec, *PictureScreenPtr;
 
-extern int		PictureScreenPrivateIndex;
-extern int		PictureWindowPrivateIndex;
+extern DevPrivateKey	PictureScreenPrivateKey;
+extern DevPrivateKey	PictureWindowPrivateKey;
 extern RESTYPE		PictureType;
 extern RESTYPE		PictFormatType;
 extern RESTYPE		GlyphSetType;
 
-#define GetPictureScreen(s) ((PictureScreenPtr) ((s)->devPrivates[PictureScreenPrivateIndex].ptr))
-#define GetPictureScreenIfSet(s) ((PictureScreenPrivateIndex != -1) ? GetPictureScreen(s) : NULL)
-#define SetPictureScreen(s,p) ((s)->devPrivates[PictureScreenPrivateIndex].ptr = (pointer) (p))
-#define GetPictureWindow(w) ((PicturePtr) ((w)->devPrivates[PictureWindowPrivateIndex].ptr))
-#define SetPictureWindow(w,p) ((w)->devPrivates[PictureWindowPrivateIndex].ptr = (pointer) (p))
+#define GetPictureScreen(s) ((PictureScreenPtr)dixLookupPrivate(&(s)->devPrivates, PictureScreenPrivateKey))
+#define GetPictureScreenIfSet(s) GetPictureScreen(s)
+#define SetPictureScreen(s,p) dixSetPrivate(&(s)->devPrivates, PictureScreenPrivateKey, p)
+#define GetPictureWindow(w) ((PicturePtr)dixLookupPrivate(&(w)->devPrivates, PictureWindowPrivateKey))
+#define SetPictureWindow(w,p) dixSetPrivate(&(w)->devPrivates, PictureWindowPrivateKey, p)
 
-#define GetGlyphPrivatesForScreen(glyph, s)				\
-    ((glyph)->devPrivates + (GetPictureScreen (s))->glyphPrivateOffset)
+#define GetGlyphPrivatesForScreen(glyph, s) \
+    ((PrivateRec **)dixLookupPrivateAddr(&(glyph)->devPrivates, s))
 
 #define VERIFY_PICTURE(pPicture, pid, client, mode, err) {\
     pPicture = SecurityLookupIDByType(client, pid, PictureType, mode);\
@@ -430,15 +422,6 @@ extern RESTYPE		GlyphSetType;
     } \
 } \
 
-void
-ResetPicturePrivateIndex (void);
-
-int
-AllocatePicturePrivateIndex (void);
-
-Bool
-AllocatePicturePrivate (ScreenPtr pScreen, int index2, unsigned int amount);
-
 Bool
 PictureDestroyWindow (WindowPtr pWindow);
 
@@ -501,9 +484,6 @@ PictureFinishInit (void);
 void
 SetPictureToDefaults (PicturePtr pPicture);
 
-PicturePtr
-AllocatePicture (ScreenPtr  pScreen);
-
 #if 0
 Bool
 miPictureInit (ScreenPtr pScreen, PictFormatPtr formats, int nformats);
diff --git a/render/render.c b/render/render.c
index e57ffb1..7b27457 100644
--- a/render/render.c
+++ b/render/render.c
@@ -216,14 +216,14 @@ RenderResetProc (ExtensionEntry *extEntry);
 static CARD8	RenderReqCode;
 #endif
 int	RenderErrBase;
-int	RenderClientPrivateIndex;
+DevPrivateKey RenderClientPrivateKey;
 
 typedef struct _RenderClient {
     int	    major_version;
     int	    minor_version;
 } RenderClientRec, *RenderClientPtr;
 
-#define GetRenderClient(pClient)    ((RenderClientPtr) (pClient)->devPrivates[RenderClientPrivateIndex].ptr)
+#define GetRenderClient(pClient) ((RenderClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RenderClientPrivateKey))
 
 static void
 RenderClientCallback (CallbackListPtr	*list,
@@ -247,9 +247,7 @@ RenderExtensionInit (void)
 	return;
     if (!PictureFinishInit ())
 	return;
-    RenderClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (RenderClientPrivateIndex, 
-				sizeof (RenderClientRec)))
+    if (!dixRequestPrivate(RenderClientPrivateKey, sizeof(RenderClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0))
 	return;
@@ -268,8 +266,6 @@ RenderExtensionInit (void)
 static void
 RenderResetProc (ExtensionEntry *extEntry)
 {
-    ResetPicturePrivateIndex();
-    ResetGlyphSetPrivateIndex();
 }
 
 static int
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 450f366..975ebc3 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -55,8 +55,7 @@
 static RESTYPE		CursorClientType;
 static RESTYPE		CursorHideCountType;
 static RESTYPE		CursorWindowType;
-static int		CursorScreenPrivateIndex = -1;
-static int		CursorGeneration;
+static DevPrivateKey	CursorScreenPrivateKey = &CursorScreenPrivateKey;
 static CursorPtr	CursorCurrent;
 static CursorPtr        pInvisibleCursor = NULL;
 
@@ -113,9 +112,9 @@ typedef struct _CursorScreen {
     CursorHideCountPtr          pCursorHideCounts;
 } CursorScreenRec, *CursorScreenPtr;
 
-#define GetCursorScreen(s)	((CursorScreenPtr) ((s)->devPrivates[CursorScreenPrivateIndex].ptr))
-#define GetCursorScreenIfSet(s) ((CursorScreenPrivateIndex != -1) ? GetCursorScreen(s) : NULL)
-#define SetCursorScreen(s,p)	((s)->devPrivates[CursorScreenPrivateIndex].ptr = (pointer) (p))
+#define GetCursorScreen(s) ((CursorScreenPtr)dixLookupPrivate(&(s)->devPrivates, CursorScreenPrivateKey))
+#define GetCursorScreenIfSet(s) GetCursorScreen(s)
+#define SetCursorScreen(s,p) dixSetPrivate(&(s)->devPrivates, CursorScreenPrivateKey, p)
 #define Wrap(as,s,elt,func)	(((as)->elt = (s)->elt), (s)->elt = func)
 #define Unwrap(as,s,elt)	((s)->elt = (as)->elt)
 
@@ -171,8 +170,6 @@ CursorCloseScreen (int index, ScreenPtr pScreen)
     deleteCursorHideCountsForScreen(pScreen);
     ret = (*pScreen->CloseScreen) (index, pScreen);
     xfree (cs);
-    if (index == 0)
-	CursorScreenPrivateIndex = -1;
     return ret;
 }
 
@@ -1011,13 +1008,6 @@ XFixesCursorInit (void)
 {
     int	i;
     
-    if (CursorGeneration != serverGeneration)
-    {
-	CursorScreenPrivateIndex = AllocateScreenPrivateIndex ();
-	if (CursorScreenPrivateIndex < 0)
-	    return FALSE;
-	CursorGeneration = serverGeneration;
-    }
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	ScreenPtr	pScreen = screenInfo.screens[i];
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index 32dee8a..0db4989 100755
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -56,7 +56,7 @@
 static unsigned char	XFixesReqCode;
 int		XFixesEventBase;
 int		XFixesErrorBase;
-static int	XFixesClientPrivateIndex;
+static DevPrivateKey XFixesClientPrivateKey = &XFixesClientPrivateKey;
 
 static int
 ProcXFixesQueryVersion(ClientPtr client)
@@ -239,9 +239,7 @@ XFixesExtensionInit(void)
 {
     ExtensionEntry *extEntry;
 
-    XFixesClientPrivateIndex = AllocateClientPrivateIndex ();
-    if (!AllocateClientPrivate (XFixesClientPrivateIndex, 
-				sizeof (XFixesClientRec)))
+    if (!dixRequestPrivate(XFixesClientPrivateKey, sizeof (XFixesClientRec)))
 	return;
     if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0))
 	return;
diff --git a/xfixes/xfixesint.h b/xfixes/xfixesint.h
index 48927ae..33a3205 100755
--- a/xfixes/xfixesint.h
+++ b/xfixes/xfixesint.h
@@ -66,7 +66,7 @@ typedef struct _XFixesClient {
     CARD32	minor_version;
 } XFixesClientRec, *XFixesClientPtr;
 
-#define GetXFixesClient(pClient)    ((XFixesClientPtr) (pClient)->devPrivates[XFixesClientPrivateIndex].ptr)
+#define GetXFixesClient(pClient) ((XFixesClientPtr)dixLookupPrivate(&(pClient)->devPrivates, XFixesClientPrivateKey))
 
 extern int	(*ProcXFixesVector[XFixesNumberRequests])(ClientPtr);
 
diff --git a/xkb/ddxFakeMtn.c b/xkb/ddxFakeMtn.c
index 1060afe..320e0ca 100644
--- a/xkb/ddxFakeMtn.c
+++ b/xkb/ddxFakeMtn.c
@@ -107,7 +107,7 @@ ScreenPtr	   pScreen, oldScreen;
 	     oldY=  y;
 	else oldY+= y;
 
-#define GetScreenPrivate(s) ((miPointerScreenPtr) ((s)->devPrivates[miPointerScreenIndex].ptr))	
+#define GetScreenPrivate(s) ((miPointerScreenPtr)dixLookupPrivate(&(s)->devPrivates, miPointerScreenKey))
 	(*(GetScreenPrivate(oldScreen))->screenFuncs->CursorOffScreen)
 	    (&pScreen, &oldX, &oldY);
     }
diff --git a/xkb/xkbActions.c b/xkb/xkbActions.c
index 2e0c89f..7f0f74d 100644
--- a/xkb/xkbActions.c
+++ b/xkb/xkbActions.c
@@ -40,8 +40,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "xkb.h"
 #include <ctype.h>
 
-static unsigned int _xkbServerGeneration;
-static int xkbDevicePrivateIndex = -1;
+static DevPrivateKey xkbDevicePrivateKey = &xkbDevicePrivateKey;
 
 static void
 xkbUnwrapProc(DeviceIntPtr device, DeviceHandleProc proc,
@@ -64,20 +63,12 @@ XkbSetExtension(DeviceIntPtr device, ProcessInputProc proc)
 {
     xkbDeviceInfoPtr xkbPrivPtr;
 
-    if (serverGeneration != _xkbServerGeneration) {
-	if ((xkbDevicePrivateIndex = AllocateDevicePrivateIndex()) == -1)
-	    return;
-	_xkbServerGeneration = serverGeneration;
-    }
-    if (!AllocateDevicePrivate(device, xkbDevicePrivateIndex))
-	return;
-
     xkbPrivPtr = (xkbDeviceInfoPtr) xalloc(sizeof(xkbDeviceInfoRec));
     if (!xkbPrivPtr)
 	return;
     xkbPrivPtr->unwrapProc = NULL;
 
-    device->devPrivates[xkbDevicePrivateIndex].ptr = xkbPrivPtr;
+    dixSetPrivate(&device->devPrivates, xkbDevicePrivateKey, xkbPrivPtr);
     WRAP_PROCESS_INPUT_PROC(device,xkbPrivPtr,
 			    proc,xkbUnwrapProc);
 }
commit 85547073265ae9bc4ae3af920a6d3214fd1ca0c5
Merge: 860a09c... 7d54399...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Aug 28 07:25:21 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	include/miscstruct.h
    	mi/mibstore.c
    	mi/midispcur.c
    	os/Makefile.am

diff --cc include/miscstruct.h
index 81f699a,d240f1b..409b102
--- a/include/miscstruct.h
+++ b/include/miscstruct.h
@@@ -50,7 -50,8 +50,7 @@@ SOFTWARE
  
  #include "misc.h"
  #include <X11/Xprotostr.h>
- #include <pixman/pixman.h>
 -#include "gc.h"
+ #include <pixman.h>
  
  typedef xPoint DDXPointRec;
  
diff --cc mi/midispcur.c
index ab10837,802fc6c..feb6c2f
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@@ -450,10 -450,7 +450,8 @@@ miDCMakeGC
      gcvals[0] = IncludeInferiors;
      gcvals[1] = FALSE;
      pGC = CreateGC((DrawablePtr)pWin,
 -		   GCSubwindowMode|GCGraphicsExposures, gcvals, &status);
 +		   GCSubwindowMode|GCGraphicsExposures, gcvals, &status,
 +		   (XID)0, serverClient);
-     if (pGC && pWin->drawable.pScreen->DrawGuarantee)
- 	(*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
      *ppGC = pGC;
      return pGC;
  }
diff --cc os/Makefile.am
index 9dd1b54,d2a9897..9b8e08d
--- a/os/Makefile.am
+++ b/os/Makefile.am
@@@ -3,9 -3,10 +3,9 @@@ noinst_LTLIBRARIES = libos.la libcwrapp
  AM_CFLAGS = $(DIX_CFLAGS)
  
  # FIXME: Add support for these in configure.ac
- SECURERPC_SRCS = rpcauth.c
  INTERNALMALLOC_SRCS = xalloc.c
  
+ SECURERPC_SRCS = rpcauth.c
 -XCSECURITY_SRCS = secauth.c
  XDMCP_SRCS = xdmcp.c
  STRLCAT_SRCS = strlcat.c strlcpy.c
  XORG_SRCS = log.c
@@@ -27,6 -28,14 +27,10 @@@ libos_la_SOURCES = 	
  	xprintf.c	\
  	$(XORG_SRCS)
  
+ if SECURE_RPC
+ libos_la_SOURCES += $(SECURERPC_SRCS)
+ endif
+ 
 -if XCSECURITY
 -libos_la_SOURCES += $(XCSECURITY_SRCS)
 -endif
 -
  if XDMCP
  libos_la_SOURCES += $(XDMCP_SRCS)
  endif
commit 860a09cfb8afc0a293c7eb5e01762724eb86847a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 16:10:44 2007 -0400

    devPrivates rework: Nevermind, can't const due to return value warnings.
    
    This reverts commit 6fd0a0b08de912421718aca17fe34a55ae285ae7.

diff --git a/dix/privates.c b/dix/privates.c
index 1ca361c..4dbba43 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -47,7 +47,7 @@ from The Open Group.
 #include "extnsionst.h"
 
 typedef struct _PrivateDesc {
-    pointer key;
+    DevPrivateKey key;
     unsigned size;
     CallbackListPtr initfuncs;
     CallbackListPtr deletefuncs;
diff --git a/include/privates.h b/include/privates.h
index e81e40a..e377b30 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -19,10 +19,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * STUFF FOR PRIVATES
  *****************************************************************/
 
-typedef void *const DevPrivateKey;
+typedef void *DevPrivateKey;
 
 typedef struct _Private {
-    pointer		key;
+    DevPrivateKey	key;
     pointer		value;
     struct _Private	*next;
 } PrivateRec;
@@ -111,7 +111,7 @@ dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
  * The calldata argument to the callbacks is a PrivateCallbackPtr.
  */
 typedef struct _PrivateCallback {
-    pointer key;	/* key used to set the private */
+    DevPrivateKey key;	/* private registration key */
     pointer *value;	/* address of private pointer */
 } PrivateCallbackRec;
 
commit 6fd0a0b08de912421718aca17fe34a55ae285ae7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 16:01:42 2007 -0400

    devPrivates rework: add const qualifier to key type.

diff --git a/dix/privates.c b/dix/privates.c
index 4dbba43..1ca361c 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -47,7 +47,7 @@ from The Open Group.
 #include "extnsionst.h"
 
 typedef struct _PrivateDesc {
-    DevPrivateKey key;
+    pointer key;
     unsigned size;
     CallbackListPtr initfuncs;
     CallbackListPtr deletefuncs;
diff --git a/include/privates.h b/include/privates.h
index e377b30..e81e40a 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -19,10 +19,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * STUFF FOR PRIVATES
  *****************************************************************/
 
-typedef void *DevPrivateKey;
+typedef void *const DevPrivateKey;
 
 typedef struct _Private {
-    DevPrivateKey	key;
+    pointer		key;
     pointer		value;
     struct _Private	*next;
 } PrivateRec;
@@ -111,7 +111,7 @@ dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
  * The calldata argument to the callbacks is a PrivateCallbackPtr.
  */
 typedef struct _PrivateCallback {
-    DevPrivateKey key;	/* private registration key */
+    pointer key;	/* key used to set the private */
     pointer *value;	/* address of private pointer */
 } PrivateCallbackRec;
 
commit b2b7817497dd5da73d23ec9cc637c563041fc490
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 15:30:25 2007 -0400

    devPrivates rework: use camelcase standard for name of key type.

diff --git a/Xext/security.c b/Xext/security.c
index bf414a5..fe1e48a 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -54,7 +54,7 @@ in this Software without prior written authorization from The Open Group.
 
 static int SecurityErrorBase;  /* first Security error number */
 static int SecurityEventBase;  /* first Security event number */
-static devprivate_key_t stateKey;
+static const DevPrivateKey stateKey = &stateKey;
 
 /* this is what we store as client security state */
 typedef struct {
@@ -64,11 +64,11 @@ typedef struct {
 } SecurityClientStateRec;
 
 #define HAVESTATE(client) (((SecurityClientStateRec *) \
-    dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->haveState)
+    dixLookupPrivate(DEVPRIV_PTR(client), stateKey))->haveState)
 #define TRUSTLEVEL(client) (((SecurityClientStateRec *) \
-    dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->trustLevel)
+    dixLookupPrivate(DEVPRIV_PTR(client), stateKey))->trustLevel)
 #define AUTHID(client)(((SecurityClientStateRec *) \
-    dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->authId)
+    dixLookupPrivate(DEVPRIV_PTR(client), stateKey))->authId)
 
 static CallbackListPtr SecurityValidateGroupCallback = NULL;
 
@@ -1812,7 +1812,7 @@ SecurityExtensionInit(INITARGS)
     RTEventClient |= RC_NEVERRETAIN;
 
     /* Allocate the private storage */
-    if (!dixRequestPrivate(&stateKey, sizeof(SecurityClientStateRec)))
+    if (!dixRequestPrivate(stateKey, sizeof(SecurityClientStateRec)))
 	FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
 
     if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL))
diff --git a/dix/privates.c b/dix/privates.c
index f2f1c49..4dbba43 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -47,7 +47,7 @@ from The Open Group.
 #include "extnsionst.h"
 
 typedef struct _PrivateDesc {
-    devprivate_key_t *key;
+    DevPrivateKey key;
     unsigned size;
     CallbackListPtr initfuncs;
     CallbackListPtr deletefuncs;
@@ -58,7 +58,7 @@ typedef struct _PrivateDesc {
 static PrivateDescRec *items = NULL;
 
 static _X_INLINE PrivateDescRec *
-findItem(devprivate_key_t *const key)
+findItem(const DevPrivateKey key)
 {
     PrivateDescRec *item = items;
     while (item) {
@@ -73,7 +73,7 @@ findItem(devprivate_key_t *const key)
  * Request pre-allocated space.
  */
 _X_EXPORT int
-dixRequestPrivate(devprivate_key_t *const key, unsigned size)
+dixRequestPrivate(const DevPrivateKey key, unsigned size)
 {
     PrivateDescRec *item = findItem(key);
     if (item) {
@@ -98,7 +98,7 @@ dixRequestPrivate(devprivate_key_t *const key, unsigned size)
  * Allocate a private and attach it to an existing object.
  */
 _X_EXPORT pointer *
-dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
+dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key)
 {
     PrivateDescRec *item = findItem(key);
     PrivateRec *ptr;
@@ -156,7 +156,7 @@ dixFreePrivates(PrivateRec *privates)
  * Callback registration
  */
 _X_EXPORT int
-dixRegisterPrivateInitFunc(devprivate_key_t *const key,
+dixRegisterPrivateInitFunc(const DevPrivateKey key,
 			   CallbackProcPtr callback, pointer data)
 {
     PrivateDescRec *item = findItem(key);
@@ -169,7 +169,7 @@ dixRegisterPrivateInitFunc(devprivate_key_t *const key,
 }
 
 _X_EXPORT int
-dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
+dixRegisterPrivateDeleteFunc(const DevPrivateKey key,
 			     CallbackProcPtr callback, pointer data)
 {
     PrivateDescRec *item = findItem(key);
diff --git a/include/privates.h b/include/privates.h
index e57f167..e377b30 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -19,10 +19,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * STUFF FOR PRIVATES
  *****************************************************************/
 
-typedef char devprivate_key_t;
+typedef void *DevPrivateKey;
 
 typedef struct _Private {
-    devprivate_key_t	*key;
+    DevPrivateKey	key;
     pointer		value;
     struct _Private	*next;
 } PrivateRec;
@@ -39,19 +39,19 @@ typedef struct _Private {
  * Calling this is not necessary if only a pointer by itself is needed.
  */
 extern int
-dixRequestPrivate(devprivate_key_t *const key, unsigned size);
+dixRequestPrivate(const DevPrivateKey key, unsigned size);
 
 /*
  * Allocates a new private and attaches it to an existing object.
  */
 extern pointer *
-dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key);
+dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key);
 
 /*
  * Look up a private pointer.
  */
 static _X_INLINE pointer
-dixLookupPrivate(PrivateRec **privates, devprivate_key_t *const key)
+dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key)
 {
     PrivateRec *rec = *privates;
     pointer *ptr;
@@ -70,7 +70,7 @@ dixLookupPrivate(PrivateRec **privates, devprivate_key_t *const key)
  * Look up the address of a private pointer.
  */
 static _X_INLINE pointer *
-dixLookupPrivateAddr(PrivateRec **privates, devprivate_key_t *const key)
+dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key)
 {
     PrivateRec *rec = *privates;
 
@@ -87,7 +87,7 @@ dixLookupPrivateAddr(PrivateRec **privates, devprivate_key_t *const key)
  * Set a private pointer.
  */
 static _X_INLINE int
-dixSetPrivate(PrivateRec **privates, devprivate_key_t *const key, pointer val)
+dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val)
 {
     PrivateRec *rec;
 
@@ -111,16 +111,16 @@ dixSetPrivate(PrivateRec **privates, devprivate_key_t *const key, pointer val)
  * The calldata argument to the callbacks is a PrivateCallbackPtr.
  */
 typedef struct _PrivateCallback {
-    devprivate_key_t *key;	/* private registration key */
-    pointer *value;		/* address of private pointer */
+    DevPrivateKey key;	/* private registration key */
+    pointer *value;	/* address of private pointer */
 } PrivateCallbackRec;
 
 extern int
-dixRegisterPrivateInitFunc(devprivate_key_t *const key,
+dixRegisterPrivateInitFunc(const DevPrivateKey key, 
 			   CallbackProcPtr callback, pointer userdata);
 
 extern int
-dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
+dixRegisterPrivateDeleteFunc(const DevPrivateKey key,
 			     CallbackProcPtr callback, pointer userdata);
 
 /*
commit 0a994d4f859a4e48d41a90ed9d2a282bb528c555
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 12:54:35 2007 -0400

    xace: add hooks + new access codes: core protocol selection requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index ece240c..bb30619 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -980,9 +980,10 @@ ProcSetSelectionOwner(ClientPtr client)
 {
     WindowPtr pWin;
     TimeStamp time;
+    int rc;
     REQUEST(xSetSelectionOwnerReq);
-
     REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
+
     UpdateCurrentTime();
     time = ClientTimeToServerTime(stuff->time);
 
@@ -992,7 +993,7 @@ ProcSetSelectionOwner(ClientPtr client)
     	return Success;
     if (stuff->window != None)
     {
-	int rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+	rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
         if (rc != Success)
             return rc;
     }
@@ -1012,6 +1013,10 @@ ProcSetSelectionOwner(ClientPtr client)
         {        
 	    xEvent event;
 
+	    rc = XaceHook(XACE_SELECTION_ACCESS, client, CurrentSelections[i],
+			  DixSetAttrAccess);
+	    if (rc != Success)
+		return rc;
 	    /* If the timestamp in client's request is in the past relative
 		to the time stamp indicating the last time the owner of the
 		selection was set, do not set the selection, just return 
@@ -1049,6 +1054,10 @@ ProcSetSelectionOwner(ClientPtr client)
 	    CurrentSelections = newsels;
 	    CurrentSelections[i].selection = stuff->selection;
 	    CurrentSelections[i].devPrivates = NULL;
+	    rc = XaceHook(XACE_SELECTION_ACCESS, CurrentSelections[i],
+			  DixSetAttrAccess);
+	    if (rc != Success)
+		return rc;
 	}
 	dixFreePrivates(CurrentSelections[i].devPrivates);
         CurrentSelections[i].lastTimeChanged = time;
@@ -1094,7 +1103,7 @@ ProcGetSelectionOwner(ClientPtr client)
 	reply.sequenceNumber = client->sequence;
         if (i < NumCurrentSelections &&
 	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
-		     DixReadAccess) == Success)
+		     DixGetAttrAccess) == Success)
             reply.owner = CurrentSelections[i].destwindow;
         else
             reply.owner = None;
@@ -1118,7 +1127,7 @@ ProcConvertSelection(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xConvertSelectionReq);
-    rc = dixLookupWindow(&pWin, stuff->requestor, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->requestor, client, DixSetAttrAccess);
     if (rc != Success)
         return rc;
 
commit 3ef2e9e623819c625a92f464fb14f1e5c181df42
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 12:27:48 2007 -0400

    xace: add hooks + new access codes: core protocol pixmap requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index f6a85bb..ece240c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1500,7 +1500,7 @@ ProcCreatePixmap(ClientPtr client)
     LEGAL_NEW_RESOURCE(stuff->pid, client);
     
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY,
-			   DixReadAccess);
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
@@ -1543,9 +1543,17 @@ CreatePmap:
     {
 	pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
 	pMap->drawable.id = stuff->pid;
+	/* security creation/labeling check */
+	rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, RT_PIXMAP,
+		      DixCreateAccess, pMap);
+	if (rc != Success) {
+	    (*pDraw->pScreen->DestroyPixmap)(pMap);
+	    return rc;
+	}
 	if (AddResource(stuff->pid, RT_PIXMAP, (pointer)pMap))
 	    return(client->noClientException);
     }
+    (*pDraw->pScreen->DestroyPixmap)(pMap);
     return (BadAlloc);
 }
 
@@ -1553,13 +1561,13 @@ int
 ProcFreePixmap(ClientPtr client)
 {
     PixmapPtr pMap;
-
+    int rc;
     REQUEST(xResourceReq);
-
     REQUEST_SIZE_MATCH(xResourceReq);
-    pMap = (PixmapPtr)SecurityLookupIDByType(client, stuff->id, RT_PIXMAP,
-					     DixDestroyAccess);
-    if (pMap) 
+
+    rc = dixLookupResource((pointer *)&pMap, stuff->id, RT_PIXMAP, client,
+			   DixDestroyAccess);
+    if (rc == Success)
     {
 	FreeResource(stuff->id, RT_NONE);
 	return(client->noClientException);
@@ -1567,7 +1575,7 @@ ProcFreePixmap(ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return (BadPixmap);
+	return (rc == BadValue) ? BadPixmap : rc;
     }
 }
 
commit fe9bc481efb0821134e10760c23993c6a7386450
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 12:02:59 2007 -0400

    xace: add hooks + new access codes: core protocol font requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 30f44fb..f6a85bb 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1354,23 +1354,21 @@ ProcQueryFont(ClientPtr client)
     xQueryFontReply	*reply;
     FontPtr pFont;
     GC *pGC;
+    int rc;
     REQUEST(xResourceReq);
-
     REQUEST_SIZE_MATCH(xResourceReq);
+
     client->errorValue = stuff->id;		/* EITHER font or gc */
-    pFont = (FontPtr)SecurityLookupIDByType(client, stuff->id, RT_FONT,
-					    DixReadAccess);
-    if (!pFont)
-    {
-	pGC = (GC *) SecurityLookupIDByType(client, stuff->id, RT_GC,
-					    DixReadAccess);
-        if (!pGC)
-	{
-	    client->errorValue = stuff->id;
-            return(BadFont);     /* procotol spec says only error is BadFont */
-	}
-	pFont = pGC->font;
+    rc = dixLookupResource((pointer *)&pFont, stuff->id, RT_FONT, client,
+			   DixGetAttrAccess);
+    if (rc == BadValue) {
+	rc = dixLookupResource((pointer *)&pGC, stuff->id, RT_GC, client,
+			       DixGetAttrAccess);
+	if (rc == Success)
+	    pFont = pGC->font;
     }
+    if (rc != Success)
+	return (rc == BadValue) ? BadFont: rc;
 
     {
 	xCharInfo	*pmax = FONTINKMAX(pFont);
@@ -1409,28 +1407,27 @@ ProcQueryFont(ClientPtr client)
 int
 ProcQueryTextExtents(ClientPtr client)
 {
-    REQUEST(xQueryTextExtentsReq);
     xQueryTextExtentsReply reply;
     FontPtr pFont;
     GC *pGC;
     ExtentInfoRec info;
     unsigned long length;
-
+    int rc;
+    REQUEST(xQueryTextExtentsReq);
     REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq);
         
-    pFont = (FontPtr)SecurityLookupIDByType(client, stuff->fid, RT_FONT,
-					    DixReadAccess);
-    if (!pFont)
-    {
-        pGC = (GC *)SecurityLookupIDByType(client, stuff->fid, RT_GC,
-					   DixReadAccess);
-        if (!pGC)
-	{
-	    client->errorValue = stuff->fid;
-            return(BadFont);
-	}
-	pFont = pGC->font;
+    client->errorValue = stuff->fid;		/* EITHER font or gc */
+    rc = dixLookupResource((pointer *)&pFont, stuff->fid, RT_FONT, client,
+			   DixGetAttrAccess);
+    if (rc == BadValue) {
+	rc = dixLookupResource((pointer *)&pGC, stuff->fid, RT_GC, client,
+			       DixGetAttrAccess);
+	if (rc == Success)
+	    pFont = pGC->font;
     }
+    if (rc != Success)
+	return (rc == BadValue) ? BadFont: rc;
+
     length = client->req_len - (sizeof(xQueryTextExtentsReq) >> 2);
     length = length << 1;
     if (stuff->oddLength)
commit e89301c8790df9fc49de13dd7c7f36e5340c0c31
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 10:57:49 2007 -0400

    xace: add hooks + new access codes: core protocol client requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 2dc32a5..30f44fb 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3519,9 +3519,14 @@ ProcGetFontPath(ClientPtr client)
 int
 ProcChangeCloseDownMode(ClientPtr client)
 {
+    int rc;
     REQUEST(xSetCloseDownModeReq);
-
     REQUEST_SIZE_MATCH(xSetCloseDownModeReq);
+
+    rc = XaceHook(XACE_CLIENT_ACCESS, client, client, DixManageAccess);
+    if (rc != Success)
+	return rc;
+
     if ((stuff->mode == AllTemporary) ||
 	(stuff->mode == RetainPermanent) ||
 	(stuff->mode == RetainTemporary))
diff --git a/dix/dixutils.c b/dix/dixutils.c
index e8d7daf..786f4e3 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -254,17 +254,25 @@ _X_EXPORT int
 dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
 {
     pointer pRes;
-    int clientIndex = CLIENT_ID(rid);
-    client->errorValue = rid;
+    int rc = BadValue, clientIndex = CLIENT_ID(rid);
 
-    dixLookupResource(&pRes, rid, RC_ANY, client, access);
+    if (!clientIndex || !clients[clientIndex] || (rid & SERVER_BIT))
+	goto bad;
 
-    if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) {
-	*pClient = clients[clientIndex];
-	return Success;
-    }
+    rc = dixLookupResource(&pRes, rid, RC_ANY, client, DixGetAttrAccess);
+    if (rc != Success)
+	goto bad;
+
+    rc = XaceHook(XACE_CLIENT_ACCESS, client, clients[clientIndex], access);
+    if (rc != Success)
+	goto bad;
+
+    *pClient = clients[clientIndex];
+    return Success;
+bad:
+    client->errorValue = rid;
     *pClient = NULL;
-    return BadValue;
+    return rc;
 }
 
 int
commit 5bee8db003a5d552ee1d85bb6c40a3cb93bd6b2b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 10:44:51 2007 -0400

    xace: drop background-none checking hook, add new hook for controlling
    access to other clients.

diff --git a/Xext/security.c b/Xext/security.c
index 0059245..bf414a5 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1197,16 +1197,6 @@ SecurityCheckMapAccess(CallbackListPtr *pcbl, pointer unused,
 }
 
 static void
-SecurityCheckBackgrndAccess(CallbackListPtr *pcbl, pointer unused,
-			    pointer calldata)
-{
-    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
-
-    if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
-	rec->status = BadAccess;
-}
-
-static void
 SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
 		       pointer calldata)
 {
@@ -1848,7 +1838,6 @@ SecurityExtensionInit(INITARGS)
     XaceRC(XACE_PROPERTY_ACCESS, SecurityCheckPropertyAccess, NULL);
     XaceRC(XACE_DRAWABLE_ACCESS, SecurityCheckDrawableAccess, NULL);
     XaceRC(XACE_MAP_ACCESS, SecurityCheckMapAccess, NULL);
-    XaceRC(XACE_BACKGRND_ACCESS, SecurityCheckBackgrndAccess, NULL);
     XaceRC(XACE_EXT_DISPATCH, SecurityCheckExtAccess, NULL);
     XaceRC(XACE_EXT_ACCESS, SecurityCheckExtAccess, NULL);
     XaceRC(XACE_SERVER_ACCESS, SecurityCheckServerAccess, NULL);
diff --git a/Xext/xace.c b/Xext/xace.c
index de1887f..54e910f 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -113,8 +113,7 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_MAP_ACCESS:
-	case XACE_BACKGRND_ACCESS: {
+	case XACE_MAP_ACCESS: {
 	    XaceMapAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, WindowPtr),
@@ -124,6 +123,17 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
+	case XACE_CLIENT_ACCESS: {
+	    XaceClientAccessRec rec = {
+		va_arg(ap, ClientPtr),
+		va_arg(ap, ClientPtr),
+		va_arg(ap, Mask),
+		Success /* default allow */
+	    };
+	    calldata = &rec;
+	    prv = &rec.status;
+	    break;
+	}
 	case XACE_EXT_DISPATCH:
 	case XACE_EXT_ACCESS: {
 	    XaceExtAccessRec rec = {
diff --git a/Xext/xace.h b/Xext/xace.h
index f7ff205..f1a6e9d 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -47,7 +47,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_PROPERTY_ACCESS		4
 #define XACE_DRAWABLE_ACCESS		5
 #define XACE_MAP_ACCESS			6
-#define XACE_BACKGRND_ACCESS		7
+#define XACE_CLIENT_ACCESS		7
 #define XACE_EXT_ACCESS			8
 #define XACE_SERVER_ACCESS		9
 #define XACE_SELECTION_ACCESS		10
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index e4db3a1..10c625b 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -71,13 +71,20 @@ typedef struct {
 } XaceDrawableAccessRec;
 
 /* XACE_MAP_ACCESS */
-/* XACE_BACKGRND_ACCESS */
 typedef struct {
     ClientPtr client;
     WindowPtr pWin;
     int status;
 } XaceMapAccessRec;
 
+/* XACE_CLIENT_ACCESS */
+typedef struct {
+    ClientPtr client;
+    ClientPtr target;
+    Mask access_mode;
+    int status;
+} XaceClientAccessRec;
+
 /* XACE_EXT_DISPATCH */
 /* XACE_EXT_ACCESS */
 typedef struct {
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 9cb2f32..1ffd79d 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1157,15 +1157,6 @@ XSELinuxMap(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 } /* XSELinuxMap */
 
 static void
-XSELinuxBackgrnd(CallbackListPtr *pcbl, pointer unused, pointer calldata)
-{
-    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
-    if (IDPerm(rec->client, rec->pWin->drawable.id,
-               SECCLASS_WINDOW, WINDOW__TRANSPARENT) != Success)
-	rec->status = BadAccess;
-} /* XSELinuxBackgrnd */
-
-static void
 XSELinuxDrawable(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
@@ -1398,7 +1389,6 @@ XSELinuxExtensionInit(INITARGS)
     XaceRegisterCallback(XACE_RESOURCE_ACCESS, XSELinuxResLookup, NULL);
     XaceRegisterCallback(XACE_MAP_ACCESS, XSELinuxMap, NULL);
     XaceRegisterCallback(XACE_SERVER_ACCESS, XSELinuxServer, NULL);
-    XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
     XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
     XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
     /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
commit b82557c9fb60f11fd2696c8fb2ae17b9dfd915ed
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 16 10:36:05 2007 -0400

    xace: add hooks + new access codes: core protocol screensaver requests

diff --git a/Xext/dpms.c b/Xext/dpms.c
index aced406..97622cb 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -218,7 +218,7 @@ ProcDPMSDisable(client)
 
     REQUEST_SIZE_MATCH(xDPMSDisableReq);
 
-    DPMSSet(DPMSModeOn);
+    DPMSSet(client, DPMSModeOn);
 
     DPMSEnabled = FALSE;
 
@@ -253,7 +253,7 @@ ProcDPMSForceLevel(client)
 	return BadValue;
     }
 
-    DPMSSet(stuff->level);
+    DPMSSet(client, stuff->level);
 
     return(client->noClientException);
 }
diff --git a/Xext/dpmsproc.h b/Xext/dpmsproc.h
index f5485ea..d57f573 100644
--- a/Xext/dpmsproc.h
+++ b/Xext/dpmsproc.h
@@ -8,7 +8,9 @@
 #ifndef _DPMSPROC_H_
 #define _DPMSPROC_H_
 
-void DPMSSet(int level);
+#include "dixstruct.h"
+
+int  DPMSSet(ClientPtr client, int level);
 int  DPMSGet(int *plevel);
 Bool DPMSSupported(void);
 
diff --git a/Xext/dpmsstubs.c b/Xext/dpmsstubs.c
index 9f99a2d..8d58935 100644
--- a/Xext/dpmsstubs.c
+++ b/Xext/dpmsstubs.c
@@ -46,7 +46,7 @@ int DPMSGet(int *plevel)
     return -1;
 }
 
-void DPMSSet(int level)
+int DPMSSet(ClientPtr client, int level)
 {
 
 }
diff --git a/Xext/saver.c b/Xext/saver.c
index a9f1dd3..dabfbea 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -454,8 +454,8 @@ ScreenSaverFreeAttr (value, id)
     pPriv->attr = NULL;
     if (pPriv->hasWindow)
     {
-	SaveScreens (SCREEN_SAVER_FORCER, ScreenSaverReset);
-	SaveScreens (SCREEN_SAVER_FORCER, ScreenSaverActive);
+	SaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
+	SaveScreens (serverClient, SCREEN_SAVER_FORCER, ScreenSaverActive);
     }
     CheckScreenPrivate (pScreen);
     return TRUE;
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 94d8974..8d879c7 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -458,7 +458,7 @@ ProcXTestFakeInput(client)
 	break;
     }
     if (screenIsSaved == SCREEN_SAVER_ON)
-	SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
+	SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
     ev->u.keyButtonPointer.time = currentTime.milliseconds;
     (*dev->public.processInputProc)(ev, dev, nev);
     return client->noClientException;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 0bf92de..2dc32a5 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3244,10 +3244,17 @@ ProcQueryBestSize (ClientPtr client)
 int
 ProcSetScreenSaver (ClientPtr client)
 {
-    int blankingOption, exposureOption;
+    int rc, i, blankingOption, exposureOption;
     REQUEST(xSetScreenSaverReq);
-
     REQUEST_SIZE_MATCH(xSetScreenSaverReq);
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i],
+		      DixSetAttrAccess);
+	if (rc != Success)
+	    return rc;
+    }
+
     blankingOption = stuff->preferBlank;
     if ((blankingOption != DontPreferBlanking) &&
         (blankingOption != PreferBlanking) &&
@@ -3301,8 +3308,16 @@ int
 ProcGetScreenSaver(ClientPtr client)
 {
     xGetScreenSaverReply rep;
-
+    int rc, i;
     REQUEST_SIZE_MATCH(xReq);
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i],
+		      DixGetAttrAccess);
+	if (rc != Success)
+	    return rc;
+    }
+
     rep.type = X_Reply;
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
@@ -3523,6 +3538,7 @@ ProcChangeCloseDownMode(ClientPtr client)
 
 int ProcForceScreenSaver(ClientPtr client)
 {    
+    int rc;
     REQUEST(xForceScreenSaverReq);
 
     REQUEST_SIZE_MATCH(xForceScreenSaverReq);
@@ -3533,7 +3549,9 @@ int ProcForceScreenSaver(ClientPtr client)
 	client->errorValue = stuff->mode;
         return BadValue;
     }
-    SaveScreens(SCREEN_SAVER_FORCER, (int)stuff->mode);
+    rc = SaveScreens(client, SCREEN_SAVER_FORCER, (int)stuff->mode);
+    if (rc != Success)
+	return rc;
     return client->noClientException;
 }
 
diff --git a/dix/main.c b/dix/main.c
index 4ae09dc..3e5d0e4 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -430,7 +430,7 @@ main(int argc, char *argv[], char *envp[])
 	for (i = 0; i < screenInfo.numScreens; i++)
 	    InitRootWindow(WindowTable[i]);
 	DefineInitialRootWindow(WindowTable[0]);
-	SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+	SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
 #ifdef PANORAMIX
 	if (!noPanoramiXExtension) {
@@ -449,7 +449,7 @@ main(int argc, char *argv[], char *envp[])
 
 	/* Now free up whatever must be freed */
 	if (screenIsSaved == SCREEN_SAVER_ON)
-	    SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
+	    SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 	FreeScreenSaverTimer();
 	CloseDownExtensions();
 
diff --git a/dix/window.c b/dix/window.c
index 9d1947a..597c55d 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3369,12 +3369,10 @@ static void DrawLogo(
 );
 #endif
 
-_X_EXPORT void
-SaveScreens(int on, int mode)
+_X_EXPORT int
+SaveScreens(ClientPtr client, int on, int mode)
 {
-    int i;
-    int what;
-    int type;
+    int rc, i, what, type;
 
     if (on == SCREEN_SAVER_FORCER)
     {
@@ -3393,6 +3391,13 @@ SaveScreens(int on, int mode)
 	if (what == screenIsSaved)
 	    type = SCREEN_SAVER_CYCLE;
     }
+
+    for (i = 0; i < screenInfo.numScreens; i++) {
+	rc = XaceHook(XACE_SCREENSAVER_ACCESS, client, screenInfo.screens[i],
+		      DixShowAccess | DixHideAccess);
+	if (rc != Success)
+	    return rc;
+    }
     for (i = 0; i < screenInfo.numScreens; i++)
     {
 	if (on == SCREEN_SAVER_FORCER)
@@ -3480,6 +3485,7 @@ SaveScreens(int on, int mode)
     screenIsSaved = what;
     if (mode == ScreenSaverReset)
        SetScreenSaverTimer();
+    return Success;
 }
 
 static Bool
diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c
index 3d7f268..97ad857 100644
--- a/hw/darwin/darwinEvents.c
+++ b/hw/darwin/darwinEvents.c
@@ -276,7 +276,7 @@ void ProcessInputEvents(void) {
     while (darwinEventQueue.head != darwinEventQueue.tail)
     {
         if (screenIsSaved == SCREEN_SAVER_ON)
-            SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
+            SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 
         e = &darwinEventQueue.events[darwinEventQueue.head];
         xe = e->event;
diff --git a/hw/dmx/dmxdpms.c b/hw/dmx/dmxdpms.c
index 5c176df..ea0d66c 100644
--- a/hw/dmx/dmxdpms.c
+++ b/hw/dmx/dmxdpms.c
@@ -175,7 +175,7 @@ void dmxDPMSTerm(DMXScreenInfo *dmxScreen)
 void dmxDPMSWakeup(void)
 {
     if (screenIsSaved == SCREEN_SAVER_ON)
-        SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
+        SaveScreens(serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 #ifdef DPMSExtension
     if (DPMSPowerLevel) DPMSSet(0);
 #endif
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index 3aa83e8..a4ae67e 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -144,20 +144,23 @@ DPMSClose(int i, ScreenPtr pScreen)
  *	Device dependent DPMS mode setting hook.  This is called whenever
  *	the DPMS mode is to be changed.
  */
-_X_EXPORT void
-DPMSSet(int level)
+_X_EXPORT int
+DPMSSet(ClientPtr client, int level)
 {
-    int i;
+    int rc, i;
     DPMSPtr pDPMS;
     ScrnInfoPtr pScrn;
 
     DPMSPowerLevel = level;
 
     if (DPMSIndex < 0)
-	return;
+	return Success;
 
-    if (level != DPMSModeOn)
-	SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverActive);
+    if (level != DPMSModeOn) {
+	rc = SaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
+	if (rc != Success)
+	    return rc;
+    }
 
     /* For each screen, set the DPMS level */
     for (i = 0; i < xf86NumScreens; i++) {
@@ -168,6 +171,7 @@ DPMSSet(int level)
 	    pScrn->DPMSSet(pScrn, level, 0);
 	}
     }
+    return Success;
 }
 
 
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index dd9c34e..7c2c250 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -853,7 +853,7 @@ xf86VTSwitch()
 #endif
 #ifdef DPMSExtension
     if (DPMSPowerLevel != DPMSModeOn)
-	DPMSSet(DPMSModeOn);
+	DPMSSet(serverClient, DPMSModeOn);
 #endif
     for (i = 0; i < xf86NumScreens; i++) {
       if (!(dispatchException & DE_TERMINATE))
@@ -902,7 +902,7 @@ xf86VTSwitch()
 	    (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
 	}
       }
-      SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+      SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
       pInfo = xf86InputDevs;
       while (pInfo) {
@@ -966,7 +966,7 @@ xf86VTSwitch()
     }
 
     /* Turn screen saver off when switching back */
-    SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
+    SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
     pInfo = xf86InputDevs;
     while (pInfo) {
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index bf7dac6..27bc9ad 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1086,7 +1086,7 @@ AbortDDX()
 #endif
 #ifdef DPMSExtension /* Turn screens back on */
   if (DPMSPowerLevel != DPMSModeOn)
-      DPMSSet(DPMSModeOn);
+      DPMSSet(serverClient, DPMSModeOn);
 #endif
   if (xf86Screens) {
       if (xf86Screens[0]->vtSema)
diff --git a/hw/xfree86/common/xf86PM.c b/hw/xfree86/common/xf86PM.c
index a6bcc34..278a514 100644
--- a/hw/xfree86/common/xf86PM.c
+++ b/hw/xfree86/common/xf86PM.c
@@ -116,7 +116,7 @@ resume(pmEvent event, Bool undo)
 	if (xf86Screens[i]->EnableDisableFBAccess)
 	    (*xf86Screens[i]->EnableDisableFBAccess) (i, TRUE);
     }
-    SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
+    SaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
     pInfo = xf86InputDevs;
     while (pInfo) {
 	EnableDevice(pInfo->dev);
diff --git a/include/window.h b/include/window.h
index 472f379..d5437a7 100644
--- a/include/window.h
+++ b/include/window.h
@@ -207,9 +207,10 @@ extern RegionPtr NotClippedByChildren(
 extern void SendVisibilityNotify(
     WindowPtr /*pWin*/);
 
-extern void SaveScreens(
-    int /*on*/,
-    int /*mode*/);
+extern int SaveScreens(
+    ClientPtr client,
+    int on,
+    int mode);
 
 extern WindowPtr FindWindowWithOptional(
     WindowPtr /*w*/);
diff --git a/mi/mieq.c b/mi/mieq.c
index 20c4b62..5093023 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -200,13 +200,13 @@ mieqProcessInputEvents(void)
 
     while (miEventQueue.head != miEventQueue.tail) {
         if (screenIsSaved == SCREEN_SAVER_ON)
-            SaveScreens (SCREEN_SAVER_OFF, ScreenSaverReset);
+            SaveScreens (serverClient, SCREEN_SAVER_OFF, ScreenSaverReset);
 #ifdef DPMSExtension
         else if (DPMSPowerLevel != DPMSModeOn)
             SetScreenSaverTimer();
 
         if (DPMSPowerLevel != DPMSModeOn)
-            DPMSSet(DPMSModeOn);
+            DPMSSet(serverClient, DPMSModeOn);
 #endif
 
         e = &miEventQueue.events[miEventQueue.head];
diff --git a/os/WaitFor.c b/os/WaitFor.c
index ec1592c..1ef79bc 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -583,7 +583,7 @@ TimerInit(void)
 
 #define DPMS_CHECK_MODE(mode,time)\
     if (time > 0 && DPMSPowerLevel < mode && timeout >= time)\
-	DPMSSet(mode);
+	DPMSSet(serverClient, mode);
 
 #define DPMS_CHECK_TIMEOUT(time)\
     if (time > 0 && (time - timeout) > 0)\
@@ -652,7 +652,7 @@ ScreenSaverTimeoutExpire(OsTimerPtr timer,CARD32 now,pointer arg)
     }
 
     ResetOsBuffers(); /* not ideal, but better than nothing */
-    SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive);
+    SaveScreens(serverClient, SCREEN_SAVER_ON, ScreenSaverActive);
 
     if (ScreenSaverInterval > 0)
     {
commit 568ae737d1d5d476a0bf85659d88910c4e0ef5e0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Aug 15 14:14:45 2007 -0400

    xace: add hooks + new access codes: core protocol server requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 8cca44b..0bf92de 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1169,6 +1169,7 @@ ProcConvertSelection(ClientPtr client)
 int
 ProcGrabServer(ClientPtr client)
 {
+    int rc;
     REQUEST_SIZE_MATCH(xReq);
     if (grabState != GrabNone && client != grabClient)
     {
@@ -1178,7 +1179,9 @@ ProcGrabServer(ClientPtr client)
 	IgnoreClient(client);
 	return(client->noClientException);
     }
-    OnlyListenToOneClient(client);
+    rc = OnlyListenToOneClient(client);
+    if (rc != Success)
+	return rc;
     grabState = GrabKickout;
     grabClient = client;
 
@@ -3478,12 +3481,14 @@ int
 ProcGetFontPath(ClientPtr client)
 {
     xGetFontPathReply reply;
-    int stringLens, numpaths;
+    int rc, stringLens, numpaths;
     unsigned char *bufferStart;
     /* REQUEST (xReq); */
 
     REQUEST_SIZE_MATCH(xReq);
-    bufferStart = GetFontPath(&numpaths, &stringLens);
+    rc = GetFontPath(client, &numpaths, &stringLens, &bufferStart);
+    if (rc != Success)
+	return rc;
 
     reply.type = X_Reply;
     reply.sequenceNumber = client->sequence;
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index c21b3ec..4ea6302 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -65,6 +65,7 @@ Equipment Corporation.
 #include "dixfontstr.h"
 #include "closestr.h"
 #include "dixfont.h"
+#include "xace.h"
 
 #ifdef DEBUG
 #include	<stdio.h>
@@ -833,6 +834,10 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
     if (length > XLFDMAXFONTNAMELEN)
 	return BadAlloc;
 
+    i = XaceHook(XACE_SERVER_ACCESS, client, DixGetAttrAccess);
+    if (i != Success)
+	return i;
+
     if (!(c = (LFclosurePtr) xalloc(sizeof *c)))
 	return BadAlloc;
     c->fpe_list = (FontPathElementPtr *)
@@ -1105,6 +1110,10 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern,
     if (length > XLFDMAXFONTNAMELEN)
 	return BadAlloc;
 
+    i = XaceHook(XACE_SERVER_ACCESS, client, DixGetAttrAccess);
+    if (i != Success)
+	return i;
+
     if (!(c = (LFWIclosurePtr) xalloc(sizeof *c)))
 	goto badAlloc;
     c->fpe_list = (FontPathElementPtr *)
@@ -1771,7 +1780,9 @@ bail:
 int
 SetFontPath(ClientPtr client, int npaths, unsigned char *paths, int *error)
 {
-    int   err = Success;
+    int err = XaceHook(XACE_SERVER_ACCESS, client, DixManageAccess);
+    if (err != Success)
+	return err;
 
     if (npaths == 0) {
 	if (SetDefaultFontPath(defaultFontPath) != Success)
@@ -1823,14 +1834,18 @@ SetDefaultFontPath(char *path)
     return err;
 }
 
-unsigned char *
-GetFontPath(int *count, int *length)
+int
+GetFontPath(ClientPtr client, int *count, int *length, unsigned char **result)
 {
     int			i;
     unsigned char       *c;
     int			len;
     FontPathElementPtr	fpe;
 
+    i = XaceHook(XACE_SERVER_ACCESS, client, DixGetAttrAccess);
+    if (i != Success)
+	return i;
+
     len = 0;
     for (i = 0; i < num_fpes; i++) {
 	fpe = font_path_elements[i];
@@ -1838,7 +1853,7 @@ GetFontPath(int *count, int *length)
     }
     font_path_string = (unsigned char *) xrealloc(font_path_string, len);
     if (!font_path_string)
-	return NULL;
+	return BadAlloc;
 
     c = font_path_string;
     *length = 0;
@@ -1850,7 +1865,8 @@ GetFontPath(int *count, int *length)
 	c += fpe->name_length;
     }
     *count = num_fpes;
-    return font_path_string;
+    *result = font_path_string;
+    return Success;
 }
 
 _X_EXPORT int
diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c
index 500b568..e5f8635 100644
--- a/hw/dmx/dmxfont.c
+++ b/hw/dmx/dmxfont.c
@@ -66,7 +66,7 @@ static char **dmxGetFontPath(int *npaths)
     char           *newfp;
     int             len, l, i;
 
-    paths = GetFontPath(npaths, &len);
+    GetFontPath(serverClient, npaths, &len, &paths);
 
     newfp = xalloc(*npaths + len);
     c = (unsigned char *)newfp;
@@ -194,7 +194,7 @@ static int dmxProcSetFontPath(ClientPtr client)
     if (total >= 4)
         return BadLength;
 
-    tmpFontPath = GetFontPath(&nOldPaths, &lenOldPaths);
+    GetFontPath(serverClient, &nOldPaths, &lenOldPaths, &tmpFontPath);
     oldFontPath = xalloc(nOldPaths + lenOldPaths);
     memmove(oldFontPath, tmpFontPath, nOldPaths + lenOldPaths);
 
diff --git a/include/dixfont.h b/include/dixfont.h
index 709da62..54017ce 100644
--- a/include/dixfont.h
+++ b/include/dixfont.h
@@ -105,8 +105,10 @@ extern int SetFontPath(ClientPtr /*client*/,
 
 extern int SetDefaultFontPath(char * /*path*/);
 
-extern unsigned char *GetFontPath(int * /*count*/,
-				  int * /*length*/);
+extern int GetFontPath(ClientPtr client,
+		       int *count,
+		       int *length,
+		       unsigned char **result);
 
 extern int LoadGlyphs(ClientPtr /*client*/,
 		      FontPtr /*pfont*/,
diff --git a/include/os.h b/include/os.h
index 3d68947..891f331 100644
--- a/include/os.h
+++ b/include/os.h
@@ -155,7 +155,7 @@ extern void AddEnabledDevice(int /*fd*/);
 
 extern void RemoveEnabledDevice(int /*fd*/);
 
-extern void OnlyListenToOneClient(ClientPtr /*client*/);
+extern int OnlyListenToOneClient(ClientPtr /*client*/);
 
 extern void ListenToAllClients(void);
 
diff --git a/os/access.c b/os/access.c
index b049acc..33b2eb6 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1493,17 +1493,20 @@ LocalClientCredAndGroups(ClientPtr client, int *pUid, int *pGid,
 #endif
 }
 
-static Bool
+static int
 AuthorizedClient(ClientPtr client)
 {
+    int rc;
+
     if (!client || defeatAccessControl)
-	return TRUE;
+	return Success;
 
     /* untrusted clients can't change host access */
-    if (XaceHook(XACE_SERVER_ACCESS, client, DixWriteAccess) != Success)
-	return FALSE;
+    rc = XaceHook(XACE_SERVER_ACCESS, client, DixManageAccess);
+    if (rc != Success)
+	return rc;
 
-    return LocalClient(client);
+    return LocalClient(client) ? Success : BadAccess;
 }
 
 /* Add a host to the access control list.  This is the external interface
@@ -1515,10 +1518,11 @@ AddHost (ClientPtr	client,
 	 unsigned       length,        /* of bytes in pAddr */
 	 pointer        pAddr)
 {
-    int			len;
+    int rc, len;
 
-    if (!AuthorizedClient(client))
-	return(BadAccess);
+    rc = AuthorizedClient(client);
+    if (rc != Success)
+	return rc;
     switch (family) {
     case FamilyLocalHost:
 	len = length;
@@ -1612,11 +1616,12 @@ RemoveHost (
     unsigned            length,        /* of bytes in pAddr */
     pointer             pAddr)
 {
-    int			len;
+    int rc, len;
     register HOST	*host, **prev;
 
-    if (!AuthorizedClient(client))
-	return(BadAccess);
+    rc = AuthorizedClient(client);
+    if (rc != Success)
+	return rc;
     switch (family) {
     case FamilyLocalHost:
 	len = length;
@@ -1873,8 +1878,9 @@ ChangeAccessControl(
     ClientPtr client,
     int fEnabled)
 {
-    if (!AuthorizedClient(client))
-	return BadAccess;
+    int rc = AuthorizedClient(client);
+    if (rc != Success)
+	return rc;
     AccessEnabled = fEnabled;
     return Success;
 }
diff --git a/os/connection.c b/os/connection.c
index c1152aa..afe392c 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -1081,11 +1081,15 @@ RemoveEnabledDevice(int fd)
  *    This routine is "undone" by ListenToAllClients()
  *****************/
 
-void
+int
 OnlyListenToOneClient(ClientPtr client)
 {
     OsCommPtr oc = (OsCommPtr)client->osPrivate;
-    int connection = oc->fd;
+    int rc, connection = oc->fd;
+
+    rc = XaceHook(XACE_SERVER_ACCESS, client, DixGrabAccess);
+    if (rc != Success)
+	return rc;
 
     if (! GrabInProgress)
     {
@@ -1106,6 +1110,7 @@ OnlyListenToOneClient(ClientPtr client)
 	XFD_ORSET(&AllSockets, &AllSockets, &AllClients);
 	GrabInProgress = client->index;
     }
+    return rc;
 }
 
 /****************
commit 3c9553ac2cac7f3a41966def44a50d722d7e645b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Aug 15 14:14:25 2007 -0400

    xace: rename hostlist security hook to "server" as this hook will be used
    for other types of server access besides just the host list.

diff --git a/Xext/security.c b/Xext/security.c
index 9e3b2dd..0059245 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1222,10 +1222,10 @@ SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
 }
 
 static void
-SecurityCheckHostlistAccess(CallbackListPtr *pcbl, pointer unused,
-			    pointer calldata)
+SecurityCheckServerAccess(CallbackListPtr *pcbl, pointer unused,
+			  pointer calldata)
 {
-    XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
+    XaceServerAccessRec *rec = (XaceServerAccessRec*)calldata;
  
     if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
     {
@@ -1851,5 +1851,5 @@ SecurityExtensionInit(INITARGS)
     XaceRC(XACE_BACKGRND_ACCESS, SecurityCheckBackgrndAccess, NULL);
     XaceRC(XACE_EXT_DISPATCH, SecurityCheckExtAccess, NULL);
     XaceRC(XACE_EXT_ACCESS, SecurityCheckExtAccess, NULL);
-    XaceRC(XACE_HOSTLIST_ACCESS, SecurityCheckHostlistAccess, NULL);
+    XaceRC(XACE_SERVER_ACCESS, SecurityCheckServerAccess, NULL);
 } /* SecurityExtensionInit */
diff --git a/Xext/xace.c b/Xext/xace.c
index 50361d0..de1887f 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -135,8 +135,8 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_HOSTLIST_ACCESS: {
-	    XaceHostlistAccessRec rec = {
+	case XACE_SERVER_ACCESS: {
+	    XaceServerAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, Mask),
 		Success /* default allow */
diff --git a/Xext/xace.h b/Xext/xace.h
index e2982cf..f7ff205 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -49,7 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_MAP_ACCESS			6
 #define XACE_BACKGRND_ACCESS		7
 #define XACE_EXT_ACCESS			8
-#define XACE_HOSTLIST_ACCESS		9
+#define XACE_SERVER_ACCESS		9
 #define XACE_SELECTION_ACCESS		10
 #define XACE_SCREEN_ACCESS		11
 #define XACE_SCREENSAVER_ACCESS		12
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 8d09251..e4db3a1 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -86,12 +86,12 @@ typedef struct {
     int status;
 } XaceExtAccessRec;
 
-/* XACE_HOSTLIST_ACCESS */
+/* XACE_SERVER_ACCESS */
 typedef struct {
     ClientPtr client;
     Mask access_mode;
     int status;
-} XaceHostlistAccessRec;
+} XaceServerAccessRec;
 
 /* XACE_SELECTION_ACCESS */
 typedef struct {
@@ -101,6 +101,8 @@ typedef struct {
     int status;
 } XaceSelectionAccessRec;
 
+/* XACE_SCREEN_ACCESS */
+/* XACE_SCREENSAVER_ACCESS */
 typedef struct {
     ClientPtr client;
     ScreenPtr screen;
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 038ec59..9cb2f32 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1175,15 +1175,15 @@ XSELinuxDrawable(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 } /* XSELinuxDrawable */
 
 static void
-XSELinuxHostlist(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+XSELinuxServer(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
+    XaceServerAccessRec *rec = (XaceServerAccessRec*)calldata;
     access_vector_t perm = (rec->access_mode == DixReadAccess) ?
 	XSERVER__GETHOSTLIST : XSERVER__SETHOSTLIST;
 
     if (ServerPerm(rec->client, SECCLASS_XSERVER, perm) != Success)
 	rec->status = BadAccess;
-} /* XSELinuxHostlist */
+} /* XSELinuxServer */
 
 /* Extension callbacks */
 static void
@@ -1397,7 +1397,7 @@ XSELinuxExtensionInit(INITARGS)
     XaceRegisterCallback(XACE_EXT_DISPATCH, XSELinuxExtDispatch, NULL);
     XaceRegisterCallback(XACE_RESOURCE_ACCESS, XSELinuxResLookup, NULL);
     XaceRegisterCallback(XACE_MAP_ACCESS, XSELinuxMap, NULL);
-    XaceRegisterCallback(XACE_HOSTLIST_ACCESS, XSELinuxHostlist, NULL);
+    XaceRegisterCallback(XACE_SERVER_ACCESS, XSELinuxServer, NULL);
     XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
     XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
     XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 4a9064d..8cca44b 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3346,7 +3346,7 @@ ProcListHosts(ClientPtr client)
     REQUEST_SIZE_MATCH(xListHostsReq);
 
     /* untrusted clients can't list hosts */
-    result = XaceHook(XACE_HOSTLIST_ACCESS, client, DixReadAccess);
+    result = XaceHook(XACE_SERVER_ACCESS, client, DixReadAccess);
     if (result != Success)
 	return result;
 
diff --git a/os/access.c b/os/access.c
index 8d96e04..b049acc 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1500,7 +1500,7 @@ AuthorizedClient(ClientPtr client)
 	return TRUE;
 
     /* untrusted clients can't change host access */
-    if (XaceHook(XACE_HOSTLIST_ACCESS, client, DixWriteAccess) != Success)
+    if (XaceHook(XACE_SERVER_ACCESS, client, DixWriteAccess) != Success)
 	return FALSE;
 
     return LocalClient(client);
commit dc84bb3418933297a8c005070902d9a91ed3d18f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Aug 15 14:13:53 2007 -0400

    xace: add hooks + new access codes: core protocol cursor requests

diff --git a/dix/cursor.c b/dix/cursor.c
index d903124..b188e3f 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -59,6 +59,7 @@ SOFTWARE.
 #include "cursorstr.h"
 #include "dixfontstr.h"
 #include "opaque.h"
+#include "xace.h"
 
 typedef struct _GlyphShare {
     FontPtr font;
@@ -161,23 +162,25 @@ CheckForEmptyMask(CursorBitsPtr bits)
  *  \param pmaskbits server-defined padding
  *  \param argb      no padding
  */
-CursorPtr 
-AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb, 
-                CursorMetricPtr cm,
-                unsigned foreRed, unsigned foreGreen, unsigned foreBlue, 
-                unsigned backRed, unsigned backGreen, unsigned backBlue)
+int
+AllocARGBCursor(unsigned char *psrcbits, unsigned char *pmaskbits,
+		CARD32 *argb, CursorMetricPtr cm,
+		unsigned foreRed, unsigned foreGreen, unsigned foreBlue, 
+		unsigned backRed, unsigned backGreen, unsigned backBlue,
+		CursorPtr *ppCurs, ClientPtr client, XID cid)
 {
     CursorBitsPtr  bits;
     CursorPtr 	pCurs;
-    int		nscr;
+    int		rc, nscr;
     ScreenPtr 	pscr;
 
+    *ppCurs = NULL;
     pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
     if (!pCurs)
     {
 	xfree(psrcbits);
 	xfree(pmaskbits);
-	return (CursorPtr)NULL;
+	return BadAlloc;
     }
     bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
     bits->source = psrcbits;
@@ -207,6 +210,15 @@ AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb,
     pCurs->backGreen = backGreen;
     pCurs->backBlue = backBlue;
 
+    /* security creation/labeling check */
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
+		  DixCreateAccess, pCurs);
+    if (rc != Success) {
+	FreeCursorBits(bits);
+	xfree(pCurs);
+	return rc;
+    }
+	
     /*
      * realize the cursor for every screen
      */
@@ -222,59 +234,43 @@ AllocCursorARGB(unsigned char *psrcbits, unsigned char *pmaskbits, CARD32 *argb,
 	    }
 	    FreeCursorBits(bits);
 	    xfree(pCurs);
-	    return (CursorPtr)NULL;
+	    return BadAlloc;
 	}
     }
-    return pCurs;
-}
-
-/**
- *
- * \param psrcbits   server-defined padding
- * \param pmaskbits  server-defined padding
- */
-CursorPtr 
-AllocCursor(unsigned char *psrcbits, unsigned char *pmaskbits, 
-            CursorMetricPtr cm,
-            unsigned foreRed, unsigned foreGreen, unsigned foreBlue,
-            unsigned backRed, unsigned backGreen, unsigned backBlue)
-{
-    return AllocCursorARGB (psrcbits, pmaskbits, (CARD32 *) 0, cm,
-			    foreRed, foreGreen, foreBlue,
-			    backRed, backGreen, backBlue);
+    *ppCurs = pCurs;
+    return rc;
 }
 
 int
 AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
                 unsigned foreRed, unsigned foreGreen, unsigned foreBlue, 
                 unsigned backRed, unsigned backGreen, unsigned backBlue,
-                CursorPtr *ppCurs, ClientPtr client)
+		CursorPtr *ppCurs, ClientPtr client, XID cid)
 {
     FontPtr  sourcefont, maskfont;
     unsigned char   *srcbits;
     unsigned char   *mskbits;
     CursorMetricRec cm;
-    int res;
+    int rc;
     CursorBitsPtr  bits;
     CursorPtr 	pCurs;
     int		nscr;
     ScreenPtr 	pscr;
     GlyphSharePtr pShare;
 
-    sourcefont = (FontPtr) SecurityLookupIDByType(client, source, RT_FONT,
-						  DixReadAccess);
-    maskfont = (FontPtr) SecurityLookupIDByType(client, mask, RT_FONT,
-						DixReadAccess);
-
-    if (!sourcefont)
+    rc = dixLookupResource((pointer *)&sourcefont, source, RT_FONT, client,
+			   DixUseAccess);
+    if (rc != Success)
     {
 	client->errorValue = source;
-	return(BadFont);
+	return (rc == BadValue) ? BadFont : rc;
     }
-    if (!maskfont && (mask != None))
+    rc = dixLookupResource((pointer *)&maskfont, mask, RT_FONT, client,
+			   DixUseAccess);
+    if (rc != Success && mask != None)
     {
 	client->errorValue = mask;
-	return(BadFont);
+	return (rc == BadValue) ? BadFont : rc;
     }
     if (sourcefont != maskfont)
 	pShare = (GlyphSharePtr)NULL;
@@ -322,13 +318,13 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
 		client->errorValue = maskChar;
 		return BadValue;
 	    }
-	    if ((res = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits)) != 0)
-		return res;
+	    if ((rc = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits)))
+		return rc;
 	}
-	if ((res = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits)) != 0)
+	if ((rc = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits)))
 	{
 	    xfree(mskbits);
-	    return res;
+	    return rc;
 	}
 	if (sourcefont != maskfont)
 	{
@@ -398,6 +394,15 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     pCurs->backGreen = backGreen;
     pCurs->backBlue = backBlue;
 
+    /* security creation/labeling check */
+    rc = XaceHook(XACE_RESOURCE_ACCESS, client, cid, RT_CURSOR,
+		  DixCreateAccess, pCurs);
+    if (rc != Success) {
+	FreeCursorBits(bits);
+	xfree(pCurs);
+	return rc;
+    }
+	
     /*
      * realize the cursor for every screen
      */
@@ -447,7 +452,8 @@ CreateRootCursor(char *unused1, unsigned int unused2)
     cm.xhot = 0;
     cm.yhot = 0;
 
-    curs = AllocCursor(NULL, NULL, &cm, 0, 0, 0, 0, 0, 0);
+    AllocARGBCursor(NULL, NULL, NULL, &cm, 0, 0, 0, 0, 0, 0,
+		    &curs, serverClient, (XID)0);
 
     if (curs == NullCursor)
         return NullCursor;
@@ -461,8 +467,8 @@ CreateRootCursor(char *unused1, unsigned int unused2)
     cursorfont = (FontPtr)LookupIDByType(fontID, RT_FONT);
     if (!cursorfont)
 	return NullCursor;
-    if (AllocGlyphCursor(fontID, 0, fontID, 1,
-			 0, 0, 0, ~0, ~0, ~0, &curs, serverClient) != Success)
+    if (AllocGlyphCursor(fontID, 0, fontID, 1, 0, 0, 0, ~0, ~0, ~0,
+			 &curs, serverClient, (XID)0) != Success)
 	return NullCursor;
 #endif
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 4260799..4a9064d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3070,28 +3070,28 @@ ProcCreateCursor (ClientPtr client)
     unsigned short	width, height;
     long		n;
     CursorMetricRec 	cm;
-
+    int rc;
 
     REQUEST(xCreateCursorReq);
 
     REQUEST_SIZE_MATCH(xCreateCursorReq);
     LEGAL_NEW_RESOURCE(stuff->cid, client);
 
-    src = (PixmapPtr)SecurityLookupIDByType(client, stuff->source,
-					      RT_PIXMAP, DixReadAccess);
-    msk = (PixmapPtr)SecurityLookupIDByType(client, stuff->mask,
-					      RT_PIXMAP, DixReadAccess);
-    if (   src == (PixmapPtr)NULL)
-    {
+    rc = dixLookupResource((pointer *)&src, stuff->source, RT_PIXMAP, client,
+			   DixReadAccess);
+    if (rc != Success) {
 	client->errorValue = stuff->source;
-	return (BadPixmap);
+	return (rc == BadValue) ? BadPixmap : rc;
     }
-    if ( msk == (PixmapPtr)NULL)
+
+    rc = dixLookupResource((pointer *)&msk, stuff->mask, RT_PIXMAP, client,
+			   DixReadAccess);
+    if (rc != Success)
     {
 	if (stuff->mask != None)
 	{
 	    client->errorValue = stuff->mask;
-	    return (BadPixmap);
+	    return (rc == BadValue) ? BadPixmap : rc;
 	}
     }
     else if (  src->drawable.width != msk->drawable.width
@@ -3139,13 +3139,17 @@ ProcCreateCursor (ClientPtr client)
     cm.height = height;
     cm.xhot = stuff->x;
     cm.yhot = stuff->y;
-    pCursor = AllocCursor( srcbits, mskbits, &cm,
-	    stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
-	    stuff->backRed, stuff->backGreen, stuff->backBlue);
+    rc = AllocARGBCursor(srcbits, mskbits, NULL, &cm,
+			 stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
+			 stuff->backRed, stuff->backGreen, stuff->backBlue,
+			 &pCursor, client, stuff->cid);
 
-    if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
-	    return (client->noClientException);
-    return BadAlloc;
+    if (rc != Success)
+	return rc;
+    if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
+	return BadAlloc;
+
+    return client->noClientException;
 }
 
 int
@@ -3163,7 +3167,7 @@ ProcCreateGlyphCursor (ClientPtr client)
 			   stuff->mask, stuff->maskChar,
 			   stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
 			   stuff->backRed, stuff->backGreen, stuff->backBlue,
-			   &pCursor, client);
+			   &pCursor, client, stuff->cid);
     if (res != Success)
 	return res;
     if (AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
@@ -3176,12 +3180,13 @@ int
 ProcFreeCursor (ClientPtr client)
 {
     CursorPtr pCursor;
+    int rc;
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->id,
-					RT_CURSOR, DixDestroyAccess);
-    if (pCursor) 
+    rc = dixLookupResource((pointer *)&pCursor, stuff->id, RT_CURSOR, client,
+			   DixDestroyAccess);
+    if (rc == Success) 
     {
 	FreeResource(stuff->id, RT_NONE);
 	return (client->noClientException);
@@ -3189,7 +3194,7 @@ ProcFreeCursor (ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return (BadCursor);
+	return (rc == BadValue) ? BadCursor : rc;
     }
 }
 
diff --git a/dix/events.c b/dix/events.c
index 3fbe9b8..f109dad 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4115,12 +4115,12 @@ ProcChangeActivePointerGrab(ClientPtr client)
 	newCursor = NullCursor;
     else
     {
-	newCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
-						RT_CURSOR, DixReadAccess);
-	if (!newCursor)
+	int rc = dixLookupResource((pointer *)&newCursor, stuff->cursor,
+				   RT_CURSOR, client, DixUseAccess);
+	if (rc != Success)
 	{
 	    client->errorValue = stuff->cursor;
-	    return BadCursor;
+	    return (rc == BadValue) ? BadCursor : rc;
 	}
     }
     if (!grab)
@@ -4889,18 +4889,18 @@ int
 ProcRecolorCursor(ClientPtr client)
 {
     CursorPtr pCursor;
-    int		nscr;
+    int		rc, nscr;
     ScreenPtr	pscr;
     Bool 	displayed;
     REQUEST(xRecolorCursorReq);
 
     REQUEST_SIZE_MATCH(xRecolorCursorReq);
-    pCursor = (CursorPtr)SecurityLookupIDByType(client, stuff->cursor,
-					RT_CURSOR, DixWriteAccess);
-    if ( !pCursor) 
+    rc = dixLookupResource((pointer *)&pCursor, stuff->cursor, RT_CURSOR,
+			   client, DixWriteAccess);
+    if (rc != Success)
     {
 	client->errorValue = stuff->cursor;
-	return (BadCursor);
+	return (rc == BadValue) ? BadCursor : rc;
     }
 
     pCursor->foreRed = stuff->foreRed;
diff --git a/dix/window.c b/dix/window.c
index 3addc73..9d1947a 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -3541,7 +3541,8 @@ TileScreenSaver(int i, int kind)
     {
 	for (j=0; j<BitmapBytePad(32)*16; j++)
 	    srcbits[j] = mskbits[j] = 0x0;
-	cursor = AllocCursor(srcbits, mskbits, &cm, 0, 0, 0, 0, 0, 0);
+	result = AllocARGBCursor(srcbits, mskbits, NULL, &cm, 0, 0, 0, 0, 0, 0,
+				 &cursor, serverClient, (XID)0);
 	if (cursor)
 	{
 	    cursorID = FakeClientID(0);
diff --git a/include/cursor.h b/include/cursor.h
index bdf4fd3..8635cf1 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -68,23 +68,7 @@ extern int FreeCursor(
     pointer /*pCurs*/,
     XID /*cid*/);
 
-/* Quartz support on Mac OS X pulls in the QuickDraw
-   framework whose AllocCursor function conflicts here. */ 
-#ifdef __DARWIN__
-#define AllocCursor Darwin_X_AllocCursor
-#endif
-extern CursorPtr AllocCursor(
-    unsigned char* /*psrcbits*/,
-    unsigned char* /*pmaskbits*/,
-    CursorMetricPtr /*cm*/,
-    unsigned /*foreRed*/,
-    unsigned /*foreGreen*/,
-    unsigned /*foreBlue*/,
-    unsigned /*backRed*/,
-    unsigned /*backGreen*/,
-    unsigned /*backBlue*/);
-
-extern CursorPtr AllocCursorARGB(
+extern int AllocARGBCursor(
     unsigned char* /*psrcbits*/,
     unsigned char* /*pmaskbits*/,
     CARD32* /*argb*/,
@@ -94,7 +78,10 @@ extern CursorPtr AllocCursorARGB(
     unsigned /*foreBlue*/,
     unsigned /*backRed*/,
     unsigned /*backGreen*/,
-    unsigned /*backBlue*/);
+    unsigned /*backBlue*/,
+    CursorPtr* /*ppCurs*/,
+    ClientPtr /*client*/,
+    XID /*cid*/);
 
 extern int AllocGlyphCursor(
     Font /*source*/,
@@ -108,7 +95,8 @@ extern int AllocGlyphCursor(
     unsigned /*backGreen*/,
     unsigned /*backBlue*/,
     CursorPtr* /*ppCurs*/,
-    ClientPtr /*client*/);
+    ClientPtr /*client*/,
+    XID /*cid*/);
 
 extern CursorPtr CreateRootCursor(
     char* /*pfilename*/,
diff --git a/render/render.c b/render/render.c
index caaa278..e57ffb1 100644
--- a/render/render.c
+++ b/render/render.c
@@ -1492,7 +1492,7 @@ ProcRenderCreateCursor (ClientPtr client)
     CursorMetricRec cm;
     CursorPtr	    pCursor;
     CARD32	    twocolor[3];
-    int		    ncolor;
+    int		    rc, ncolor;
 
     REQUEST_SIZE_MATCH (xRenderCreateCursorReq);
     LEGAL_NEW_RESOURCE(stuff->cid, client);
@@ -1659,16 +1659,20 @@ ProcRenderCreateCursor (ClientPtr client)
     cm.height = height;
     cm.xhot = stuff->x;
     cm.yhot = stuff->y;
-    pCursor = AllocCursorARGB (srcbits, mskbits, argbbits, &cm,
-			       GetColor(twocolor[0], 16),
-			       GetColor(twocolor[0], 8),
-			       GetColor(twocolor[0], 0),
-			       GetColor(twocolor[1], 16),
-			       GetColor(twocolor[1], 8),
-			       GetColor(twocolor[1], 0));
-    if (pCursor && AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
-	return (client->noClientException);
-    return BadAlloc;
+    rc = AllocARGBCursor(srcbits, mskbits, argbbits, &cm,
+			 GetColor(twocolor[0], 16),
+			 GetColor(twocolor[0], 8),
+			 GetColor(twocolor[0], 0),
+			 GetColor(twocolor[1], 16),
+			 GetColor(twocolor[1], 8),
+			 GetColor(twocolor[1], 0),
+			 &pCursor, client, stuff->cid);
+    if (rc != Success)
+	return rc;
+    if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
+	return BadAlloc;
+
+    return client->noClientException;
 }
 
 static int
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 401c403..450f366 100755
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -980,6 +980,7 @@ createInvisibleCursor (void)
     CursorPtr pCursor;
     static unsigned int *psrcbits, *pmaskbits;
     CursorMetricRec cm;
+    int rc;
 
     psrcbits = (unsigned int *) xalloc(4);
     pmaskbits = (unsigned int *) xalloc(4);
@@ -994,12 +995,13 @@ createInvisibleCursor (void)
     cm.xhot = 0;
     cm.yhot = 0;
 
-    pCursor = AllocCursor(
+    rc = AllocARGBCursor(
 	        (unsigned char *)psrcbits,
 		(unsigned char *)pmaskbits,
-		&cm,
+		NULL, &cm,
 		0, 0, 0,
-		0, 0, 0);
+		0, 0, 0,
+		&pCursor, serverClient, (XID)0);
 
     return pCursor;
 }
commit b424e01ec59d9600a02823f1522949325797268c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Aug 14 13:20:42 2007 -0400

    xace: add hooks + new access codes: core protocol property requests

diff --git a/dix/property.c b/dix/property.c
index c0de5b3..5f12dec 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -129,7 +129,7 @@ ProcRotateProperties(ClientPtr client)
 
     REQUEST_FIXED_SIZE(xRotatePropertiesReq, stuff->nAtoms << 2);
     UpdateCurrentTime();
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetPropAccess);
     if (rc != Success)
         return rc;
     if (!stuff->nAtoms)
@@ -217,7 +217,7 @@ ProcChangeProperty(ClientPtr client)
     totalSize = len * sizeInBytes;
     REQUEST_FIXED_SIZE(xChangePropertyReq, totalSize);
 
-    err = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    err = dixLookupWindow(&pWin, stuff->window, client, DixSetPropAccess);
     if (err != Success)
 	return err;
     if (!ValidAtom(stuff->property))
@@ -277,7 +277,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 	pProp->size = len;
 	pProp->devPrivates = NULL;
 	rc = XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
-		      DixCreateAccess);
+		      DixCreateAccess|DixWriteAccess);
 	if (rc != Success) {
 	    xfree(data);
 	    xfree(pProp);
@@ -449,13 +449,15 @@ ProcGetProperty(ClientPtr client)
     int rc;
     WindowPtr pWin;
     xGetPropertyReply reply;
-    Mask access_mode = DixReadAccess;
+    Mask access_mode = DixGetPropAccess;
     REQUEST(xGetPropertyReq);
 
     REQUEST_SIZE_MATCH(xGetPropertyReq);
-    if (stuff->delete)
+    if (stuff->delete) {
 	UpdateCurrentTime();
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+	access_mode |= DixSetPropAccess;
+    }
+    rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
     if (rc != Success)
 	return rc;
 
@@ -490,6 +492,7 @@ ProcGetProperty(ClientPtr client)
     if (!pProp) 
 	return NullPropertyReply(client, None, 0, &reply);
 
+    access_mode = DixReadAccess;
     if (stuff->delete)
 	access_mode |= DixDestroyAccess;
 
@@ -581,7 +584,7 @@ ProcListProperties(ClientPtr client)
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixListPropAccess);
     if (rc != Success)
         return rc;
 
@@ -625,7 +628,7 @@ ProcDeleteProperty(ClientPtr client)
               
     REQUEST_SIZE_MATCH(xDeletePropertyReq);
     UpdateCurrentTime();
-    result = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    result = dixLookupWindow(&pWin, stuff->window, client, DixSetPropAccess);
     if (result != Success)
         return result;
     if (!ValidAtom(stuff->property))
commit 42d6112ec21949a336ee8b34469f2695273ee2d6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Aug 14 13:09:38 2007 -0400

    xace: add hooks + new access codes: core protocol GC requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 69b1922..4260799 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1583,15 +1583,16 @@ ProcCreateGC(ClientPtr client)
     REQUEST_AT_LEAST_SIZE(xCreateGCReq);
     client->errorValue = stuff->gc;
     LEGAL_NEW_RESOURCE(stuff->gc, client);
-    rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixReadAccess);
+    rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
     len = client->req_len -  (sizeof(xCreateGCReq) >> 2);
     if (len != Ones(stuff->mask))
         return BadLength;
-    pGC = (GC *)CreateGC(pDraw, stuff->mask, 
-			 (XID *) &stuff[1], &error);
+    pGC = (GC *)CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error,
+			 stuff->gc, client);
     if (error != Success)
         return error;
     if (!AddResource(stuff->gc, RT_GC, (pointer)pGC))
@@ -1608,7 +1609,7 @@ ProcChangeGC(ClientPtr client)
     REQUEST(xChangeGCReq);
     REQUEST_AT_LEAST_SIZE(xChangeGCReq);
 
-    result = dixLookupGC(&pGC, stuff->gc, client, DixWriteAccess);
+    result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess);
     if (result != Success)
 	return result;
 
@@ -1635,10 +1636,10 @@ ProcCopyGC(ClientPtr client)
     REQUEST(xCopyGCReq);
     REQUEST_SIZE_MATCH(xCopyGCReq);
 
-    result = dixLookupGC(&pGC, stuff->srcGC, client, DixReadAccess);
+    result = dixLookupGC(&pGC, stuff->srcGC, client, DixGetAttrAccess);
     if (result != Success)
 	return result;
-    result = dixLookupGC(&dstGC, stuff->dstGC, client, DixWriteAccess);
+    result = dixLookupGC(&dstGC, stuff->dstGC, client, DixSetAttrAccess);
     if (result != Success)
 	return result;
     if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth))
@@ -1667,7 +1668,7 @@ ProcSetDashes(ClientPtr client)
          return BadValue;
     }
 
-    result = dixLookupGC(&pGC,stuff->gc, client, DixWriteAccess);
+    result = dixLookupGC(&pGC,stuff->gc, client, DixSetAttrAccess);
     if (result != Success)
 	return result;
 
@@ -1696,7 +1697,7 @@ ProcSetClipRectangles(ClientPtr client)
 	client->errorValue = stuff->ordering;
         return BadValue;
     }
-    result = dixLookupGC(&pGC,stuff->gc, client, DixWriteAccess);
+    result = dixLookupGC(&pGC,stuff->gc, client, DixSetAttrAccess);
     if (result != Success)
 	return result;
 		 
diff --git a/dix/gc.c b/dix/gc.c
index e7c4849..ccd586b 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -63,6 +63,7 @@ SOFTWARE.
 
 #include "privates.h"
 #include "dix.h"
+#include "xace.h"
 #include <assert.h>
 
 extern XID clientErrorValue;
@@ -148,7 +149,7 @@ _X_EXPORT int
 dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr pUnion)
 {
     BITS32 	index2;
-    int 	error = 0;
+    int 	rc, error = 0;
     PixmapPtr 	pPixmap;
     BITS32	maskQ;
 
@@ -267,14 +268,15 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		if (pUnion)
 		{
 		    NEXT_PTR(PixmapPtr, pPixmap);
+		    rc = Success;
 		}
 		else
 		{
 		    NEXTVAL(XID, newpix);
-		    pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
-					newpix, RT_PIXMAP, DixReadAccess);
+		    rc = dixLookupResource((pointer *)&pPixmap, newpix,
+					   RT_PIXMAP, client, DixReadAccess);
 		}
-		if (pPixmap)
+		if (rc == Success)
 		{
 		    if ((pPixmap->drawable.depth != pGC->depth) ||
 			(pPixmap->drawable.pScreen != pGC->pScreen))
@@ -293,7 +295,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		else
 		{
 		    clientErrorValue = newpix;
-		    error = BadPixmap;
+		    error = (rc == BadValue) ? BadPixmap : rc;
 		}
 		break;
 	    }
@@ -303,14 +305,15 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		if (pUnion)
 		{
 		    NEXT_PTR(PixmapPtr, pPixmap);
+		    rc = Success;
 		}
 		else
 		{
 		    NEXTVAL(XID, newstipple)
-		    pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
-				newstipple, RT_PIXMAP, DixReadAccess);
+		    rc = dixLookupResource((pointer *)&pPixmap, newstipple,
+					   RT_PIXMAP, client, DixReadAccess);
 		}
-		if (pPixmap)
+		if (rc == Success)
 		{
 		    if ((pPixmap->drawable.depth != 1) ||
 			(pPixmap->drawable.pScreen != pGC->pScreen))
@@ -328,7 +331,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		else
 		{
 		    clientErrorValue = newstipple;
-		    error = BadPixmap;
+		    error = (rc == BadValue) ? BadPixmap : rc;
 		}
 		break;
 	    }
@@ -345,14 +348,15 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		if (pUnion)
 		{
 		    NEXT_PTR(FontPtr, pFont);
+		    rc = Success;
 		}
 		else
 		{
 		    NEXTVAL(XID, newfont)
-		    pFont = (FontPtr)SecurityLookupIDByType(client, newfont,
-						RT_FONT, DixReadAccess);
+		    rc = dixLookupResource((pointer *)&pFont, newfont,
+					   RT_FONT, client, DixUseAccess);
 		}
-		if (pFont)
+		if (rc == Success)
 		{
 		    pFont->refcnt++;
 		    if (pGC->font)
@@ -362,7 +366,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		else
 		{
 		    clientErrorValue = newfont;
-		    error = BadFont;
+		    error = (rc == BadValue) ? BadFont : rc;
 		}
 		break;
 	    }
@@ -415,9 +419,15 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 			clipType = CT_NONE;
 			pPixmap = NullPixmap;
 		    }
-		    else
-		        pPixmap = (PixmapPtr)SecurityLookupIDByType(client,
-					pid, RT_PIXMAP, DixReadAccess);
+		    else {
+			rc = dixLookupResource((pointer *)&pPixmap, pid,
+					       RT_PIXMAP, client,
+					       DixReadAccess);
+			if (rc != Success) {
+			    clientErrorValue = pid;
+			    error = (rc == BadValue) ? BadPixmap : rc;
+			}
+		    }
 		}
 
 		if (pPixmap)
@@ -433,11 +443,6 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 			pPixmap->refcnt++;
 		    }
 		}
-		else if (!pUnion && (pid != None))
-		{
-		    clientErrorValue = pid;
-		    error = BadPixmap;
-		}
 		if(error == Success)
 		{
 		    (*pGC->funcs->ChangeClip)(pGC, clipType,
@@ -601,7 +606,8 @@ AllocateGC(ScreenPtr pScreen)
 }
 
 _X_EXPORT GCPtr
-CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus)
+CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus,
+	 XID gcid, ClientPtr client)
 {
     GCPtr pGC;
 
@@ -663,6 +669,12 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus)
     pGC->stipple = pGC->pScreen->PixmapPerDepth[0];
     pGC->stipple->refcnt++;
 
+    /* security creation/labeling check */
+    *pStatus = XaceHook(XACE_RESOURCE_ACCESS, client, gcid, RT_GC,
+			DixCreateAccess|DixSetAttrAccess, pGC);
+    if (*pStatus != Success)
+	goto out;
+
     pGC->stateChanges = (1 << (GCLastBit+1)) - 1;
     if (!(*pGC->pScreen->CreateGC)(pGC))
 	*pStatus = BadAlloc;
@@ -670,6 +682,8 @@ CreateGC(DrawablePtr pDrawable, BITS32 mask, XID *pval, int *pStatus)
         *pStatus = ChangeGC(pGC, mask, pval);
     else
 	*pStatus = Success;
+
+out:
     if (*pStatus != Success)
     {
 	if (!pGC->tileIsPixel && !pGC->tile.pixmap)
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 6abe31c..70a9469 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -1844,7 +1844,8 @@ xf86XVFillKeyHelperDrawable (DrawablePtr pDraw, CARD32 key, RegionPtr clipboxes)
        int status;
        pval[0] = key;
        pval[1] = IncludeInferiors;
-       pGC = CreateGC(pDraw, GCForeground | GCSubwindowMode, pval, &status);
+       pGC = CreateGC(pDraw, GCForeground | GCSubwindowMode, pval, &status,
+		      (XID)0, serverClient);
        if(!pGC) return;
        ValidateGC(pDraw, pGC);
        if (pPriv) pPriv->pGC = pGC;
diff --git a/include/dix.h b/include/dix.h
index daf16cb..05366ec 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -88,7 +88,7 @@ SOFTWARE.
 			       DixWriteAccess);\
 	if (rc != Success)\
 	    return rc;\
-	rc = dixLookupGC(&(pGC), stuff->gc, client, DixReadAccess);\
+	rc = dixLookupGC(&(pGC), stuff->gc, client, DixUseAccess);\
 	if (rc != Success)\
 	    return rc;\
 	if ((pGC->depth != pDraw->depth) || (pGC->pScreen != pDraw->pScreen))\
diff --git a/include/gc.h b/include/gc.h
index 3b7e38e..bf4c268 100644
--- a/include/gc.h
+++ b/include/gc.h
@@ -115,7 +115,9 @@ extern GCPtr CreateGC(
     DrawablePtr /*pDrawable*/,
     BITS32 /*mask*/,
     XID* /*pval*/,
-    int* /*pStatus*/);
+    int* /*pStatus*/,
+    XID /*gcid*/,
+    ClientPtr /*client*/);
 
 extern int CopyGC(
     GCPtr/*pgcSrc*/,
diff --git a/mi/mibstore.c b/mi/mibstore.c
index 70839ce..e27c681 100644
--- a/mi/mibstore.c
+++ b/mi/mibstore.c
@@ -3468,7 +3468,8 @@ miBSValidateGC (pGC, stateChanges, pDrawable)
 
 	/* We never want ops with the backingGC to generate GraphicsExpose */
 	pBackingGC = CreateGC ((DrawablePtr)pWindowPriv->pBackingPixmap,
-			       GCGraphicsExposures, &noexpose, &status);
+			       GCGraphicsExposures, &noexpose, &status,
+			       (XID)0, serverClient);
 	if (status != Success)
 	    lift_functions = TRUE;
 	else
diff --git a/mi/midispcur.c b/mi/midispcur.c
index de009cb..ab10837 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -450,7 +450,8 @@ miDCMakeGC(
     gcvals[0] = IncludeInferiors;
     gcvals[1] = FALSE;
     pGC = CreateGC((DrawablePtr)pWin,
-		   GCSubwindowMode|GCGraphicsExposures, gcvals, &status);
+		   GCSubwindowMode|GCGraphicsExposures, gcvals, &status,
+		   (XID)0, serverClient);
     if (pGC && pWin->drawable.pScreen->DrawGuarantee)
 	(*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
     *ppGC = pGC;
@@ -746,7 +747,7 @@ miDCMoveCursor (pScreen, pCursor, x, y, w, h, dx, dy, source, mask)
     if (!pScreenPriv->pMoveGC)
     {
 	pScreenPriv->pMoveGC = CreateGC ((DrawablePtr)pTemp,
-	    GCGraphicsExposures, &gcval, &status);
+	    GCGraphicsExposures, &gcval, &status, (XID)0, serverClient);
 	if (!pScreenPriv->pMoveGC)
 	    return FALSE;
     }
@@ -782,14 +783,14 @@ miDCMoveCursor (pScreen, pCursor, x, y, w, h, dx, dy, source, mask)
 	if (!pScreenPriv->pPixSourceGC)
 	{
 	    pScreenPriv->pPixSourceGC = CreateGC ((DrawablePtr)pTemp,
-		GCGraphicsExposures, &gcval, &status);
+		GCGraphicsExposures, &gcval, &status, (XID)0, serverClient);
 	    if (!pScreenPriv->pPixSourceGC)
 		return FALSE;
 	}
 	if (!pScreenPriv->pPixMaskGC)
 	{
 	    pScreenPriv->pPixMaskGC = CreateGC ((DrawablePtr)pTemp,
-		GCGraphicsExposures, &gcval, &status);
+		GCGraphicsExposures, &gcval, &status, (XID)0, serverClient);
 	    if (!pScreenPriv->pPixMaskGC)
 		return FALSE;
 	}
diff --git a/mi/miexpose.c b/mi/miexpose.c
index df04bd2..332b216 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -763,7 +763,7 @@ int what;
 	    if (!ResType && !(ResType = CreateNewResourceType(tossGC)))
 		return;
 	    screenContext[i] = CreateGC((DrawablePtr)pWin, (BITS32) 0,
-					(XID *)NULL, &status);
+					(XID *)NULL, &status, 0, serverClient);
 	    if (!screenContext[i])
 		return;
 	    numGCs++;
diff --git a/miext/cw/cw.c b/miext/cw/cw.c
index 7ee013b..b03f5e3 100644
--- a/miext/cw/cw.c
+++ b/miext/cw/cw.c
@@ -123,7 +123,7 @@ cwCreateBackingGC(GCPtr pGC, DrawablePtr pDrawable)
 
     pBackingDrawable = cwGetBackingDrawable(pDrawable, &x_off, &y_off);
     pPriv->pBackingGC = CreateGC(pBackingDrawable, GCGraphicsExposures,
-				 &noexpose, &status);
+				 &noexpose, &status, (XID)0, serverClient);
     if (status != Success)
 	return FALSE;
 
commit 9a183d7ba50e31afa133cc03aee7991517a283ea
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Aug 14 11:39:26 2007 -0400

    dix: remove caching of drawables and graphics contexts.  The security checks
    simply bypass the cached values so they are unused.

diff --git a/Xext/mbuf.c b/Xext/mbuf.c
index ed352e2..ee2ef64 100644
--- a/Xext/mbuf.c
+++ b/Xext/mbuf.c
@@ -235,7 +235,7 @@ MultibufferExtensionInit()
      * create the resource types
      */
     MultibufferDrawableResType =
-	CreateNewResourceType(MultibufferDrawableDelete)|RC_CACHED|RC_DRAWABLE;
+	CreateNewResourceType(MultibufferDrawableDelete)|RC_DRAWABLE;
     MultibufferResType = CreateNewResourceType(MultibufferDelete);
     MultibuffersResType = CreateNewResourceType(MultibuffersDelete);
     OtherClientResType = CreateNewResourceType(OtherClientDelete);
diff --git a/dbe/dbe.c b/dbe/dbe.c
index d63620d..aec626b 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -1783,7 +1783,7 @@ DbeExtensionInit(void)
 
     /* Create the resource types. */
     dbeDrawableResType =
-        CreateNewResourceType(DbeDrawableDelete) | RC_CACHED | RC_DRAWABLE;
+        CreateNewResourceType(DbeDrawableDelete) | RC_DRAWABLE;
     dbeWindowPrivResType =
         CreateNewResourceType(DbeWindowPrivDelete);
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 1c40e2f..69b1922 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -258,34 +258,6 @@ InitSelections(void)
     CurrentSelections = (Selection *)NULL;
     NumCurrentSelections = 0;
 }
-
-void 
-FlushClientCaches(XID id)
-{
-    int i;
-    ClientPtr client;
-
-    client = clients[CLIENT_ID(id)];
-    if (client == NullClient)
-        return ;
-    for (i=0; i<currentMaxClients; i++)
-    {
-	client = clients[i];
-        if (client != NullClient)
-	{
-            if (client->lastDrawableID == id)
-	    {
-		client->lastDrawableID = WindowTable[0]->drawable.id;
-		client->lastDrawable = (DrawablePtr)WindowTable[0];
-	    }
-            else if (client->lastGCID == id)
-	    {
-                client->lastGCID = INVALID;
-		client->lastGC = (GCPtr)NULL;
-	    }
-	}
-    }
-}
 #ifdef SMART_SCHEDULE
 
 #undef SMART_DEBUG
@@ -3702,20 +3674,7 @@ void InitClient(ClientPtr client, int i, pointer ospriv)
     client->sequence = 0; 
     client->clientAsMask = ((Mask)i) << CLIENTOFFSET;
     client->clientGone = FALSE;
-    if (i)
-    {
-	client->closeDownMode = DestroyAll;
-	client->lastDrawable = (DrawablePtr)WindowTable[0];
-	client->lastDrawableID = WindowTable[0]->drawable.id;
-    }
-    else
-    {
-	client->closeDownMode = RetainPermanent;
-	client->lastDrawable = (DrawablePtr)NULL;
-	client->lastDrawableID = INVALID;
-    }
-    client->lastGC = (GCPtr) NULL;
-    client->lastGCID = INVALID;
+    client->closeDownMode = i ? DestroyAll : RetainPermanent;
     client->numSaved = 0;
     client->saveSet = (SaveSetElt *)NULL;
     client->noClientException = Success;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 14ef7e6..e8d7daf 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -208,7 +208,6 @@ dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
 		  Mask type, Mask access)
 {
     DrawablePtr pTmp;
-    RESTYPE rtype;
     int rc;
 
     *pDraw = NULL;
@@ -217,28 +216,15 @@ dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
     if (id == INVALID)
 	return BadDrawable;
 
-    if (id == client->lastDrawableID) {
-	pTmp = client->lastDrawable;
+    rc = dixLookupResource((pointer *)&pTmp, id, RC_DRAWABLE, client, access);
 
-	/* an access check is required for cached drawables */
-	rtype = (type & M_WINDOW) ? RT_WINDOW : RT_PIXMAP;
-	rc = XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, access, pTmp);
-        if (rc != Success)
-	    return rc;
-    } else
-	dixLookupResource((void **)&pTmp, id, RC_DRAWABLE, client, access);
-
-    if (!pTmp)
+    if (rc == BadValue)
 	return BadDrawable;
+    if (rc != Success)
+	return rc;
     if (!((1 << pTmp->type) & (type ? type : M_DRAWABLE)))
 	return BadMatch;
 
-    if (type & M_DRAWABLE) {
-	client->lastDrawable = pTmp;
-	client->lastDrawableID = id;
-	client->lastGCID = INVALID;
-	client->lastGC = (GCPtr)NULL;
-    }
     *pDraw = pTmp;
     return Success;
 }
diff --git a/dix/resource.c b/dix/resource.c
index ea0a310..844d12e 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -585,8 +585,6 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
 
 		CallResourceStateCallback(ResourceStateFreeing, res);
 
-		if (rtype & RC_CACHED)
-		    FlushClientCaches(res->id);
 		if (rtype != skipDeleteFuncType)
 		    (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
 		xfree(res);
@@ -597,11 +595,6 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
 	    else
 		prev = &res->next;
         }
-	if(clients[cid] && (id == clients[cid]->lastDrawableID))
-	{
-	    clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0];
-	    clients[cid]->lastDrawableID = WindowTable[0]->drawable.id;
-	}
     }
     if (!gotOne)
 	ErrorF("Freeing resource id=%lX which isn't there.\n",
@@ -632,8 +625,6 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 
 		CallResourceStateCallback(ResourceStateFreeing, res);
 
-		if (type & RC_CACHED)
-		    FlushClientCaches(res->id);
 		if (!skipFree)
 		    (*DeleteFuncs[type & TypeMask])(res->value, res->id);
 		xfree(res);
@@ -642,11 +633,6 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 	    else
 		prev = &res->next;
         }
-	if(clients[cid] && (id == clients[cid]->lastDrawableID))
-	{
-	    clients[cid]->lastDrawable = (DrawablePtr)WindowTable[0];
-	    clients[cid]->lastDrawableID = WindowTable[0]->drawable.id;
-	}
     }
 }
 
@@ -669,8 +655,6 @@ ChangeResourceValue (XID id, RESTYPE rtype, pointer value)
 	for (; res; res = res->next)
 	    if ((res->id == id) && (res->type == rtype))
 	    {
-		if (rtype & RC_CACHED)
-		    FlushClientCaches(res->id);
 		res->value = value;
 		return TRUE;
 	    }
@@ -801,8 +785,6 @@ FreeClientNeverRetainResources(ClientPtr client)
 
 		CallResourceStateCallback(ResourceStateFreeing, this);
 
-		if (rtype & RC_CACHED)
-		    FlushClientCaches(this->id);
 		(*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
 		xfree(this);
 	    }
@@ -854,8 +836,6 @@ FreeClientResources(ClientPtr client)
 
 	    CallResourceStateCallback(ResourceStateFreeing, this);
 
-	    if (rtype & RC_CACHED)
-		FlushClientCaches(this->id);
 	    (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
 	    xfree(this);
 	}
diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c
index 825d3dc..2cfe0ff 100755
--- a/hw/xwin/winclipboardwrappers.c
+++ b/hw/xwin/winclipboardwrappers.c
@@ -431,7 +431,6 @@ winProcSetSelectionOwner (ClientPtr client)
    * and we currently own the Win32 clipboard.
    */
   if (None == stuff->window
-      && g_iClipboardWindow != client->lastDrawableID
       && (None == s_iOwners[CLIP_OWN_PRIMARY]
 	  || g_iClipboardWindow == s_iOwners[CLIP_OWN_PRIMARY])
       && (None == s_iOwners[CLIP_OWN_CLIPBOARD]
diff --git a/include/dix.h b/include/dix.h
index 71f4c23..daf16cb 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -82,8 +82,6 @@ SOFTWARE.
     }
 
 #define VALIDATE_DRAWABLE_AND_GC(drawID, pDraw, pGC, client)\
-    if ((stuff->gc == INVALID) || (client->lastGCID != stuff->gc) ||\
-	(client->lastDrawableID != drawID))\
     {\
 	int rc;\
 	rc = dixLookupDrawable(&(pDraw), drawID, client, M_ANY,\
@@ -95,15 +93,6 @@ SOFTWARE.
 	    return rc;\
 	if ((pGC->depth != pDraw->depth) || (pGC->pScreen != pDraw->pScreen))\
 	    return (BadMatch);\
-	client->lastDrawable = pDraw;\
-	client->lastDrawableID = drawID;\
-	client->lastGC = pGC;\
-	client->lastGCID = stuff->gc;\
-    }\
-    else\
-    {\
-        pGC = client->lastGC;\
-        pDraw = client->lastDrawable;\
     }\
     if (pGC->serialNumber != pDraw->serialNumber)\
 	ValidateGC(pDraw, pGC);
@@ -160,8 +149,6 @@ extern void UpdateCurrentTimeIf(void);
 
 extern void InitSelections(void);
 
-extern void FlushClientCaches(XID /*id*/);
-
 extern int dixDestroyPixmap(
     pointer /*value*/,
     XID /*pid*/);
diff --git a/include/dixstruct.h b/include/dixstruct.h
index dd6347f..2a3e696 100644
--- a/include/dixstruct.h
+++ b/include/dixstruct.h
@@ -101,10 +101,6 @@ typedef struct _Client {
     int         clientGone;
     int         noClientException;	/* this client died or needs to be
 					 * killed */
-    DrawablePtr lastDrawable;
-    Drawable    lastDrawableID;
-    GCPtr       lastGC;
-    GContext    lastGCID;
     SaveSetElt	*saveSet;
     int         numSaved;
     pointer     screenPrivate[MAXSCREENS];
diff --git a/include/resource.h b/include/resource.h
index d2ecfde..087d62c 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -72,9 +72,9 @@ typedef unsigned long RESTYPE;
 
 /* types for Resource routines */
 
-#define RT_WINDOW	((RESTYPE)1|RC_CACHED|RC_DRAWABLE)
-#define RT_PIXMAP	((RESTYPE)2|RC_CACHED|RC_DRAWABLE)
-#define RT_GC		((RESTYPE)3|RC_CACHED)
+#define RT_WINDOW	((RESTYPE)1|RC_DRAWABLE)
+#define RT_PIXMAP	((RESTYPE)2|RC_DRAWABLE)
+#define RT_GC		((RESTYPE)3)
 #undef RT_FONT
 #undef RT_CURSOR
 #define RT_FONT		((RESTYPE)4)
commit 2763056ab5ae31bed422a0948198d98c6ace6d55
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Aug 13 13:40:47 2007 -0400

    xace: add hooks + new access codes: core protocol window requests

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 83d761b..1c40e2f 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -556,12 +556,12 @@ ProcCreateWindow(ClientPtr client)
 {
     WindowPtr pParent, pWin;
     REQUEST(xCreateWindowReq);
-    int result, len, rc;
+    int len, rc;
 
     REQUEST_AT_LEAST_SIZE(xCreateWindowReq);
     
     LEGAL_NEW_RESOURCE(stuff->wid, client);
-    rc = dixLookupWindow(&pParent, stuff->parent, client, DixWriteAccess);
+    rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess);
     if (rc != Success)
         return rc;
     len = client->req_len - (sizeof(xCreateWindowReq) >> 2);
@@ -577,7 +577,7 @@ ProcCreateWindow(ClientPtr client)
 			      stuff->borderWidth, stuff->class,
 			      stuff->mask, (XID *) &stuff[1], 
 			      (int)stuff->depth, 
-			      client, stuff->visual, &result);
+			      client, stuff->visual, &rc);
     if (pWin)
     {
 	Mask mask = pWin->eventMask;
@@ -590,7 +590,7 @@ ProcCreateWindow(ClientPtr client)
     if (client->noClientException != Success)
         return(client->noClientException);
     else
-        return(result);
+        return rc;
 }
 
 int
@@ -602,7 +602,7 @@ ProcChangeWindowAttributes(ClientPtr client)
     int len, rc;
 
     REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixSetAttrAccess);
     if (rc != Success)
         return rc;
     len = client->req_len - (sizeof(xChangeWindowAttributesReq) >> 2);
@@ -627,7 +627,7 @@ ProcGetWindowAttributes(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     GetWindowAttributes(pWin, client, &wa);
@@ -646,8 +646,13 @@ ProcDestroyWindow(ClientPtr client)
     rc = dixLookupWindow(&pWin, stuff->id, client, DixDestroyAccess);
     if (rc != Success)
 	return rc;
-    if (pWin->parent)
+    if (pWin->parent) {
+	rc = dixLookupWindow(&pWin, pWin->parent->drawable.id, client,
+			     DixRemoveAccess);
+	if (rc != Success)
+	    return rc;
 	FreeResource(stuff->id, RT_NONE);
+    }
     return(client->noClientException);
 }
 
@@ -659,7 +664,7 @@ ProcDestroySubwindows(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixDestroyAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixRemoveAccess);
     if (rc != Success)
 	return rc;
     DestroySubwindows(pWin, client);
@@ -674,7 +679,7 @@ ProcChangeSaveSet(ClientPtr client)
     int result, rc;
 		  
     REQUEST_SIZE_MATCH(xChangeSaveSetReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
     if (rc != Success)
         return rc;
     if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)))
@@ -702,10 +707,10 @@ ProcReparentWindow(ClientPtr client)
     int result, rc;
 
     REQUEST_SIZE_MATCH(xReparentWindowReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
     if (rc != Success)
         return rc;
-    rc = dixLookupWindow(&pParent, stuff->parent, client, DixWriteAccess);
+    rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess);
     if (rc != Success)
         return rc;
     if (SAME_SCREENS(pWin->drawable, pParent->drawable))
@@ -735,7 +740,7 @@ ProcMapWindow(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixShowAccess);
     if (rc != Success)
         return rc;
     MapWindow(pWin, client);
@@ -751,7 +756,7 @@ ProcMapSubwindows(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess);
     if (rc != Success)
         return rc;
     MapSubwindows(pWin, client);
@@ -767,7 +772,7 @@ ProcUnmapWindow(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixHideAccess);
     if (rc != Success)
         return rc;
     UnmapWindow(pWin, FALSE);
@@ -783,7 +788,7 @@ ProcUnmapSubwindows(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess);
     if (rc != Success)
         return rc;
     UnmapSubwindows(pWin);
@@ -799,7 +804,8 @@ ProcConfigureWindow(ClientPtr client)
     int len, rc;
 
     REQUEST_AT_LEAST_SIZE(xConfigureWindowReq);
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client,
+			 DixManageAccess|DixSetAttrAccess);
     if (rc != Success)
         return rc;
     len = client->req_len - (sizeof(xConfigureWindowReq) >> 2);
@@ -827,7 +833,7 @@ ProcCirculateWindow(ClientPtr client)
 	client->errorValue = stuff->direction;
         return BadValue;
     }
-    rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess);
+    rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
     if (rc != Success)
         return rc;
     CirculateWindow(pWin, (int)stuff->direction, client);
@@ -842,7 +848,7 @@ GetGeometry(ClientPtr client, xGetGeometryReply *rep)
     REQUEST(xResourceReq);
     REQUEST_SIZE_MATCH(xResourceReq);
 
-    rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixReadAccess);
+    rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixGetAttrAccess);
     if (rc != Success)
 	return rc;
 
@@ -903,7 +909,7 @@ ProcQueryTree(ClientPtr client)
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess);
     if (rc != Success)
         return rc;
     reply.type = X_Reply;
@@ -1260,10 +1266,10 @@ ProcTranslateCoords(ClientPtr client)
     int rc;
 
     REQUEST_SIZE_MATCH(xTranslateCoordsReq);
-    rc = dixLookupWindow(&pWin, stuff->srcWid, client, DixReadAccess);
+    rc = dixLookupWindow(&pWin, stuff->srcWid, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
-    rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixReadAccess);
+    rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixGetAttrAccess);
     if (rc != Success)
         return rc;
     rep.type = X_Reply;
@@ -3233,12 +3239,15 @@ ProcQueryBestSize (ClientPtr client)
     }
 
     rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY,
-			   DixReadAccess);
+			   DixGetAttrAccess);
     if (rc != Success)
 	return rc;
     if (stuff->class != CursorShape && pDraw->type == UNDRAWABLE_WINDOW)
 	return (BadMatch);
     pScreen = pDraw->pScreen;
+    rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess);
+    if (rc != Success)
+	return rc;
     (* pScreen->QueryBestSize)(stuff->class, &stuff->width,
 			       &stuff->height, pScreen);
     reply.type = X_Reply;
diff --git a/dix/window.c b/dix/window.c
index 2f151b0..3addc73 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -733,20 +733,14 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
     /*  security creation/labeling check
      */
     *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW,
-		      DixCreateAccess, pWin);
+		      DixCreateAccess|DixSetAttrAccess, pWin);
     if (*error != Success) {
 	xfree(pWin);
 	return NullWindow;
     }
-    /*  can't let untrusted clients have background None windows;
-     *  they make it too easy to steal window contents
-     */
-    if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin) == Success)
-	pWin->backgroundState = None;
-    else {
-	pWin->backgroundState = BackgroundPixel;
-	pWin->background.pixel = 0;
-    }
+
+    pWin->backgroundState = BackgroundPixel;
+    pWin->background.pixel = 0;
 
     pWin->borderIsPixel = pParent->borderIsPixel;
     pWin->border = pParent->border;
@@ -980,7 +974,7 @@ DeleteWindow(pointer value, XID wid)
     return Success;
 }
 
-void
+int
 DestroySubwindows(WindowPtr pWin, ClientPtr client)
 {
     /* XXX
@@ -992,8 +986,15 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client)
      * If you care, simply delete the call to UnmapSubwindows.
      */
     UnmapSubwindows(pWin);
-    while (pWin->lastChild)
+    while (pWin->lastChild) {
+	int rc = XaceHook(XACE_RESOURCE_ACCESS, client,
+			  pWin->lastChild->drawable.id, RT_WINDOW,
+			  DixDestroyAccess, pWin->lastChild);
+	if (rc != Success)
+	    return rc;
 	FreeResource(pWin->lastChild->drawable.id, RT_NONE);
+    }
+    return Success;
 }
 
 #define DeviceEventMasks (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
@@ -1010,25 +1011,20 @@ DestroySubwindows(WindowPtr pWin, ClientPtr client)
 _X_EXPORT int
 ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 {
-    Mask index2;
     XID *pVlist;
     PixmapPtr pPixmap;
     Pixmap pixID;
     CursorPtr pCursor, pOldCursor;
     Cursor cursorID;
-    WindowPtr pChild;
+    WindowPtr pChild, pLayerWin;
     Colormap cmap;
     ColormapPtr	pCmap;
     xEvent xE;
-    int result;
+    int error, rc;
     ScreenPtr pScreen;
-    Mask vmaskCopy = 0;
-    Mask tmask;
+    Mask index2, tmask, vmaskCopy = 0;
     unsigned int val;
-    int error;
-    Bool checkOptional = FALSE;
-    Bool borderRelative = FALSE;
-    WindowPtr pLayerWin;
+    Bool checkOptional = FALSE, borderRelative = FALSE;
 
     if ((pWin->drawable.class == InputOnly) && (vmask & (~INPUTONLY_LEGAL_MASK)))
 	return BadMatch;
@@ -1050,17 +1046,13 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		borderRelative = TRUE;
 	    if (pixID == None)
 	    {
-		/*  can't let untrusted clients have background None windows */
-		if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin) == Success) {
-		    if (pWin->backgroundState == BackgroundPixmap)
-			(*pScreen->DestroyPixmap)(pWin->background.pixmap);
-		    if (!pWin->parent)
-			MakeRootTile(pWin);
-		    else
-			pWin->backgroundState = None;
-		} else {
-		    /* didn't change the backgrnd to None, so don't tell ddx */
-		    index2 = 0; 
+		if (pWin->backgroundState == BackgroundPixmap)
+		    (*pScreen->DestroyPixmap)(pWin->background.pixmap);
+		if (!pWin->parent)
+		    MakeRootTile(pWin);
+		else {
+		    pWin->backgroundState = BackgroundPixel;
+		    pWin->background.pixel = 0;
 		}
 	    }
 	    else if (pixID == ParentRelative)
@@ -1083,9 +1075,9 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 	    }
 	    else
 	    {	
-		pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
-						RT_PIXMAP, DixReadAccess);
-		if (pPixmap != (PixmapPtr) NULL)
+		rc = dixLookupResource((pointer *)&pPixmap, pixID, RT_PIXMAP,
+				       client, DixReadAccess);
+		if (rc == Success)
 		{
 		    if	((pPixmap->drawable.depth != pWin->drawable.depth) ||
 			 (pPixmap->drawable.pScreen != pScreen))
@@ -1101,7 +1093,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		}
 		else
 		{
-		    error = BadPixmap;
+		    error = (rc == BadValue) ? BadPixmap : rc;
 		    client->errorValue = pixID;
 		    goto PatchUp;
 		}
@@ -1130,42 +1122,40 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		    error = BadMatch;
 		    goto PatchUp;
 		}
-		if (pWin->borderIsPixel == FALSE)
-		    (*pScreen->DestroyPixmap)(pWin->border.pixmap);
-		pWin->border = pWin->parent->border;
-		if ((pWin->borderIsPixel = pWin->parent->borderIsPixel) == TRUE)
-		{
+		if (pWin->parent->borderIsPixel == TRUE) {
+		    if (pWin->borderIsPixel == FALSE)
+			(*pScreen->DestroyPixmap)(pWin->border.pixmap);
+		    pWin->border = pWin->parent->border;
+		    pWin->borderIsPixel = TRUE;
 		    index2 = CWBorderPixel;
+		    break;
 		}
 		else
 		{
-		    pWin->parent->border.pixmap->refcnt++;
+		    pixID = pWin->parent->border.pixmap->drawable.id;
 		}
 	    }
-	    else
-	    {	
-		pPixmap = (PixmapPtr)SecurityLookupIDByType(client, pixID,
-					RT_PIXMAP, DixReadAccess);
-		if (pPixmap)
-		{
-		    if	((pPixmap->drawable.depth != pWin->drawable.depth) ||
-			 (pPixmap->drawable.pScreen != pScreen))
-		    {
-			error = BadMatch;
-			goto PatchUp;
-		    }
-		    if (pWin->borderIsPixel == FALSE)
-			(*pScreen->DestroyPixmap)(pWin->border.pixmap);
-		    pWin->borderIsPixel = FALSE;
-		    pWin->border.pixmap = pPixmap;
-		    pPixmap->refcnt++;
-		}
-		else
+	    rc = dixLookupResource((pointer *)&pPixmap, pixID, RT_PIXMAP,
+				   client, DixReadAccess);
+	    if (rc == Success)
+	    {
+		if ((pPixmap->drawable.depth != pWin->drawable.depth) ||
+		    (pPixmap->drawable.pScreen != pScreen))
 		{
-		    error = BadPixmap;
-		    client->errorValue = pixID;
+		    error = BadMatch;
 		    goto PatchUp;
 		}
+		if (pWin->borderIsPixel == FALSE)
+		    (*pScreen->DestroyPixmap)(pWin->border.pixmap);
+		pWin->borderIsPixel = FALSE;
+		pWin->border.pixmap = pPixmap;
+		pPixmap->refcnt++;
+	    }
+	    else
+	    {
+		error = (rc == BadValue) ? BadPixmap : rc;
+		client->errorValue = pixID;
+		goto PatchUp;
 	    }
 	    break;
 	  case CWBorderPixel:
@@ -1290,20 +1280,20 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 #endif /* DO_SAVE_UNDERS */
 	    break;
 	  case CWEventMask:
-	    result = EventSelectForWindow(pWin, client, (Mask )*pVlist);
-	    if (result)
+	    rc = EventSelectForWindow(pWin, client, (Mask )*pVlist);
+	    if (rc)
 	    {
-		error = result;
+		error = rc;
 		goto PatchUp;
 	    }
 	    pVlist++;
 	    break;
 	  case CWDontPropagate:
-	    result = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
+	    rc = EventSuppressForWindow(pWin, client, (Mask )*pVlist,
 					    &checkOptional);
-	    if (result)
+	    if (rc)
 	    {
-		error = result;
+		error = rc;
 		goto PatchUp;
 	    }
 	    pVlist++;
@@ -1317,6 +1307,15 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		client->errorValue = val;
 		goto PatchUp;
 	    }
+	    if (val == xTrue) {
+		rc = XaceHook(XACE_RESOURCE_ACCESS, client, pWin->drawable.id,
+			      RT_WINDOW, DixGrabAccess, pWin);
+		if (rc != Success) {
+		    error = rc;
+		    client->errorValue = pWin->drawable.id;
+		    goto PatchUp;
+		}
+	    }
 	    pWin->overrideRedirect = val;
 	    break;
 	  case CWColormap:
@@ -1354,11 +1353,11 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		error = BadMatch;
 		goto PatchUp;
 	    }
-	    pCmap = (ColormapPtr)SecurityLookupIDByType(client, cmap,
-					      RT_COLORMAP, DixReadAccess);
-	    if (!pCmap)
+	    rc = dixLookupResource((pointer *)&pCmap, cmap, RT_COLORMAP,
+				   client, DixUseAccess);
+	    if (rc != Success)
 	    {
-		error = BadColor;
+		error = (rc == BadValue) ? BadColor : rc;
 		client->errorValue = cmap;
 		goto PatchUp;
 	    }
@@ -1430,11 +1429,11 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 	    }
 	    else
 	    {
-		pCursor = (CursorPtr)SecurityLookupIDByType(client, cursorID,
-						RT_CURSOR, DixReadAccess);
-		if (!pCursor)
+		rc = dixLookupResource((pointer *)&pCursor, cursorID,
+				       RT_CURSOR, client, DixReadAccess);
+		if (rc != Success)
 		{
-		    error = BadCursor;
+		    error = (rc == BadValue) ? BadCursor : rc;
 		    client->errorValue = cursorID;
 		    goto PatchUp;
 		}
@@ -2267,7 +2266,7 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
     unsigned short w = pWin->drawable.width,
 		   h = pWin->drawable.height,
 		   bw = pWin->borderWidth;
-    int action, smode = Above;
+    int rc, action, smode = Above;
 #ifdef XAPPGROUP
     ClientPtr win_owner;
     ClientPtr ag_leader = NULL;
@@ -2328,12 +2327,11 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
 	  case CWSibling:
 	    sibwid = (Window ) *pVlist;
 	    pVlist++;
-	    pSib = (WindowPtr )SecurityLookupIDByType(client, sibwid,
-						RT_WINDOW, DixReadAccess);
-	    if (!pSib)
+	    rc = dixLookupWindow(&pSib, sibwid, client, DixGetAttrAccess);
+	    if (rc != Success)
 	    {
 		client->errorValue = sibwid;
-		return(BadWindow);
+		return rc;
 	    }
 	    if (pSib->parent != pParent)
 		return(BadMatch);
diff --git a/include/window.h b/include/window.h
index 312b75e..472f379 100644
--- a/include/window.h
+++ b/include/window.h
@@ -119,7 +119,7 @@ extern int DeleteWindow(
     pointer /*pWin*/,
     XID /*wid*/);
 
-extern void DestroySubwindows(
+extern int DestroySubwindows(
     WindowPtr /*pWin*/,
     ClientPtr /*client*/);
 
commit d744df32a15103aa14237175f506350d25b2fec0
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Aug 6 12:23:21 2007 -0400

    xace: add hooks + new access codes: core protocol colormap requests

diff --git a/dix/colormap.c b/dix/colormap.c
index 5155570..7d6e7da 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -64,6 +64,7 @@ SOFTWARE.
 #include "resource.h"
 #include "windowstr.h"
 #include "privates.h"
+#include "xace.h"
 
 extern XID clientErrorValue;
 extern int colormapPrivateCount;
@@ -412,6 +413,16 @@ CreateColormap (Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 	}
     }
 
+    /*  
+     * Security creation/labeling check
+     */
+    i = XaceHook(XACE_RESOURCE_ACCESS, clients[client], mid, RT_COLORMAP,
+		 DixCreateAccess, pmap);
+    if (i != Success) {
+	FreeResource(mid, RT_NONE);
+	return i;
+    }
+
     if (!(*pScreen->CreateColormap)(pmap))
     {
 	FreeResource (mid, RT_NONE);
diff --git a/dix/dispatch.c b/dix/dispatch.c
index ffaad87..83d761b 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -2495,7 +2495,7 @@ ProcCreateColormap(ClientPtr client)
     }
     mid = stuff->mid;
     LEGAL_NEW_RESOURCE(mid, client);
-    result = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+    result = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (result != Success)
         return result;
 
@@ -2521,12 +2521,13 @@ int
 ProcFreeColormap(ClientPtr client)
 {
     ColormapPtr pmap;
+    int rc;
     REQUEST(xResourceReq);
 
     REQUEST_SIZE_MATCH(xResourceReq);
-    pmap = (ColormapPtr )SecurityLookupIDByType(client, stuff->id, RT_COLORMAP,
-						DixDestroyAccess);
-    if (pmap) 
+    rc = dixLookupResource((pointer *)&pmap, stuff->id, RT_COLORMAP, client,
+			   DixDestroyAccess);
+    if (rc == Success)
     {
 	/* Freeing a default colormap is a no-op */
 	if (!(pmap->flags & IsDefault))
@@ -2536,7 +2537,7 @@ ProcFreeColormap(ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return (BadColor);
+	return rc;
     }
 }
 
@@ -2547,24 +2548,25 @@ ProcCopyColormapAndFree(ClientPtr client)
     Colormap	mid;
     ColormapPtr	pSrcMap;
     REQUEST(xCopyColormapAndFreeReq);
-    int result;
+    int rc;
 
     REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq);
     mid = stuff->mid;
     LEGAL_NEW_RESOURCE(mid, client);
-    if( (pSrcMap = (ColormapPtr )SecurityLookupIDByType(client,	stuff->srcCmap,
-		RT_COLORMAP, DixReadAccess|DixWriteAccess)) )
+    rc = dixLookupResource((pointer *)&pSrcMap, stuff->srcCmap, RT_COLORMAP,
+			   client, DixReadAccess|DixRemoveAccess);
+    if (rc == Success)
     {
-	result = CopyColormapAndFree(mid, pSrcMap, client->index);
+	rc = CopyColormapAndFree(mid, pSrcMap, client->index);
 	if (client->noClientException != Success)
             return(client->noClientException);
 	else
-            return(result);
+            return rc;
     }
     else
     {
 	client->errorValue = stuff->srcCmap;
-	return(BadColor);
+	return rc;
     }
 }
 
@@ -2572,43 +2574,51 @@ int
 ProcInstallColormap(ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xResourceReq);
-
     REQUEST_SIZE_MATCH(xResourceReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
-					    RT_COLORMAP, DixReadAccess);
-    if (pcmp)
-    {
-        (*(pcmp->pScreen->InstallColormap)) (pcmp);
-        return (client->noClientException);        
-    }
-    else
-    {
-        client->errorValue = stuff->id;
-        return (BadColor);
-    }
+
+    rc = dixLookupResource((pointer *)&pcmp, stuff->id, RT_COLORMAP, client,
+			   DixInstallAccess);
+    if (rc != Success)
+	goto out;
+
+    rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess);
+    if (rc != Success)
+	goto out;
+
+    (*(pcmp->pScreen->InstallColormap)) (pcmp);
+
+    rc = client->noClientException;
+out:
+    client->errorValue = stuff->id;
+    return (rc == BadValue) ? BadColor : rc;
 }
 
 int
 ProcUninstallColormap(ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xResourceReq);
-
     REQUEST_SIZE_MATCH(xResourceReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->id,
-					RT_COLORMAP, DixReadAccess);
-    if (pcmp)
-    {
-	if(pcmp->mid != pcmp->pScreen->defColormap)
-            (*(pcmp->pScreen->UninstallColormap)) (pcmp);
-        return (client->noClientException);        
-    }
-    else
-    {
-        client->errorValue = stuff->id;
-        return (BadColor);
-    }
+
+    rc = dixLookupResource((pointer *)&pcmp, stuff->id, RT_COLORMAP, client,
+			   DixUninstallAccess);
+    if (rc != Success)
+	goto out;
+
+    rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess);
+    if (rc != Success)
+	goto out;
+
+    if(pcmp->mid != pcmp->pScreen->defColormap)
+	(*(pcmp->pScreen->UninstallColormap)) (pcmp);
+
+    rc = client->noClientException;
+out:
+    client->errorValue = stuff->id;
+    return (rc == BadValue) ? BadColor : rc;
 }
 
 int
@@ -2618,11 +2628,16 @@ ProcListInstalledColormaps(ClientPtr client)
     int nummaps, rc;
     WindowPtr pWin;
     REQUEST(xResourceReq);
-
     REQUEST_SIZE_MATCH(xResourceReq);
-    rc = dixLookupWindow(&pWin, stuff->id, client, DixReadAccess);
+
+    rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess);
     if (rc != Success)
-        return rc;
+	goto out;
+
+    rc = XaceHook(XACE_SCREEN_ACCESS, client, pWin->drawable.pScreen,
+		  DixGetAttrAccess);
+    if (rc != Success)
+	goto out;
 
     preply = (xListInstalledColormapsReply *) 
 		ALLOCATE_LOCAL(sizeof(xListInstalledColormapsReply) +
@@ -2641,21 +2656,23 @@ ProcListInstalledColormaps(ClientPtr client)
     client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
     WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1]);
     DEALLOCATE_LOCAL(preply);
-    return(client->noClientException);
+    rc = client->noClientException;
+out:
+    return (rc == BadValue) ? BadColor : rc;
 }
 
 int
 ProcAllocColor (ClientPtr client)
 {
     ColormapPtr pmap;
-    int	retval;
+    int rc;
     xAllocColorReply acr;
     REQUEST(xAllocColorReq);
 
     REQUEST_SIZE_MATCH(xAllocColorReq);
-    pmap = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixWriteAccess);
-    if (pmap)
+    rc = dixLookupResource((pointer *)&pmap, stuff->cmap, RT_COLORMAP, client,
+			   DixAddAccess);
+    if (rc == Success)
     {
 	acr.type = X_Reply;
 	acr.length = 0;
@@ -2664,13 +2681,13 @@ ProcAllocColor (ClientPtr client)
 	acr.green = stuff->green;
 	acr.blue = stuff->blue;
 	acr.pixel = 0;
-	if( (retval = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
+	if( (rc = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
 	                       &acr.pixel, client->index)) )
 	{
             if (client->noClientException != Success)
                 return(client->noClientException);
 	    else
-	        return (retval);
+	        return rc;
 	}
 #ifdef PANORAMIX
 	if (noPanoramiXExtension || !pmap->pScreen->myNum)
@@ -2682,7 +2699,7 @@ ProcAllocColor (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2690,15 +2707,14 @@ int
 ProcAllocNamedColor (ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xAllocNamedColorReq);
 
     REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					    RT_COLORMAP, DixWriteAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixAddAccess);
+    if (rc == Success)
     {
-	int		retval;
-
 	xAllocNamedColorReply ancr;
 
 	ancr.type = X_Reply;
@@ -2712,14 +2728,14 @@ ProcAllocNamedColor (ClientPtr client)
 	    ancr.screenGreen = ancr.exactGreen;
 	    ancr.screenBlue = ancr.exactBlue;
 	    ancr.pixel = 0;
-	    if( (retval = AllocColor(pcmp,
+	    if( (rc = AllocColor(pcmp,
 	                 &ancr.screenRed, &ancr.screenGreen, &ancr.screenBlue,
 			 &ancr.pixel, client->index)) )
 	    {
                 if (client->noClientException != Success)
                     return(client->noClientException);
                 else
-    	            return(retval);
+		    return rc;
 	    }
 #ifdef PANORAMIX
 	    if (noPanoramiXExtension || !pcmp->pScreen->myNum)
@@ -2734,7 +2750,7 @@ ProcAllocNamedColor (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2742,15 +2758,16 @@ int
 ProcAllocColorCells (ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xAllocColorCellsReq);
 
     REQUEST_SIZE_MATCH(xAllocColorCellsReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixWriteAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixAddAccess);
+    if (rc == Success)
     {
 	xAllocColorCellsReply	accr;
-	int			npixels, nmasks, retval;
+	int			npixels, nmasks;
 	long			length;
 	Pixel			*ppixels, *pmasks;
 
@@ -2772,14 +2789,14 @@ ProcAllocColorCells (ClientPtr client)
             return(BadAlloc);
 	pmasks = ppixels + npixels;
 
-	if( (retval = AllocColorCells(client->index, pcmp, npixels, nmasks, 
+	if( (rc = AllocColorCells(client->index, pcmp, npixels, nmasks, 
 				    (Bool)stuff->contiguous, ppixels, pmasks)) )
 	{
 	    DEALLOCATE_LOCAL(ppixels);
             if (client->noClientException != Success)
                 return(client->noClientException);
 	    else
-	        return(retval);
+	        return rc;
 	}
 #ifdef PANORAMIX
 	if (noPanoramiXExtension || !pcmp->pScreen->myNum)
@@ -2800,7 +2817,7 @@ ProcAllocColorCells (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2808,15 +2825,16 @@ int
 ProcAllocColorPlanes(ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xAllocColorPlanesReq);
 
     REQUEST_SIZE_MATCH(xAllocColorPlanesReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixWriteAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixAddAccess);
+    if (rc == Success)
     {
 	xAllocColorPlanesReply	acpr;
-	int			npixels, retval;
+	int			npixels;
 	long			length;
 	Pixel			*ppixels;
 
@@ -2838,7 +2856,7 @@ ProcAllocColorPlanes(ClientPtr client)
 	ppixels = (Pixel *)ALLOCATE_LOCAL(length);
 	if(!ppixels)
             return(BadAlloc);
-	if( (retval = AllocColorPlanes(client->index, pcmp, npixels,
+	if( (rc = AllocColorPlanes(client->index, pcmp, npixels,
 	    (int)stuff->red, (int)stuff->green, (int)stuff->blue,
 	    (Bool)stuff->contiguous, ppixels,
 	    &acpr.redMask, &acpr.greenMask, &acpr.blueMask)) )
@@ -2847,7 +2865,7 @@ ProcAllocColorPlanes(ClientPtr client)
             if (client->noClientException != Success)
                 return(client->noClientException);
 	    else
-	        return(retval);
+	        return rc;
 	}
 	acpr.length = length >> 2;
 #ifdef PANORAMIX
@@ -2864,7 +2882,7 @@ ProcAllocColorPlanes(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2872,34 +2890,34 @@ int
 ProcFreeColors(ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xFreeColorsReq);
 
     REQUEST_AT_LEAST_SIZE(xFreeColorsReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixWriteAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixRemoveAccess);
+    if (rc == Success)
     {
 	int	count;
-        int     retval;
 
 	if(pcmp->flags & AllAllocated)
 	    return(BadAccess);
 	count = ((client->req_len << 2)- sizeof(xFreeColorsReq)) >> 2;
-	retval =  FreeColors(pcmp, client->index, count,
+	rc = FreeColors(pcmp, client->index, count,
 	    (Pixel *)&stuff[1], (Pixel)stuff->planeMask);
         if (client->noClientException != Success)
             return(client->noClientException);
         else
 	{
 	    client->errorValue = clientErrorValue;
-            return(retval);
+            return rc;
 	}
 
     }
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2907,33 +2925,33 @@ int
 ProcStoreColors (ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xStoreColorsReq);
 
     REQUEST_AT_LEAST_SIZE(xStoreColorsReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixWriteAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixWriteAccess);
+    if (rc == Success)
     {
 	int	count;
-        int     retval;
 
         count = (client->req_len << 2) - sizeof(xStoreColorsReq);
 	if (count % sizeof(xColorItem))
 	    return(BadLength);
 	count /= sizeof(xColorItem);
-	retval = StoreColors(pcmp, count, (xColorItem *)&stuff[1]);
+	rc = StoreColors(pcmp, count, (xColorItem *)&stuff[1]);
         if (client->noClientException != Success)
             return(client->noClientException);
         else
 	{
 	    client->errorValue = clientErrorValue;
-            return(retval);
+            return rc;
 	}
     }
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2941,33 +2959,33 @@ int
 ProcStoreNamedColor (ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xStoreNamedColorReq);
 
     REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixWriteAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixWriteAccess);
+    if (rc == Success)
     {
 	xColorItem	def;
-        int             retval;
 
 	if(OsLookupColor(pcmp->pScreen->myNum, (char *)&stuff[1],
 	                 stuff->nbytes, &def.red, &def.green, &def.blue))
 	{
 	    def.flags = stuff->flags;
 	    def.pixel = stuff->pixel;
-	    retval = StoreColors(pcmp, 1, &def);
+	    rc = StoreColors(pcmp, 1, &def);
             if (client->noClientException != Success)
                 return(client->noClientException);
 	    else
-		return(retval);
+		return rc;
 	}
         return (BadName);        
     }
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
@@ -2975,14 +2993,15 @@ int
 ProcQueryColors(ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xQueryColorsReq);
 
     REQUEST_AT_LEAST_SIZE(xQueryColorsReq);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixReadAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixReadAccess);
+    if (rc == Success)
     {
-	int			count, retval;
+	int			count;
 	xrgb 			*prgbs;
 	xQueryColorsReply	qcr;
 
@@ -2990,7 +3009,7 @@ ProcQueryColors(ClientPtr client)
 	prgbs = (xrgb *)ALLOCATE_LOCAL(count * sizeof(xrgb));
 	if(!prgbs && count)
             return(BadAlloc);
-	if( (retval = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
+	if( (rc = QueryColors(pcmp, count, (Pixel *)&stuff[1], prgbs)) )
 	{
    	    if (prgbs) DEALLOCATE_LOCAL(prgbs);
 	    if (client->noClientException != Success)
@@ -2998,7 +3017,7 @@ ProcQueryColors(ClientPtr client)
 	    else
 	    {
 		client->errorValue = clientErrorValue;
-	        return (retval);
+	        return rc;
 	    }
 	}
 	qcr.type = X_Reply;
@@ -3018,7 +3037,7 @@ ProcQueryColors(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 } 
 
@@ -3026,12 +3045,13 @@ int
 ProcLookupColor(ClientPtr client)
 {
     ColormapPtr pcmp;
+    int rc;
     REQUEST(xLookupColorReq);
 
     REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes);
-    pcmp = (ColormapPtr)SecurityLookupIDByType(client, stuff->cmap,
-					RT_COLORMAP, DixReadAccess);
-    if (pcmp)
+    rc = dixLookupResource((pointer *)&pcmp, stuff->cmap, RT_COLORMAP, client,
+			   DixReadAccess);
+    if (rc == Success)
     {
 	xLookupColorReply lcr;
 
@@ -3056,7 +3076,7 @@ ProcLookupColor(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (BadColor);
+        return (rc == BadValue) ? BadColor : rc;
     }
 }
 
commit acc9a42c926a3f84159780de12ecc1dc6186068a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Aug 6 12:16:59 2007 -0400

    Temporarily disable Security and SELinux extensions
    while changes to XACE are being made.

diff --git a/configure.ac b/configure.ac
index 2af3114..a0fc31f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -510,8 +510,8 @@ AC_ARG_ENABLE(xinerama,	      AS_HELP_STRING([--disable-xinerama], [Build Xinera
 AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: auto)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=auto])
 AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: auto)]), [XF86MISC=$enableval], [XF86MISC=auto])
 AC_ARG_ENABLE(xace,           AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
-AC_ARG_ENABLE(xselinux,       AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: enabled)]), [XSELINUX=$enableval], [XSELINUX=$XACE])
-AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (default: enabled)]), [XCSECURITY=$enableval], [XCSECURITY=$XACE])
+AC_ARG_ENABLE(xselinux,       AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (TEMPORARILY DISABLED)]), [XSELINUX=no], [XSELINUX=no])
+AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (TEMPORARILY DISABLED)]), [XCSECURITY=no], [XCSECURITY=no])
 AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
 AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
 AC_ARG_ENABLE(tslib,          AS_HELP_STRING([--enable-tslib], [Build kdrive tslib touchscreen support (default: disabled)]), [TSLIB=$enableval], [TSLIB=no])
commit 102df4f9bac59d95963572d1a7f31d1a064ca4ca
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Aug 6 09:16:30 2007 -0400

    xace: drop site-policy and declare-extension-security hooks, add 2 new hooks
    for controlling access to screens and screen savers.

diff --git a/Xext/xace.c b/Xext/xace.c
index 46fe7bc..50361d0 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -156,24 +156,18 @@ int XaceHook(int hook, ...)
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_SITE_POLICY: {
-	    XaceSitePolicyRec rec = {
-		va_arg(ap, char*),
-		va_arg(ap, int),
-		BadValue /* default unrecognized */
+	case XACE_SCREEN_ACCESS:
+	case XACE_SCREENSAVER_ACCESS: {
+	    XaceScreenAccessRec rec = {
+		va_arg(ap, ClientPtr),
+		va_arg(ap, ScreenPtr),
+		va_arg(ap, Mask),
+		Success /* default allow */
 	    };
 	    calldata = &rec;
 	    prv = &rec.status;
 	    break;
 	}
-	case XACE_DECLARE_EXT_SECURE: {
-	    XaceDeclareExtSecureRec rec = {
-		va_arg(ap, ExtensionEntry*),
-		va_arg(ap, Bool)
-	    };
-	    calldata = &rec;
-	    break;
-	}
 	case XACE_AUTH_AVAIL: {
 	    XaceAuthAvailRec rec = {
 		va_arg(ap, ClientPtr),
diff --git a/Xext/xace.h b/Xext/xace.h
index 0832612..e2982cf 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -51,8 +51,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_EXT_ACCESS			8
 #define XACE_HOSTLIST_ACCESS		9
 #define XACE_SELECTION_ACCESS		10
-#define XACE_SITE_POLICY		11
-#define XACE_DECLARE_EXT_SECURE		12
+#define XACE_SCREEN_ACCESS		11
+#define XACE_SCREENSAVER_ACCESS		12
 #define XACE_AUTH_AVAIL			13
 #define XACE_KEY_AVAIL			14
 #define XACE_AUDIT_BEGIN		15
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 8eb74d5..8d09251 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -101,18 +101,12 @@ typedef struct {
     int status;
 } XaceSelectionAccessRec;
 
-/* XACE_SITE_POLICY */
 typedef struct {
-    char *policyString;
-    int len;
+    ClientPtr client;
+    ScreenPtr screen;
+    Mask access_mode;
     int status;
-} XaceSitePolicyRec;
-
-/* XACE_DECLARE_EXT_SECURE */
-typedef struct {
-    ExtensionEntry *ext;
-    Bool secure;
-} XaceDeclareExtSecureRec;
+} XaceScreenAccessRec;
 
 /* XACE_AUTH_AVAIL */
 typedef struct {
commit 375864cb74cced40ae688078b1f7750998972535
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Aug 3 13:23:34 2007 -0400

    security: drop support for XC-QUERY-SECURITY authorization method.

diff --git a/Xext/SecurityPolicy b/Xext/SecurityPolicy
index 0000c5a..04dfb0e 100644
--- a/Xext/SecurityPolicy
+++ b/Xext/SecurityPolicy
@@ -2,13 +2,6 @@ version-1
 
 # $Xorg: SecurityPolicy,v 1.3 2000/08/17 19:47:56 cpqbld Exp $
 
-# The site policy fields are interpreted by the XC-QUERY-SECURITY-1
-# authorization protocol.  The values are arbitrary and site-specific.
-# Refer to the Security Extension Specification for the usage of the policies.
-#sitepolicy A
-#sitepolicy B
-#sitepolicy C
-
 # Property access rules:
 # property <property> <window> <permissions>
 # <window> ::= any | root | <propertyselector>
diff --git a/Xext/security.c b/Xext/security.c
index b1c0ce0..9e3b2dd 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1526,64 +1526,6 @@ SecurityParseExtensionRule(
 
 } /* SecurityParseExtensionRule */
 
-static char **SecurityPolicyStrings = NULL;
-static int nSecurityPolicyStrings = 0;
-
-static Bool
-SecurityParseSitePolicy(
-    char *p)
-{
-    char *policyStr = SecurityParseString(&p);
-    char *copyPolicyStr;
-    char **newStrings;
-
-    if (!policyStr)
-	return FALSE;
-
-    copyPolicyStr = (char *)Xalloc(strlen(policyStr) + 1);
-    if (!copyPolicyStr)
-	return TRUE;
-    strcpy(copyPolicyStr, policyStr);
-    newStrings = (char **)Xrealloc(SecurityPolicyStrings,
-			  sizeof (char *) * (nSecurityPolicyStrings + 1));
-    if (!newStrings)
-    {
-	Xfree(copyPolicyStr);
-	return TRUE;
-    }
-
-    SecurityPolicyStrings = newStrings;
-    SecurityPolicyStrings[nSecurityPolicyStrings++] = copyPolicyStr;
-
-    return TRUE;
-
-} /* SecurityParseSitePolicy */
-
-
-char **
-SecurityGetSitePolicyStrings(n)
-    int *n;
-{
-    *n = nSecurityPolicyStrings;
-    return SecurityPolicyStrings;
-} /* SecurityGetSitePolicyStrings */
-
-static void
-SecurityFreeSitePolicyStrings(void)
-{
-    if (SecurityPolicyStrings)
-    {
-	assert(nSecurityPolicyStrings);
-	while (nSecurityPolicyStrings--)
-	{
-	    Xfree(SecurityPolicyStrings[nSecurityPolicyStrings]);
-	}
-	Xfree(SecurityPolicyStrings);
-	SecurityPolicyStrings = NULL;
-	nSecurityPolicyStrings = 0;
-    }
-} /* SecurityFreeSitePolicyStrings */
-
 static void
 SecurityFreeTrustedExtensionStrings(void)
 {
@@ -1646,6 +1588,7 @@ SecurityLoadPropertyAccessList(void)
 	    switch (SecurityParseKeyword(&p))
 	    {
 		case SecurityKeywordComment:
+		case SecurityKeywordSitePolicy:
 		    validLine = TRUE;
 		break;
 
@@ -1653,10 +1596,6 @@ SecurityLoadPropertyAccessList(void)
 		    validLine = SecurityParsePropertyAccessRule(p);
 		break;
 
-		case SecurityKeywordSitePolicy:
-		    validLine = SecurityParseSitePolicy(p);
-		break;
-
 		case SecurityKeywordExtension:
 		    validLine = SecurityParseExtensionRule(p);
 		break;
@@ -1837,7 +1776,6 @@ SecurityResetProc(
 {
     SecurityFreePropertyAccessList();
     SecurityFreeTrustedExtensionStrings();
-    SecurityFreeSitePolicyStrings();
 } /* SecurityResetProc */
 
 
diff --git a/Xext/securitysrv.h b/Xext/securitysrv.h
index 67d864e..7320ab7 100644
--- a/Xext/securitysrv.h
+++ b/Xext/securitysrv.h
@@ -84,6 +84,4 @@ extern int XSecurityOptions(int argc, char **argv, int i);
 
 #define SECURITY_POLICY_FILE_VERSION "version-1"
 
-extern char **SecurityGetSitePolicyStrings(int *n);
-
 #endif /* _SECURITY_SRV_H */
diff --git a/os/Makefile.am b/os/Makefile.am
index 53b2d7f..9dd1b54 100644
--- a/os/Makefile.am
+++ b/os/Makefile.am
@@ -6,7 +6,6 @@ AM_CFLAGS = $(DIX_CFLAGS)
 SECURERPC_SRCS = rpcauth.c
 INTERNALMALLOC_SRCS = xalloc.c
 
-XCSECURITY_SRCS = secauth.c
 XDMCP_SRCS = xdmcp.c
 STRLCAT_SRCS = strlcat.c strlcpy.c
 XORG_SRCS = log.c
@@ -28,10 +27,6 @@ libos_la_SOURCES = 	\
 	xprintf.c	\
 	$(XORG_SRCS)
 
-if XCSECURITY
-libos_la_SOURCES += $(XCSECURITY_SRCS)
-endif
-
 if XDMCP
 libos_la_SOURCES += $(XDMCP_SRCS)
 endif
@@ -48,7 +43,7 @@ libcwrapper_la_CFLAGS = \
 	$(AM_CFLAGS)
 
 EXTRA_DIST = $(SECURERPC_SRCS) $(INTERNALMALLOC_SRCS) \
-     $(XCSECURITY_SRCS) $(XDMCP_SRCS) $(STRLCAT_SRCS)
+     $(XDMCP_SRCS) $(STRLCAT_SRCS)
 
 if XSERVER_DTRACE
 # Generate dtrace object code for probes in libos & libdix
diff --git a/os/auth.c b/os/auth.c
index b2a145f..d2aa980 100644
--- a/os/auth.c
+++ b/os/auth.c
@@ -42,9 +42,6 @@ from The Open Group.
 # include   "dixstruct.h"
 # include   <sys/types.h>
 # include   <sys/stat.h>
-#ifdef XCSECURITY
-# include   "securitysrv.h"
-#endif
 #ifdef WIN32
 #include    <X11/Xw32defs.h>
 #endif
@@ -89,14 +86,6 @@ static struct protocol   protocols[] = {
 #endif
 },
 #endif
-#ifdef XCSECURITY
-{   (unsigned short) XSecurityAuthorizationNameLen,
-	XSecurityAuthorizationName,
-		NULL, AuthSecurityCheck, NULL,
-		NULL, NULL, NULL,
-		NULL
-},
-#endif
 };
 
 # define NUM_AUTHORIZATION  (sizeof (protocols) /\
diff --git a/os/connection.c b/os/connection.c
index d975f87..c1152aa 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -140,9 +140,6 @@ SOFTWARE.
 #include "appgroup.h"
 #endif
 #include "xace.h"
-#ifdef XCSECURITY
-#include "securitysrv.h"
-#endif
 
 #ifdef X_NOT_POSIX
 #define Pid_t int
@@ -669,13 +666,7 @@ ClientAuthorized(ClientPtr client,
 
     if (auth_id == (XID) ~0L)
     {
-	if (
-#ifdef XCSECURITY	    
-	    (proto_n == 0 ||
-	    strncmp (auth_proto, XSecurityAuthorizationName, proto_n) != 0) &&
-#endif
-	    _XSERVTransGetPeerAddr (trans_conn,
-	        &family, &fromlen, &from) != -1)
+	if (_XSERVTransGetPeerAddr(trans_conn, &family, &fromlen, &from) != -1)
 	{
 	    if (InvalidHost ((struct sockaddr *) from, fromlen, client))
 		AuthAudit(client, FALSE, (struct sockaddr *) from,
diff --git a/os/osdep.h b/os/osdep.h
index 965436d..0c07a90 100644
--- a/os/osdep.h
+++ b/os/osdep.h
@@ -260,9 +260,6 @@ extern int  SecureRPCRemove   (AuthRemCArgs);
 extern int  SecureRPCReset    (AuthRstCArgs);
 #endif
 
-/* in secauth.c */
-extern XID AuthSecurityCheck (AuthCheckArgs);
-
 /* in xdmcp.c */
 extern void XdmcpUseMsg (void);
 extern int XdmcpOptions(int argc, char **argv, int i);
diff --git a/os/secauth.c b/os/secauth.c
deleted file mode 100644
index d01879b..0000000
--- a/os/secauth.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
-Copyright 1996, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included
-in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall
-not be used in advertising or otherwise to promote the sale, use or
-other dealings in this Software without prior written authorization
-from The Open Group.
-*/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include "os.h"
-#include "osdep.h"
-#include "dixstruct.h"
-#include "swaprep.h"
-
-#ifdef XCSECURITY
-#include "securitysrv.h"
-#endif
-
-static char InvalidPolicyReason[] = "invalid policy specification";
-static char PolicyViolationReason[] = "policy violation";
-
-static Bool
-AuthCheckSitePolicy(
-    unsigned short *data_lengthP,
-    char	**dataP,
-    ClientPtr	client,
-    char	**reason)
-{
-    CARD8	*policy = *(CARD8 **)dataP;
-    int		length;
-    Bool	permit;
-    int		nPolicies;
-    char	**sitePolicies;
-    int		nSitePolicies;
-    Bool	found = FALSE;
-
-    if ((length = *data_lengthP) < 2) {
-	*reason = InvalidPolicyReason;
-	return FALSE;
-    }
-
-    permit = (*policy++ == 0);
-    nPolicies = (CARD8) *policy++;
-
-    length -= 2;
-
-    sitePolicies = SecurityGetSitePolicyStrings(&nSitePolicies);
-
-    while (nPolicies) {
-	int strLen, sitePolicy;
-
-	if (length == 0) {
-	    *reason = InvalidPolicyReason;
-	    return FALSE;
-	}
-
-	strLen = (CARD8) *policy++;
-	if (--length < strLen) {
-	    *reason = InvalidPolicyReason;
-	    return FALSE;
-	}
-
-	if (!found)
-	{
-	    for (sitePolicy = 0; sitePolicy < nSitePolicies; sitePolicy++)
-	    {
-		char *testPolicy = sitePolicies[sitePolicy];
-		if ((strLen == strlen(testPolicy)) &&
-		    (strncmp((char *)policy, testPolicy, strLen) == 0))
-		{
-		    found = TRUE; /* need to continue parsing the policy... */
-		    break;
-		}
-	    }
-	}
-
-	policy += strLen;
-	length -= strLen;
-	nPolicies--;
-    }
-
-    if (found != permit)
-    {
-	*reason = PolicyViolationReason;
-	return FALSE;
-    }
-
-    *data_lengthP = length;
-    *dataP = (char *)policy;
-    return TRUE;
-}
-
-XID
-AuthSecurityCheck (
-    unsigned short	data_length,
-    char		*data,
-    ClientPtr		client,
-    char		**reason)
-{
-#ifdef XCSECURITY
-    xConnSetupPrefix csp;
-    xReq freq;
-
-    if (client->clientState == ClientStateCheckedSecurity)
-    {
-	*reason = "repeated security check not permitted";
-	return (XID) -1;
-    }
-    else if (data_length > 0)
-    {
-	char policy_mask = *data++;
-
-	if (--data_length == 1) {
-	    *reason = InvalidPolicyReason;
-	    return (XID) -1;
-	}
-
-	if (policy_mask & 0x01)	/* Extensions policy */
-	{
-	 /* AuthCheckExtensionPolicy(&data_length, &data, client, reason) */
-	    *reason = "security policy not implemented";
-	    return (XID) -1;
-	}
-
-	if (policy_mask & 0x02)	/* Site policy */
-	{
-	    if (!AuthCheckSitePolicy(&data_length, &data, client, reason))
-		return (XID) -1;
-	}
-
-	if (data_length > 0) {	/* did we consume the whole policy? */
-	    *reason = InvalidPolicyReason;
-	    return (XID) -1;
-	}
-
-    }
-    else if (!GetAccessControl())
-    {
-	/*
-	 * The client - possibly the X FireWall Proxy - gave
-	 * no auth data and host-based authorization is turned
-	 * off.  In this case, the client should be denied
-	 * access to the X server.
-	 */
-	*reason = "server host access control is disabled";
-	return (XID) -1;
-    }
-
-    client->clientState = ClientStateCheckingSecurity;
-
-    csp.success = 2 /* Authenticate */;
-    csp.lengthReason = 0;
-    csp.length = 0;
-    csp.majorVersion = X_PROTOCOL;
-    csp.minorVersion = X_PROTOCOL_REVISION;
-    if (client->swapped)
-	WriteSConnSetupPrefix(client, &csp);
-    else
-	(void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
-
-    /*
-     * Next time the client sends the real auth data, we want
-     * ProcEstablishConnection to be called.
-     */
-
-    freq.reqType = 1;
-    freq.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
-    client->swapped = FALSE;
-    if (!InsertFakeRequest(client, (char *)&freq, sz_xReq))
-    {
-	*reason = "internal error";
-	return (XID) -1;
-    }
-
-    return (XID) 0;
-#else
-    *reason = "method not supported";
-    return (XID) -1;
-#endif
-}
commit d445d2f22b5c97fa010370f4ba9cb0555df4a853
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Aug 3 10:56:18 2007 -0400

    security: drop the "declare extension security" dix call.  Use the
    SecurityPolicy configuration file instead.

diff --git a/Xext/SecurityPolicy b/Xext/SecurityPolicy
index cc521c2..0000c5a 100644
--- a/Xext/SecurityPolicy
+++ b/Xext/SecurityPolicy
@@ -86,3 +86,8 @@ property XDCCC_GRAY_CORRECTION	root	ar
 # To let untrusted clients use the overlay visuals that many vendors
 # support, include this line.
 property SERVER_OVERLAY_VISUALS	root	ar
+
+# Only trusted extensions can be used by untrusted clients
+trust extension XC-MISC
+trust extension BIG-REQUESTS
+trust extension XpExtension
diff --git a/Xext/bigreq.c b/Xext/bigreq.c
index fcd848a..d388790 100644
--- a/Xext/bigreq.c
+++ b/Xext/bigreq.c
@@ -66,8 +66,6 @@ BigReqExtensionInit(INITARGS)
 			ProcBigReqDispatch, ProcBigReqDispatch,
 			BigReqResetProc, StandardMinorOpcode);
 #endif
-
-    DeclareExtensionSecurity(XBigReqExtensionName, TRUE);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/security.c b/Xext/security.c
index b6df61a..b1c0ce0 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -63,8 +63,6 @@ typedef struct {
     XID authId;
 } SecurityClientStateRec;
 
-#define EXTLEVEL(extnsn) ((Bool) \
-    dixLookupPrivate(DEVPRIV_PTR(extnsn), &stateKey))
 #define HAVESTATE(client) (((SecurityClientStateRec *) \
     dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->haveState)
 #define TRUSTLEVEL(client) (((SecurityClientStateRec *) \
@@ -74,6 +72,9 @@ typedef struct {
 
 static CallbackListPtr SecurityValidateGroupCallback = NULL;
 
+static char **SecurityTrustedExtensions = NULL;
+static int nSecurityTrustedExtensions = 0;
+
 RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
 
 static RESTYPE RTEventClient;
@@ -1210,10 +1211,13 @@ SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
 		       pointer calldata)
 {
     XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
+    int i, trusted = 0;
 
-    if ((TRUSTLEVEL(rec->client) != XSecurityClientTrusted) &&
-	!EXTLEVEL(rec->ext))
+    for (i = 0; i < nSecurityTrustedExtensions; i++)
+	if (!strcmp(SecurityTrustedExtensions[i], rec->ext->name))
+	    trusted = 1;
 
+    if ((TRUSTLEVEL(rec->client) != XSecurityClientTrusted) && !trusted)
 	rec->status = BadAccess;
 }
 
@@ -1235,16 +1239,6 @@ SecurityCheckHostlistAccess(CallbackListPtr *pcbl, pointer unused,
     }
 }
 
-static void
-SecurityDeclareExtSecure(CallbackListPtr *pcbl, pointer unused,
-			 pointer calldata)
-{
-    XaceDeclareExtSecureRec *rec = (XaceDeclareExtSecureRec*)calldata;
-
-    /* security state for extensions is simply a boolean trust value */
-    dixSetPrivate(DEVPRIV_PTR(rec->ext), &stateKey, (pointer)rec->secure);
-}
-
 /**********************************************************************/
 
 typedef struct _PropertyAccessRec {
@@ -1276,7 +1270,9 @@ static char *SecurityKeywords[] = {
 #define SecurityKeywordRoot 3
     "root",
 #define SecurityKeywordAny 4
-    "any"
+    "any",
+#define SecurityKeywordExtension 5
+    "trust extension",
 };
 
 #define NUMKEYWORDS (sizeof(SecurityKeywords) / sizeof(char *))
@@ -1500,6 +1496,36 @@ SecurityParsePropertyAccessRule(
     return TRUE;
 } /* SecurityParsePropertyAccessRule */
 
+static Bool
+SecurityParseExtensionRule(
+    char *p)
+{
+    char *extName = SecurityParseString(&p);
+    char *copyExtName;
+    char **newStrings;
+
+    if (!extName)
+	return FALSE;
+
+    copyExtName = (char *)Xalloc(strlen(extName) + 1);
+    if (!copyExtName)
+	return TRUE;
+    strcpy(copyExtName, extName);
+    newStrings = (char **)Xrealloc(SecurityTrustedExtensions,
+			  sizeof (char *) * (nSecurityTrustedExtensions + 1));
+    if (!newStrings)
+    {
+	Xfree(copyExtName);
+	return TRUE;
+    }
+
+    SecurityTrustedExtensions = newStrings;
+    SecurityTrustedExtensions[nSecurityTrustedExtensions++] = copyExtName;
+
+    return TRUE;
+
+} /* SecurityParseExtensionRule */
+
 static char **SecurityPolicyStrings = NULL;
 static int nSecurityPolicyStrings = 0;
 
@@ -1558,6 +1584,21 @@ SecurityFreeSitePolicyStrings(void)
     }
 } /* SecurityFreeSitePolicyStrings */
 
+static void
+SecurityFreeTrustedExtensionStrings(void)
+{
+    if (SecurityTrustedExtensions)
+    {
+	assert(nSecurityTrustedExtensions);
+	while (nSecurityTrustedExtensions--)
+	{
+	    Xfree(SecurityTrustedExtensions[nSecurityTrustedExtensions]);
+	}
+	Xfree(SecurityTrustedExtensions);
+	SecurityTrustedExtensions = NULL;
+	nSecurityTrustedExtensions = 0;
+    }
+} /* SecurityFreeSiteTrustedExtensions */
 
 static void
 SecurityLoadPropertyAccessList(void)
@@ -1616,6 +1657,10 @@ SecurityLoadPropertyAccessList(void)
 		    validLine = SecurityParseSitePolicy(p);
 		break;
 
+		case SecurityKeywordExtension:
+		    validLine = SecurityParseExtensionRule(p);
+		break;
+
 		default:
 		    validLine = (*p == '\0'); /* blank lines OK, others not */
 		break;
@@ -1791,6 +1836,7 @@ SecurityResetProc(
     ExtensionEntry *extEntry)
 {
     SecurityFreePropertyAccessList();
+    SecurityFreeTrustedExtensionStrings();
     SecurityFreeSitePolicyStrings();
 } /* SecurityResetProc */
 
@@ -1811,32 +1857,6 @@ XSecurityOptions(argc, argv, i)
 } /* XSecurityOptions */
 
 
-/* SecurityExtensionSetup
- *
- * Arguments: none.
- *
- * Returns: nothing.
- *
- * Side Effects:
- *	Sets up the Security extension if possible.
- *      This function contains things that need to be done
- *      before any other extension init functions get called.
- */
-
-void
-SecurityExtensionSetup(INITARGS)
-{
-    /* FIXME: this is here so it is registered before other extensions
-     * init themselves.  This also required commit 5e946dd853a4ebc... to
-     * call the setup functions on each server reset.
-     *
-     * The extension security bit should be delivered in some other way,
-     * either in a symbol or in the module data.
-     */
-    XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, SecurityDeclareExtSecure, 0);
-} /* SecurityExtensionSetup */
-
-
 /* SecurityExtensionInit
  *
  * Arguments: none.
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 8c7a86e..d9a7f10 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -80,8 +80,6 @@ XCMiscExtensionInit(INITARGS)
 			ProcXCMiscDispatch, SProcXCMiscDispatch,
 			XCMiscResetProc, StandardMinorOpcode);
 #endif
-
-    DeclareExtensionSecurity(XCMiscExtensionName, TRUE);
 }
 
 /*ARGSUSED*/
diff --git a/Xext/xprint.c b/Xext/xprint.c
index 4ac13e6..ff739c0 100644
--- a/Xext/xprint.c
+++ b/Xext/xprint.c
@@ -335,7 +335,6 @@ XpExtensionInit(INITARGS)
 	    screenInfo.screens[i]->CloseScreen = XpCloseScreen;
 	}
     }
-    DeclareExtensionSecurity(XP_PRINTNAME, TRUE);
 }
 
 static void
diff --git a/dix/extension.c b/dix/extension.c
index ad4e697..ec47ef1 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -250,14 +250,6 @@ GetExtensionEntry(int major)
     return extensions[major];
 }
 
-_X_EXPORT void
-DeclareExtensionSecurity(char *extname, Bool secure)
-{
-    int i = FindExtension(extname, strlen(extname));
-    if (i >= 0)
-	XaceHook(XACE_DECLARE_EXT_SECURE, extensions[i], secure);
-}
-
 _X_EXPORT unsigned short
 StandardMinorOpcode(ClientPtr client)
 {
diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 131b9e6..fb75092 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -135,7 +135,6 @@ extern void XSELinuxExtensionInit(INITARGS);
 #endif
 
 #if 1
-extern void SecurityExtensionSetup(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
 #endif
 
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 043f2db..1af076b 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -200,7 +200,6 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(AddExtension)
     SYMFUNC(AddExtensionAlias)
     SYMFUNC(CheckExtension)
-    SYMFUNC(DeclareExtensionSecurity)
     SYMFUNC(MinorOpcodeOfRequest)
     SYMFUNC(StandardMinorOpcode)
 #ifdef XEVIE
diff --git a/include/extnsionst.h b/include/extnsionst.h
index 28ae1d5..58bf0a2 100644
--- a/include/extnsionst.h
+++ b/include/extnsionst.h
@@ -107,9 +107,5 @@ extern Bool AddExtensionAlias(
 extern ExtensionEntry *CheckExtension(const char *extname);
 extern ExtensionEntry *GetExtensionEntry(int major);
 
-extern void DeclareExtensionSecurity(
-    char * /*extname*/,
-    Bool /*secure*/);
-
 #endif /* EXTENSIONSTRUCT_H */
 
diff --git a/mi/miinitext.c b/mi/miinitext.c
index f142540..964ef3e 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -321,7 +321,6 @@ extern void XagExtensionInit(INITARGS);
 extern void XaceExtensionInit(INITARGS);
 #endif
 #ifdef XCSECURITY
-extern void SecurityExtensionSetup(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
 #endif
 #ifdef XSELINUX
@@ -538,9 +537,6 @@ InitExtensions(argc, argv)
     int		argc;
     char	*argv[];
 {
-#ifdef XCSECURITY
-    SecurityExtensionSetup();
-#endif
 #ifdef XSELINUX
     XSELinuxExtensionSetup();
 #endif
@@ -719,7 +715,7 @@ static ExtensionModule staticExtensions[] = {
     { XaceExtensionInit, XACE_EXTENSION_NAME, NULL, NULL, NULL },
 #endif
 #ifdef XCSECURITY
-    { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, SecurityExtensionSetup, NULL },
+    { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, NULL, NULL },
 #endif
 #ifdef XSELINUX
     { XSELinuxExtensionInit, XSELINUX_EXTENSION_NAME, NULL, XSELinuxExtensionSetup, NULL },
commit e34fcd2bf42dbd72ab6ce2df80f2dcaa13416e74
Merge: 32c0dcc... f3955c0...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Aug 2 14:27:03 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	dix/devices.c
    	dix/property.c
    	include/dix.h

diff --cc dix/devices.c
index 45833d0,923bc0d..4ddfa63
--- a/dix/devices.c
+++ b/dix/devices.c
@@@ -139,14 -149,9 +150,15 @@@ AddInputDevice(DeviceProc deviceProc, B
  #ifdef XKB
      dev->xkb_interest = NULL;
  #endif
+     dev->config_info = NULL;
 -    dev->nPrivates = 0;
 -    dev->devPrivates = NULL;
 +    /* must pre-allocate one private for the new devPrivates support */
 +    dev->nPrivates = 1;
 +    dev->devPrivates = (DevUnion *)xcalloc(1, sizeof(DevUnion));
 +    if (!dev->devPrivates) {
 +	xfree(dev);
 +	return NULL;
 +    }
 +
      dev->unwrapProc = NULL;
      dev->coreEvents = TRUE;
      dev->inited = FALSE;
diff --cc dix/property.c
index 09f9e31,e281dd7..c0de5b3
--- a/dix/property.c
+++ b/dix/property.c
@@@ -91,19 -91,19 +91,32 @@@ PrintPropertys(WindowPtr pWin
  }
  #endif
  
 +static _X_INLINE PropertyPtr
 +FindProperty(WindowPtr pWin, Atom propertyName)
 +{
 +    PropertyPtr pProp = wUserProps(pWin);
 +    while (pProp)
 +    {
 +	if (pProp->propertyName == propertyName)
 +	    break;
 +	pProp = pProp->next;
 +    }
 +    return pProp;
 +}
 +
+ static void
+ deliverPropertyNotifyEvent(WindowPtr pWin, int state, Atom atom)
+ {
+     xEvent event;
+ 
+     event.u.u.type = PropertyNotify;
+     event.u.property.window = pWin->drawable.id;
+     event.u.property.state = state;
+     event.u.property.atom = atom;
+     event.u.property.time = currentTime.milliseconds;
+     DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+ }
+ 
  int
  ProcRotateProperties(ClientPtr client)
  {
@@@ -236,13 -243,13 +241,12 @@@ ProcChangeProperty(ClientPtr client
  }
  
  _X_EXPORT int
 -ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, 
 -                     int mode, unsigned long len, pointer value, 
 -                     Bool sendevent)
 +dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 +			Atom type, int format, int mode, unsigned long len,
 +			pointer value, Bool sendevent)
  {
      PropertyPtr pProp;
-     xEvent event;
 -    int sizeInBytes;
 -    int totalSize;
 +    int sizeInBytes, totalSize, rc;
      pointer data;
  
      sizeInBytes = format>>3;
@@@ -392,13 -375,7 +390,8 @@@ DeleteProperty(WindowPtr pWin, Atom pro
          {
              prevProp->next = pProp->next;
          }
- 	event.u.u.type = PropertyNotify;
- 	event.u.property.window = pWin->drawable.id;
- 	event.u.property.state = PropertyDelete;
-         event.u.property.atom = pProp->propertyName;
- 	event.u.property.time = currentTime.milliseconds;
- 	DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+ 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
 +	dixFreePrivates(pProp->devPrivates);
  	xfree(pProp->data);
          xfree(pProp);
      }
@@@ -414,14 -390,8 +406,9 @@@ DeleteAllWindowProperties(WindowPtr pWi
      pProp = wUserProps (pWin);
      while (pProp)
      {
- 	event.u.u.type = PropertyNotify;
- 	event.u.property.window = pWin->drawable.id;
- 	event.u.property.state = PropertyDelete;
- 	event.u.property.atom = pProp->propertyName;
- 	event.u.property.time = currentTime.milliseconds;
- 	DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+ 	deliverPropertyNotifyEvent(pWin, PropertyDelete, pProp->propertyName);
  	pNextProp = pProp->next;
 +	dixFreePrivates(pProp->devPrivates);
          xfree(pProp->data);
          xfree(pProp);
  	pProp = pNextProp;
diff --cc include/dix.h
index 41240b1,c1d609a..71f4c23
--- a/include/dix.h
+++ b/include/dix.h
@@@ -627,39 -640,4 +627,36 @@@ typedef struct 
  extern int xstrcasecmp(char *s1, char *s2);
  #endif
  
- /* ffs.c */
- extern int ffs(int i);
- 
 +/*
 + * These are deprecated compatibility functions and will be removed soon!
 + * Please use the noted replacements instead.
 + */
 +
 +/* replaced by dixLookupWindow */
 +extern WindowPtr SecurityLookupWindow(
 +    XID id,
 +    ClientPtr client,
 +    Mask access_mode);
 +
 +/* replaced by dixLookupWindow */
 +extern WindowPtr LookupWindow(
 +    XID id,
 +    ClientPtr client);
 +
 +/* replaced by dixLookupDrawable */
 +extern pointer SecurityLookupDrawable(
 +    XID id,
 +    ClientPtr client,
 +    Mask access_mode);
 +
 +/* replaced by dixLookupDrawable */
 +extern pointer LookupDrawable(
 +    XID id,
 +    ClientPtr client);
 +
 +/* replaced by dixLookupClient */
 +extern ClientPtr LookupClient(
 +    XID id,
 +    ClientPtr client);
 +
  #endif /* DIX_H */
commit 32c0dcc8c0d1edba5d7e418fd2dc916847a4f069
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jun 21 15:39:19 2007 -0400

    xselinux: adjust the config file format to that expected by libselinux.
    
    This file will eventually be moved out of the X source tree.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index 38b7831..66f93c5 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -3,141 +3,131 @@
 #
 
 #
-# The nonlocal_context rule defines a context to be used for all clients
-# connecting to the server from a remote host.  The nonlocal context must
-# be defined, and it must be a valid context according to the SELinux
-# security policy.  Only one nonlocal_context rule may be defined.
+# The default client rule defines a context to be used for all clients
+# connecting to the server from a remote host.
 #
-nonlocal_context			system_u:object_r:remote_xclient_t:s0
+client	*				system_u:object_r:remote_xclient_t:s0
 
 #
-# Property rules map a property name to a SELinux type.  The type must
-# be valid according to the SELinux security policy.  There can be any
-# number of property rules.  Additionally, a default property type can be
-# defined for all properties not explicitly listed.  The default
-# property type may not be omitted.  The default rule may appear in
-# any position (it need not be the last property rule listed).
+# Property rules map a property name to a context.  A default property
+# rule indicated by an asterisk should follow all other property rules.
 #
 # Properties set by typical clients: WM, _NET_WM, etc.
-property WM_NAME			client_xproperty_t
-property WM_CLASS			client_xproperty_t
-property WM_ICON_NAME			client_xproperty_t
-property WM_HINTS			client_xproperty_t
-property WM_NORMAL_HINTS		client_xproperty_t
-property WM_COMMAND			client_xproperty_t
-property WM_CLIENT_MACHINE		client_xproperty_t
-property WM_LOCALE_NAME			client_xproperty_t
-property WM_CLIENT_LEADER		client_xproperty_t
-property WM_STATE			client_xproperty_t
-property WM_PROTOCOLS			client_xproperty_t
-property WM_WINDOW_ROLE			client_xproperty_t
-property WM_TRANSIENT_FOR		client_xproperty_t
-property _NET_WM_NAME			client_xproperty_t
-property _NET_WM_ICON			client_xproperty_t
-property _NET_WM_ICON_NAME		client_xproperty_t
-property _NET_WM_PID			client_xproperty_t
-property _NET_WM_STATE			client_xproperty_t
-property _NET_WM_DESKTOP		client_xproperty_t
-property _NET_WM_SYNC_REQUEST_COUNTER	client_xproperty_t
-property _NET_WM_WINDOW_TYPE		client_xproperty_t
-property _NET_WM_USER_TIME		client_xproperty_t
-property _MOTIF_DRAG_RECEIVER_INFO	client_xproperty_t
-property XdndAware			client_xproperty_t
+property WM_NAME			system_u:object_r:client_xproperty_t:s0
+property WM_CLASS			system_u:object_r:client_xproperty_t:s0
+property WM_ICON_NAME			system_u:object_r:client_xproperty_t:s0
+property WM_HINTS			system_u:object_r:client_xproperty_t:s0
+property WM_NORMAL_HINTS		system_u:object_r:client_xproperty_t:s0
+property WM_COMMAND			system_u:object_r:client_xproperty_t:s0
+property WM_CLIENT_MACHINE		system_u:object_r:client_xproperty_t:s0
+property WM_LOCALE_NAME			system_u:object_r:client_xproperty_t:s0
+property WM_CLIENT_LEADER		system_u:object_r:client_xproperty_t:s0
+property WM_STATE			system_u:object_r:client_xproperty_t:s0
+property WM_PROTOCOLS			system_u:object_r:client_xproperty_t:s0
+property WM_WINDOW_ROLE			system_u:object_r:client_xproperty_t:s0
+property WM_TRANSIENT_FOR		system_u:object_r:client_xproperty_t:s0
+property _NET_WM_NAME			system_u:object_r:client_xproperty_t:s0
+property _NET_WM_ICON			system_u:object_r:client_xproperty_t:s0
+property _NET_WM_ICON_NAME		system_u:object_r:client_xproperty_t:s0
+property _NET_WM_PID			system_u:object_r:client_xproperty_t:s0
+property _NET_WM_STATE			system_u:object_r:client_xproperty_t:s0
+property _NET_WM_DESKTOP		system_u:object_r:client_xproperty_t:s0
+property _NET_WM_SYNC_REQUEST_COUNTER	system_u:object_r:client_xproperty_t:s0
+property _NET_WM_WINDOW_TYPE		system_u:object_r:client_xproperty_t:s0
+property _NET_WM_USER_TIME		system_u:object_r:client_xproperty_t:s0
+property _MOTIF_DRAG_RECEIVER_INFO	system_u:object_r:client_xproperty_t:s0
+property XdndAware			system_u:object_r:client_xproperty_t:s0
 
 # Properties written by xrdb
-property RESOURCE_MANAGER		rm_xproperty_t
-property SCREEN_RESOURCES		rm_xproperty_t
+property RESOURCE_MANAGER		system_u:object_r:rm_xproperty_t:s0
+property SCREEN_RESOURCES		system_u:object_r:rm_xproperty_t:s0
 
 # Properties written by window managers
-property _MIT_PRIORITY_COLORS		wm_xproperty_t
+property _MIT_PRIORITY_COLORS		system_u:object_r:wm_xproperty_t:s0
 
 # Properties used for security labeling
-property _SELINUX_CLIENT_CONTEXT	seclabel_xproperty_t
+property _SELINUX_CLIENT_CONTEXT	system_u:object_r:seclabel_xproperty_t:s0
 
 # Properties used to communicate screen information
-property XFree86_VT			info_xproperty_t
-property XFree86_DDC_EDID1_RAWDATA	info_xproperty_t
+property XFree86_VT			system_u:object_r:info_xproperty_t:s0
+property XFree86_DDC_EDID1_RAWDATA	system_u:object_r:info_xproperty_t:s0
 
 # Clipboard and selection properties
-property CUT_BUFFER0			clipboard_xproperty_t
-property CUT_BUFFER1			clipboard_xproperty_t
-property CUT_BUFFER2			clipboard_xproperty_t
-property CUT_BUFFER3			clipboard_xproperty_t
-property CUT_BUFFER4			clipboard_xproperty_t
-property CUT_BUFFER5			clipboard_xproperty_t
-property CUT_BUFFER6			clipboard_xproperty_t
-property CUT_BUFFER7			clipboard_xproperty_t
-property _XT_SELECTION_0		clipboard_xproperty_t
+property CUT_BUFFER0			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER1			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER2			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER3			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER4			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER5			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER6			system_u:object_r:clipboard_xproperty_t:s0
+property CUT_BUFFER7			system_u:object_r:clipboard_xproperty_t:s0
+property _XT_SELECTION_0		system_u:object_r:clipboard_xproperty_t:s0
 
 # Default fallback type
-property default			unknown_xproperty_t
+property *	   			system_u:object_r:unknown_xproperty_t:s0
 
 #
-# Extension rules map an extension name to a SELinux type.  The type must
-# be valid according to the SELinux security policy.  There can be any
-# number of extension rules.  Additionally, a default extension type can
-# be defined for all extensions not explicitly listed.  The default
-# extension type may not be omitted.  The default rule may appear in
-# any position (it need not be the last extension rule listed).
+# Extension rules map an extension name to a context.  A default extension
+# rule indicated by an asterisk should follow all other extension rules.
 #
 # Standard extensions
-extension BIG-REQUESTS			std_xext_t
-extension DOUBLE-BUFFER			std_xext_t
-extension Extended-Visual-Information	std_xext_t
-extension MIT-SUNDRY-NONSTANDARD	std_xext_t
-extension SHAPE				std_xext_t
-extension SYNC				std_xext_t
-extension XC-MISC			std_xext_t
-extension XFIXES			std_xext_t
-extension XFree86-Misc			std_xext_t
-extension XpExtension                   std_xext_t
+extension BIG-REQUESTS			system_u:object_r:std_xext_t:s0
+extension DOUBLE-BUFFER			system_u:object_r:std_xext_t:s0
+extension Extended-Visual-Information	system_u:object_r:std_xext_t:s0
+extension MIT-SUNDRY-NONSTANDARD	system_u:object_r:std_xext_t:s0
+extension SHAPE				system_u:object_r:std_xext_t:s0
+extension SYNC				system_u:object_r:std_xext_t:s0
+extension XC-MISC			system_u:object_r:std_xext_t:s0
+extension XFIXES			system_u:object_r:std_xext_t:s0
+extension XFree86-Misc			system_u:object_r:std_xext_t:s0
+extension XpExtension                   system_u:object_r:std_xext_t:s0
 
 # Screen management and multihead extensions
-extension RANDR				output_xext_t
-extension XINERAMA			std_xext_t
+extension RANDR				system_u:object_r:output_xext_t:s0
+extension XINERAMA			system_u:object_r:std_xext_t:s0
 
 # Input extensions
-extension XInputExtension		input_xext_t
-extension XKEYBOARD			input_xext_t
+extension XInputExtension		system_u:object_r:input_xext_t:s0
+extension XKEYBOARD			system_u:object_r:input_xext_t:s0
 
 # Screensaver, power management extensions
-extension DPMS				screensaver_xext_t
-extension MIT-SCREEN-SAVER		screensaver_xext_t
+extension DPMS				system_u:object_r:screensaver_xext_t:s0
+extension MIT-SCREEN-SAVER		system_u:object_r:screensaver_xext_t:s0
 
 # Fonting extensions
-extension FontCache			font_xext_t
-extension XFree86-Bigfont		font_xext_t
+extension FontCache			system_u:object_r:font_xext_t:s0
+extension XFree86-Bigfont		system_u:object_r:font_xext_t:s0
 
 # Shared memory extensions
-extension MIT-SHM			shmem_xext_t
+extension MIT-SHM			system_u:object_r:shmem_xext_t:s0
 
 # Accelerated graphics, OpenGL, direct rendering extensions
-extension DAMAGE			accelgraphics_xext_t
-extension GLX				accelgraphics_xext_t
-extension NV-CONTROL			accelgraphics_xext_t
-extension NV-GLX			accelgraphics_xext_t
-extension NVIDIA-GLX			accelgraphics_xext_t
-extension RENDER			std_xext_t
-extension XFree86-DGA			accelgraphics_xext_t
+extension DAMAGE			system_u:object_r:accelgraphics_xext_t:s0
+extension GLX				system_u:object_r:accelgraphics_xext_t:s0
+extension NV-CONTROL			system_u:object_r:accelgraphics_xext_t:s0
+extension NV-GLX			system_u:object_r:accelgraphics_xext_t:s0
+extension NVIDIA-GLX			system_u:object_r:accelgraphics_xext_t:s0
+extension RENDER			system_u:object_r:std_xext_t:s0
+extension XFree86-DGA			system_u:object_r:accelgraphics_xext_t:s0
 
 # Debugging, testing, and recording extensions
-extension RECORD			debug_xext_t
-extension X-Resource			debug_xext_t
-extension XTEST				debug_xext_t
+extension RECORD			system_u:object_r:debug_xext_t:s0
+extension X-Resource			system_u:object_r:debug_xext_t:s0
+extension XTEST				system_u:object_r:debug_xext_t:s0
 
 # Extensions just for window managers
-extension TOG-CUP			windowmgr_xext_t
+extension TOG-CUP			system_u:object_r:windowmgr_xext_t:s0
 
 # Security-related extensions
-extension SECURITY			security_xext_t
-extension SELinux			security_xext_t
-extension XAccessControlExtension	security_xext_t
-extension XC-APPGROUP			security_xext_t
+extension SECURITY			system_u:object_r:security_xext_t:s0
+extension SELinux			system_u:object_r:security_xext_t:s0
+extension XAccessControlExtension	system_u:object_r:security_xext_t:s0
+extension XC-APPGROUP			system_u:object_r:security_xext_t:s0
 
 # Video extensions
-extension XFree86-VidModeExtension	video_xext_t
-extension XVideo			video_xext_t
-extension XVideo-MotionCompensation	video_xext_t
+extension XFree86-VidModeExtension	system_u:object_r:video_xext_t:s0
+extension XVideo			system_u:object_r:video_xext_t:s0
+extension XVideo-MotionCompensation	system_u:object_r:video_xext_t:s0
 
 # Default fallback type
-extension default			unknown_xext_t
+extension *	   			system_u:object_r:unknown_xext_t:s0
commit 2030e9e5395be43bd8eab15b65c21ca4c2f1e619
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Jun 21 15:37:18 2007 -0400

    xselinux: use new libselinux support for context labeling.
    
    Remove all the config file parsing code and use the new lookup interface
    instead.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index cdb3b33..038ec59 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #include <selinux/selinux.h>
-#include <selinux/context.h>
+#include <selinux/label.h>
 #include <selinux/avc.h>
 
 #include <libaudit.h>
@@ -69,27 +69,13 @@ typedef struct {
     char *extension;	/* extension name, if any */
 } XSELinuxAuditRec;
 
-/*
- * Table of SELinux types for property names.
- */
-static char **propertyTypes = NULL;
-static int propertyTypesCount = 0;
-char *XSELinuxPropertyTypeDefault = NULL;
-
-/*
- * Table of SELinux types for each extension.
- */
-static char **extensionTypes = NULL;
-static int extensionTypesCount = 0;
-static char *XSELinuxExtensionTypeDefault = NULL;
+/* labeling handle */
+static struct selabel_handle *label_hnd;
 
 /* Atoms for SELinux window labeling properties */
 Atom atom_ctx;
 Atom atom_client_ctx;
 
-/* security context for non-local clients */
-static char *XSELinuxNonlocalContextDefault = NULL;
-
 /* Selection stuff from dix */
 extern Selection *CurrentSelections;
 extern int NumCurrentSelections;
@@ -325,41 +311,22 @@ IDPerm(ClientPtr sclient,
 static security_id_t
 GetPropertySID(security_context_t base, const char *name)
 {
-    security_context_t new, result;
-    context_t con;
+    security_context_t con, result;
     security_id_t sid = NULL;
-    char **ptr, *type = NULL;
-
-    /* make a new context-manipulation object */
-    con = context_new(base);
-    if (!con)
-	goto out;
 
     /* look in the mappings of names to types */
-    for (ptr = propertyTypes; *ptr; ptr+=2)
-	if (!strcmp(*ptr, name))
-	    break;
-    type = ptr[1];
-
-    /* set the role and type in the context (user unchanged) */
-    if (context_type_set(con, type) ||
-	context_role_set(con, "object_r"))
-	goto out2;
-
-    /* get a context string from the context-manipulation object */
-    new = context_str(con);
-    if (!new)
-	goto out2;
+    if (selabel_lookup(label_hnd, &con, name, SELABEL_X_PROP) < 0)
+	goto out;
 
     /* perform a transition to obtain the final context */
-    if (security_compute_create(base, new, SECCLASS_PROPERTY, &result) < 0)
+    if (security_compute_create(base, con, SECCLASS_PROPERTY, &result) < 0)
 	goto out2;
 
     /* get a SID for the context */
     avc_context_to_sid(result, &sid);
     freecon(result);
   out2:
-    context_free(con);
+    freecon(con);
   out:
     return sid;
 }
@@ -375,41 +342,26 @@ GetPropertySID(security_context_t base, const char *name)
 static security_id_t
 GetExtensionSID(const char *name)
 {
-    security_context_t base, new;
-    context_t con;
+    security_context_t base, con, result;
     security_id_t sid = NULL;
-    char **ptr, *type = NULL;
 
     /* get server context */
     if (getcon(&base) < 0)
 	goto out;
 
-    /* make a new context-manipulation object */
-    con = context_new(base);
-    if (!con)
-	goto out2;
-
     /* look in the mappings of names to types */
-    for (ptr = extensionTypes; *ptr; ptr+=2)
-	if (!strcmp(*ptr, name))
-	    break;
-    type = ptr[1];
-
-    /* set the role and type in the context (user unchanged) */
-    if (context_type_set(con, type) ||
-	context_role_set(con, "object_r"))
-	goto out3;
+    if (selabel_lookup(label_hnd, &con, name, SELABEL_X_EXT) < 0)
+	goto out2;
 
-    /* get a context string from the context-manipulation object */
-    new = context_str(con);
-    if (!new)
+    /* perform a transition to obtain the final context */
+    if (security_compute_create(base, con, SECCLASS_XEXTENSION, &result) < 0)
 	goto out3;
 
     /* get a SID for the context */
-    avc_context_to_sid(new, &sid);
-
+    avc_context_to_sid(result, &sid);
+    freecon(result);
   out3:
-    context_free(con);
+    freecon(con);
   out2:
     freecon(base);
   out:
@@ -467,7 +419,7 @@ AssignServerState(void)
 static void
 AssignClientState(ClientPtr client)
 {
-    int i, needToFree = 0;
+    int i;
     security_context_t basectx, objctx;
     XSELinuxClientStateRec *state;
 
@@ -481,11 +433,12 @@ AssignClientState(ClientPtr client)
 	if (getpeercon(fd, &basectx) < 0)
 	    FatalError("Client %d: couldn't get context from socket\n",
 		       client->index);
-	needToFree = 1;
     }
     else
 	/* for remote clients, need to use a default context */
-	basectx = XSELinuxNonlocalContextDefault;
+	if (selabel_lookup(label_hnd, &basectx, NULL, SELABEL_X_CLIENT) < 0)
+	    FatalError("Client %d: couldn't get default remote connection context\n",
+		       client->index);
 
     /* get a SID from the context */
     if (avc_context_to_sid(basectx, &state->sid) < 0)
@@ -506,10 +459,9 @@ AssignClientState(ClientPtr client)
 	freecon(objctx);
     }
 
-    /* mark as set up, free base context if necessary, and return */
+    /* mark as set up, free base context, and return */
     state->haveState = TRUE;
-    if (needToFree)
-	freecon(basectx);
+    freecon(basectx);
 }
 
 /*
@@ -1294,509 +1246,26 @@ XSELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	FatalError("XSELinux: Failed to set context property on window!\n");
 } /* XSELinuxResourceState */
 
-static char *XSELinuxKeywords[] = {
-#define XSELinuxKeywordComment 0
-    "#",
-#define XSELinuxKeywordProperty 1
-    "property",
-#define XSELinuxKeywordExtension 2
-    "extension",
-#define XSELinuxKeywordNonlocalContext 3
-    "nonlocal_context",
-#define XSELinuxKeywordDefault 4
-    "default"
-};
-
-#define NUMKEYWORDS (sizeof(XSELinuxKeywords) / sizeof(char *))
-
-#ifndef __UNIXOS2__
-#define XSELinuxIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') )
-#else
-#define XSELinuxIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') )
-#endif
-
-static char *
-XSELinuxSkipWhitespace(
-    char *p)
-{
-    while (XSELinuxIsWhitespace(*p))
-	p++;
-    return p;
-} /* XSELinuxSkipWhitespace */
-
-static char *
-XSELinuxParseString(
-    char **rest)
-{
-    char *startOfString;
-    char *s = *rest;
-    char endChar = 0;
-
-    s = XSELinuxSkipWhitespace(s);
-
-    if (*s == '"' || *s == '\'')
-    {
-	endChar = *s++;
-	startOfString = s;
-	while (*s && (*s != endChar))
-	    s++;
-    }
-    else
-    {
-	startOfString = s;
-	while (*s && !XSELinuxIsWhitespace(*s))
-	    s++;
-    }
-    if (*s)
-    {
-	*s = '\0';
-	*rest = s + 1;
-	return startOfString;
-    }
-    else
-    {
-	*rest = s;
-	return (endChar) ? NULL : startOfString;
-    }
-} /* XSELinuxParseString */
-
-static int
-XSELinuxParseKeyword(
-    char **p)
-{
-    int i;
-    char *s = *p;
-    s = XSELinuxSkipWhitespace(s);
-    for (i = 0; i < NUMKEYWORDS; i++)
-    {
-	int len = strlen(XSELinuxKeywords[i]);
-	if (strncmp(s, XSELinuxKeywords[i], len) == 0)
-	{
-	    *p = s + len;
-	    return (i);
-	}
-    }
-    *p = s;
-    return -1;
-} /* XSELinuxParseKeyword */
-
-static Bool
-XSELinuxTypeIsValid(char *typename)
-{
-    security_context_t base, new;
-    context_t con;
-    Bool ret = FALSE;
-
-    /* get the server's context */
-    if (getcon(&base) < 0)
-        goto out;
-
-    /* make a new context-manipulation object */
-    con = context_new(base);
-    if (!con)
-        goto out_free;
-
-    /* set the role */
-    if (context_role_set(con, "object_r"))
-        goto out_free2;
-
-    /* set the type */
-    if (context_type_set(con, typename))
-        goto out_free2;
-
-    /* get a context string - note: context_str() returns a pointer
-     * to the string inside the context; the returned pointer should
-     * not be freed
-     */
-    new = context_str(con);
-    if (!new)
-        goto out_free2;
-
-    /* finally, check to see if it's valid */
-    if (security_check_context(new) == 0)
-        ret = TRUE;
-
-out_free2:
-    context_free(con);
-out_free:
-    freecon(base);
-out:
-    return ret;
-}
-
-static Bool
-XSELinuxParsePropertyTypeRule(char *p)
-{
-    int keyword;
-    char *propname = NULL, *propcopy = NULL;
-    char *typename = NULL, *typecopy = NULL;
-    char **newTypes;
-    Bool defaultPropertyType = FALSE;
-
-    /* get property name */
-    keyword = XSELinuxParseKeyword(&p);
-    if (keyword == XSELinuxKeywordDefault)
-    {
-        defaultPropertyType = TRUE;
-    }
-    else
-    {
-        propname = XSELinuxParseString(&p);
-        if (!propname || (strlen(propname) == 0))
-        {
-            return FALSE;
-        }
-    }
-
-    /* get the SELinux type corresponding to the property */
-    typename = XSELinuxParseString(&p);
-    if (!typename || (strlen(typename) == 0))
-        return FALSE;
-
-    /* validate the type */
-    if (XSELinuxTypeIsValid(typename) != TRUE)
-        return FALSE;
-
-    /* if it's the default property, save it to append to the end of the
-     * property types list
-     */
-    if (defaultPropertyType == TRUE)
-    {
-        if (XSELinuxPropertyTypeDefault != NULL)
-        {
-            return FALSE;
-        }
-        else
-        {
-            XSELinuxPropertyTypeDefault = (char *)xalloc(strlen(typename)+1);
-            if (!XSELinuxPropertyTypeDefault)
-            {
-                ErrorF("XSELinux: out of memory\n");
-                return FALSE;
-            }
-            strcpy(XSELinuxPropertyTypeDefault, typename);
-            return TRUE;
-        }
-    }
-
-    /* insert the property and type into the propertyTypes array */
-    propcopy = (char *)xalloc(strlen(propname)+1);
-    if (!propcopy)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        return FALSE;
-    }
-    strcpy(propcopy, propname);
-
-    typecopy = (char *)xalloc(strlen(typename)+1);
-    if (!typecopy)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        xfree(propcopy);
-        return FALSE;
-    }
-    strcpy(typecopy, typename);
-
-    newTypes = (char **)xrealloc(propertyTypes, sizeof (char *) * ((propertyTypesCount+1) * 2));
-    if (!newTypes)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        xfree(propcopy);
-        xfree(typecopy);
-        return FALSE;
-    }
-
-    propertyTypesCount++;
-
-    newTypes[propertyTypesCount*2 - 2] = propcopy;
-    newTypes[propertyTypesCount*2 - 1] = typecopy;
-
-    propertyTypes = newTypes;
-
-    return TRUE;
-} /* XSELinuxParsePropertyTypeRule */
-
-static Bool
-XSELinuxParseExtensionTypeRule(char *p)
-{
-    int keyword;
-    char *extname = NULL, *extcopy = NULL;
-    char *typename = NULL, *typecopy = NULL;
-    char **newTypes;
-    Bool defaultExtensionType = FALSE;
-
-    /* get extension name */
-    keyword = XSELinuxParseKeyword(&p);
-    if (keyword == XSELinuxKeywordDefault)
-    {
-        defaultExtensionType = TRUE;
-    }
-    else
-    {
-        extname = XSELinuxParseString(&p);
-        if (!extname || (strlen(extname) == 0))
-        {
-            return FALSE;
-        }
-    }
-
-    /* get the SELinux type corresponding to the extension */
-    typename = XSELinuxParseString(&p);
-    if (!typename || (strlen(typename) == 0))
-        return FALSE;
-
-    /* validate the type */
-    if (XSELinuxTypeIsValid(typename) != TRUE)
-        return FALSE;
-
-    /* if it's the default extension, save it to append to the end of the
-     * extension types list
-     */
-    if (defaultExtensionType == TRUE)
-    {
-        if (XSELinuxExtensionTypeDefault != NULL)
-        {
-            return FALSE;
-        }
-        else
-        {
-            XSELinuxExtensionTypeDefault = (char *)xalloc(strlen(typename)+1);
-            if (!XSELinuxExtensionTypeDefault)
-            {
-                ErrorF("XSELinux: out of memory\n");
-                return FALSE;
-            }
-            strcpy(XSELinuxExtensionTypeDefault, typename);
-            return TRUE;
-        }
-    }
-
-    /* insert the extension and type into the extensionTypes array */
-    extcopy = (char *)xalloc(strlen(extname)+1);
-    if (!extcopy)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        return FALSE;
-    }
-    strcpy(extcopy, extname);
-
-    typecopy = (char *)xalloc(strlen(typename)+1);
-    if (!typecopy)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        xfree(extcopy);
-        return FALSE;
-    }
-    strcpy(typecopy, typename);
-
-    newTypes = (char **)xrealloc(extensionTypes, sizeof(char *) *( (extensionTypesCount+1) * 2));
-    if (!newTypes)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        xfree(extcopy);
-        xfree(typecopy);
-        return FALSE;
-    }
-
-    extensionTypesCount++;
-
-    newTypes[extensionTypesCount*2 - 2] = extcopy;
-    newTypes[extensionTypesCount*2 - 1] = typecopy;
-
-    extensionTypes = newTypes;
-
-    return TRUE;
-} /* XSELinuxParseExtensionTypeRule */
-
-static Bool
-XSELinuxParseNonlocalContext(char *p)
-{
-    char *context;
-
-    context = XSELinuxParseString(&p);
-    if (!context || (strlen(context) == 0))
-    {
-        return FALSE;
-    }
-
-    if (XSELinuxNonlocalContextDefault != NULL)
-    {
-        return FALSE;
-    }
-
-    /* validate the context */
-    if (security_check_context(context))
-    {
-        return FALSE;
-    }
-
-    XSELinuxNonlocalContextDefault = (char *)xalloc(strlen(context)+1);
-    if (!XSELinuxNonlocalContextDefault)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        return FALSE;
-    }
-    strcpy(XSELinuxNonlocalContextDefault, context);
-
-    return TRUE;
-} /* XSELinuxParseNonlocalContext */
-
 static Bool
 XSELinuxLoadConfigFile(void)
 {
-    FILE *f;
-    int lineNumber = 0;
-    char **newTypes;
-    Bool ret = FALSE;
+    struct selinux_opt options[] = {
+	{ SELABEL_OPT_PATH, XSELINUXCONFIGFILE },
+	{ SELABEL_OPT_VALIDATE, (char *)1 },
+    };
 
     if (!XSELINUXCONFIGFILE)
         return FALSE;
 
-    /* some initial bookkeeping */
-    propertyTypesCount = extensionTypesCount = 0;
-    propertyTypes = extensionTypes = NULL;
-    XSELinuxPropertyTypeDefault = XSELinuxExtensionTypeDefault = NULL;
-    XSELinuxNonlocalContextDefault = NULL;
-
-#ifndef __UNIXOS2__
-    f = fopen(XSELINUXCONFIGFILE, "r");
-#else
-    f = fopen((char*)__XOS2RedirRoot(XSELINUXCONFIGFILE), "r");
-#endif
-    if (!f)
-    {
-        ErrorF("Error opening XSELinux policy file %s\n", XSELINUXCONFIGFILE);
-        return FALSE;
-    }
-
-    while (!feof(f))
-    {
-        char buf[200];
-        Bool validLine;
-        char *p;
-
-        if (!(p = fgets(buf, sizeof(buf), f)))
-            break;
-        lineNumber++;
-
-        switch (XSELinuxParseKeyword(&p))
-        {
-            case XSELinuxKeywordComment:
-                validLine = TRUE;
-                break;
-
-            case XSELinuxKeywordProperty:
-                validLine = XSELinuxParsePropertyTypeRule(p);
-                break;
-
-            case XSELinuxKeywordExtension:
-                validLine = XSELinuxParseExtensionTypeRule(p);
-                break;
-
-            case XSELinuxKeywordNonlocalContext:
-                validLine = XSELinuxParseNonlocalContext(p);
-                break;
-
-            default:
-                validLine = (*p == '\0');
-                break;
-        }
-
-        if (!validLine)
-        {
-            ErrorF("XSELinux: Line %d of %s is invalid\n",
-                   lineNumber, XSELINUXCONFIGFILE);
-            goto out;
-        }
-    }
-
-    /* check to make sure the default types and the nonlocal context
-     * were specified
-     */
-    if (XSELinuxPropertyTypeDefault == NULL)
-    {
-        ErrorF("XSELinux: No default property type specified\n");
-        goto out;
-    }
-    else if (XSELinuxExtensionTypeDefault == NULL)
-    {
-        ErrorF("XSELinux: No default extension type specified\n");
-        goto out;
-    }
-    else if (XSELinuxNonlocalContextDefault == NULL)
-    {
-        ErrorF("XSELinux: No default context for non-local clients specified\n");
-        goto out;
-    }
-
-    /* Finally, append the default property and extension types to the
-     * bottoms of the propertyTypes and extensionTypes arrays, respectively.
-     * The 'name' of the property / extension is NULL.
-     */
-    newTypes = (char **)xrealloc(propertyTypes, sizeof(char *) *((propertyTypesCount+1) * 2));
-    if (!newTypes)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        goto out;
-    }
-    propertyTypesCount++;
-    newTypes[propertyTypesCount*2 - 2] = NULL;
-    newTypes[propertyTypesCount*2 - 1] = XSELinuxPropertyTypeDefault;
-    propertyTypes = newTypes;
-
-    newTypes = (char **)xrealloc(extensionTypes, sizeof(char *) *((extensionTypesCount+1) * 2));
-    if (!newTypes)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        goto out;
-    }
-    extensionTypesCount++;
-    newTypes[extensionTypesCount*2 - 2] = NULL;
-    newTypes[extensionTypesCount*2 - 1] = XSELinuxExtensionTypeDefault;
-    extensionTypes = newTypes;
-
-    ret = TRUE;
-
-out:
-    fclose(f);
-    return ret;
+    label_hnd = selabel_open(SELABEL_CTX_X, options, 2);
+    return !!label_hnd;
 } /* XSELinuxLoadConfigFile */
 
 static void
 XSELinuxFreeConfigData(void)
 {
-    char **ptr;
-
-    /* Free all the memory in the table until we reach the NULL, then
-     * skip one past the NULL and free the default type.  Then take care
-     * of some bookkeeping.
-     */
-    for (ptr = propertyTypes; *ptr; ptr++)
-        xfree(*ptr);
-    ptr++;
-    xfree(*ptr);
-
-    XSELinuxPropertyTypeDefault = NULL;
-    propertyTypesCount = 0;
-
-    xfree(propertyTypes);
-    propertyTypes = NULL;
-
-    /* ... and the same for the extension type table */
-    for (ptr = extensionTypes; *ptr; ptr++)
-        xfree(*ptr);
-    ptr++;
-    xfree(*ptr);
-
-    XSELinuxExtensionTypeDefault = NULL;
-    extensionTypesCount = 0;
-
-    xfree(extensionTypes);
-    extensionTypes = NULL;
-
-    /* finally, take care of the context for non-local connections */
-    xfree(XSELinuxNonlocalContextDefault);
-    XSELinuxNonlocalContextDefault = NULL;
+    selabel_close(label_hnd);
+    label_hnd = NULL;
 } /* XSELinuxFreeConfigData */
 
 /* Extension dispatch functions */
commit e2a720c9a17dc860ee0a858c2b21fd71e86cdcd0
Merge: 878cac7... 3f9adb1...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Jun 11 15:29:11 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	dix/dixutils.c

diff --cc dix/dixutils.c
index 4d082cd,c1e30ff..14ef7e6
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@@ -271,8 -269,6 +271,8 @@@ dixLookupClient(ClientPtr *pClient, XI
      int clientIndex = CLIENT_ID(rid);
      client->errorValue = rid;
  
-     dixLookupResource(&pRes, rid, RC_ANY, client, DixReadAccess);
++    dixLookupResource(&pRes, rid, RC_ANY, client, access);
 +
      if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) {
  	*pClient = clients[clientIndex];
  	return Success;
commit 878cac71aa0018deee861b297638c0744dba631b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Jun 11 14:19:37 2007 -0400

    xselinux: use new libselinux support for private Flask definitions.
    
    Removes indirect dependency on kernel headers.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 3cec21b..cdb3b33 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -22,8 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * All rights reserved.
  */
 
-#include <selinux/flask.h>
-#include <selinux/av_permissions.h>
 #include <selinux/selinux.h>
 #include <selinux/context.h>
 #include <selinux/avc.h>
@@ -96,6 +94,42 @@ static char *XSELinuxNonlocalContextDefault = NULL;
 extern Selection *CurrentSelections;
 extern int NumCurrentSelections;
 
+/* Dynamically allocated security classes and permissions */
+static struct security_class_mapping map[] = {
+    { "drawable",
+      { "create", "destroy", "draw", "copy", "getattr", NULL }},
+    { "window",
+      { "addchild", "create", "destroy", "map", "unmap", "chstack",
+	"chproplist", "chprop", "listprop", "getattr", "setattr", "setfocus",
+	"move", "chselection", "chparent", "ctrllife", "enumerate",
+	"transparent", "mousemotion", "clientcomevent", "inputevent",
+	"drawevent", "windowchangeevent", "windowchangerequest",
+	"serverchangeevent", "extensionevent", NULL }},
+    { "gc",
+      { "create", "free", "getattr", "setattr", NULL }},
+    { "font",
+      { "load", "free", "getattr", "use", NULL }},
+    { "colormap",
+      { "create", "free", "install", "uninstall", "list", "read", "store",
+	"getattr", "setattr", NULL }},
+    { "property",
+      { "create", "free", "read", "write", NULL }},
+    { "cursor",
+      { "create", "createglyph", "free", "assign", "setattr", NULL }},
+    { "xclient",
+      { "kill", NULL }},
+    { "xinput",
+      { "lookup", "getattr", "setattr", "setfocus", "warppointer",
+	"activegrab", "passivegrab", "ungrab", "bell", "mousemotion",
+	"relabelinput", NULL }},
+    { "xserver",
+      { "screensaver", "gethostlist", "sethostlist", "getfontpath",
+	"setfontpath", "getattr", "grab", "ungrab", NULL }},
+    { "xextension",
+      { "query", "use", NULL }},
+    { NULL }
+};
+
 /*
  * list of classes corresponding to SIDs in the
  * rsid array of the security state structure (below).
@@ -1851,6 +1885,10 @@ XSELinuxExtensionInit(INITARGS)
         return;
     }
 
+    if (selinux_set_mapping(map) < 0) {
+	FatalError("XSELinux: Failed to set up security class mapping\n");
+    }
+
     if (avc_init("xserver", NULL, &alc, NULL, NULL) < 0)
     {
 	FatalError("XSELinux: Couldn't initialize SELinux userspace AVC\n");
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
index eff6db5..57fcbb2 100644
--- a/Xext/xselinux.h
+++ b/Xext/xselinux.h
@@ -20,10 +20,103 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _XSELINUX_H
 #define _XSELINUX_H
 
+/* Extension info */
 #define XSELINUX_EXTENSION_NAME		"SELinux"
 #define XSELINUX_MAJOR_VERSION		1
 #define XSELINUX_MINOR_VERSION		0
 #define XSELinuxNumberEvents		0
 #define XSELinuxNumberErrors		0
 
+/* Private Flask definitions */
+#define SECCLASS_DRAWABLE		1
+#define DRAWABLE__CREATE		0x00000001UL
+#define DRAWABLE__DESTROY		0x00000002UL
+#define DRAWABLE__DRAW			0x00000004UL
+#define DRAWABLE__COPY			0x00000008UL
+#define DRAWABLE__GETATTR		0x00000010UL
+#define SECCLASS_WINDOW			2
+#define WINDOW__ADDCHILD		0x00000001UL
+#define WINDOW__CREATE			0x00000002UL
+#define WINDOW__DESTROY			0x00000004UL
+#define WINDOW__MAP			0x00000008UL
+#define WINDOW__UNMAP			0x00000010UL
+#define WINDOW__CHSTACK			0x00000020UL
+#define WINDOW__CHPROPLIST		0x00000040UL
+#define WINDOW__CHPROP			0x00000080UL
+#define WINDOW__LISTPROP		0x00000100UL
+#define WINDOW__GETATTR			0x00000200UL
+#define WINDOW__SETATTR			0x00000400UL
+#define WINDOW__SETFOCUS		0x00000800UL
+#define WINDOW__MOVE			0x00001000UL
+#define WINDOW__CHSELECTION		0x00002000UL
+#define WINDOW__CHPARENT		0x00004000UL
+#define WINDOW__CTRLLIFE		0x00008000UL
+#define WINDOW__ENUMERATE		0x00010000UL
+#define WINDOW__TRANSPARENT		0x00020000UL
+#define WINDOW__MOUSEMOTION		0x00040000UL
+#define WINDOW__CLIENTCOMEVENT		0x00080000UL
+#define WINDOW__INPUTEVENT		0x00100000UL
+#define WINDOW__DRAWEVENT		0x00200000UL
+#define WINDOW__WINDOWCHANGEEVENT	0x00400000UL
+#define WINDOW__WINDOWCHANGEREQUEST	0x00800000UL
+#define WINDOW__SERVERCHANGEEVENT	0x01000000UL
+#define WINDOW__EXTENSIONEVENT		0x02000000UL
+#define SECCLASS_GC			3
+#define GC__CREATE			0x00000001UL
+#define GC__FREE			0x00000002UL
+#define GC__GETATTR			0x00000004UL
+#define GC__SETATTR			0x00000008UL
+#define SECCLASS_FONT			4
+#define FONT__LOAD			0x00000001UL
+#define FONT__FREE			0x00000002UL
+#define FONT__GETATTR			0x00000004UL
+#define FONT__USE			0x00000008UL
+#define SECCLASS_COLORMAP		5
+#define COLORMAP__CREATE		0x00000001UL
+#define COLORMAP__FREE			0x00000002UL
+#define COLORMAP__INSTALL		0x00000004UL
+#define COLORMAP__UNINSTALL		0x00000008UL
+#define COLORMAP__LIST			0x00000010UL
+#define COLORMAP__READ			0x00000020UL
+#define COLORMAP__STORE			0x00000040UL
+#define COLORMAP__GETATTR		0x00000080UL
+#define COLORMAP__SETATTR		0x00000100UL
+#define SECCLASS_PROPERTY		6
+#define PROPERTY__CREATE		0x00000001UL
+#define PROPERTY__FREE			0x00000002UL
+#define PROPERTY__READ			0x00000004UL
+#define PROPERTY__WRITE			0x00000008UL
+#define SECCLASS_CURSOR			7
+#define CURSOR__CREATE			0x00000001UL
+#define CURSOR__CREATEGLYPH		0x00000002UL
+#define CURSOR__FREE			0x00000004UL
+#define CURSOR__ASSIGN			0x00000008UL
+#define CURSOR__SETATTR			0x00000010UL
+#define SECCLASS_XCLIENT		8
+#define XCLIENT__KILL			0x00000001UL
+#define SECCLASS_XINPUT			9
+#define XINPUT__LOOKUP			0x00000001UL
+#define XINPUT__GETATTR			0x00000002UL
+#define XINPUT__SETATTR			0x00000004UL
+#define XINPUT__SETFOCUS		0x00000008UL
+#define XINPUT__WARPPOINTER		0x00000010UL
+#define XINPUT__ACTIVEGRAB		0x00000020UL
+#define XINPUT__PASSIVEGRAB		0x00000040UL
+#define XINPUT__UNGRAB			0x00000080UL
+#define XINPUT__BELL			0x00000100UL
+#define XINPUT__MOUSEMOTION		0x00000200UL
+#define XINPUT__RELABELINPUT		0x00000400UL
+#define SECCLASS_XSERVER		10
+#define XSERVER__SCREENSAVER		0x00000001UL
+#define XSERVER__GETHOSTLIST		0x00000002UL
+#define XSERVER__SETHOSTLIST		0x00000004UL
+#define XSERVER__GETFONTPATH		0x00000008UL
+#define XSERVER__SETFONTPATH		0x00000010UL
+#define XSERVER__GETATTR		0x00000020UL
+#define XSERVER__GRAB			0x00000040UL
+#define XSERVER__UNGRAB			0x00000080UL
+#define SECCLASS_XEXTENSION		11
+#define XEXTENSION__QUERY		0x00000001UL
+#define XEXTENSION__USE			0x00000002UL
+
 #endif /* _XSELINUX_H */
commit 793470a8356976ddd427280a738dfb6e1c0e4e70
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Jun 4 12:33:49 2007 -0400

    dix: fix null pointer dereference in new resource lookup function.

diff --git a/dix/resource.c b/dix/resource.c
index 67124c7..e89ad1f 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -908,7 +908,6 @@ dixLookupResource(pointer *result, XID id, RESTYPE rtype,
     ResourcePtr res = NULL;
 
     *result = NULL;
-    client->errorValue = id;
 
     if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
 	res = clientTable[cid].resources[Hash(cid, id)];
@@ -922,6 +921,7 @@ dixLookupResource(pointer *result, XID id, RESTYPE rtype,
 	return BadValue;
 
     if (client) {
+	client->errorValue = id;
 	cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type,
 		       mode, res->value);
 	if (cid != Success)
commit ddb26bccd275f4fc011f7a2be685d1ce58555a00
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu May 24 12:20:24 2007 -0400

    dix: Add a bunch of new access codes.
    
    These were determined through an analysis of the core protocol and 35 of
    the most common protocol extensions.  There remain four bits for future
    use.

diff --git a/include/dixaccess.h b/include/dixaccess.h
index 205b76c..3c62ee3 100644
--- a/include/dixaccess.h
+++ b/include/dixaccess.h
@@ -25,5 +25,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define DixWriteAccess		(1<<1)	/* changing the object */
 #define DixDestroyAccess	(1<<2)	/* destroying the object */
 #define DixCreateAccess		(1<<3)	/* creating the object */
+#define DixGetAttrAccess	(1<<4)	/* get object attributes */
+#define DixSetAttrAccess	(1<<5)	/* set object attributes */
+#define DixListPropAccess	(1<<6)  /* list properties of object */
+#define DixGetPropAccess	(1<<7)	/* get properties of object */
+#define DixSetPropAccess	(1<<8)	/* set properties of object */
+#define DixGetFocusAccess	(1<<9)	/* get focus of object */
+#define DixSetFocusAccess	(1<<10)	/* set focus of object */
+#define DixListAccess		(1<<11)	/* list objects */
+#define DixAddAccess		(1<<12)	/* add object */
+#define DixRemoveAccess		(1<<13)	/* remove object */
+#define DixHideAccess		(1<<14)	/* hide object */
+#define DixShowAccess		(1<<15)	/* show object */
+#define DixBlendAccess		(1<<16)	/* mix contents of objects */
+#define DixGrabAccess		(1<<17)	/* exclusive access to object */
+#define DixFreezeAccess		(1<<18)	/* freeze status of object */
+#define DixForceAccess		(1<<19)	/* force status of object */
+#define DixInstallAccess	(1<<20)	/* install object */
+#define DixUninstallAccess	(1<<21)	/* uninstall object */
+#define DixSendAccess		(1<<22)	/* send to object */
+#define DixReceiveAccess	(1<<23)	/* receive from object */
+#define DixUseAccess		(1<<24)	/* use object */
+#define DixManageAccess		(1<<25)	/* manage object */
+#define DixDebugAccess		(1<<26)	/* debug object */
+#define DixBellAccess		(1<<27)	/* audible sound */
 
 #endif /* DIX_ACCESS_H */
commit 2a4aa63a23ddd816b647b851a01865861827a7eb
Merge: 9cee4ec... cc648e6...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue May 22 14:50:26 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	include/miscstruct.h

diff --cc include/miscstruct.h
index f784587,4f5b1d5..81f699a
--- a/include/miscstruct.h
+++ b/include/miscstruct.h
@@@ -50,6 -50,8 +50,7 @@@ SOFTWARE
  
  #include "misc.h"
  #include <X11/Xprotostr.h>
 -#include "gc.h"
+ #include <pixman/pixman.h>
  
  typedef xPoint DDXPointRec;
  
commit 9cee4ec5e6e06d23aafb302494b082c77ade4623
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Apr 17 16:01:56 2007 -0400

    xace: change the semantics of the return value of XACE hooks to allow
    arbitrary X status codes instead of just TRUE/FALSE.
    
    The dix layer in most cases still does not propagate the return value of
    XACE hooks back to the client, however.  There is more error propagation
    work to do.

diff --git a/Xext/security.c b/Xext/security.c
index 12e79f9..0d46359 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -806,7 +806,7 @@ SecurityCheckDeviceAccess(CallbackListPtr *pcbl, pointer unused,
 	    case X_SetModifierMapping:
 		SecurityAudit("client %d attempted request %d\n",
 			      client->index, reqtype);
-		rec->rval = FALSE;
+		rec->status = BadAccess;
 		return;
 	    default:
 		break;
@@ -875,7 +875,7 @@ SecurityCheckDeviceAccess(CallbackListPtr *pcbl, pointer unused,
 	else
 	    SecurityAudit("client %d attempted to access device %d (%s)\n",
 			  client->index, dev->id, devname);
-	rec->rval = FALSE;
+	rec->status = BadAccess;
     }
     return;
 } /* SecurityCheckDeviceAccess */
@@ -1084,7 +1084,7 @@ SecurityCheckResourceIDAccess(CallbackListPtr *pcbl, pointer unused,
     return;
   deny:
     SecurityAuditResourceIDAccess(client, id);
-    rec->rval = FALSE;	/* deny access */
+    rec->status = BadAccess; /* deny access */
 } /* SecurityCheckResourceIDAccess */
 
 
@@ -1176,7 +1176,7 @@ SecurityCheckDrawableAccess(CallbackListPtr *pcbl, pointer unused,
     XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
 
     if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
-	rec->rval = FALSE;
+	rec->status = BadAccess;
 }
 
 static void
@@ -1192,7 +1192,7 @@ SecurityCheckMapAccess(CallbackListPtr *pcbl, pointer unused,
 	pWin->parent && pWin->parent->parent &&
 	(TRUSTLEVEL(wClient(pWin->parent)) == XSecurityClientTrusted))
 
-	rec->rval = FALSE;
+	rec->status = BadAccess;
 }
 
 static void
@@ -1202,7 +1202,7 @@ SecurityCheckBackgrndAccess(CallbackListPtr *pcbl, pointer unused,
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
 
     if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
-	rec->rval = FALSE;
+	rec->status = BadAccess;
 }
 
 static void
@@ -1214,7 +1214,7 @@ SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
     if ((TRUSTLEVEL(rec->client) != XSecurityClientTrusted) &&
 	!EXTLEVEL(rec->ext))
 
-	rec->rval = FALSE;
+	rec->status = BadAccess;
 }
 
 static void
@@ -1225,7 +1225,7 @@ SecurityCheckHostlistAccess(CallbackListPtr *pcbl, pointer unused,
  
     if (TRUSTLEVEL(rec->client) != XSecurityClientTrusted)
     {
-	rec->rval = FALSE;
+	rec->status = BadAccess;
 	if (rec->access_mode == DixWriteAccess)
 	    SecurityAudit("client %d attempted to change host access\n",
 			  rec->client->index);
@@ -1255,14 +1255,14 @@ typedef struct _PropertyAccessRec {
 #define SecurityAnyWindow          0
 #define SecurityRootWindow         1
 #define SecurityWindowWithProperty 2
-    char readAction;
-    char writeAction;
-    char destroyAction;
+    int readAction;
+    int writeAction;
+    int destroyAction;
     struct _PropertyAccessRec *next;
 } PropertyAccessRec, *PropertyAccessPtr;
 
 static PropertyAccessPtr PropertyAccessList = NULL;
-static char SecurityDefaultAction = XaceErrorOperation;
+static int SecurityDefaultAction = BadAtom;
 static char *SecurityPolicyFile = DEFAULTPOLICYFILE;
 static ATOM SecurityMaxPropertyName = 0;
 
@@ -1372,8 +1372,8 @@ SecurityParsePropertyAccessRule(
 {
     char *propname;
     char c;
-    char action = SecurityDefaultAction;
-    char readAction, writeAction, destroyAction;
+    int action = SecurityDefaultAction;
+    int readAction, writeAction, destroyAction;
     PropertyAccessPtr pacl, prev, cur;
     char *mustHaveProperty = NULL;
     char *mustHaveValue = NULL;
@@ -1418,9 +1418,9 @@ SecurityParsePropertyAccessRule(
     {
 	switch (c)
 	{
-	    case 'i': action = XaceIgnoreOperation; break;
-	    case 'a': action = XaceAllowOperation;  break;
-	    case 'e': action = XaceErrorOperation;  break;
+	    case 'i': action = XaceIgnoreError; break;
+	    case 'a': action = Success;  break;
+	    case 'e': action = BadAtom;  break;
 
 	    case 'r': readAction    = action; break;
 	    case 'w': writeAction   = action; break;
@@ -1678,7 +1678,7 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
     ATOM propertyName = rec->pProp->propertyName;
     Mask access_mode = rec->access_mode;
     PropertyAccessPtr pacl;
-    char action = SecurityDefaultAction;
+    int action = SecurityDefaultAction;
 
     /* if client trusted or window untrusted, allow operation */
 
@@ -1757,7 +1757,7 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
 	     * If pacl doesn't apply, something above should have
 	     * executed a continue, which will skip the follwing code.
 	     */
-	    action = XaceAllowOperation;
+	    action = Success;
 	    if (access_mode & DixReadAccess)
 		action = max(action, pacl->readAction);
 	    if (access_mode & DixWriteAccess)
@@ -1768,19 +1768,18 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
 	} /* end for each pacl */
     } /* end if propertyName <= SecurityMaxPropertyName */
 
-    if (XaceAllowOperation != action)
+    if (action != Success)
     { /* audit the access violation */
 	int cid = CLIENT_ID(pWin->drawable.id);
 	int reqtype = ((xReq *)client->requestBuffer)->reqType;
-	char *actionstr = (XaceIgnoreOperation == action) ?
-							"ignored" : "error";
+	char *actionstr = (XaceIgnoreError == action) ? "ignored" : "error";
 	SecurityAudit("client %d attempted request %d with window 0x%x property %s (atom 0x%x) of client %d, %s\n",
 		client->index, reqtype, pWin->drawable.id,
 		      NameForAtom(propertyName), propertyName, cid, actionstr);
     }
     /* return codes increase with strictness */
-    if (action > rec->rval)
-        rec->rval = action;
+    if (action != Success)
+        rec->status = action;
 } /* SecurityCheckPropertyAccess */
 
 
diff --git a/Xext/xace.c b/Xext/xace.c
index aff45d9..46fe7bc 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -61,10 +61,10 @@ int XaceHook(int hook, ...)
 	case XACE_CORE_DISPATCH: {
 	    XaceCoreDispatchRec rec = {
 		va_arg(ap, ClientPtr),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_RESOURCE_ACCESS: {
@@ -74,10 +74,10 @@ int XaceHook(int hook, ...)
 		va_arg(ap, RESTYPE),
 		va_arg(ap, Mask),
 		va_arg(ap, pointer),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_DEVICE_ACCESS: {
@@ -85,10 +85,10 @@ int XaceHook(int hook, ...)
 		va_arg(ap, ClientPtr),
 		va_arg(ap, DeviceIntPtr),
 		va_arg(ap, Bool),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_PROPERTY_ACCESS: {
@@ -97,20 +97,20 @@ int XaceHook(int hook, ...)
 		va_arg(ap, WindowPtr),
 		va_arg(ap, PropertyPtr),
 		va_arg(ap, Mask),
-		XaceAllowOperation   /* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_DRAWABLE_ACCESS: {
 	    XaceDrawableAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, DrawablePtr),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_MAP_ACCESS:
@@ -118,10 +118,10 @@ int XaceHook(int hook, ...)
 	    XaceMapAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, WindowPtr),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_EXT_DISPATCH:
@@ -129,20 +129,20 @@ int XaceHook(int hook, ...)
 	    XaceExtAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, ExtensionEntry*),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_HOSTLIST_ACCESS: {
 	    XaceHostlistAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, Mask),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_SELECTION_ACCESS: {
@@ -150,20 +150,20 @@ int XaceHook(int hook, ...)
 		va_arg(ap, ClientPtr),
 		va_arg(ap, Selection*),
 		va_arg(ap, Mask),
-		TRUE	/* default allow */
+		Success /* default allow */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_SITE_POLICY: {
 	    XaceSitePolicyRec rec = {
 		va_arg(ap, char*),
 		va_arg(ap, int),
-		FALSE	/* default unrecognized */
+		BadValue /* default unrecognized */
 	    };
 	    calldata = &rec;
-	    prv = &rec.rval;
+	    prv = &rec.status;
 	    break;
 	}
 	case XACE_DECLARE_EXT_SECURE: {
@@ -271,13 +271,14 @@ static int
 XaceCatchDispatchProc(ClientPtr client)
 {
     REQUEST(xReq);
-    int major = stuff->reqType;
+    int rc, major = stuff->reqType;
 
     if (!ProcVector[major])
 	return (BadRequest);
 
-    if (!XaceHook(XACE_CORE_DISPATCH, client))
-	return (BadAccess);
+    rc = XaceHook(XACE_CORE_DISPATCH, client);
+    if (rc != Success)
+        return rc;
 
     return client->swapped ? 
 	(* SwappedProcVector[major])(client) :
@@ -294,7 +295,7 @@ XaceCatchExtProc(ClientPtr client)
     if (!ext || !ProcVector[major])
 	return (BadRequest);
 
-    if (!XaceHook(XACE_EXT_DISPATCH, client, ext))
+    if (XaceHook(XACE_EXT_DISPATCH, client, ext) != Success)
 	return (BadRequest); /* pretend extension doesn't exist */
 
     return client->swapped ?
diff --git a/Xext/xace.h b/Xext/xace.h
index ec13842..0832612 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -20,10 +20,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _XACE_H
 #define _XACE_H
 
-/* Hook return codes */
-#define XaceErrorOperation  0
-#define XaceAllowOperation  1
-#define XaceIgnoreOperation 2
+/* Special value used for ignore operation.  This is a deprecated feature
+ * only for Security extension support.  Do not use in new code.
+ */
+#define XaceIgnoreError BadRequest
 
 #ifdef XACE
 
@@ -97,10 +97,10 @@ extern void XaceCensorImage(
 /* Define calls away when XACE is not being built. */
 
 #ifdef __GNUC__
-#define XaceHook(args...) XaceAllowOperation
+#define XaceHook(args...) Success
 #define XaceCensorImage(args...) { ; }
 #else
-#define XaceHook(...) XaceAllowOperation
+#define XaceHook(...) Success
 #define XaceCensorImage(...) { ; }
 #endif
 
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 184fb9b..8eb74d5 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -33,7 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 /* XACE_CORE_DISPATCH */
 typedef struct {
     ClientPtr client;
-    int rval;
+    int status;
 } XaceCoreDispatchRec;
 
 /* XACE_RESOURCE_ACCESS */
@@ -43,7 +43,7 @@ typedef struct {
     RESTYPE rtype;
     Mask access_mode;
     pointer res;
-    int rval;
+    int status;
 } XaceResourceAccessRec;
 
 /* XACE_DEVICE_ACCESS */
@@ -51,7 +51,7 @@ typedef struct {
     ClientPtr client;
     DeviceIntPtr dev;
     Bool fromRequest;
-    int rval;
+    int status;
 } XaceDeviceAccessRec;
 
 /* XACE_PROPERTY_ACCESS */
@@ -60,14 +60,14 @@ typedef struct {
     WindowPtr pWin;
     PropertyPtr pProp;
     Mask access_mode;
-    int rval;
+    int status;
 } XacePropertyAccessRec;
 
 /* XACE_DRAWABLE_ACCESS */
 typedef struct {
     ClientPtr client;
     DrawablePtr pDraw;
-    int rval;
+    int status;
 } XaceDrawableAccessRec;
 
 /* XACE_MAP_ACCESS */
@@ -75,7 +75,7 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     WindowPtr pWin;
-    int rval;
+    int status;
 } XaceMapAccessRec;
 
 /* XACE_EXT_DISPATCH */
@@ -83,14 +83,14 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     ExtensionEntry *ext;
-    int rval;
+    int status;
 } XaceExtAccessRec;
 
 /* XACE_HOSTLIST_ACCESS */
 typedef struct {
     ClientPtr client;
     Mask access_mode;
-    int rval;
+    int status;
 } XaceHostlistAccessRec;
 
 /* XACE_SELECTION_ACCESS */
@@ -98,14 +98,14 @@ typedef struct {
     ClientPtr client;
     Selection *selection;
     Mask access_mode;
-    int rval;
+    int status;
 } XaceSelectionAccessRec;
 
 /* XACE_SITE_POLICY */
 typedef struct {
     char *policyString;
     int len;
-    int rval;
+    int status;
 } XaceSitePolicyRec;
 
 /* XACE_DECLARE_EXT_SECURE */
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 648bb6e..3cec21b 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -193,7 +193,7 @@ SwapXID(ClientPtr client, XID id)
  * class: Security class of the server object being accessed.
  * perm: Permissions required on the object.
  *
- * Returns: boolean TRUE=allowed, FALSE=denied.
+ * Returns: X status code.
  */
 static int
 ServerPerm(ClientPtr client,
@@ -211,18 +211,19 @@ ServerPerm(ClientPtr client,
         if (avc_has_perm(SID(client), RSID(serverClient,idx), class,
                          perm, &AEREF(client), &auditdata) < 0)
         {
-            if (errno != EACCES)
-                ErrorF("ServerPerm: unexpected error %d\n", errno);
-            return FALSE;
+            if (errno == EACCES)
+		return BadAccess;
+	    ErrorF("ServerPerm: unexpected error %d\n", errno);
+	    return BadValue;
         }
     }
     else
     {
 	ErrorF("No client state in server-perm check!\n");
-        return TRUE;
+        return Success;
     }
 
-    return TRUE;
+    return Success;
 }
 
 /*
@@ -234,7 +235,7 @@ ServerPerm(ClientPtr client,
  * class: Security class of the resource being accessed.
  * perm: Permissions required on the resource.
  *
- * Returns: boolean TRUE=allowed, FALSE=denied.
+ * Returns: X status code.
  */
 static int
 IDPerm(ClientPtr sclient,
@@ -247,7 +248,7 @@ IDPerm(ClientPtr sclient,
     XSELinuxAuditRec auditdata;
 
     if (id == None)
-	return TRUE;
+	return Success;
 
     CheckXID(id);
     tclient = clients[CLIENT_ID(id)];
@@ -259,7 +260,7 @@ IDPerm(ClientPtr sclient,
      */
     if (!tclient || !HAVESTATE(tclient) || !HAVESTATE(sclient))
     {
-	return TRUE;
+	return Success;
     }
 
     auditdata.client = sclient;
@@ -269,12 +270,13 @@ IDPerm(ClientPtr sclient,
     if (avc_has_perm(SID(sclient), RSID(tclient,idx), class,
 		     perm, &AEREF(sclient), &auditdata) < 0)
     {
-	if (errno != EACCES)
-	    ErrorF("IDPerm: unexpected error %d\n", errno);
-	return FALSE;
+	if (errno == EACCES)
+	    return BadAccess;
+	ErrorF("IDPerm: unexpected error %d\n", errno);
+	return BadValue;
     }
 
-    return TRUE;
+    return Success;
 }
 
 /*
@@ -501,8 +503,9 @@ FreeClientState(ClientPtr client)
 #define REQUEST_SIZE_CHECK(client, req) \
     (client->req_len >= (sizeof(req) >> 2))
 #define IDPERM(client, req, field, class, perm) \
-    (REQUEST_SIZE_CHECK(client,req) && \
-    IDPerm(client, SwapXID(client,((req*)stuff)->field), class, perm))
+    (REQUEST_SIZE_CHECK(client,req) ? \
+     IDPerm(client, SwapXID(client,((req*)stuff)->field), class, perm) : \
+     BadLength)
 
 static int
 CheckSendEventPerms(ClientPtr client)
@@ -513,7 +516,7 @@ CheckSendEventPerms(ClientPtr client)
 
     /* might need type bounds checking here */
     if (!REQUEST_SIZE_CHECK(client, xSendEventReq))
-	return FALSE;
+	return BadLength;
 
     switch (stuff->event.u.u.type) {
 	case SelectionClear:
@@ -574,11 +577,11 @@ static int
 CheckConvertSelectionPerms(ClientPtr client)
 {
     register char n;
-    int rval = TRUE;
+    int rval = Success;
     REQUEST(xConvertSelectionReq);
 
     if (!REQUEST_SIZE_CHECK(client, xConvertSelectionReq))
-	return FALSE;
+	return BadLength;
 
     if (client->swapped)
     {
@@ -591,24 +594,26 @@ CheckConvertSelectionPerms(ClientPtr client)
 	int i = 0;
 	while ((i < NumCurrentSelections) &&
 	       CurrentSelections[i].selection != stuff->selection) i++;
-	if (i < NumCurrentSelections)
-	    rval = rval && IDPerm(client, CurrentSelections[i].window,
-				  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
-    }
-    rval = rval && IDPerm(client, stuff->requestor,
+	if (i < NumCurrentSelections) {
+	    rval = IDPerm(client, CurrentSelections[i].window,
 			  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
-    return rval;
+	    if (rval != Success)
+		return rval;
+	}
+    }
+    return IDPerm(client, stuff->requestor,
+		  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
 }
 
 static int
 CheckSetSelectionOwnerPerms(ClientPtr client)
 {
     register char n;
-    int rval = TRUE;
+    int rval = Success;
     REQUEST(xSetSelectionOwnerReq);
 
     if (!REQUEST_SIZE_CHECK(client, xSetSelectionOwnerReq))
-	return FALSE;
+	return BadLength;
 
     if (client->swapped)
     {
@@ -621,13 +626,15 @@ CheckSetSelectionOwnerPerms(ClientPtr client)
 	int i = 0;
 	while ((i < NumCurrentSelections) &&
 	       CurrentSelections[i].selection != stuff->selection) i++;
-	if (i < NumCurrentSelections)
-	    rval = rval && IDPerm(client, CurrentSelections[i].window,
-				  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+	if (i < NumCurrentSelections) {
+	    rval = IDPerm(client, CurrentSelections[i].window,
+			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+	    if (rval != Success)
+		return rval;
+	}
     }
-    rval = rval && IDPerm(client, stuff->window,
+    return IDPerm(client, stuff->window,
 			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
-    return rval;
 }
 
 static void
@@ -636,7 +643,7 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     XaceCoreDispatchRec *rec = (XaceCoreDispatchRec*)calldata;
     ClientPtr client = rec->client;
     REQUEST(xReq);
-    Bool rval;
+    int rval = Success, rval2 = Success, rval3 = Success;
 
     switch(stuff->reqType) {
     /* Drawable class control requirements */
@@ -668,9 +675,9 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     case X_CopyArea:
     case X_CopyPlane:
 	rval = IDPERM(client, xCopyAreaReq, srcDrawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__COPY)
-	    && IDPERM(client, xCopyAreaReq, dstDrawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
+	rval2 = IDPERM(client, xCopyAreaReq, dstDrawable,
+		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
 	break;
     case X_GetImage:
 	rval = IDPERM(client, xGetImageReq, drawable,
@@ -712,12 +719,12 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     case X_CreateWindow:
 	rval = IDPERM(client, xCreateWindowReq, wid,
 		      SECCLASS_WINDOW,
-		      WINDOW__CREATE | WINDOW__SETATTR | WINDOW__MOVE)
-	    && IDPERM(client, xCreateWindowReq, parent,
-		      SECCLASS_WINDOW,
-		      WINDOW__CHSTACK | WINDOW__ADDCHILD)
-	    && IDPERM(client, xCreateWindowReq, wid,
-		      SECCLASS_DRAWABLE, DRAWABLE__CREATE);
+		      WINDOW__CREATE | WINDOW__SETATTR | WINDOW__MOVE);
+	rval2 = IDPERM(client, xCreateWindowReq, parent,
+		       SECCLASS_WINDOW,
+		       WINDOW__CHSTACK | WINDOW__ADDCHILD);
+	rval3 = IDPERM(client, xCreateWindowReq, wid,
+		       SECCLASS_DRAWABLE, DRAWABLE__CREATE);
 	break;
     case X_DeleteProperty:
 	rval = IDPERM(client, xDeletePropertyReq, window,
@@ -728,9 +735,9 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     case X_DestroySubwindows:
 	rval = IDPERM(client, xResourceReq, id,
 		      SECCLASS_WINDOW,
-		      WINDOW__ENUMERATE | WINDOW__UNMAP | WINDOW__DESTROY)
-	    && IDPERM(client, xResourceReq, id,
-		      SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
+		      WINDOW__ENUMERATE | WINDOW__UNMAP | WINDOW__DESTROY);
+	rval2 = IDPERM(client, xResourceReq, id,
+		       SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
 	break;
     case X_GetMotionEvents:
 	rval = IDPERM(client, xGetMotionEventsReq, window,
@@ -768,26 +775,26 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
     case X_ReparentWindow:
 	rval = IDPERM(client, xReparentWindowReq, window,
-		      SECCLASS_WINDOW, WINDOW__CHPARENT | WINDOW__MOVE)
-	    && IDPERM(client, xReparentWindowReq, parent,
-		      SECCLASS_WINDOW, WINDOW__CHSTACK | WINDOW__ADDCHILD);
+		      SECCLASS_WINDOW, WINDOW__CHPARENT | WINDOW__MOVE);
+	rval2 = IDPERM(client, xReparentWindowReq, parent,
+		       SECCLASS_WINDOW, WINDOW__CHSTACK | WINDOW__ADDCHILD);
 	break;
     case X_SendEvent:
 	rval = CheckSendEventPerms(client);
 	break;
     case X_SetInputFocus:
 	rval = IDPERM(client, xSetInputFocusReq, focus,
-		      SECCLASS_WINDOW, WINDOW__SETFOCUS)
-	    && ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETFOCUS);
+		      SECCLASS_WINDOW, WINDOW__SETFOCUS);
+	rval2 = ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETFOCUS);
 	break;
     case X_SetSelectionOwner:
 	rval = CheckSetSelectionOwnerPerms(client);
 	break;
     case X_TranslateCoords:
 	rval = IDPERM(client, xTranslateCoordsReq, srcWid,
-		      SECCLASS_WINDOW, WINDOW__GETATTR)
-	    && IDPERM(client, xTranslateCoordsReq, dstWid,
 		      SECCLASS_WINDOW, WINDOW__GETATTR);
+	rval2 = IDPERM(client, xTranslateCoordsReq, dstWid,
+		       SECCLASS_WINDOW, WINDOW__GETATTR);
 	break;
     case X_UnmapWindow:
     case X_UnmapSubwindows:
@@ -798,10 +805,10 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
     case X_WarpPointer:
 	rval = IDPERM(client, xWarpPointerReq, srcWid,
-		      SECCLASS_WINDOW, WINDOW__GETATTR)
-	    && IDPERM(client, xWarpPointerReq, dstWid,
-		      SECCLASS_WINDOW, WINDOW__GETATTR)
-	    && ServerPerm(client, SECCLASS_XINPUT, XINPUT__WARPPOINTER);
+		      SECCLASS_WINDOW, WINDOW__GETATTR);
+	rval2 = IDPERM(client, xWarpPointerReq, dstWid,
+		       SECCLASS_WINDOW, WINDOW__GETATTR);
+	rval3 = ServerPerm(client, SECCLASS_XINPUT, XINPUT__WARPPOINTER);
 	break;
 
     /* Input class control requirements */
@@ -852,16 +859,16 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
     case X_CopyColormapAndFree:
 	rval = IDPERM(client, xCopyColormapAndFreeReq, mid,
-		      SECCLASS_COLORMAP, COLORMAP__CREATE)
-	    && IDPERM(client, xCopyColormapAndFreeReq, srcCmap,
-		      SECCLASS_COLORMAP,
-		      COLORMAP__READ | COLORMAP__FREE);
+		      SECCLASS_COLORMAP, COLORMAP__CREATE);
+	rval2 = IDPERM(client, xCopyColormapAndFreeReq, srcCmap,
+		       SECCLASS_COLORMAP,
+		       COLORMAP__READ | COLORMAP__FREE);
 	break;
     case X_CreateColormap:
 	rval = IDPERM(client, xCreateColormapReq, mid,
-		      SECCLASS_COLORMAP, COLORMAP__CREATE)
-	    && IDPERM(client, xCreateColormapReq, window,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+		      SECCLASS_COLORMAP, COLORMAP__CREATE);
+	rval2 = IDPERM(client, xCreateColormapReq, window,
+		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
 	break;
     case X_FreeColormap:
 	rval = IDPERM(client, xResourceReq, id,
@@ -873,8 +880,8 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
     case X_InstallColormap:
 	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__INSTALL)
-	    && ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__INSTALL);
+		      SECCLASS_COLORMAP, COLORMAP__INSTALL);
+	rval2 = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__INSTALL);
 	break;
     case X_ListInstalledColormaps:
 	rval = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__LIST);
@@ -891,8 +898,8 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
     case X_UninstallColormap:
 	rval = IDPERM(client, xResourceReq, id,
-		      SECCLASS_COLORMAP, COLORMAP__UNINSTALL)
-	    && ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
+		      SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
+	rval2 = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
 	break;
 
     /* Font class control requirements */
@@ -907,18 +914,18 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
 	break;
     case X_OpenFont:
-	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD)
-	    && IDPERM(client, xOpenFontReq, fid,
-		      SECCLASS_FONT, FONT__USE);
+	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD);
+	rval2 = IDPERM(client, xOpenFontReq, fid,
+		       SECCLASS_FONT, FONT__USE);
 	break;
     case X_PolyText8:
     case X_PolyText16:
 	/* Font accesses checked through the resource manager */
-	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD)
-	    && IDPERM(client, xPolyTextReq, gc,
-		      SECCLASS_GC, GC__SETATTR)
-	    && IDPERM(client, xPolyTextReq, drawable,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD);
+	rval2 = IDPERM(client, xPolyTextReq, gc,
+		       SECCLASS_GC, GC__SETATTR);
+	rval3 = IDPERM(client, xPolyTextReq, drawable,
+		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
 	break;
 
     /* Pixmap class control requirements */
@@ -934,19 +941,19 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     /* Cursor class control requirements */
     case X_CreateCursor:
 	rval = IDPERM(client, xCreateCursorReq, cid,
-		      SECCLASS_CURSOR, CURSOR__CREATE)
-	    && IDPERM(client, xCreateCursorReq, source,
-		      SECCLASS_DRAWABLE, DRAWABLE__DRAW)
-	    && IDPERM(client, xCreateCursorReq, mask,
-		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
+		      SECCLASS_CURSOR, CURSOR__CREATE);
+	rval2 = IDPERM(client, xCreateCursorReq, source,
+		       SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	rval3 = IDPERM(client, xCreateCursorReq, mask,
+		       SECCLASS_DRAWABLE, DRAWABLE__COPY);
 	break;
     case X_CreateGlyphCursor:
 	rval = IDPERM(client, xCreateGlyphCursorReq, cid,
-		      SECCLASS_CURSOR, CURSOR__CREATEGLYPH)
-	    && IDPERM(client, xCreateGlyphCursorReq, source,
-		      SECCLASS_FONT, FONT__USE)
-	    && IDPERM(client, xCreateGlyphCursorReq, mask,
-		      SECCLASS_FONT, FONT__USE);
+		      SECCLASS_CURSOR, CURSOR__CREATEGLYPH);
+	rval2 = IDPERM(client, xCreateGlyphCursorReq, source,
+		       SECCLASS_FONT, FONT__USE);
+	rval3 = IDPERM(client, xCreateGlyphCursorReq, mask,
+		       SECCLASS_FONT, FONT__USE);
 	break;
     case X_RecolorCursor:
 	rval = IDPERM(client, xRecolorCursorReq, cursor,
@@ -970,9 +977,9 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
     case X_CopyGC:
 	rval = IDPERM(client, xCopyGCReq, srcGC,
-		      SECCLASS_GC, GC__GETATTR)
-	    && IDPERM(client, xCopyGCReq, dstGC,
-		      SECCLASS_GC, GC__SETATTR);
+		      SECCLASS_GC, GC__GETATTR);
+	rval2 = IDPERM(client, xCopyGCReq, dstGC,
+		       SECCLASS_GC, GC__SETATTR);
 	break;
     case X_FreeGC:
 	rval = IDPERM(client, xResourceReq, id,
@@ -1009,11 +1016,14 @@ XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	break;
 
     default:
-	rval = TRUE;
 	break;
     }
-    if (!rval)
-	rec->rval = FALSE;
+    if (rval != Success)
+	rec->status = rval;
+    if (rval2 != Success)
+	rec->status = rval2;
+    if (rval != Success)
+	rec->status = rval3;
 }
 
 static void
@@ -1050,9 +1060,10 @@ XSELinuxExtDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (avc_has_perm(SID(client), extsid, SECCLASS_XEXTENSION,
 			 perm, &AEREF(client), &auditdata) < 0)
 	{
-	    if (errno != EACCES)
-		ErrorF("ExtDispatch: unexpected error %d\n", errno);
-	    rec->rval = FALSE;
+	    if (errno == EACCES)
+		rec->status = BadAccess;
+	    ErrorF("ExtDispatch: unexpected error %d\n", errno);
+	    rec->status = BadValue;
 	}
     } else
 	ErrorF("No client state in extension dispatcher!\n");
@@ -1096,9 +1107,10 @@ XSELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	if (avc_has_perm(SID(client), propsid, SECCLASS_PROPERTY,
 			 perm, &AEREF(client), &auditdata) < 0)
 	{
-	    if (errno != EACCES)
-		ErrorF("Property: unexpected error %d\n", errno);
-	    rec->rval = XaceIgnoreOperation;
+	    if (errno == EACCES)
+		rec->status = BadAccess;
+	    ErrorF("Property: unexpected error %d\n", errno);
+	    rec->status = BadValue;
 	}
     } else
 	ErrorF("No client state in property callback!\n");
@@ -1114,7 +1126,7 @@ XSELinuxResLookup(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     ClientPtr client = rec->client;
     REQUEST(xReq);
     access_vector_t perm = 0;
-    Bool rval = TRUE;
+    int rval = Success;
 
     /* serverClient requests OK */
     if (client->index == 0)
@@ -1145,35 +1157,35 @@ XSELinuxResLookup(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	default:
 	    break;
     }
-    if (!rval)
-	rec->rval = FALSE;
+    if (rval != Success)
+	rec->status = rval;
 } /* XSELinuxResLookup */
 
 static void
 XSELinuxMap(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
-    if (!IDPerm(rec->client, rec->pWin->drawable.id,
-		SECCLASS_WINDOW, WINDOW__MAP))
-	rec->rval = FALSE;
+    if (IDPerm(rec->client, rec->pWin->drawable.id,
+               SECCLASS_WINDOW, WINDOW__MAP) != Success)
+	rec->status = BadAccess;
 } /* XSELinuxMap */
 
 static void
 XSELinuxBackgrnd(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
-    if (!IDPerm(rec->client, rec->pWin->drawable.id,
-		SECCLASS_WINDOW, WINDOW__TRANSPARENT))
-	rec->rval = FALSE;
+    if (IDPerm(rec->client, rec->pWin->drawable.id,
+               SECCLASS_WINDOW, WINDOW__TRANSPARENT) != Success)
+	rec->status = BadAccess;
 } /* XSELinuxBackgrnd */
 
 static void
 XSELinuxDrawable(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
-    if (!IDPerm(rec->client, rec->pDraw->id,
-		SECCLASS_DRAWABLE, DRAWABLE__COPY))
-	rec->rval = FALSE;
+    if (IDPerm(rec->client, rec->pDraw->id,
+               SECCLASS_DRAWABLE, DRAWABLE__COPY) != Success)
+	rec->status = BadAccess;
 } /* XSELinuxDrawable */
 
 static void
@@ -1183,8 +1195,8 @@ XSELinuxHostlist(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     access_vector_t perm = (rec->access_mode == DixReadAccess) ?
 	XSERVER__GETHOSTLIST : XSERVER__SETHOSTLIST;
 
-    if (!ServerPerm(rec->client, SECCLASS_XSERVER, perm))
-	rec->rval = FALSE;
+    if (ServerPerm(rec->client, SECCLASS_XSERVER, perm) != Success)
+	rec->status = BadAccess;
 } /* XSELinuxHostlist */
 
 /* Extension callbacks */
diff --git a/dix/devices.c b/dix/devices.c
index 1ce6be6..5ffa81d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1206,7 +1206,7 @@ DoSetModifierMapping(ClientPtr client, KeyCode *inputMap,
                 }
             }
 
-            if (!XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE))
+            if (XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE) != Success)
                 return BadAccess;
 
             /* None of the modifiers (old or new) may be down while we change
@@ -1330,7 +1330,7 @@ ProcChangeKeyboardMapping(ClientPtr client)
 
     for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
         if ((pDev->coreEvents || pDev == inputInfo.keyboard) && pDev->key) {
-            if (!XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE))
+            if (XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE) != Success)
                 return BadAccess;
         }
     }
@@ -1682,7 +1682,7 @@ ProcChangeKeyboardControl (ClientPtr client)
     for (pDev = inputInfo.devices; pDev; pDev = pDev->next) {
         if ((pDev->coreEvents || pDev == inputInfo.keyboard) &&
             pDev->kbdfeed && pDev->kbdfeed->CtrlProc) {
-            if (!XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE))
+            if (XaceHook(XACE_DEVICE_ACCESS, client, pDev, TRUE) != Success)
                 return BadAccess;
         }
     }
@@ -1944,10 +1944,10 @@ ProcQueryKeymap(ClientPtr client)
     rep.length = 2;
 
     if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
+	bzero((char *)&rep.map[0], 32);
+    else
 	for (i = 0; i<32; i++)
 	    rep.map[i] = down[i];
-    else
-	bzero((char *)&rep.map[0], 32);
 
     WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
     return Success;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 0a86dc5..4519d85 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1120,7 +1120,7 @@ ProcGetSelectionOwner(ClientPtr client)
 	reply.sequenceNumber = client->sequence;
         if (i < NumCurrentSelections &&
 	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
-		     DixReadAccess))
+		     DixReadAccess) == Success)
             reply.owner = CurrentSelections[i].destwindow;
         else
             reply.owner = None;
@@ -1161,7 +1161,7 @@ ProcConvertSelection(ClientPtr client)
 	if ((i < NumCurrentSelections) &&
 	    (CurrentSelections[i].window != None) &&
 	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
-		     DixReadAccess))
+		     DixReadAccess) == Success)
 	{        
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
@@ -2276,7 +2276,7 @@ DoGetImage(ClientPtr client, int format, Drawable drawable,
     }
 
     if (pDraw->type == DRAWABLE_WINDOW &&
-	!XaceHook(XACE_DRAWABLE_ACCESS, client, pDraw))
+	XaceHook(XACE_DRAWABLE_ACCESS, client, pDraw) != Success)
     {
 	pVisibleRegion = NotClippedByChildren((WindowPtr)pDraw);
 	if (pVisibleRegion)
@@ -3343,8 +3343,9 @@ ProcListHosts(ClientPtr client)
     REQUEST_SIZE_MATCH(xListHostsReq);
 
     /* untrusted clients can't list hosts */
-    if (!XaceHook(XACE_HOSTLIST_ACCESS, client, DixReadAccess))
-	return BadAccess;
+    result = XaceHook(XACE_HOSTLIST_ACCESS, client, DixReadAccess);
+    if (result != Success)
+	return result;
 
     result = GetHosts(&pdata, &nHosts, &len, &reply.enabled);
     if (result != Success)
diff --git a/dix/dixutils.c b/dix/dixutils.c
index e97a791..4d082cd 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -209,6 +209,8 @@ dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
 {
     DrawablePtr pTmp;
     RESTYPE rtype;
+    int rc;
+
     *pDraw = NULL;
     client->errorValue = id;
 
@@ -220,8 +222,9 @@ dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
 
 	/* an access check is required for cached drawables */
 	rtype = (type & M_WINDOW) ? RT_WINDOW : RT_PIXMAP;
-	if (!XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, access, pTmp))
-	    return BadDrawable;
+	rc = XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, access, pTmp);
+        if (rc != Success)
+	    return rc;
     } else
 	dixLookupResource((void **)&pTmp, id, RC_DRAWABLE, client, access);
 
diff --git a/dix/events.c b/dix/events.c
index bc6b6ae..88895b5 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2682,7 +2682,7 @@ CheckPassiveGrabsOnWindow(
 	     (grab->confineTo->realized && 
 				BorderSizeNotEmpty(grab->confineTo))))
 	{
-	    if (!XaceHook(XACE_DEVICE_ACCESS, wClient(pWin), device, FALSE))
+	    if (XaceHook(XACE_DEVICE_ACCESS, wClient(pWin), device, FALSE))
 		return FALSE;
 #ifdef XKB
 	    if (!noXkbExtension) {
@@ -3529,7 +3529,7 @@ EnterLeaveEvent(
 	xKeymapEvent ke;
 	ClientPtr client = grab ? rClient(grab)
 				: clients[CLIENT_ID(pWin->drawable.id)];
-	if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, FALSE))
+	if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, FALSE) == Success)
 	    memmove((char *)&ke.map[0], (char *)&keybd->key->down[1], 31);
 	else
 	    bzero((char *)&ke.map[0], 31);
@@ -3636,7 +3636,7 @@ FocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
     {
 	xKeymapEvent ke;
 	ClientPtr client = clients[CLIENT_ID(pWin->drawable.id)];
-	if (XaceHook(XACE_DEVICE_ACCESS, client, dev, FALSE))
+	if (XaceHook(XACE_DEVICE_ACCESS, client, dev, FALSE) == Success)
 	    memmove((char *)&ke.map[0], (char *)&dev->key->down[1], 31);
 	else
 	    bzero((char *)&ke.map[0], 31);
@@ -3924,7 +3924,7 @@ ProcSetInputFocus(client)
 
     REQUEST_SIZE_MATCH(xSetInputFocusReq);
 
-    if (!XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
+    if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
 	return Success;
 
     return SetInputFocus(client, inputInfo.keyboard, stuff->focus,
@@ -4239,15 +4239,14 @@ ProcGrabKeyboard(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xGrabKeyboardReq);
 
-    if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE))
-	result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode,
+    if (XaceHook(XACE_DEVICE_ACCESS, client, inputInfo.keyboard, TRUE)) {
+	result = Success;
+	rep.status = AlreadyGrabbed;
+    } else
+        result = GrabDevice(client, inputInfo.keyboard, stuff->keyboardMode,
 			    stuff->pointerMode, stuff->grabWindow,
 			    stuff->ownerEvents, stuff->time,
 			    KeyPressMask | KeyReleaseMask, &rep.status);
-    else {
-	result = Success;
-	rep.status = AlreadyGrabbed;
-    }
 
     if (result != Success)
 	return result;
diff --git a/dix/extension.c b/dix/extension.c
index d409c3f..ad4e697 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -319,7 +319,7 @@ ProcQueryExtension(ClientPtr client)
     else
     {
 	i = FindExtension((char *)&stuff[1], stuff->nbytes);
-        if (i < 0 || !XaceHook(XACE_EXT_ACCESS, client, extensions[i]))
+        if (i < 0 || XaceHook(XACE_EXT_ACCESS, client, extensions[i]))
             reply.present = xFalse;
         else
         {            
@@ -355,7 +355,7 @@ ProcListExtensions(ClientPtr client)
         for (i=0;  i<NumExtensions; i++)
 	{
 	    /* call callbacks to find out whether to show extension */
-	    if (!XaceHook(XACE_EXT_ACCESS, client, extensions[i]))
+	    if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success)
 		continue;
 
 	    total_length += strlen(extensions[i]->name) + 1;
@@ -370,7 +370,7 @@ ProcListExtensions(ClientPtr client)
         for (i=0;  i<NumExtensions; i++)
         {
 	    int len;
-	    if (!XaceHook(XACE_EXT_ACCESS, client, extensions[i]))
+	    if (XaceHook(XACE_EXT_ACCESS, client, extensions[i]) != Success)
 		continue;
 
             *bufptr++ = len = strlen(extensions[i]->name);
diff --git a/dix/property.c b/dix/property.c
index 8deb621..09f9e31 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -144,16 +144,12 @@ ProcRotateProperties(ClientPtr client)
 	    DEALLOCATE_LOCAL(props);
 	    return BadMatch;
 	}
-	switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
-			 DixReadAccess|DixWriteAccess))
-	{
-	case XaceErrorOperation:
+	rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
+		      DixReadAccess|DixWriteAccess);
+	if (rc != Success) {
             DEALLOCATE_LOCAL(props);
 	    client->errorValue = atoms[i];
-            return BadAtom;
-	case XaceIgnoreOperation:
-            DEALLOCATE_LOCAL(props);
-	    return Success;
+            return (rc == XaceIgnoreError) ? Success : rc;
 	}
         props[i] = pProp;
     }
@@ -246,8 +242,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 {
     PropertyPtr pProp;
     xEvent event;
-    int sizeInBytes;
-    int totalSize;
+    int sizeInBytes, totalSize, rc;
     pointer data;
 
     sizeInBytes = format>>3;
@@ -277,32 +272,24 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 	    memmove((char *)data, (char *)value, totalSize);
 	pProp->size = len;
 	pProp->devPrivates = NULL;
-	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
-			 DixCreateAccess))
-	{
-	case XaceErrorOperation:
+	rc = XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
+		      DixCreateAccess);
+	if (rc != Success) {
 	    xfree(data);
 	    xfree(pProp);
 	    pClient->errorValue = property;
-	    return BadAtom;
-	case XaceIgnoreOperation:
-	    xfree(data);
-	    xfree(pProp);
-	    return Success;
+	    return (rc == XaceIgnoreError) ? Success : rc;
 	}
         pProp->next = pWin->optional->userProps;
         pWin->optional->userProps = pProp;
     }
     else
     {
-	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
-			 DixWriteAccess))
-	{
-	case XaceErrorOperation:
+	rc = XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
+		      DixWriteAccess);
+	if (rc != Success) {
 	    pClient->errorValue = property;
-	    return BadAtom;
-	case XaceIgnoreOperation:
-	    return Success;
+	    return (rc == XaceIgnoreError) ? Success : rc;
 	}
 	/* To append or prepend to a property the request format and type
 		must match those of the already defined property.  The
@@ -471,7 +458,8 @@ int
 ProcGetProperty(ClientPtr client)
 {
     PropertyPtr pProp, prevProp;
-    unsigned long n, len, ind, rc;
+    unsigned long n, len, ind;
+    int rc;
     WindowPtr pWin;
     xGetPropertyReply reply;
     Mask access_mode = DixReadAccess;
@@ -517,13 +505,12 @@ ProcGetProperty(ClientPtr client)
 
     if (stuff->delete)
 	access_mode |= DixDestroyAccess;
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, access_mode))
-    {
-    case XaceErrorOperation:
+
+    rc = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, access_mode);
+    if (rc != Success) {
 	client->errorValue = stuff->property;
-	return BadAtom;;
-    case XaceIgnoreOperation:
-	return NullPropertyReply(client, pProp->type, pProp->format, &reply);
+	return (rc == XaceIgnoreError) ? 
+	    NullPropertyReply(client, pProp->type, pProp->format, &reply) : rc;
     }
 
     /* If the request type and actual type don't match. Return the
@@ -669,14 +656,11 @@ ProcDeleteProperty(ClientPtr client)
 	return (BadAtom);
     }
 
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
-		     FindProperty(pWin, stuff->property), DixDestroyAccess))
-    {
-    case XaceErrorOperation:
+    result = XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
+		      FindProperty(pWin, stuff->property), DixDestroyAccess);
+    if (result != Success) {
 	client->errorValue = stuff->property;
-	return BadAtom;;
-    case XaceIgnoreOperation:
-	return Success;
+	return (result == XaceIgnoreError) ? Success : result;
     }
 
     result = DeleteProperty(pWin, stuff->property);
diff --git a/dix/resource.c b/dix/resource.c
index e1bb74f..67124c7 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -918,12 +918,16 @@ dixLookupResource(pointer *result, XID id, RESTYPE rtype,
 				    (!istype && res->type & rtype)))
 		break;
     }
-    if (res) {
-	if (client && !XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type,
-				mode, res->value))
-	    return BadAccess;
-	*result = res->value;
-	return Success;
+    if (!res)
+	return BadValue;
+
+    if (client) {
+	cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type,
+		       mode, res->value);
+	if (cid != Success)
+	    return cid;
     }
-    return BadValue;
+
+    *result = res->value;
+    return Success;
 }
diff --git a/dix/window.c b/dix/window.c
index b505947..95b7b16 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -732,17 +732,16 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 
     /*  security creation/labeling check
      */
-    if (!XaceHook(XACE_RESOURCE_ACCESS, client,
-		  wid, RT_WINDOW, DixCreateAccess, pWin))
-    {
+    *error = XaceHook(XACE_RESOURCE_ACCESS, client, wid, RT_WINDOW,
+		      DixCreateAccess, pWin);
+    if (*error != Success) {
 	xfree(pWin);
-	*error = BadAccess;
 	return NullWindow;
     }
     /*  can't let untrusted clients have background None windows;
      *  they make it too easy to steal window contents
      */
-    if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin))
+    if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin) == Success)
 	pWin->backgroundState = None;
     else {
 	pWin->backgroundState = BackgroundPixel;
@@ -1052,7 +1051,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 	    if (pixID == None)
 	    {
 		/*  can't let untrusted clients have background None windows */
-		if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin)) {
+		if (XaceHook(XACE_BACKGRND_ACCESS, client, pWin) == Success) {
 		    if (pWin->backgroundState == BackgroundPixmap)
 			(*pScreen->DestroyPixmap)(pWin->background.pixmap);
 		    if (!pWin->parent)
@@ -2773,7 +2772,7 @@ MapWindow(WindowPtr pWin, ClientPtr client)
 	return(Success);
 
     /*  general check for permission to map window */
-    if (!XaceHook(XACE_MAP_ACCESS, client, pWin))
+    if (XaceHook(XACE_MAP_ACCESS, client, pWin) != Success)
 	 return Success;
 
     pScreen = pWin->drawable.pScreen;
diff --git a/os/access.c b/os/access.c
index 221b8cb..d9fcd44 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1528,7 +1528,7 @@ AuthorizedClient(ClientPtr client)
 	return TRUE;
 
     /* untrusted clients can't change host access */
-    if (!XaceHook(XACE_HOSTLIST_ACCESS, client, DixWriteAccess))
+    if (XaceHook(XACE_HOSTLIST_ACCESS, client, DixWriteAccess) != Success)
 	return FALSE;
 
     return LocalClient(client);
commit 47bd311e3dcc501cbb202ce79a55ac32e9db50f2
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Apr 17 13:46:55 2007 -0400

    security: remove debugging code.

diff --git a/Xext/security.c b/Xext/security.c
index ad04045..12e79f9 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1281,9 +1281,6 @@ static char *SecurityKeywords[] = {
 
 #define NUMKEYWORDS (sizeof(SecurityKeywords) / sizeof(char *))
 
-#undef PROPDEBUG
-/*#define PROPDEBUG  1*/
-
 static void
 SecurityFreePropertyAccessList(void)
 {
@@ -1638,32 +1635,6 @@ SecurityLoadPropertyAccessList(void)
 		   lineNumber, SecurityPolicyFile);
     } /* end while more input */
 
-#ifdef PROPDEBUG
-    {
-	PropertyAccessPtr pacl;
-	char *op = "aie";
-	for (pacl = PropertyAccessList; pacl; pacl = pacl->next)
-	{
-	    ErrorF("property %s ", NameForAtom(pacl->name));
-	    switch (pacl->windowRestriction)
-	    {
-		case SecurityAnyWindow: ErrorF("any "); break;
-		case SecurityRootWindow: ErrorF("root "); break;
-		case SecurityWindowWithProperty:
-		{
-		    ErrorF("%s ", NameForAtom(pacl->mustHaveProperty));
-		    if (pacl->mustHaveValue)
-			ErrorF(" = \"%s\" ", pacl->mustHaveValue);
-
-		}
-		break;
-	    }
-	    ErrorF("%cr %cw %cd\n", op[pacl->readAction],
-		   op[pacl->writeAction], op[pacl->destroyAction]);
-	}
-    }
-#endif /* PROPDEBUG */
-
     fclose(f);
 } /* SecurityLoadPropertyAccessList */
 
@@ -1696,11 +1667,6 @@ SecurityMatchString(
 	     && (*cs == '\0') );
 } /* SecurityMatchString */
 
-#ifdef PROPDEBUG
-#include <sys/types.h>
-#include <sys/stat.h>
-#endif
-
 
 static void
 SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
@@ -1720,25 +1686,6 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
 	 (TRUSTLEVEL(wClient(pWin)) != XSecurityClientTrusted) )
 	return;
 
-#ifdef PROPDEBUG
-    /* For testing, it's more convenient if the property rules file gets
-     * reloaded whenever it changes, so we can rapidly try things without
-     * having to reset the server.
-     */
-    {
-	struct stat buf;
-	static time_t lastmod = 0;
-	int ret = stat(SecurityPolicyFile , &buf);
-	if ( (ret == 0) && (buf.st_mtime > lastmod) )
-	{
-	    ErrorF("reloading property rules\n");
-	    SecurityFreePropertyAccessList();
-	    SecurityLoadPropertyAccessList();
-	    lastmod = buf.st_mtime;
-	}
-    }
-#endif
-
     /* If the property atom is bigger than any atoms on the list, 
      * we know we won't find it, so don't even bother looking.
      */
commit 1f06d32ef58749d0f0c062193d237ee98f60e90f
Merge: cf962a8... fc162c6...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Apr 17 12:10:22 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	dix/privates.c

diff --cc dix/privates.c
index 4cb2e35,2465971..f2f1c49
--- a/dix/privates.c
+++ b/dix/privates.c
@@@ -292,17 -59,15 +292,17 @@@ int extensionPrivateLen
  unsigned *extensionPrivateSizes;
  unsigned totalExtensionSize;
  
 -void
 +static int
- ResetExtensionPrivates()
+ ResetExtensionPrivates(void)
  {
 -    extensionPrivateCount = 0;
 -    extensionPrivateLen = 0;
 +    extensionPrivateCount = 1;
 +    extensionPrivateLen = 1;
      xfree(extensionPrivateSizes);
 -    extensionPrivateSizes = (unsigned *)NULL;
 -    totalExtensionSize =
 -	((sizeof(ExtensionEntry) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
 +    extensionPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
 +    if (!extensionPrivateSizes)
 +	return FALSE;
 +    totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
 +    return TRUE;
  }
  
  _X_EXPORT int
@@@ -351,17 -116,15 +351,17 @@@ int clientPrivateLen
  unsigned *clientPrivateSizes;
  unsigned totalClientSize;
  
 -void
 +static int
- ResetClientPrivates()
+ ResetClientPrivates(void)
  {
 -    clientPrivateCount = 0;
 -    clientPrivateLen = 0;
 +    clientPrivateCount = 1;
 +    clientPrivateLen = 1;
      xfree(clientPrivateSizes);
 -    clientPrivateSizes = (unsigned *)NULL;
 -    totalClientSize =
 -	((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
 +    clientPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
 +    if (!clientPrivateSizes)
 +	return FALSE;
 +    totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
 +    return TRUE;
  }
  
  _X_EXPORT int
@@@ -407,10 -170,10 +407,10 @@@ AllocateClientPrivate(int index2, unsig
  
  int  screenPrivateCount;
  
 -void
 +static void
- ResetScreenPrivates()
+ ResetScreenPrivates(void)
  {
 -    screenPrivateCount = 0;
 +    screenPrivateCount = 1;
  }
  
  /* this can be called after some screens have been created,
@@@ -449,10 -212,10 +449,10 @@@ AllocateScreenPrivateIndex(void
  
  static int  windowPrivateCount;
  
 -void
 +static void
- ResetWindowPrivates()
+ ResetWindowPrivates(void)
  {
 -    windowPrivateCount = 0;
 +    windowPrivateCount = 1;
  }
  
  _X_EXPORT int
@@@ -499,10 -262,10 +499,10 @@@ AllocateWindowPrivate(ScreenPtr pScreen
  
  static int  gcPrivateCount;
  
 -void
 +static void
- ResetGCPrivates()
+ ResetGCPrivates(void)
  {
 -    gcPrivateCount = 0;
 +    gcPrivateCount = 1;
  }
  
  _X_EXPORT int
@@@ -548,10 -311,10 +548,10 @@@ AllocateGCPrivate(ScreenPtr pScreen, in
   */
  static int  pixmapPrivateCount;
  
 -void
 +static void
- ResetPixmapPrivates()
+ ResetPixmapPrivates(void)
  {
 -    pixmapPrivateCount = 0;
 +    pixmapPrivateCount = 1;
  }
  
  _X_EXPORT int
@@@ -599,10 -362,10 +599,10 @@@ AllocatePixmapPrivate(ScreenPtr pScreen
  
  int  colormapPrivateCount;
  
 -void
 +static void
- ResetColormapPrivates()
+ ResetColormapPrivates(void)
  {
 -    colormapPrivateCount = 0;
 +    colormapPrivateCount = 1;
  }
  
  
commit cf962a849db2b259ca558c6265ea7e3328a4d312
Merge: 5ad5625... 5a804f2...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Apr 5 14:41:39 2007 -0400

    Merge branch 'master' into XACE-SELINUX
    
    Conflicts:
    
    	configure.ac

diff --cc configure.ac
index cdbf234,cb8b435..270c3a5
--- a/configure.ac
+++ b/configure.ac
@@@ -514,8 -520,7 +520,8 @@@ AC_ARG_ENABLE(dri,            AS_HELP_S
  AC_ARG_ENABLE(xinerama,	      AS_HELP_STRING([--disable-xinerama], [Build Xinerama extension (default: enabled)]), [XINERAMA=$enableval], [XINERAMA=yes])
  AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: auto)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=auto])
  AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: auto)]), [XF86MISC=$enableval], [XF86MISC=auto])
- AC_ARG_ENABLE(xace,     AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
- AC_ARG_ENABLE(xselinux,     AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: enabled)]), [XSELINUX=$enableval], [XSELINUX=$XACE])
+ AC_ARG_ENABLE(xace,           AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
++AC_ARG_ENABLE(xselinux,       AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: enabled)]), [XSELINUX=$enableval], [XSELINUX=$XACE])
  AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (default: enabled)]), [XCSECURITY=$enableval], [XCSECURITY=$XACE])
  AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
  AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
commit 5ad562565ac8ef9257da3afb0de1ae4f90f80fe9
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Apr 5 14:18:05 2007 -0400

    devPrivates rework: properly free devPrivates on compatibility structures,
    type pixmap.  Requires ddx'es to call the free function from DestroyPixmap.

diff --git a/afb/afb.h b/afb/afb.h
index 5aa2b0c..b3ed1ee 100644
--- a/afb/afb.h
+++ b/afb/afb.h
@@ -55,6 +55,7 @@ SOFTWARE.
 #include "gc.h"
 #include "colormap.h"
 #include "regionstr.h"
+#include "privates.h"
 #include "mibstore.h"
 #include "mfb.h"
 
diff --git a/afb/afbpixmap.c b/afb/afbpixmap.c
index 77ba535..5a81679 100644
--- a/afb/afbpixmap.c
+++ b/afb/afbpixmap.c
@@ -113,6 +113,7 @@ afbDestroyPixmap(pPixmap)
 {
 	if(--pPixmap->refcnt)
 		return(TRUE);
+	dixFreePrivates(*DEVPRIV_PTR(pPixmap));
 	xfree(pPixmap);
 	return(TRUE);
 }
diff --git a/cfb/cfb.h b/cfb/cfb.h
index 8c682ae..15332ff 100644
--- a/cfb/cfb.h
+++ b/cfb/cfb.h
@@ -37,6 +37,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "colormap.h"
 #include "miscstruct.h"
 #include "servermd.h"
+#include "privates.h"
 #include "windowstr.h"
 #include "mfb.h"
 #undef PixelType
diff --git a/cfb/cfbpixmap.c b/cfb/cfbpixmap.c
index 6fdf3ea..ed01316 100644
--- a/cfb/cfbpixmap.c
+++ b/cfb/cfbpixmap.c
@@ -107,6 +107,7 @@ cfbDestroyPixmap(pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
+    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
     xfree(pPixmap);
     return TRUE;
 }
diff --git a/fb/fb.h b/fb/fb.h
index e605078..9e88667 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -38,6 +38,7 @@
 #include "mi.h"
 #include "migc.h"
 #include "mibstore.h"
+#include "privates.h"
 #ifdef RENDER
 #include "picturestr.h"
 #else
diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index 18c1204..8c3216a 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -98,6 +98,7 @@ fbDestroyPixmap (PixmapPtr pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
+    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
     xfree(pPixmap);
     return TRUE;
 }
diff --git a/hw/dmx/dmxpixmap.c b/hw/dmx/dmxpixmap.c
index 9340606..e617134 100644
--- a/hw/dmx/dmxpixmap.c
+++ b/hw/dmx/dmxpixmap.c
@@ -45,6 +45,7 @@
 
 #include "pixmapstr.h"
 #include "servermd.h"
+#include "privates.h"
 
 /** Initialize a private area in \a pScreen for pixmap information. */
 Bool dmxInitPixmap(ScreenPtr pScreen)
@@ -173,6 +174,7 @@ Bool dmxDestroyPixmap(PixmapPtr pPixmap)
 	    dmxSync(dmxScreen, FALSE);
 	}
     }
+    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
     xfree(pPixmap);
 
 #if 0
diff --git a/hw/xgl/xglpixmap.c b/hw/xgl/xglpixmap.c
index 368c3ea..166c33e 100644
--- a/hw/xgl/xglpixmap.c
+++ b/hw/xgl/xglpixmap.c
@@ -310,6 +310,7 @@ xglDestroyPixmap (PixmapPtr pPixmap)
 
     xglFiniPixmap (pPixmap);
 
+    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
     xfree (pPixmap);
 
     return TRUE;
diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c
index 612df8d..c4b8aa6 100644
--- a/hw/xnest/Pixmap.c
+++ b/hw/xnest/Pixmap.c
@@ -24,6 +24,7 @@ is" without express or implied warranty.
 #include "regionstr.h"
 #include "gc.h"
 #include "servermd.h"
+#include "privates.h"
 #include "mi.h"
 
 #include "Xnest.h"
@@ -74,6 +75,7 @@ xnestDestroyPixmap(PixmapPtr pPixmap)
   if(--pPixmap->refcnt)
     return TRUE;
   XFreePixmap(xnestDisplay, xnestPixmap(pPixmap));
+  dixFreePrivates(*DEVPRIV_PTR(pPixmap));
   xfree(pPixmap);
   return TRUE;
 }
diff --git a/hw/xprint/ps/PsPixmap.c b/hw/xprint/ps/PsPixmap.c
index c3259c9..220feab 100644
--- a/hw/xprint/ps/PsPixmap.c
+++ b/hw/xprint/ps/PsPixmap.c
@@ -79,6 +79,7 @@ in this Software without prior written authorization from The Open Group.
 
 #include "windowstr.h"
 #include "gcstruct.h"
+#include "privates.h"
 
 #include "Ps.h"
 
@@ -111,9 +112,13 @@ PsCreatePixmap(
   pPixmap->devKind               = 0;
   pPixmap->refcnt                = 1;
 
+  pPixmap->devPrivates = (DevUnion *)xcalloc(1, sizeof(DevUnion));
+  if( !pPixmap->devPrivates )
+    { xfree(pPixmap); return NullPixmap; }
+
   pPixmap->devPrivate.ptr = (PsPixmapPrivPtr)xcalloc(1, sizeof(PsPixmapPrivRec));
   if( !pPixmap->devPrivate.ptr )
-    { xfree(pPixmap); return NullPixmap; }
+    { xfree(pPixmap->devPrivates); xfree(pPixmap); return NullPixmap; }
   return pPixmap;
 }
 
@@ -196,6 +201,7 @@ PsDestroyPixmap(PixmapPtr pPixmap)
   PsScrubPixmap(pPixmap);
 
   xfree(priv);
+  dixFreePrivates(*DEVPRIV_PTR(pPixmap));
   xfree(pPixmap);
   return TRUE;
 }
diff --git a/mfb/mfb.h b/mfb/mfb.h
index f597b16..3cded7b 100644
--- a/mfb/mfb.h
+++ b/mfb/mfb.h
@@ -58,6 +58,7 @@ SOFTWARE.
 #include "region.h"
 #include "gc.h"
 #include "colormap.h"
+#include "privates.h"
 #include "miscstruct.h"
 #include "mibstore.h"
 
diff --git a/mfb/mfbpixmap.c b/mfb/mfbpixmap.c
index e349724..b13e3af 100644
--- a/mfb/mfbpixmap.c
+++ b/mfb/mfbpixmap.c
@@ -113,6 +113,7 @@ mfbDestroyPixmap(pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
+    dixFreePrivates(*DEVPRIV_PTR(pPixmap));
     xfree(pPixmap);
     return TRUE;
 }
commit 1d550bb2c5cb5b3e588f0e0b68a421dc1cb8bd7c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Apr 5 12:12:58 2007 -0400

    devPrivates rework: minor fix; use calloc and avoid initialization.

diff --git a/dix/devices.c b/dix/devices.c
index 4a7ec4d..ab64fcb 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -128,12 +128,11 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 #endif
     /* must pre-allocate one private for the new devPrivates support */
     dev->nPrivates = 1;
-    dev->devPrivates = (DevUnion *)xalloc(sizeof(DevUnion));
+    dev->devPrivates = (DevUnion *)xcalloc(1, sizeof(DevUnion));
     if (!dev->devPrivates) {
 	xfree(dev);
 	return NULL;
     }
-    dev->devPrivates[0].ptr = NULL;
 
     dev->unwrapProc = NULL;
     dev->coreEvents = TRUE;
diff --git a/dix/main.c b/dix/main.c
index b5db193..cae50c8 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -720,20 +720,17 @@ AddScreen(
 
     /* must pre-allocate one private for the new devPrivates support */
     pScreen->WindowPrivateLen = 1;
-    pScreen->WindowPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->WindowPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
     pScreen->totalWindowSize = PadToLong(sizeof(WindowRec)) + sizeof(DevUnion);
     pScreen->GCPrivateLen = 1;
-    pScreen->GCPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->GCPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
     pScreen->totalGCSize = PadToLong(sizeof(GC)) + sizeof(DevUnion);
     pScreen->PixmapPrivateLen = 1;
-    pScreen->PixmapPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->PixmapPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
     pScreen->totalPixmapSize = BitmapBytePad(8 * (sizeof(PixmapRec) +
 						  sizeof(DevUnion)));
-    if (pScreen->WindowPrivateSizes && pScreen->GCPrivateSizes &&
-	pScreen->PixmapPrivateSizes)
-	*pScreen->WindowPrivateSizes = *pScreen->GCPrivateSizes =
-	    *pScreen->PixmapPrivateSizes = 0;
-    else {
+    if (!pScreen->WindowPrivateSizes || !pScreen->GCPrivateSizes ||
+	!pScreen->PixmapPrivateSizes) {
 	xfree(pScreen);
 	return -1;
     }
diff --git a/dix/privates.c b/dix/privates.c
index 8a39437..4cb2e35 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -298,10 +298,9 @@ ResetExtensionPrivates()
     extensionPrivateCount = 1;
     extensionPrivateLen = 1;
     xfree(extensionPrivateSizes);
-    extensionPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    extensionPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
     if (!extensionPrivateSizes)
 	return FALSE;
-    *extensionPrivateSizes = 0;
     totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
     return TRUE;
 }
@@ -358,10 +357,9 @@ ResetClientPrivates()
     clientPrivateCount = 1;
     clientPrivateLen = 1;
     xfree(clientPrivateSizes);
-    clientPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    clientPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
     if (!clientPrivateSizes)
 	return FALSE;
-    *clientPrivateSizes = 0;
     totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
     return TRUE;
 }
commit ed75b056511ccb429c48c6c55d14dc7ae79e75a3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Apr 4 12:00:15 2007 -0400

    dix: add new, combined resource lookup function.  Move all dix lookup API
    deprecated so far to a new file dix/deprecated.c.  Remove the deprecation
    warnings for the time being.

diff --git a/dix/Makefile.am b/dix/Makefile.am
index a1f02c1..ff0d5d6 100644
--- a/dix/Makefile.am
+++ b/dix/Makefile.am
@@ -8,6 +8,7 @@ libdix_la_SOURCES = 	\
 	atom.c		\
 	colormap.c	\
 	cursor.c	\
+	deprecated.c	\
 	devices.c	\
 	dispatch.c	\
 	dispatch.h	\
diff --git a/dix/deprecated.c b/dix/deprecated.c
new file mode 100644
index 0000000..2bb8119
--- /dev/null
+++ b/dix/deprecated.c
@@ -0,0 +1,162 @@
+/***********************************************************
+
+Copyright 1987, 1998  The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.  
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "dix.h"
+#include "misc.h"
+#include "dixstruct.h"
+
+/*
+ * These are deprecated compatibility functions and will be marked as such
+ * and removed soon!
+ *
+ * Please use the noted replacements instead.
+ */
+
+/* replaced by dixLookupWindow */
+_X_EXPORT WindowPtr
+SecurityLookupWindow(XID id, ClientPtr client, Mask access_mode)
+{
+    WindowPtr pWin;
+    int i = dixLookupWindow(&pWin, id, client, access_mode);
+    static int warn = 1;
+    if (warn > 0 && --warn)
+	ErrorF("Warning: LookupWindow()/SecurityLookupWindow() "
+	       "are deprecated.  Please convert your driver/module "
+	       "to use dixLookupWindow().\n");
+    return (i == Success) ? pWin : NULL;
+}
+
+/* replaced by dixLookupWindow */
+_X_EXPORT WindowPtr
+LookupWindow(XID id, ClientPtr client)
+{
+    return SecurityLookupWindow(id, client, DixUnknownAccess);
+}
+
+/* replaced by dixLookupDrawable */
+_X_EXPORT pointer
+SecurityLookupDrawable(XID id, ClientPtr client, Mask access_mode)
+{
+    DrawablePtr pDraw;
+    int i = dixLookupDrawable(&pDraw, id, client, M_DRAWABLE, access_mode);
+    static int warn = 1;
+    if (warn > 0 && --warn)
+	ErrorF("Warning: LookupDrawable()/SecurityLookupDrawable() "
+	       "are deprecated.  Please convert your driver/module "
+	       "to use dixLookupDrawable().\n");
+    return (i == Success) ? pDraw : NULL;
+}
+
+/* replaced by dixLookupDrawable */
+_X_EXPORT pointer
+LookupDrawable(XID id, ClientPtr client)
+{
+    return SecurityLookupDrawable(id, client, DixUnknownAccess);
+}
+
+/* replaced by dixLookupClient */
+_X_EXPORT ClientPtr
+LookupClient(XID id, ClientPtr client)
+{
+    ClientPtr pClient;
+    int i = dixLookupClient(&pClient, id, client, DixUnknownAccess);
+    static int warn = 1;
+    if (warn > 0 && --warn)
+	ErrorF("Warning: LookupClient() is deprecated.  Please convert your "
+	       "driver/module to use dixLookupClient().\n");
+    return (i == Success) ? pClient : NULL;
+}
+
+/* replaced by dixLookupResource */
+_X_EXPORT pointer
+SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype,
+		       Mask access_mode)
+{
+    pointer retval;
+    int i = dixLookupResource(&retval, id, rtype, client, access_mode);
+    static int warn = 1;
+    if (warn > 0 && --warn)
+	ErrorF("Warning: LookupIDByType()/SecurityLookupIDByType() "
+	       "are deprecated.  Please convert your driver/module "
+	       "to use dixLookupResource().\n");
+    return (i == Success) ? retval : NULL;
+}
+
+/* replaced by dixLookupResource */
+_X_EXPORT pointer
+SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes,
+			Mask access_mode)
+{
+    pointer retval;
+    int i = dixLookupResource(&retval, id, classes, client, access_mode);
+    static int warn = 1;
+    if (warn > 0 && --warn)
+	ErrorF("Warning: LookupIDByClass()/SecurityLookupIDByClass() "
+	       "are deprecated.  Please convert your driver/module "
+	       "to use dixLookupResource().\n");
+    return (i == Success) ? retval : NULL;
+}
+
+/* replaced by dixLookupResource */
+_X_EXPORT pointer
+LookupIDByType(XID id, RESTYPE rtype)
+{
+    return SecurityLookupIDByType(NullClient, id, rtype, DixUnknownAccess);
+}
+
+/* replaced by dixLookupResource */
+_X_EXPORT pointer
+LookupIDByClass(XID id, RESTYPE classes)
+{
+    return SecurityLookupIDByClass(NullClient, id, classes, DixUnknownAccess);
+}
+
+/* end deprecated functions */
diff --git a/dix/dixutils.c b/dix/dixutils.c
index 44d82c9..94e0f2c 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -223,8 +223,8 @@ dixLookupDrawable(DrawablePtr *pDraw, XID id, ClientPtr client,
 	if (!XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, access, pTmp))
 	    return BadDrawable;
     } else
-	pTmp = (DrawablePtr)SecurityLookupIDByClass(client, id, RC_DRAWABLE,
-						   access);
+	dixLookupResource((void **)&pTmp, id, RC_DRAWABLE, client, access);
+
     if (!pTmp)
 	return BadDrawable;
     if (!((1 << pTmp->type) & (type ? type : M_DRAWABLE)))
@@ -264,11 +264,12 @@ dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access)
 _X_EXPORT int
 dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
 {
-    pointer pRes = (pointer)SecurityLookupIDByClass(client, rid, RC_ANY,
-						    DixReadAccess);
+    pointer pRes;
     int clientIndex = CLIENT_ID(rid);
     client->errorValue = rid;
 
+    dixLookupResource(&pRes, rid, RC_ANY, client, DixReadAccess);
+
     if (clientIndex && pRes && clients[clientIndex] && !(rid & SERVER_BIT)) {
 	*pClient = clients[clientIndex];
 	return Success;
@@ -277,62 +278,6 @@ dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access)
     return BadValue;
 }
 
-/*
- * These are deprecated compatibility functions and will be removed soon!
- * Please use the new dixLookup*() functions above.
- */
-_X_EXPORT _X_DEPRECATED WindowPtr
-SecurityLookupWindow(XID id, ClientPtr client, Mask access_mode)
-{
-    WindowPtr pWin;
-    int i = dixLookupWindow(&pWin, id, client, access_mode);
-    static int warn = 1;
-    if (warn-- > 0)
-	ErrorF("Warning: LookupWindow()/SecurityLookupWindow() "
-	       "are deprecated.  Please convert your driver/module "
-	       "to use dixLookupWindow().\n");
-    return (i == Success) ? pWin : NULL;
-}
-
-_X_EXPORT _X_DEPRECATED WindowPtr
-LookupWindow(XID id, ClientPtr client)
-{
-    return SecurityLookupWindow(id, client, DixUnknownAccess);
-}
-
-_X_EXPORT _X_DEPRECATED pointer
-SecurityLookupDrawable(XID id, ClientPtr client, Mask access_mode)
-{
-    DrawablePtr pDraw;
-    int i = dixLookupDrawable(&pDraw, id, client, M_DRAWABLE, access_mode);
-    static int warn = 1;
-    if (warn-- > 0)
-	ErrorF("Warning: LookupDrawable()/SecurityLookupDrawable() "
-	       "are deprecated.  Please convert your driver/module "
-	       "to use dixLookupDrawable().\n");
-    return (i == Success) ? pDraw : NULL;
-}
-
-_X_EXPORT _X_DEPRECATED pointer
-LookupDrawable(XID id, ClientPtr client)
-{
-    return SecurityLookupDrawable(id, client, DixUnknownAccess);
-}
-
-_X_EXPORT _X_DEPRECATED ClientPtr
-LookupClient(XID id, ClientPtr client)
-{
-    ClientPtr pClient;
-    int i = dixLookupClient(&pClient, id, client, DixUnknownAccess);
-    static int warn = 1;
-    if (warn-- > 0)
-	ErrorF("Warning: LookupClient() is deprecated.  Please convert your "
-	       "driver/module to use dixLookupClient().\n");
-    return (i == Success) ? pClient : NULL;
-}
-
-/* end deprecated functions */
-
 int
 AlterSaveSetForClient(ClientPtr client, WindowPtr pWin, unsigned mode,
                       Bool toRoot, Bool remap)
diff --git a/dix/resource.c b/dix/resource.c
index 81269c3..7530e86 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -899,81 +899,31 @@ LegalNewID(XID id, ClientPtr client)
 	     !LookupIDByClass(id, RC_ANY)));
 }
 
-/* SecurityLookupIDByType and SecurityLookupIDByClass:
- * These are the heart of the resource ID security system.  They take
- * two additional arguments compared to the old LookupID functions:
- * the client doing the lookup, and the access mode (see resource.h).
- * The resource is returned if it exists and the client is allowed access,
- * else NULL is returned.
- */
-
-_X_EXPORT pointer
-SecurityLookupIDByType(ClientPtr client, XID id, RESTYPE rtype, Mask mode)
-{
-    int    cid;
-    ResourcePtr res;
-    pointer retval = NULL;
-
-    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
-	clientTable[cid].buckets)
-    {
-	res = clientTable[cid].resources[Hash(cid, id)];
-
-	for (; res; res = res->next)
-	    if ((res->id == id) && (res->type == rtype))
-	    {
-		retval = res->value;
-		break;
-	    }
-    }
-    if (retval && client && 
-	!XaceHook(XACE_RESOURCE_ACCESS, client, id, rtype, mode, retval))
-	retval = NULL;
-
-    return retval;
-}
-
-
-_X_EXPORT pointer
-SecurityLookupIDByClass(ClientPtr client, XID id, RESTYPE classes, Mask mode)
+_X_EXPORT int
+dixLookupResource(pointer *result, XID id, RESTYPE rtype,
+		  ClientPtr client, Mask mode)
 {
-    int    cid;
+    int cid = CLIENT_ID(id);
+    int istype = (rtype & TypeMask) && (rtype != RC_ANY);
     ResourcePtr res = NULL;
-    pointer retval = NULL;
 
-    if (((cid = CLIENT_ID(id)) < MAXCLIENTS) &&
-	clientTable[cid].buckets)
-    {
+    *result = NULL;
+    client->errorValue = id;
+
+    if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
 	res = clientTable[cid].resources[Hash(cid, id)];
 
 	for (; res; res = res->next)
-	    if ((res->id == id) && (res->type & classes))
-	    {
-		retval = res->value;
+	    if ((res->id == id) && ((istype && res->type == rtype) ||
+				    (!istype && res->type & rtype)))
 		break;
-	    }
     }
-    if (retval && client &&
-	!XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, mode, retval))
-	retval = NULL;
-
-    return retval;
-}
-
-/* We can't replace the LookupIDByType and LookupIDByClass functions with
- * macros because of compatibility with loadable servers.
- */
-
-_X_EXPORT pointer
-LookupIDByType(XID id, RESTYPE rtype)
-{
-    return SecurityLookupIDByType(NullClient, id, rtype,
-				  DixUnknownAccess);
-}
-
-_X_EXPORT pointer
-LookupIDByClass(XID id, RESTYPE classes)
-{
-    return SecurityLookupIDByClass(NullClient, id, classes,
-				   DixUnknownAccess);
+    if (res) {
+	if (client && !XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type,
+				mode, res->value))
+	    return BadAccess;
+	*result = res->value;
+	return Success;
+    }
+    return BadValue;
 }
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 2991c18..043f2db 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -114,6 +114,16 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(QueryColors)
     /* cursor.c */
     SYMFUNC(FreeCursor)
+    /* deprecated.c */
+    SYMFUNC(LookupClient)
+    SYMFUNC(LookupDrawable)
+    SYMFUNC(LookupWindow)
+    SYMFUNC(SecurityLookupDrawable)
+    SYMFUNC(SecurityLookupWindow)
+    SYMFUNC(LookupIDByType)
+    SYMFUNC(LookupIDByClass)
+    SYMFUNC(SecurityLookupIDByClass)
+    SYMFUNC(SecurityLookupIDByType)
     /* devices.c */
     SYMFUNC(Ones)
     SYMFUNC(InitButtonClassDeviceStruct)
@@ -160,13 +170,6 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(dixLookupWindow)
     SYMFUNC(dixLookupClient)
     SYMFUNC(dixLookupGC)
-    /* following are deprecated */
-    SYMFUNC(LookupClient)
-    SYMFUNC(LookupDrawable)
-    SYMFUNC(LookupWindow)
-    SYMFUNC(SecurityLookupDrawable)
-    SYMFUNC(SecurityLookupWindow)
-    /* end deprecated */
     SYMFUNC(NoopDDA)
     SYMFUNC(QueueWorkProc)
     SYMFUNC(RegisterBlockAndWakeupHandlers)
@@ -287,16 +290,13 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(ChangeResourceValue)
     SYMFUNC(CreateNewResourceClass)
     SYMFUNC(CreateNewResourceType)
+    SYMFUNC(dixLookupResource)
     SYMFUNC(FakeClientID)
     SYMFUNC(FreeResource)
     SYMFUNC(FreeResourceByType)
     SYMFUNC(GetXIDList)
     SYMFUNC(GetXIDRange)
-    SYMFUNC(LookupIDByType)
-    SYMFUNC(LookupIDByClass)
     SYMFUNC(LegalNewID)
-    SYMFUNC(SecurityLookupIDByClass)
-    SYMFUNC(SecurityLookupIDByType)
     SYMFUNC(FindClientResourcesByType)
     SYMFUNC(FindAllClientResources)
     SYMVAR(lastResourceType)
diff --git a/include/dix.h b/include/dix.h
index 798d617..41240b1 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -233,17 +233,6 @@ extern int dixLookupClient(
     ClientPtr client,
     Mask access_mode);
 
-/*
- * These are deprecated compatibility functions and will be removed soon!
- * Please use the new dixLookup*() functions above.
- */
-extern WindowPtr SecurityLookupWindow(XID, ClientPtr, Mask);
-extern WindowPtr LookupWindow(XID, ClientPtr);
-extern pointer SecurityLookupDrawable(XID, ClientPtr, Mask);
-extern pointer LookupDrawable(XID, ClientPtr);
-extern ClientPtr LookupClient(XID, ClientPtr);
-/* end deprecated functions */
-
 extern void NoopDDA(void);
 
 extern int AlterSaveSetForClient(
@@ -641,4 +630,36 @@ extern int xstrcasecmp(char *s1, char *s2);
 /* ffs.c */
 extern int ffs(int i);
 
+/*
+ * These are deprecated compatibility functions and will be removed soon!
+ * Please use the noted replacements instead.
+ */
+
+/* replaced by dixLookupWindow */
+extern WindowPtr SecurityLookupWindow(
+    XID id,
+    ClientPtr client,
+    Mask access_mode);
+
+/* replaced by dixLookupWindow */
+extern WindowPtr LookupWindow(
+    XID id,
+    ClientPtr client);
+
+/* replaced by dixLookupDrawable */
+extern pointer SecurityLookupDrawable(
+    XID id,
+    ClientPtr client,
+    Mask access_mode);
+
+/* replaced by dixLookupDrawable */
+extern pointer LookupDrawable(
+    XID id,
+    ClientPtr client);
+
+/* replaced by dixLookupClient */
+extern ClientPtr LookupClient(
+    XID id,
+    ClientPtr client);
+
 #endif /* DIX_H */
diff --git a/include/resource.h b/include/resource.h
index f7fa5f1..d2ecfde 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -212,32 +212,18 @@ extern Bool LegalNewID(
     XID /*id*/,
     ClientPtr /*client*/);
 
-extern pointer LookupIDByType(
-    XID /*id*/,
-    RESTYPE /*rtype*/);
-
-extern pointer LookupIDByClass(
-    XID /*id*/,
-    RESTYPE /*classes*/);
-
 extern pointer LookupClientResourceComplex(
     ClientPtr client,
     RESTYPE type,
     FindComplexResType func,
     pointer cdata);
 
-extern pointer SecurityLookupIDByType(
-    ClientPtr /*client*/,
-    XID /*id*/,
-    RESTYPE /*rtype*/,
-    Mask /*access_mode*/);
-
-extern pointer SecurityLookupIDByClass(
-    ClientPtr /*client*/,
-    XID /*id*/,
-    RESTYPE /*classes*/,
-    Mask /*access_mode*/);
-
+extern int dixLookupResource(
+    pointer *result,
+    XID id,
+    RESTYPE rtype,
+    ClientPtr client,
+    Mask access_mode);
 
 extern void GetXIDRange(
     int /*client*/,
@@ -258,5 +244,34 @@ extern Atom *ResourceNames;
 void RegisterResourceName(RESTYPE type, char* name);
 #endif
 
+/*
+ * These are deprecated compatibility functions and will be removed soon!
+ * Please use the noted replacements instead.
+ */
+
+/* replaced by dixLookupResource */
+extern pointer SecurityLookupIDByType(
+    ClientPtr client,
+    XID id,
+    RESTYPE rtype,
+    Mask access_mode);
+
+/* replaced by dixLookupResource */
+extern pointer SecurityLookupIDByClass(
+    ClientPtr client,
+    XID id,
+    RESTYPE classes,
+    Mask access_mode);
+
+/* replaced by dixLookupResource */
+extern pointer LookupIDByType(
+    XID id,
+    RESTYPE rtype);
+
+/* replaced by dixLookupResource */
+extern pointer LookupIDByClass(
+    XID id,
+    RESTYPE classes);
+
 #endif /* RESOURCE_H */
 
commit 63e46e4fc3e98751f2edbed9c79ef3d5dc2dadc6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Apr 4 15:59:51 2007 -0400

    devPrivates rework: properly free devPrivates on compatibility structures,
    excluding pixmap.

diff --git a/dix/colormap.c b/dix/colormap.c
index 73b6669..5155570 100644
--- a/dix/colormap.c
+++ b/dix/colormap.c
@@ -63,6 +63,7 @@ SOFTWARE.
 #include "scrnintstr.h"
 #include "resource.h"
 #include "windowstr.h"
+#include "privates.h"
 
 extern XID clientErrorValue;
 extern int colormapPrivateCount;
@@ -474,6 +475,7 @@ FreeColormap (pointer value, XID mid)
         }
     }
 
+    dixFreePrivates(*DEVPRIV_PTR(pmap));
     if (pmap->devPrivates)
 	xfree(pmap->devPrivates);
 
diff --git a/dix/devices.c b/dix/devices.c
index e51d1b3..4a7ec4d 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -69,6 +69,7 @@ SOFTWARE.
 #ifdef XKB
 #include <xkbsrv.h>
 #endif
+#include "privates.h"
 #include "xace.h"
 
 #include "dispatch.h"
@@ -502,6 +503,7 @@ CloseDevice(DeviceIntPtr dev)
 	XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
 #endif
 
+    dixFreePrivates(*DEVPRIV_PTR(dev));
     if (dev->devPrivates)
 	xfree(dev->devPrivates);
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 68499f1..4fb680f 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -134,6 +134,7 @@ int ProcInitialConnection();
 #include "panoramiX.h"
 #include "panoramiXsrv.h"
 #endif
+#include "privates.h"
 #include "xace.h"
 #ifdef XAPPGROUP
 #include "appgroup.h"
@@ -3651,6 +3652,7 @@ CloseDownClient(ClientPtr client)
 #ifdef SMART_SCHEDULE
 	SmartLastClient = NullClient;
 #endif
+	dixFreePrivates(*DEVPRIV_PTR(client));
 	xfree(client);
 
 	while (!clients[currentMaxClients-1])
diff --git a/dix/extension.c b/dix/extension.c
index 88dff15..b338c81 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -59,6 +59,7 @@ SOFTWARE.
 #include "gcstruct.h"
 #include "scrnintstr.h"
 #include "dispatch.h"
+#include "privates.h"
 #include "xace.h"
 
 #define EXTENSION_BASE  128
@@ -290,6 +291,7 @@ CloseDownExtensions()
 	for (j = extensions[i]->num_aliases; --j >= 0;)
 	    xfree(extensions[i]->aliases[j]);
 	xfree(extensions[i]->aliases);
+	dixFreePrivates(*DEVPRIV_PTR(extensions[i]));
 	xfree(extensions[i]);
     }
     xfree(extensions);
diff --git a/dix/gc.c b/dix/gc.c
index 7a76dd9..e7c4849 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -61,6 +61,7 @@ SOFTWARE.
 #include "scrnintstr.h"
 #include "region.h"
 
+#include "privates.h"
 #include "dix.h"
 #include <assert.h>
 
@@ -903,6 +904,7 @@ FreeGC(pointer value, XID gid)
     (*pGC->funcs->DestroyGC) (pGC);
     if (pGC->dash != DefaultDash)
 	xfree(pGC->dash);
+    dixFreePrivates(*DEVPRIV_PTR(pGC));
     xfree(pGC);
     return(Success);
 }
diff --git a/dix/main.c b/dix/main.c
index 852cbcb..b5db193 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -103,6 +103,7 @@ Equipment Corporation.
 #include "site.h"
 #include "dixfont.h"
 #include "extnsionst.h"
+#include "privates.h"
 #ifdef XPRINT
 #include "DiPrint.h"
 #endif
@@ -496,6 +497,7 @@ main(int argc, char *argv[], char *envp[])
 
 	FreeAuditTimer();
 
+	dixFreePrivates(*DEVPRIV_PTR(serverClient));
 	xfree(serverClient->devPrivates);
 	serverClient->devPrivates = NULL;
 
@@ -801,6 +803,7 @@ FreeScreen(ScreenPtr pScreen)
     xfree(pScreen->WindowPrivateSizes);
     xfree(pScreen->GCPrivateSizes);
     xfree(pScreen->PixmapPrivateSizes);
+    dixFreePrivates(*DEVPRIV_PTR(pScreen));
     xfree(pScreen->devPrivates);
     xfree(pScreen);
 }
diff --git a/dix/window.c b/dix/window.c
index 9967053..b505947 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -126,6 +126,7 @@ Equipment Corporation.
 #ifdef XAPPGROUP
 #include "appgroup.h"
 #endif
+#include "privates.h"
 #include "xace.h"
 
 /******
@@ -975,6 +976,7 @@ DeleteWindow(pointer value, XID wid)
 	if (pWin->prevSib)
 	    pWin->prevSib->nextSib = pWin->nextSib;
     }
+    dixFreePrivates(*DEVPRIV_PTR(pWin));
     xfree(pWin);
     return Success;
 }
commit 1cb84768f376b477a08a558854609b0743f2bd29
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Apr 3 15:31:16 2007 -0400

    security: rewrite to use new devPrivates support.

diff --git a/Xext/security.c b/Xext/security.c
index bc92594..ad04045 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -30,6 +30,7 @@ in this Software without prior written authorization from The Open Group.
 
 #include "scrnintstr.h"
 #include "colormapst.h"
+#include "privates.h"
 #include "xacestr.h"
 #include "securitysrv.h"
 #include <X11/extensions/securstr.h>
@@ -53,23 +54,23 @@ in this Software without prior written authorization from The Open Group.
 
 static int SecurityErrorBase;  /* first Security error number */
 static int SecurityEventBase;  /* first Security event number */
-static int securityClientPrivateIndex;
-static int securityExtnsnPrivateIndex;
+static devprivate_key_t stateKey;
 
 /* this is what we store as client security state */
 typedef struct {
+    int haveState;
     unsigned int trustLevel;
     XID authId;
 } SecurityClientStateRec;
 
-#define STATEVAL(extnsn) \
-    ((extnsn)->devPrivates[securityExtnsnPrivateIndex].val)
-#define STATEPTR(client) \
-    ((client)->devPrivates[securityClientPrivateIndex].ptr)
-#define TRUSTLEVEL(client) \
-    (((SecurityClientStateRec*)STATEPTR(client))->trustLevel)
-#define AUTHID(client) \
-    (((SecurityClientStateRec*)STATEPTR(client))->authId)
+#define EXTLEVEL(extnsn) ((Bool) \
+    dixLookupPrivate(DEVPRIV_PTR(extnsn), &stateKey))
+#define HAVESTATE(client) (((SecurityClientStateRec *) \
+    dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->haveState)
+#define TRUSTLEVEL(client) (((SecurityClientStateRec *) \
+    dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->trustLevel)
+#define AUTHID(client)(((SecurityClientStateRec *) \
+    dixLookupPrivate(DEVPRIV_PTR(client), &stateKey))->authId)
 
 static CallbackListPtr SecurityValidateGroupCallback = NULL;
 
@@ -1149,7 +1150,7 @@ SecurityClientStateCallback(CallbackListPtr *pcbl, pointer unused,
 	    SecurityAuthorizationPtr pAuth;
 
 	    /* client may not have any state (bad authorization) */
-	    if (!STATEPTR(client))
+	    if (!HAVESTATE(client))
 		break;
 
 	    pAuth = (SecurityAuthorizationPtr)LookupIDByType(AUTHID(client),
@@ -1185,7 +1186,7 @@ SecurityCheckMapAccess(CallbackListPtr *pcbl, pointer unused,
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
     WindowPtr pWin = rec->pWin;
 
-    if (STATEPTR(rec->client) &&
+    if (HAVESTATE(rec->client) &&
 	(TRUSTLEVEL(rec->client) != XSecurityClientTrusted) &&
 	(pWin->drawable.class == InputOnly) &&
 	pWin->parent && pWin->parent->parent &&
@@ -1211,7 +1212,7 @@ SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
     XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
 
     if ((TRUSTLEVEL(rec->client) != XSecurityClientTrusted) &&
-	!STATEVAL(rec->ext))
+	!EXTLEVEL(rec->ext))
 
 	rec->rval = FALSE;
 }
@@ -1241,7 +1242,7 @@ SecurityDeclareExtSecure(CallbackListPtr *pcbl, pointer unused,
     XaceDeclareExtSecureRec *rec = (XaceDeclareExtSecureRec*)calldata;
 
     /* security state for extensions is simply a boolean trust value */
-    STATEVAL(rec->ext) = rec->secure;
+    dixSetPrivate(DEVPRIV_PTR(rec->ext), &stateKey, (pointer)rec->secure);
 }
 
 /**********************************************************************/
@@ -1887,29 +1888,14 @@ XSecurityOptions(argc, argv, i)
 void
 SecurityExtensionSetup(INITARGS)
 {
-    /* Allocate the client private index */
-    securityClientPrivateIndex = AllocateClientPrivateIndex();
-    if (!AllocateClientPrivate(securityClientPrivateIndex,
-			       sizeof (SecurityClientStateRec)))
-	FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
-
-    /* Allocate the extension private index */
-    securityExtnsnPrivateIndex = AllocateExtensionPrivateIndex();
-    if (!AllocateExtensionPrivate(securityExtnsnPrivateIndex, 0))
-	FatalError("SecurityExtensionSetup: Can't allocate extnsn private.\n");
-
-    /* register callbacks */
-#define XaceRC XaceRegisterCallback
-    XaceRC(XACE_RESOURCE_ACCESS, SecurityCheckResourceIDAccess, NULL);
-    XaceRC(XACE_DEVICE_ACCESS, SecurityCheckDeviceAccess, NULL);
-    XaceRC(XACE_PROPERTY_ACCESS, SecurityCheckPropertyAccess, NULL);
-    XaceRC(XACE_DRAWABLE_ACCESS, SecurityCheckDrawableAccess, NULL);
-    XaceRC(XACE_MAP_ACCESS, SecurityCheckMapAccess, NULL);
-    XaceRC(XACE_BACKGRND_ACCESS, SecurityCheckBackgrndAccess, NULL);
-    XaceRC(XACE_EXT_DISPATCH, SecurityCheckExtAccess, NULL);
-    XaceRC(XACE_EXT_ACCESS, SecurityCheckExtAccess, NULL);
-    XaceRC(XACE_HOSTLIST_ACCESS, SecurityCheckHostlistAccess, NULL);
-    XaceRC(XACE_DECLARE_EXT_SECURE, SecurityDeclareExtSecure, NULL);
+    /* FIXME: this is here so it is registered before other extensions
+     * init themselves.  This also required commit 5e946dd853a4ebc... to
+     * call the setup functions on each server reset.
+     *
+     * The extension security bit should be delivered in some other way,
+     * either in a symbol or in the module data.
+     */
+    XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, SecurityDeclareExtSecure, 0);
 } /* SecurityExtensionSetup */
 
 
@@ -1939,6 +1925,10 @@ SecurityExtensionInit(INITARGS)
 
     RTEventClient |= RC_NEVERRETAIN;
 
+    /* Allocate the private storage */
+    if (!dixRequestPrivate(&stateKey, sizeof(SecurityClientStateRec)))
+	FatalError("SecurityExtensionSetup: Can't allocate client private.\n");
+
     if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL))
 	return;
 
@@ -1955,4 +1945,15 @@ SecurityExtensionInit(INITARGS)
 
     SecurityLoadPropertyAccessList();
 
+    /* register callbacks */
+#define XaceRC XaceRegisterCallback
+    XaceRC(XACE_RESOURCE_ACCESS, SecurityCheckResourceIDAccess, NULL);
+    XaceRC(XACE_DEVICE_ACCESS, SecurityCheckDeviceAccess, NULL);
+    XaceRC(XACE_PROPERTY_ACCESS, SecurityCheckPropertyAccess, NULL);
+    XaceRC(XACE_DRAWABLE_ACCESS, SecurityCheckDrawableAccess, NULL);
+    XaceRC(XACE_MAP_ACCESS, SecurityCheckMapAccess, NULL);
+    XaceRC(XACE_BACKGRND_ACCESS, SecurityCheckBackgrndAccess, NULL);
+    XaceRC(XACE_EXT_DISPATCH, SecurityCheckExtAccess, NULL);
+    XaceRC(XACE_EXT_ACCESS, SecurityCheckExtAccess, NULL);
+    XaceRC(XACE_HOSTLIST_ACCESS, SecurityCheckHostlistAccess, NULL);
 } /* SecurityExtensionInit */
commit 14aea12cadef647369e44639ff5024dd7034570a
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Apr 3 15:23:56 2007 -0400

    xace: forgot one of the hook call arguments.  Add it.

diff --git a/dix/window.c b/dix/window.c
index 2e85209..9967053 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -731,7 +731,8 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 
     /*  security creation/labeling check
      */
-    if (!XaceHook(XACE_RESOURCE_ACCESS, wid, RT_WINDOW, DixCreateAccess, pWin))
+    if (!XaceHook(XACE_RESOURCE_ACCESS, client,
+		  wid, RT_WINDOW, DixCreateAccess, pWin))
     {
 	xfree(pWin);
 	*error = BadAccess;
commit 353e19fd5e18ad55a0dd12a7b63f6af9df7bfe6b
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Apr 3 14:06:02 2007 -0400

    devPrivates rework: zero out newly allocated private space.

diff --git a/dix/privates.c b/dix/privates.c
index cc4b016..8a39437 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -107,7 +107,7 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
     if (item)
 	size += item->size;
 
-    ptr = (PrivateRec *)xalloc(size);
+    ptr = (PrivateRec *)xcalloc(size, 1);
     if (!ptr)
 	return NULL;
     ptr->key = key;
commit 327bc332a61294209d39286228199f54bdde73d1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 28 13:00:03 2007 -0400

    xace: minor comment fixes.

diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index dc1bdfc..184fb9b 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -37,7 +37,6 @@ typedef struct {
 } XaceCoreDispatchRec;
 
 /* XACE_RESOURCE_ACCESS */
-/* XACE_RESOURCE_CREATE */
 typedef struct {
     ClientPtr client;
     XID id;
@@ -79,7 +78,7 @@ typedef struct {
     int rval;
 } XaceMapAccessRec;
 
-/* XACE_EXT_DISPATCH_ACCESS */
+/* XACE_EXT_DISPATCH */
 /* XACE_EXT_ACCESS */
 typedef struct {
     ClientPtr client;
commit 299ff4c82998d2a32204bfbecde4993dfbd3d4a5
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 28 12:57:11 2007 -0400

    xace: provide creation-time resource hook call in CreateWindow().

diff --git a/dix/window.c b/dix/window.c
index e4f1ae1..2e85209 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -729,6 +729,14 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
 
     pWin->borderWidth = bw;
 
+    /*  security creation/labeling check
+     */
+    if (!XaceHook(XACE_RESOURCE_ACCESS, wid, RT_WINDOW, DixCreateAccess, pWin))
+    {
+	xfree(pWin);
+	*error = BadAccess;
+	return NullWindow;
+    }
     /*  can't let untrusted clients have background None windows;
      *  they make it too easy to steal window contents
      */
commit 99b220969f2f8ba829bc8294b27ca90fd9311be4
Merge: 728ad64... 82a8b99...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 28 12:54:04 2007 -0400

    Merge branch 'master' into XACE-SELINUX

commit 728ad64d979fd9e5cca28e8c15118c18d707c431
Merge: 0331c6a... 6a0bed1...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Mar 27 13:16:40 2007 -0400

    Merge branch 'master' into XACE-SELINUX

commit 0331c6a8fcba1dc27ef45aaf5f694799d0085413
Merge: 84a066c... f7c5aa0...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 26 10:28:05 2007 -0400

    Merge branch 'master' into XACE-SELINUX

commit 84a066cc88fe4326ddacd04ab5e1158a80571c33
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Mar 23 10:33:53 2007 -0400

    xace: pass serverClient as default argument to dixChangeWindowProperty
    instead of NullClient.

diff --git a/Xext/security.c b/Xext/security.c
index 7ea032f..74ba8d4 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1715,7 +1715,7 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
 
     /* if client trusted or window untrusted, allow operation */
 
-    if (!client || (TRUSTLEVEL(client) == XSecurityClientTrusted) ||
+    if ((TRUSTLEVEL(client) == XSecurityClientTrusted) ||
 	 (TRUSTLEVEL(wClient(pWin)) != XSecurityClientTrusted) )
 	return;
 
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 4ed2784..648bb6e 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1070,7 +1070,7 @@ XSELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     char *propname = NameForAtom(rec->pProp->propertyName);
 
     tclient = wClient(pWin);
-    if (!client || !tclient || !HAVESTATE(tclient))
+    if (!tclient || !HAVESTATE(tclient))
         return;
 
     propsid = GetPropertySID(SID(tclient)->ctx, propname);
@@ -1235,13 +1235,15 @@ XSELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 	rc = avc_sid_to_context(SID(client), &ctx);
 	if (rc < 0)
 	    FatalError("XSELinux: Failed to get security context!\n");
-	rc = ChangeWindowProperty(pWin, atom_client_ctx, XA_STRING, 8,
-				  PropModeReplace, strlen(ctx), ctx, FALSE);
+	rc = dixChangeWindowProperty(serverClient,
+				     pWin, atom_client_ctx, XA_STRING, 8,
+				     PropModeReplace, strlen(ctx), ctx, FALSE);
 	freecon(ctx);
     }
     else
-	rc = ChangeWindowProperty(pWin, atom_client_ctx, XA_STRING, 8,
-				  PropModeReplace, 10, "UNLABELED!", FALSE);
+	rc = dixChangeWindowProperty(serverClient,
+				     pWin, atom_client_ctx, XA_STRING, 8,
+				     PropModeReplace, 10, "UNLABELED!", FALSE);
     if (rc != Success)
 	FatalError("XSELinux: Failed to set context property on window!\n");
 } /* XSELinuxResourceState */
diff --git a/dix/property.c b/dix/property.c
index 9ff6993..74d548d 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -374,7 +374,7 @@ ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format,
 		     int mode, unsigned long len, pointer value, 
 		     Bool sendevent)
 {
-    return dixChangeWindowProperty(NullClient, pWin, property, type, format,
+    return dixChangeWindowProperty(serverClient, pWin, property, type, format,
 				   mode, len, value, sendevent);
 }
 
commit e1cc68add0bcdd5e0e4e15cf6ee8a3da136d3534
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 22 17:33:16 2007 -0400

    xace: drop the name argument from the property callback.

diff --git a/Xext/security.c b/Xext/security.c
index 00180b9..7ea032f 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1708,7 +1708,7 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
     XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
     ClientPtr client = rec->client;
     WindowPtr pWin = rec->pWin;
-    ATOM propertyName = rec->propertyName;
+    ATOM propertyName = rec->pProp->propertyName;
     Mask access_mode = rec->access_mode;
     PropertyAccessPtr pacl;
     char action = SecurityDefaultAction;
diff --git a/Xext/xace.c b/Xext/xace.c
index 8e277ac..a3c4d42 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -96,7 +96,6 @@ int XaceHook(int hook, ...)
 		va_arg(ap, ClientPtr),
 		va_arg(ap, WindowPtr),
 		va_arg(ap, PropertyPtr),
-		va_arg(ap, Atom),
 		va_arg(ap, Mask),
 		XaceAllowOperation   /* default allow */
 	    };
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 19d1540..dc1bdfc 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -20,7 +20,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifndef _XACESTR_H
 #define _XACESTR_H
 
-#include <X11/Xdefs.h>
 #include "dixstruct.h"
 #include "resource.h"
 #include "extnsionst.h"
@@ -61,7 +60,6 @@ typedef struct {
     ClientPtr client;
     WindowPtr pWin;
     PropertyPtr pProp;
-    Atom propertyName;
     Mask access_mode;
     int rval;
 } XacePropertyAccessRec;
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index eb721a7..4ed2784 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1067,7 +1067,7 @@ XSELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     ClientPtr tclient;
     access_vector_t perm = 0;
     security_id_t propsid;
-    char *propname = NameForAtom(rec->propertyName);
+    char *propname = NameForAtom(rec->pProp->propertyName);
 
     tclient = wClient(pWin);
     if (!client || !tclient || !HAVESTATE(tclient))
diff --git a/dix/property.c b/dix/property.c
index c760ef1..9ff6993 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -144,7 +144,7 @@ ProcRotateProperties(ClientPtr client)
 	    DEALLOCATE_LOCAL(props);
 	    return BadMatch;
 	}
-	switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, atoms[i],
+	switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
 			 DixReadAccess|DixWriteAccess))
 	{
 	case XaceErrorOperation:
@@ -277,8 +277,8 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 	    memmove((char *)data, (char *)value, totalSize);
 	pProp->size = len;
 	pProp->devPrivates = NULL;
-	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp, property,
-			 DixWriteAccess))
+	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
+			 DixCreateAccess))
 	{
 	case XaceErrorOperation:
 	    xfree(data);
@@ -295,7 +295,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
     }
     else
     {
-	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp, property,
+	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp,
 			 DixWriteAccess))
 	{
 	case XaceErrorOperation:
@@ -517,8 +517,7 @@ ProcGetProperty(ClientPtr client)
 
     if (stuff->delete)
 	access_mode |= DixDestroyAccess;
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
-		     stuff->property, access_mode))
+    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, access_mode))
     {
     case XaceErrorOperation:
 	client->errorValue = stuff->property;
@@ -671,8 +670,7 @@ ProcDeleteProperty(register ClientPtr client)
     }
 
     switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
-		     FindProperty(pWin, stuff->property), stuff->property,
-		     DixDestroyAccess))
+		     FindProperty(pWin, stuff->property), DixDestroyAccess))
     {
     case XaceErrorOperation:
 	client->errorValue = stuff->property;
commit c9fb8a35332d101897607d8f06ed5a6512eac7cf
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 22 17:23:26 2007 -0400

    dix: move access codes to separate header file, add DixCreateAccess.

diff --git a/include/Makefile.am b/include/Makefile.am
index 4d8910b..82e7190 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -11,6 +11,7 @@ sdk_HEADERS =		\
 	cursor.h	\
 	cursorstr.h	\
 	dix.h		\
+	dixaccess.h	\
 	dixevents.h	\
 	dixfont.h	\
 	dixfontstr.h	\
diff --git a/include/dixaccess.h b/include/dixaccess.h
new file mode 100644
index 0000000..205b76c
--- /dev/null
+++ b/include/dixaccess.h
@@ -0,0 +1,29 @@
+/***********************************************************
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+
+#ifndef DIX_ACCESS_H
+#define DIX_ACCESS_H
+
+/* These are the access modes that can be passed in the last parameter
+ * to several of the dix lookup functions.  They were originally part
+ * of the Security extension, now used by XACE.
+ *
+ * You can or these values together to indicate multiple modes
+ * simultaneously.
+ */
+
+#define DixUnknownAccess	0	/* don't know intentions */
+#define DixReadAccess		(1<<0)	/* inspecting the object */
+#define DixWriteAccess		(1<<1)	/* changing the object */
+#define DixDestroyAccess	(1<<2)	/* destroying the object */
+#define DixCreateAccess		(1<<3)	/* creating the object */
+
+#endif /* DIX_ACCESS_H */
diff --git a/include/resource.h b/include/resource.h
index 9949dd2..f7fa5f1 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -48,6 +48,7 @@ SOFTWARE.
 #ifndef RESOURCE_H
 #define RESOURCE_H 1
 #include "misc.h"
+#include "dixaccess.h"
 
 /*****************************************************************
  * STUFF FOR RESOURCES 
@@ -225,20 +226,6 @@ extern pointer LookupClientResourceComplex(
     FindComplexResType func,
     pointer cdata);
 
-/* These are the access modes that can be passed in the last parameter
- * to SecurityLookupIDByType/Class.  The Security extension doesn't
- * currently make much use of these; they're mainly provided as an
- * example of what you might need for discretionary access control.
- * You can or these values together to indicate multiple modes
- * simultaneously.
- */
-
-#define DixUnknownAccess	0	/* don't know intentions */
-#define DixReadAccess		(1<<0)	/* inspecting the object */
-#define DixWriteAccess		(1<<1)	/* changing the object */
-#define DixReadWriteAccess	(DixReadAccess|DixWriteAccess)
-#define DixDestroyAccess	(1<<2)	/* destroying the object */
-
 extern pointer SecurityLookupIDByType(
     ClientPtr /*client*/,
     XID /*id*/,
commit 1b766ffc0647d5e9a9bf6938d33548d977b5535e
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 22 15:55:35 2007 -0400

    dix: reorganize property code to better support xace hook; requires new API for
    changing a property, dixChangeWindowProperty, taking an additional client argument.

diff --git a/Xext/security.c b/Xext/security.c
index b7a0925..00180b9 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -1715,7 +1715,7 @@ SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
 
     /* if client trusted or window untrusted, allow operation */
 
-    if ( (TRUSTLEVEL(client) == XSecurityClientTrusted) ||
+    if (!client || (TRUSTLEVEL(client) == XSecurityClientTrusted) ||
 	 (TRUSTLEVEL(wClient(pWin)) != XSecurityClientTrusted) )
 	return;
 
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 4056d9e..eb721a7 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1070,7 +1070,7 @@ XSELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
     char *propname = NameForAtom(rec->propertyName);
 
     tclient = wClient(pWin);
-    if (!tclient || !HAVESTATE(tclient))
+    if (!client || !tclient || !HAVESTATE(tclient))
         return;
 
     propsid = GetPropertySID(SID(tclient)->ctx, propname);
diff --git a/dix/property.c b/dix/property.c
index 5e11b5f..c760ef1 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -230,19 +230,9 @@ ProcChangeProperty(ClientPtr client)
 	return(BadAtom);
     }
 
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
-		     FindProperty(pWin, stuff->property), stuff->property,
-		     DixWriteAccess))
-    {
-    case XaceErrorOperation:
-	client->errorValue = stuff->property;
-	return BadAtom;
-    case XaceIgnoreOperation:
-	return Success;
-    }
-
-    err = ChangeWindowProperty(pWin, stuff->property, stuff->type, (int)format,
-			       (int)mode, len, (pointer)&stuff[1], TRUE);
+    err = dixChangeWindowProperty(client, pWin, stuff->property, stuff->type,
+				  (int)format, (int)mode, len, &stuff[1],
+				  TRUE);
     if (err != Success)
 	return err;
     else
@@ -250,9 +240,9 @@ ProcChangeProperty(ClientPtr client)
 }
 
 _X_EXPORT int
-ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, 
-                     int mode, unsigned long len, pointer value, 
-                     Bool sendevent)
+dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
+			Atom type, int format, int mode, unsigned long len,
+			pointer value, Bool sendevent)
 {
     PropertyPtr pProp;
     xEvent event;
@@ -286,12 +276,34 @@ ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format,
 	if (len)
 	    memmove((char *)data, (char *)value, totalSize);
 	pProp->size = len;
-        pProp->next = pWin->optional->userProps;
 	pProp->devPrivates = NULL;
+	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp, property,
+			 DixWriteAccess))
+	{
+	case XaceErrorOperation:
+	    xfree(data);
+	    xfree(pProp);
+	    pClient->errorValue = property;
+	    return BadAtom;
+	case XaceIgnoreOperation:
+	    xfree(data);
+	    xfree(pProp);
+	    return Success;
+	}
+        pProp->next = pWin->optional->userProps;
         pWin->optional->userProps = pProp;
     }
     else
     {
+	switch (XaceHook(XACE_PROPERTY_ACCESS, pClient, pWin, pProp, property,
+			 DixWriteAccess))
+	{
+	case XaceErrorOperation:
+	    pClient->errorValue = property;
+	    return BadAtom;
+	case XaceIgnoreOperation:
+	    return Success;
+	}
 	/* To append or prepend to a property the request format and type
 		must match those of the already defined property.  The
 		existing format and type are irrelevant when using the mode
@@ -357,6 +369,15 @@ ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format,
     return(Success);
 }
 
+_X_EXPORT int
+ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format, 
+		     int mode, unsigned long len, pointer value, 
+		     Bool sendevent)
+{
+    return dixChangeWindowProperty(NullClient, pWin, property, type, format,
+				   mode, len, value, sendevent);
+}
+
 int
 DeleteProperty(WindowPtr pWin, Atom propName)
 {
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 1732d1f..6957f06 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -192,6 +192,7 @@ _X_HIDDEN void *dixLookupTab[] = {
 #endif
     /* property.c */
     SYMFUNC(ChangeWindowProperty)
+    SYMFUNC(dixChangeWindowProperty)
     /* extension.c */
     SYMFUNC(AddExtension)
     SYMFUNC(AddExtensionAlias)
diff --git a/include/property.h b/include/property.h
index 8b6dc09..77536aa 100644
--- a/include/property.h
+++ b/include/property.h
@@ -52,6 +52,17 @@ SOFTWARE.
 
 typedef struct _Property *PropertyPtr;
 
+extern int dixChangeWindowProperty(
+    ClientPtr /*pClient*/,
+    WindowPtr /*pWin*/,
+    Atom /*property*/,
+    Atom /*type*/,
+    int /*format*/,
+    int /*mode*/,
+    unsigned long /*len*/,
+    pointer /*value*/,
+    Bool /*sendevent*/);
+
 extern int ChangeWindowProperty(
     WindowPtr /*pWin*/,
     Atom /*property*/,
commit 1b58304ac837735920747ed0f0d10ba331bdaeb7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 22 13:06:50 2007 -0400

    xace: add new argument to property hook for property structure itself.

diff --git a/Xext/security.c b/Xext/security.c
index 98e91ad..b7a0925 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -28,14 +28,8 @@ in this Software without prior written authorization from The Open Group.
 #include <dix-config.h>
 #endif
 
-#include "dixstruct.h"
-#include "extnsionst.h"
-#include "windowstr.h"
-#include "inputstr.h"
 #include "scrnintstr.h"
-#include "gcstruct.h"
 #include "colormapst.h"
-#include "propertyst.h"
 #include "xacestr.h"
 #include "securitysrv.h"
 #include <X11/extensions/securstr.h>
diff --git a/Xext/xace.c b/Xext/xace.c
index 9502b5d..8e277ac 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -22,9 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #include <stdarg.h>
-#include "windowstr.h"
 #include "scrnintstr.h"
-#include "gcstruct.h"
 #include "xacestr.h"
 #include "modinit.h"
 
@@ -97,6 +95,7 @@ int XaceHook(int hook, ...)
 	    XacePropertyAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, WindowPtr),
+		va_arg(ap, PropertyPtr),
 		va_arg(ap, Atom),
 		va_arg(ap, Mask),
 		XaceAllowOperation   /* default allow */
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index edf7b66..19d1540 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "gcstruct.h"
 #include "windowstr.h"
 #include "inputstr.h"
+#include "propertyst.h"
 #include "selection.h"
 #include "xace.h"
 
@@ -59,6 +60,7 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     WindowPtr pWin;
+    PropertyPtr pProp;
     Atom propertyName;
     Mask access_mode;
     int rval;
diff --git a/dix/property.c b/dix/property.c
index 3aa8e77..5e11b5f 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -91,6 +91,19 @@ PrintPropertys(WindowPtr pWin)
 }
 #endif
 
+static _X_INLINE PropertyPtr
+FindProperty(WindowPtr pWin, Atom propertyName)
+{
+    PropertyPtr pProp = wUserProps(pWin);
+    while (pProp)
+    {
+	if (pProp->propertyName == propertyName)
+	    break;
+	pProp = pProp->next;
+    }
+    return pProp;
+}
+
 int
 ProcRotateProperties(ClientPtr client)
 {
@@ -115,35 +128,33 @@ ProcRotateProperties(ClientPtr client)
 	return(BadAlloc);
     for (i = 0; i < stuff->nAtoms; i++)
     {
-	char action = XaceHook(XACE_PROPERTY_ACCESS, client, pWin, atoms[i],
-				DixReadAccess|DixWriteAccess);
-
-        if (!ValidAtom(atoms[i]) || (XaceErrorOperation == action)) {
+        if (!ValidAtom(atoms[i])) {
             DEALLOCATE_LOCAL(props);
 	    client->errorValue = atoms[i];
             return BadAtom;
         }
-	if (XaceIgnoreOperation == action) {
-            DEALLOCATE_LOCAL(props);
-	    return Success;
-	}
-
         for (j = i + 1; j < stuff->nAtoms; j++)
             if (atoms[j] == atoms[i])
             {
                 DEALLOCATE_LOCAL(props);
                 return BadMatch;
             }
-        pProp = wUserProps (pWin);
-        while (pProp)
-        {
-            if (pProp->propertyName == atoms[i])
-                goto found;
-	    pProp = pProp->next;
-        }
-        DEALLOCATE_LOCAL(props);
-        return BadMatch;
-found: 
+	pProp = FindProperty(pWin, atoms[i]);
+	if (!pProp) {
+	    DEALLOCATE_LOCAL(props);
+	    return BadMatch;
+	}
+	switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp, atoms[i],
+			 DixReadAccess|DixWriteAccess))
+	{
+	case XaceErrorOperation:
+            DEALLOCATE_LOCAL(props);
+	    client->errorValue = atoms[i];
+            return BadAtom;
+	case XaceIgnoreOperation:
+            DEALLOCATE_LOCAL(props);
+	    return Success;
+	}
         props[i] = pProp;
     }
     delta = stuff->nPositions;
@@ -219,7 +230,8 @@ ProcChangeProperty(ClientPtr client)
 	return(BadAtom);
     }
 
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, stuff->property,
+    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
+		     FindProperty(pWin, stuff->property), stuff->property,
 		     DixWriteAccess))
     {
     case XaceErrorOperation:
@@ -252,14 +264,8 @@ ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format,
     totalSize = len * sizeInBytes;
 
     /* first see if property already exists */
+    pProp = FindProperty(pWin, property);
 
-    pProp = wUserProps (pWin);
-    while (pProp)
-    {
-	if (pProp->propertyName == property)
-	    break;
-	pProp = pProp->next;
-    }
     if (!pProp)   /* just add to list */
     {
 	if (!pWin->optional && !MakeWindowOptional (pWin))
@@ -490,8 +496,8 @@ ProcGetProperty(ClientPtr client)
 
     if (stuff->delete)
 	access_mode |= DixDestroyAccess;
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, stuff->property,
-		     access_mode))
+    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, pProp,
+		     stuff->property, access_mode))
     {
     case XaceErrorOperation:
 	client->errorValue = stuff->property;
@@ -643,7 +649,8 @@ ProcDeleteProperty(register ClientPtr client)
 	return (BadAtom);
     }
 
-    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin, stuff->property,
+    switch (XaceHook(XACE_PROPERTY_ACCESS, client, pWin,
+		     FindProperty(pWin, stuff->property), stuff->property,
 		     DixDestroyAccess))
     {
     case XaceErrorOperation:
commit 5486be4898766205149fadce71529724eb78fbf3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 22 10:59:21 2007 -0400

    dix: devPrivates support for PropertyRec.

diff --git a/dix/property.c b/dix/property.c
index d402849..3aa8e77 100644
--- a/dix/property.c
+++ b/dix/property.c
@@ -281,6 +281,7 @@ ChangeWindowProperty(WindowPtr pWin, Atom property, Atom type, int format,
 	    memmove((char *)data, (char *)value, totalSize);
 	pProp->size = len;
         pProp->next = pWin->optional->userProps;
+	pProp->devPrivates = NULL;
         pWin->optional->userProps = pProp;
     }
     else
@@ -383,6 +384,7 @@ DeleteProperty(WindowPtr pWin, Atom propName)
         event.u.property.atom = pProp->propertyName;
 	event.u.property.time = currentTime.milliseconds;
 	DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
+	dixFreePrivates(pProp->devPrivates);
 	xfree(pProp->data);
         xfree(pProp);
     }
@@ -405,6 +407,7 @@ DeleteAllWindowProperties(WindowPtr pWin)
 	event.u.property.time = currentTime.milliseconds;
 	DeliverEvents(pWin, &event, 1, (WindowPtr)NULL);
 	pNextProp = pProp->next;
+	dixFreePrivates(pProp->devPrivates);
         xfree(pProp->data);
         xfree(pProp);
 	pProp = pNextProp;
@@ -569,6 +572,7 @@ ProcGetProperty(ClientPtr client)
 	}
 	else
 	    prevProp->next = pProp->next;
+	dixFreePrivates(pProp->devPrivates);
 	xfree(pProp->data);
 	xfree(pProp);
     }
diff --git a/include/propertyst.h b/include/propertyst.h
index 6add81d..fd1148e 100644
--- a/include/propertyst.h
+++ b/include/propertyst.h
@@ -49,6 +49,7 @@ SOFTWARE.
 #define PROPERTYSTRUCT_H 
 #include "misc.h"
 #include "property.h"
+#include "privates.h"
 /* 
  *   PROPERTY -- property element
  */
@@ -60,6 +61,7 @@ typedef struct _Property {
 	short		format;     /* format of data for swapping - 8,16,32 */
 	long		size;       /* size of data in (format/8) bytes */
 	pointer         data;       /* private to client */
+	PrivateRec	*devPrivates;
 } PropertyRec;
 
 #endif /* PROPERTYSTRUCT_H */
commit a3296d111dc4d76aa3afa7e338cbab93eb390ec4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 21 17:01:26 2007 -0400

    xace: add access_mode argument to selection hook.

diff --git a/Xext/xace.c b/Xext/xace.c
index 2b873cb..9502b5d 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -151,6 +151,7 @@ int XaceHook(int hook, ...)
 	    XaceSelectionAccessRec rec = {
 		va_arg(ap, ClientPtr),
 		va_arg(ap, Selection*),
+		va_arg(ap, Mask),
 		TRUE	/* default allow */
 	    };
 	    calldata = &rec;
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 4c480a4..edf7b66 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -98,6 +98,7 @@ typedef struct {
 typedef struct {
     ClientPtr client;
     Selection *selection;
+    Mask access_mode;
     int rval;
 } XaceSelectionAccessRec;
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index b5ed13d..e4bc937 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1119,7 +1119,8 @@ ProcGetSelectionOwner(register ClientPtr client)
 	reply.length = 0;
 	reply.sequenceNumber = client->sequence;
         if (i < NumCurrentSelections &&
-	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i]))
+	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
+		     DixReadAccess))
             reply.owner = CurrentSelections[i].destwindow;
         else
             reply.owner = None;
@@ -1159,7 +1160,8 @@ ProcConvertSelection(register ClientPtr client)
 	       CurrentSelections[i].selection != stuff->selection) i++;
 	if ((i < NumCurrentSelections) &&
 	    (CurrentSelections[i].window != None) &&
-	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i]))
+	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i],
+		     DixReadAccess))
 	{        
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
commit 4c1fb8069d5dd30a73277698503e9dcc2e9d64c6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 21 16:17:14 2007 -0400

    dix: add new selection fields supporting redirection.
    This is a minor ABI break.

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 498f18a..b5ed13d 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1074,11 +1074,16 @@ ProcSetSelectionOwner(register ClientPtr client)
 	    NumCurrentSelections++;
 	    CurrentSelections = newsels;
 	    CurrentSelections[i].selection = stuff->selection;
+	    CurrentSelections[i].devPrivates = NULL;
 	}
+	dixFreePrivates(CurrentSelections[i].devPrivates);
         CurrentSelections[i].lastTimeChanged = time;
 	CurrentSelections[i].window = stuff->window;
+	CurrentSelections[i].destwindow = stuff->window;
 	CurrentSelections[i].pWin = pWin;
 	CurrentSelections[i].client = (pWin ? client : NullClient);
+	CurrentSelections[i].destclient = (pWin ? client : NullClient);
+	CurrentSelections[i].devPrivates = NULL;
 	if (SelectionCallback)
 	{
 	    SelectionInfoRec	info;
@@ -1115,7 +1120,7 @@ ProcGetSelectionOwner(register ClientPtr client)
 	reply.sequenceNumber = client->sequence;
         if (i < NumCurrentSelections &&
 	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i]))
-            reply.owner = CurrentSelections[i].window;
+            reply.owner = CurrentSelections[i].destwindow;
         else
             reply.owner = None;
         WriteReplyToClient(client, sizeof(xGetSelectionOwnerReply), &reply);
@@ -1158,14 +1163,13 @@ ProcConvertSelection(register ClientPtr client)
 	{        
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
-	    event.u.selectionRequest.owner = 
-			CurrentSelections[i].window;
+	    event.u.selectionRequest.owner = CurrentSelections[i].window;
 	    event.u.selectionRequest.requestor = stuff->requestor;
 	    event.u.selectionRequest.selection = stuff->selection;
 	    event.u.selectionRequest.target = stuff->target;
 	    event.u.selectionRequest.property = stuff->property;
 	    if (TryClientEvents(
-		CurrentSelections[i].client, &event, 1, NoEventMask,
+		CurrentSelections[i].destclient, &event, 1, NoEventMask,
 		NoEventMask /* CantBeFiltered */, NullGrab))
 		return (client->noClientException);
 	}
@@ -4020,9 +4024,11 @@ DeleteWindowFromAnySelections(WindowPtr pWin)
 		info.kind = SelectionWindowDestroy;
 		CallCallbacks(&SelectionCallback, &info);
 	    }
+	    dixFreePrivates(CurrentSelections[i].devPrivates);
             CurrentSelections[i].pWin = (WindowPtr)NULL;
             CurrentSelections[i].window = None;
 	    CurrentSelections[i].client = NullClient;
+	    CurrentSelections[i].devPrivates = NULL;
 	}
 }
 
@@ -4042,9 +4048,11 @@ DeleteClientFromAnySelections(ClientPtr client)
 		info.kind = SelectionWindowDestroy;
 		CallCallbacks(&SelectionCallback, &info);
 	    }
+	    dixFreePrivates(CurrentSelections[i].devPrivates);
             CurrentSelections[i].pWin = (WindowPtr)NULL;
             CurrentSelections[i].window = None;
 	    CurrentSelections[i].client = NullClient;
+	    CurrentSelections[i].devPrivates = NULL;
 	}
 }
 
diff --git a/include/selection.h b/include/selection.h
index fbe7cfc..9347376 100644
--- a/include/selection.h
+++ b/include/selection.h
@@ -50,6 +50,7 @@ SOFTWARE.
 ******************************************************************/
 
 #include "dixstruct.h"
+#include "privates.h"
 /*
  *
  *  Selection data structures 
@@ -61,6 +62,9 @@ typedef struct _Selection {
     Window window;
     WindowPtr pWin;
     ClientPtr client;
+    ClientPtr destclient; /* support for redirection */
+    Window destwindow;    /* support for redirection */
+    PrivateRec *devPrivates;
 } Selection;
 
 #endif /* SELECTION_H */
commit 4fa482b4be1150bcffeabb64d018c00ac5951e41
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 21 14:49:56 2007 -0400

    xace: bump major version since the hooks have changed.

diff --git a/Xext/xace.h b/Xext/xace.h
index 020a047..d3d5a84 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #ifdef XACE
 
 #define XACE_EXTENSION_NAME		"XAccessControlExtension"
-#define XACE_MAJOR_VERSION		1
+#define XACE_MAJOR_VERSION		2
 #define XACE_MINOR_VERSION		0
 
 #include "pixmap.h"     /* for DrawablePtr */
commit 9c144f8ac5cea25deaa543767dbaf371d029c608
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 21 14:39:00 2007 -0400

    xace: add XACE_SELECTION_ACCESS hook for selection redirection/access.

diff --git a/Xext/xace.c b/Xext/xace.c
index ee0f39c..2b873cb 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -147,6 +147,16 @@ int XaceHook(int hook, ...)
 	    prv = &rec.rval;
 	    break;
 	}
+	case XACE_SELECTION_ACCESS: {
+	    XaceSelectionAccessRec rec = {
+		va_arg(ap, ClientPtr),
+		va_arg(ap, Selection*),
+		TRUE	/* default allow */
+	    };
+	    calldata = &rec;
+	    prv = &rec.rval;
+	    break;
+	}
 	case XACE_SITE_POLICY: {
 	    XaceSitePolicyRec rec = {
 		va_arg(ap, char*),
diff --git a/Xext/xace.h b/Xext/xace.h
index 7360dae..020a047 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -50,13 +50,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_BACKGRND_ACCESS		7
 #define XACE_EXT_ACCESS			8
 #define XACE_HOSTLIST_ACCESS		9
-#define XACE_SITE_POLICY		10
-#define XACE_DECLARE_EXT_SECURE		11
-#define XACE_AUTH_AVAIL			12
-#define XACE_KEY_AVAIL			13
-#define XACE_AUDIT_BEGIN		14
-#define XACE_AUDIT_END			15
-#define XACE_NUM_HOOKS			16
+#define XACE_SELECTION_ACCESS		10
+#define XACE_SITE_POLICY		11
+#define XACE_DECLARE_EXT_SECURE		12
+#define XACE_AUTH_AVAIL			13
+#define XACE_KEY_AVAIL			14
+#define XACE_AUDIT_BEGIN		15
+#define XACE_AUDIT_END			16
+#define XACE_NUM_HOOKS			17
 
 extern CallbackListPtr XaceHooks[XACE_NUM_HOOKS];
 
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index bd30883..4c480a4 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "gcstruct.h"
 #include "windowstr.h"
 #include "inputstr.h"
+#include "selection.h"
 #include "xace.h"
 
 /* XACE_CORE_DISPATCH */
@@ -93,6 +94,13 @@ typedef struct {
     int rval;
 } XaceHostlistAccessRec;
 
+/* XACE_SELECTION_ACCESS */
+typedef struct {
+    ClientPtr client;
+    Selection *selection;
+    int rval;
+} XaceSelectionAccessRec;
+
 /* XACE_SITE_POLICY */
 typedef struct {
     char *policyString;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index d44687e..498f18a 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1113,7 +1113,8 @@ ProcGetSelectionOwner(register ClientPtr client)
         reply.type = X_Reply;
 	reply.length = 0;
 	reply.sequenceNumber = client->sequence;
-        if (i < NumCurrentSelections)
+        if (i < NumCurrentSelections &&
+	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i]))
             reply.owner = CurrentSelections[i].window;
         else
             reply.owner = None;
@@ -1153,9 +1154,7 @@ ProcConvertSelection(register ClientPtr client)
 	       CurrentSelections[i].selection != stuff->selection) i++;
 	if ((i < NumCurrentSelections) &&
 	    (CurrentSelections[i].window != None) &&
-	    XaceHook(XACE_RESOURCE_ACCESS, client,
-		     CurrentSelections[i].window, RT_WINDOW,
-		     DixReadAccess, CurrentSelections[i].pWin))
+	    XaceHook(XACE_SELECTION_ACCESS, client, &CurrentSelections[i]))
 	{        
 	    event.u.u.type = SelectionRequest;
 	    event.u.selectionRequest.time = stuff->time;
commit 2945deba1d4a7dce4f6dd0c568297a1c537fdfb4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 19 17:09:10 2007 -0400

    xace: drop XACE_WINDOW_INIT hook, it has been superseded by ResourceStateCallback.

diff --git a/Xext/xace.c b/Xext/xace.c
index 6fc5c12..ee0f39c 100644
--- a/Xext/xace.c
+++ b/Xext/xace.c
@@ -182,14 +182,6 @@ int XaceHook(int hook, ...)
 	    calldata = &rec;
 	    break;
 	}
-	case XACE_WINDOW_INIT: {
-	    XaceWindowRec rec = {
-		va_arg(ap, ClientPtr),
-		va_arg(ap, WindowPtr)
-	    };
-	    calldata = &rec;
-	    break;
-	}
 	case XACE_AUDIT_BEGIN: {
 	    XaceAuditRec rec = {
 		va_arg(ap, ClientPtr),
diff --git a/Xext/xace.h b/Xext/xace.h
index 7231b04..7360dae 100644
--- a/Xext/xace.h
+++ b/Xext/xace.h
@@ -54,10 +54,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XACE_DECLARE_EXT_SECURE		11
 #define XACE_AUTH_AVAIL			12
 #define XACE_KEY_AVAIL			13
-#define XACE_WINDOW_INIT		14
-#define XACE_AUDIT_BEGIN		15
-#define XACE_AUDIT_END			16
-#define XACE_NUM_HOOKS			17
+#define XACE_AUDIT_BEGIN		14
+#define XACE_AUDIT_END			15
+#define XACE_NUM_HOOKS			16
 
 extern CallbackListPtr XaceHooks[XACE_NUM_HOOKS];
 
diff --git a/Xext/xacestr.h b/Xext/xacestr.h
index 7114d06..bd30883 100644
--- a/Xext/xacestr.h
+++ b/Xext/xacestr.h
@@ -119,12 +119,6 @@ typedef struct {
     int count;
 } XaceKeyAvailRec;
 
-/* XACE_WINDOW_INIT */
-typedef struct {
-    ClientPtr client;
-    WindowPtr pWin;
-} XaceWindowRec;
-
 /* XACE_AUDIT_BEGIN */
 /* XACE_AUDIT_END */
 typedef struct {
diff --git a/dix/window.c b/dix/window.c
index e33140d..02496f5 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -529,8 +529,6 @@ InitRootWindow(WindowPtr pWin)
     /* We SHOULD check for an error value here XXX */
     (*pScreen->ChangeWindowAttributes)(pWin, backFlag);
 
-    XaceHook(XACE_WINDOW_INIT, serverClient, pWin);
-
     MapWindow(pWin, serverClient);
 }
 
@@ -763,8 +761,6 @@ CreateWindow(Window wid, register WindowPtr pParent, int x, int y, unsigned w,
     REGION_NULL(pScreen, &pWin->winSize);
     REGION_NULL(pScreen, &pWin->borderSize);
 
-    XaceHook(XACE_WINDOW_INIT, client, pWin);
-
     pHead = RealChildHead(pParent);
     if (pHead)
     {
commit 78c962da76efe644b8d485265f1ecdda84b45d27
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 19 17:04:51 2007 -0400

    xselinux: use the new ResourceStateCallback instead of the XACE_WINDOW_INIT hook.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 74d4c60..4056d9e 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1217,26 +1217,34 @@ XSELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 
 /* Labeling callbacks */
 static void
-XSELinuxWindowInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
+XSELinuxResourceState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
-    XaceWindowRec *rec = (XaceWindowRec*)calldata;
+    ResourceStateInfoRec *rec = (ResourceStateInfoRec *)calldata;
+    WindowPtr pWin;
+    ClientPtr client;
     security_context_t ctx;
     int rc;
 
-    if (HAVESTATE(rec->client)) {
-	rc = avc_sid_to_context(SID(rec->client), &ctx);
+    if (rec->type != RT_WINDOW)
+	return;
+
+    pWin = (WindowPtr)rec->value;
+    client = wClient(pWin);
+
+    if (HAVESTATE(client)) {
+	rc = avc_sid_to_context(SID(client), &ctx);
 	if (rc < 0)
 	    FatalError("XSELinux: Failed to get security context!\n");
-	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
+	rc = ChangeWindowProperty(pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, strlen(ctx), ctx, FALSE);
 	freecon(ctx);
     }
     else
-	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
+	rc = ChangeWindowProperty(pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, 10, "UNLABELED!", FALSE);
     if (rc != Success)
 	FatalError("XSELinux: Failed to set context property on window!\n");
-} /* XSELinuxWindowInit */
+} /* XSELinuxResourceState */
 
 static char *XSELinuxKeywords[] = {
 #define XSELinuxKeywordComment 0
@@ -1836,6 +1844,8 @@ XSELinuxExtensionInit(INITARGS)
 
     if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
 	return;
+    if (!AddCallback(&ResourceStateCallback, XSELinuxResourceState, NULL))
+	return;
 
     /* Create atoms for doing window labeling */
     atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1);
@@ -1870,7 +1880,6 @@ XSELinuxExtensionInit(INITARGS)
     XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
     XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
     XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
-    XaceRegisterCallback(XACE_WINDOW_INIT, XSELinuxWindowInit, NULL);
     /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
     XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
 
commit 6a89106e9c963a495fd40427d242ba0abd44f764
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 19 16:51:29 2007 -0400

    xselinux + security: remove confusing CALLBACK macro.

diff --git a/Xext/security.c b/Xext/security.c
index 7202d39..98e91ad 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -83,9 +83,6 @@ RESTYPE SecurityAuthorizationResType; /* resource type for authorizations */
 
 static RESTYPE RTEventClient;
 
-#define CALLBACK(name) static void \
-name(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
-
 /* SecurityAudit
  *
  * Arguments:
@@ -779,7 +776,9 @@ SecurityDetermineEventPropogationLimits(
  *	An audit message is generated if access is denied.
  */
 
-CALLBACK(SecurityCheckDeviceAccess)
+static void
+SecurityCheckDeviceAccess(CallbackListPtr *pcbl, pointer unused,
+			  pointer calldata)
 {
     XaceDeviceAccessRec *rec = (XaceDeviceAccessRec*)calldata;
     ClientPtr client = rec->client;
@@ -955,7 +954,9 @@ SecurityAuditResourceIDAccess(
  *	Disallowed resource accesses are audited.
  */
 
-CALLBACK(SecurityCheckResourceIDAccess)
+static void
+SecurityCheckResourceIDAccess(CallbackListPtr *pcbl, pointer unused,
+			      pointer calldata)
 {
     XaceResourceAccessRec *rec = (XaceResourceAccessRec*)calldata;
     ClientPtr client = rec->client;
@@ -1114,7 +1115,9 @@ CALLBACK(SecurityCheckResourceIDAccess)
  * if it is now zero, the timer for this authorization is started.
  */
 
-CALLBACK(SecurityClientStateCallback)
+static void
+SecurityClientStateCallback(CallbackListPtr *pcbl, pointer unused,
+			    pointer calldata)
 {
     NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
     ClientPtr client = pci->client;
@@ -1171,7 +1174,9 @@ CALLBACK(SecurityClientStateCallback)
     }
 } /* SecurityClientStateCallback */
 
-CALLBACK(SecurityCheckDrawableAccess)
+static void
+SecurityCheckDrawableAccess(CallbackListPtr *pcbl, pointer unused,
+			    pointer calldata)
 {
     XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
 
@@ -1179,7 +1184,9 @@ CALLBACK(SecurityCheckDrawableAccess)
 	rec->rval = FALSE;
 }
 
-CALLBACK(SecurityCheckMapAccess)
+static void
+SecurityCheckMapAccess(CallbackListPtr *pcbl, pointer unused,
+		       pointer calldata)
 {
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
     WindowPtr pWin = rec->pWin;
@@ -1193,7 +1200,9 @@ CALLBACK(SecurityCheckMapAccess)
 	rec->rval = FALSE;
 }
 
-CALLBACK(SecurityCheckBackgrndAccess)
+static void
+SecurityCheckBackgrndAccess(CallbackListPtr *pcbl, pointer unused,
+			    pointer calldata)
 {
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
 
@@ -1201,7 +1210,9 @@ CALLBACK(SecurityCheckBackgrndAccess)
 	rec->rval = FALSE;
 }
 
-CALLBACK(SecurityCheckExtAccess)
+static void
+SecurityCheckExtAccess(CallbackListPtr *pcbl, pointer unused,
+		       pointer calldata)
 {
     XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
 
@@ -1211,7 +1222,9 @@ CALLBACK(SecurityCheckExtAccess)
 	rec->rval = FALSE;
 }
 
-CALLBACK(SecurityCheckHostlistAccess)
+static void
+SecurityCheckHostlistAccess(CallbackListPtr *pcbl, pointer unused,
+			    pointer calldata)
 {
     XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
  
@@ -1227,7 +1240,9 @@ CALLBACK(SecurityCheckHostlistAccess)
     }
 }
 
-CALLBACK(SecurityDeclareExtSecure)
+static void
+SecurityDeclareExtSecure(CallbackListPtr *pcbl, pointer unused,
+			 pointer calldata)
 {
     XaceDeclareExtSecureRec *rec = (XaceDeclareExtSecureRec*)calldata;
 
@@ -1692,7 +1707,9 @@ SecurityMatchString(
 #endif
 
 
-CALLBACK(SecurityCheckPropertyAccess)
+static void
+SecurityCheckPropertyAccess(CallbackListPtr *pcbl, pointer unused,
+			    pointer calldata)
 {    
     XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
     ClientPtr client = rec->client;
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index ab4827e..74d4c60 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -503,8 +503,6 @@ FreeClientState(ClientPtr client)
 #define IDPERM(client, req, field, class, perm) \
     (REQUEST_SIZE_CHECK(client,req) && \
     IDPerm(client, SwapXID(client,((req*)stuff)->field), class, perm))
-#define CALLBACK(name) static void \
-name(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
 
 static int
 CheckSendEventPerms(ClientPtr client)
@@ -632,7 +630,8 @@ CheckSetSelectionOwnerPerms(ClientPtr client)
     return rval;
 }
 
-CALLBACK(XSELinuxCoreDispatch)
+static void
+XSELinuxCoreDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceCoreDispatchRec *rec = (XaceCoreDispatchRec*)calldata;
     ClientPtr client = rec->client;
@@ -1017,7 +1016,8 @@ CALLBACK(XSELinuxCoreDispatch)
 	rec->rval = FALSE;
 }
 
-CALLBACK(XSELinuxExtDispatch)
+static void
+XSELinuxExtDispatch(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
     ClientPtr client = rec->client;
@@ -1058,7 +1058,8 @@ CALLBACK(XSELinuxExtDispatch)
 	ErrorF("No client state in extension dispatcher!\n");
 } /* XSELinuxExtDispatch */
 
-CALLBACK(XSELinuxProperty)
+static void
+XSELinuxProperty(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
     WindowPtr pWin = rec->pWin;
@@ -1106,7 +1107,8 @@ CALLBACK(XSELinuxProperty)
     sidput(propsid);
 } /* XSELinuxProperty */
 
-CALLBACK(XSELinuxResLookup)
+static void
+XSELinuxResLookup(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceResourceAccessRec *rec = (XaceResourceAccessRec*)calldata;
     ClientPtr client = rec->client;
@@ -1147,7 +1149,8 @@ CALLBACK(XSELinuxResLookup)
 	rec->rval = FALSE;
 } /* XSELinuxResLookup */
 
-CALLBACK(XSELinuxMap)
+static void
+XSELinuxMap(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
     if (!IDPerm(rec->client, rec->pWin->drawable.id,
@@ -1155,7 +1158,8 @@ CALLBACK(XSELinuxMap)
 	rec->rval = FALSE;
 } /* XSELinuxMap */
 
-CALLBACK(XSELinuxBackgrnd)
+static void
+XSELinuxBackgrnd(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
     if (!IDPerm(rec->client, rec->pWin->drawable.id,
@@ -1163,7 +1167,8 @@ CALLBACK(XSELinuxBackgrnd)
 	rec->rval = FALSE;
 } /* XSELinuxBackgrnd */
 
-CALLBACK(XSELinuxDrawable)
+static void
+XSELinuxDrawable(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
     if (!IDPerm(rec->client, rec->pDraw->id,
@@ -1171,7 +1176,8 @@ CALLBACK(XSELinuxDrawable)
 	rec->rval = FALSE;
 } /* XSELinuxDrawable */
 
-CALLBACK(XSELinuxHostlist)
+static void
+XSELinuxHostlist(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
     access_vector_t perm = (rec->access_mode == DixReadAccess) ?
@@ -1182,7 +1188,8 @@ CALLBACK(XSELinuxHostlist)
 } /* XSELinuxHostlist */
 
 /* Extension callbacks */
-CALLBACK(XSELinuxClientState)
+static void
+XSELinuxClientState(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
     ClientPtr client = pci->client;
@@ -1209,7 +1216,8 @@ CALLBACK(XSELinuxClientState)
 } /* XSELinuxClientState */
 
 /* Labeling callbacks */
-CALLBACK(XSELinuxWindowInit)
+static void
+XSELinuxWindowInit(CallbackListPtr *pcbl, pointer unused, pointer calldata)
 {
     XaceWindowRec *rec = (XaceWindowRec*)calldata;
     security_context_t ctx;
commit fe05ba75a10ec080e7ec34bff6936103185586b3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 8 12:14:30 2007 -0500

    devPrivates rework: pass address of pointer to private callbacks instead of
    the pointer itself.

diff --git a/dix/privates.c b/dix/privates.c
index 29e261f..8aab32d 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -117,7 +117,7 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
 
     /* call any init funcs and return */
     if (item) {
-	PrivateCallbackRec calldata = { key, ptr->value };
+	PrivateCallbackRec calldata = { key, &ptr->value };
 	CallCallbacks(&item->initfuncs, &calldata);
     }
     return &ptr->value;
@@ -138,7 +138,7 @@ dixFreePrivates(PrivateRec *privates)
 	item = findItem(ptr->key);
 	if (item) {
 	    calldata.key = ptr->key;
-	    calldata.value = ptr->value;
+	    calldata.value = &ptr->value;
 	    CallCallbacks(&item->deletefuncs, &calldata);
 	}
     }
diff --git a/include/privates.h b/include/privates.h
index 6071e39..e57f167 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -112,7 +112,7 @@ dixSetPrivate(PrivateRec **privates, devprivate_key_t *const key, pointer val)
  */
 typedef struct _PrivateCallback {
     devprivate_key_t *key;	/* private registration key */
-    pointer value;		/* pointer to private */
+    pointer *value;		/* address of private pointer */
 } PrivateCallbackRec;
 
 extern int
commit 18339375cd332f0ab1cbdade3dcd9140212ce1ca
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 8 12:14:06 2007 -0500

    xselinux: remove context validation function for now.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 5b77269..ab4827e 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -57,42 +57,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define XSELINUXCONFIGFILE  NULL
 #endif
 
-
-/* Make sure a locally connecting client has a valid context.  The context
- * for this client is retrieved again later on in AssignClientState(), but
- * by that point it's too late to reject the client.
- */
-static char *
-XSELinuxValidContext (ClientPtr client)
-{
-    security_context_t ctx = NULL;
-    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
-    char reason[256];
-    char *ret = (char *)NULL;
-
-    if (_XSERVTransIsLocal(ci))
-    {
-        int fd = _XSERVTransGetConnectionNumber(ci);
-        if (getpeercon(fd, &ctx) < 0)
-        {
-            snprintf(reason, sizeof(reason), "Failed to retrieve SELinux context from socket");
-            ret = reason;
-            goto out;
-        }
-        if (security_check_context(ctx))
-        {
-            snprintf(reason, sizeof(reason), "Client's SELinux context is invalid: %s", ctx);
-            ret = reason;
-        }
-
-        freecon(ctx);
-    }
-
-out:
-    return ret;
-}
-
-
 /* devPrivates in client and extension */
 static int clientPrivateIndex;
 static int extnsnPrivateIndex;
commit b9cff1670f29949a5bc41afc19aca443f434febb
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 8 12:13:52 2007 -0500

    Add ResourceStateCallback similar in function to ClientStateCallback.

diff --git a/dix/resource.c b/dix/resource.c
index 2cad7c0..edf32ff 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -193,6 +193,17 @@ _X_EXPORT RESTYPE TypeMask;
 
 static DeleteType *DeleteFuncs = (DeleteType *)NULL;
 
+_X_EXPORT CallbackListPtr ResourceStateCallback;
+
+static _X_INLINE void
+CallResourceStateCallback(ResourceState state, ResourceRec *res)
+{
+    if (ResourceStateCallback) {
+	ResourceStateInfoRec rsi = { state, res->id, res->type, res->value };
+	CallCallbacks(&ResourceStateCallback, &rsi);
+    }
+}
+
 #ifdef XResExtension
 
 _X_EXPORT Atom * ResourceNames = NULL;
@@ -492,6 +503,7 @@ AddResource(XID id, RESTYPE type, pointer value)
     rrec->elements++;
     if (!(id & SERVER_BIT) && (id >= rrec->expectID))
 	rrec->expectID = id + 1;
+    CallResourceStateCallback(ResourceStateAdding, res);
     return TRUE;
 }
 
@@ -572,6 +584,9 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
 #endif		    
 		*prev = res->next;
 		elements = --*eltptr;
+
+		CallResourceStateCallback(ResourceStateFreeing, res);
+
 		if (rtype & RC_CACHED)
 		    FlushClientCaches(res->id);
 		if (rtype != skipDeleteFuncType)
@@ -616,6 +631,9 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 			      res->value, TypeNameString(res->type));
 #endif		    		    
 		*prev = res->next;
+
+		CallResourceStateCallback(ResourceStateFreeing, res);
+
 		if (type & RC_CACHED)
 		    FlushClientCaches(res->id);
 		if (!skipFree)
@@ -782,6 +800,9 @@ FreeClientNeverRetainResources(ClientPtr client)
 			      this->value, TypeNameString(this->type));
 #endif		    
 		*prev = this->next;
+
+		CallResourceStateCallback(ResourceStateFreeing, this);
+
 		if (rtype & RC_CACHED)
 		    FlushClientCaches(this->id);
 		(*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
@@ -832,6 +853,9 @@ FreeClientResources(ClientPtr client)
 			  this->value, TypeNameString(this->type));
 #endif		    
 	    *head = this->next;
+
+	    CallResourceStateCallback(ResourceStateFreeing, this);
+
 	    if (rtype & RC_CACHED)
 		FlushClientCaches(this->id);
 	    (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index e6c2baa..1732d1f 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -300,6 +300,7 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(FindAllClientResources)
     SYMVAR(lastResourceType)
     SYMVAR(TypeMask)
+    SYMVAR(ResourceStateCallback)
 #ifdef RES
     SYMFUNC(RegisterResourceName)
     SYMVAR(ResourceNames)
diff --git a/include/resource.h b/include/resource.h
index 3231e8c..9949dd2 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -120,6 +120,19 @@ typedef unsigned long RESTYPE;
 
 #define BAD_RESOURCE 0xe0000000
 
+/* Resource state callback */
+extern CallbackListPtr ResourceStateCallback;
+
+typedef enum {ResourceStateAdding,
+	      ResourceStateFreeing} ResourceState;
+
+typedef struct {
+    ResourceState state;
+    XID id;
+    RESTYPE type;
+    pointer value;
+} ResourceStateInfoRec;
+
 typedef int (*DeleteType)(
     pointer /*value*/,
     XID /*id*/);
commit 2fcb45eb5dc1803b372df8b5765f6a43bea83611
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 8 12:13:36 2007 -0500

    devPrivates rework: redo field offset registration, drop RC_PRIVATES class.

diff --git a/dix/privates.c b/dix/privates.c
index 01d327b..29e261f 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -195,12 +195,14 @@ dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
 
     /* resize offsets table if necessary */
     while (type >= offsetsSize) {
-	offsets = (unsigned *)xrealloc(offsets,
-				       offsetsSize * 2 * sizeof(unsigned));
+	unsigned i = offsetsSize * 2 * sizeof(int);
+	offsets = (unsigned *)xrealloc(offsets, i);
 	if (!offsets) {
 	    offsetsSize = 0;
 	    return FALSE;
 	}
+	for (i=offsetsSize; i < 2*offsetsSize; i++)
+	    offsets[i] = -1;
 	offsetsSize *= 2;
     }
 
@@ -208,10 +210,9 @@ dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
     return TRUE;
 }
 
-_X_EXPORT unsigned
+_X_EXPORT int
 dixLookupPrivateOffset(RESTYPE type)
 {
-    assert(type & RC_PRIVATES);
     type = type & TypeMask;
     assert(type < offsetsSize);
     return offsets[type];
@@ -233,19 +234,22 @@ int
 dixResetPrivates(void)
 {
     PrivateDescRec *next;
+    unsigned i;
+
+    /* reset internal structures */
     while (items) {
 	next = items->next;
 	xfree(items);
 	items = next;
     }
-
     if (offsets)
 	xfree(offsets);
-
     offsetsSize = 16;
     offsets = (unsigned *)xalloc(offsetsSize * sizeof(unsigned));
     if (!offsets)
 	return FALSE;
+    for (i=0; i < offsetsSize; i++)
+	offsets[i] = -1;
 
     /* reset legacy devPrivates support */
     if (!ResetExtensionPrivates() || !ResetClientPrivates())
diff --git a/include/privates.h b/include/privates.h
index d1e269b..6071e39 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -142,9 +142,10 @@ dixResetPrivates(void);
  */
 
 /*
- * Looks up the offset where the devPrivates field is located by type.
+ * Looks up the offset where the devPrivates field is located.
+ * Returns -1 if no offset has been registered for the resource type.
  */
-extern unsigned
+extern int
 dixLookupPrivateOffset(RESTYPE type);
 
 /*
diff --git a/include/resource.h b/include/resource.h
index 40259ac..3231e8c 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -66,12 +66,7 @@ typedef unsigned long RESTYPE;
  *  Extensions can use this too!
  */
 #define RC_NEVERRETAIN	((RESTYPE)1<<29)
-/*  Use class RC_PRIVATES for resources that support extra private data.
- *  Resources having this class must provide a field of type PrivateRec *.
- *  Refer to the X server documentation on devPrivates for the details.
- */
-#define RC_PRIVATES	((RESTYPE)1<<28)
-#define RC_LASTPREDEF	RC_PRIVATES
+#define RC_LASTPREDEF	RC_NEVERRETAIN
 #define RC_ANY		(~(RESTYPE)0)
 
 /* types for Resource routines */
commit 947f8d249bac61beb10669d935888c4c280b5062
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 8 12:13:18 2007 -0500

    devPrivates rework: redo interface again, dropping parent and type parameters
    as well as preallocation routine.

diff --git a/dix/privates.c b/dix/privates.c
index 57da0fa..01d327b 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -48,8 +48,6 @@ from The Open Group.
 
 typedef struct _PrivateDesc {
     devprivate_key_t *key;
-    RESTYPE type;
-    pointer parent;
     unsigned size;
     CallbackListPtr initfuncs;
     CallbackListPtr deletefuncs;
@@ -72,15 +70,13 @@ findItem(devprivate_key_t *const key)
 }
 
 /*
- * Request pre-allocated space in resources of a given type.
+ * Request pre-allocated space.
  */
 _X_EXPORT int
-dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
-		  unsigned size, pointer parent)
+dixRequestPrivate(devprivate_key_t *const key, unsigned size)
 {
     PrivateDescRec *item = findItem(key);
     if (item) {
-	assert(item->type == type);
 	if (size > item->size)
 	    item->size = size;
     } else {
@@ -91,8 +87,6 @@ dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
 
 	/* add privates descriptor */
 	item->key = key;
-	item->type = type;
-	item->parent = parent;
 	item->size = size;
 	item->next = items;
 	items = item;
@@ -116,7 +110,6 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
     ptr = (PrivateRec *)xalloc(size);
     if (!ptr)
 	return NULL;
-    memset(ptr, 0, size);
     ptr->key = key;
     ptr->value = (size > sizeof(PrivateRec)) ? (ptr + 1) : NULL;
     ptr->next = *privates;
@@ -131,57 +124,6 @@ dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
 }
 
 /*
- * Allocates pre-requested privates in a single chunk.
- */
-_X_EXPORT PrivateRec *
-dixAllocatePrivates(RESTYPE type, pointer parent)
-{
-    unsigned count = 0, size = 0;
-    PrivateCallbackRec calldata;
-    PrivateDescRec *item;
-    PrivateRec *ptr;
-    char *value;
-
-    /* first pass figures out total size */
-    for (item = items; item; item = item->next)
-	if ((item->type == type || item->type == RC_ANY) &&
-	    (item->parent == NULL || item->parent == parent)) {
-
-	    size += sizeof(PrivateRec) + item->size;
-	    count++;
-	}
-
-    /* allocate one chunk of memory for everything */
-    ptr = (PrivateRec *)xalloc(size);
-    if (!ptr)
-	return NULL;
-    memset(ptr, 0, size);
-    value = (char *)(ptr + count);
-
-    /* second pass sets up records and calls init funcs */
-    count = 0;
-    for (item = items; item; item = item->next)
-	if ((item->type == type || item->type == RC_ANY) &&
-	    (item->parent == NULL || item->parent == parent)) {
-
-	    ptr[count].key = calldata.key = item->key;
-	    ptr[count].dontfree = (count > 0);
-	    ptr[count].value = calldata.value = (items->size ? value : NULL);
-	    ptr[count].next = ptr + (count + 1);
-
-	    CallCallbacks(&item->initfuncs, &calldata);
-
-	    count++;
-	    value += item->size;
-	}
-
-    if (count > 0)
-	ptr[count-1].next = NULL;
-
-    return ptr;
-}
-
-/*
  * Called to free privates at object deletion time.
  */
 _X_EXPORT void
@@ -204,16 +146,9 @@ dixFreePrivates(PrivateRec *privates)
     /* second pass frees the memory */
     ptr = privates;
     while (ptr) {
-	if (ptr->dontfree)
-	    ptr = ptr->next;
-	else {
-	    next = ptr->next;
-	    while (next && next->dontfree)
-		next = next->next;
-
-	    xfree(ptr);
-	    ptr = next;
-	}
+	next = ptr->next;
+	xfree(ptr);
+	ptr = next;
     }
 }
 
@@ -225,8 +160,11 @@ dixRegisterPrivateInitFunc(devprivate_key_t *const key,
 			   CallbackProcPtr callback, pointer data)
 {
     PrivateDescRec *item = findItem(key);
-    if (!item)
-	return FALSE;
+    if (!item) {
+	if (!dixRequestPrivate(key, 0))
+	    return FALSE;
+	item = findItem(key);
+    }
     return AddCallback(&item->initfuncs, callback, data);
 }
 
@@ -235,8 +173,11 @@ dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 			     CallbackProcPtr callback, pointer data)
 {
     PrivateDescRec *item = findItem(key);
-    if (!item)
-	return FALSE;
+    if (!item) {
+	if (!dixRequestPrivate(key, 0))
+	    return FALSE;
+	item = findItem(key);
+    }
     return AddCallback(&item->deletefuncs, callback, data);
 }
 
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 6b52aea..e6c2baa 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -264,7 +264,6 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(dixRegisterPrivateInitFunc)
     SYMFUNC(dixRegisterPrivateDeleteFunc)
     SYMFUNC(dixAllocatePrivate)
-    SYMFUNC(dixAllocatePrivates)
     SYMFUNC(dixFreePrivates)
     SYMFUNC(dixRegisterPrivateOffset)
     SYMFUNC(dixLookupPrivateOffset)
diff --git a/include/privates.h b/include/privates.h
index 9c95350..d1e269b 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -19,13 +19,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * STUFF FOR PRIVATES
  *****************************************************************/
 
-typedef struct _PrivateKey {
-    int unused;
-} devprivate_key_t;
+typedef char devprivate_key_t;
 
 typedef struct _Private {
     devprivate_key_t	*key;
-    int			dontfree;
     pointer		value;
     struct _Private	*next;
 } PrivateRec;
@@ -39,11 +36,10 @@ typedef struct _Private {
 
 /*
  * Request pre-allocated private space for your driver/module.
- * A non-null pScreen argument restricts to objects on a given screen.
+ * Calling this is not necessary if only a pointer by itself is needed.
  */
 extern int
-dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
-		  unsigned size, pointer pScreen);
+dixRequestPrivate(devprivate_key_t *const key, unsigned size);
 
 /*
  * Allocates a new private and attaches it to an existing object.
@@ -128,13 +124,7 @@ dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 			     CallbackProcPtr callback, pointer userdata);
 
 /*
- * Allocates all pre-requested private space in one chunk.
- */
-extern PrivateRec *
-dixAllocatePrivates(RESTYPE type, pointer parent);
-
-/*
- * Frees any private space that is not part of an object.
+ * Frees private data.
  */
 extern void
 dixFreePrivates(PrivateRec *privates);
commit c45f6762080ef00b41d9f73441a9f0e605253008
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 7 11:22:42 2007 -0500

    devPrivates rework: hook up new mechanism in backwards-compatibility mode
    on existing structures that support devPrivates.

diff --git a/dix/devices.c b/dix/devices.c
index 9f42184..2e04403 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -124,8 +124,15 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 #ifdef XKB
     dev->xkb_interest = NULL;
 #endif
-    dev->nPrivates = 0;
-    dev->devPrivates = NULL;
+    /* must pre-allocate one private for the new devPrivates support */
+    dev->nPrivates = 1;
+    dev->devPrivates = (DevUnion *)xalloc(sizeof(DevUnion));
+    if (!dev->devPrivates) {
+	xfree(dev);
+	return NULL;
+    }
+    dev->devPrivates[0].ptr = NULL;
+
     dev->unwrapProc = NULL;
     dev->coreEvents = TRUE;
     dev->inited = FALSE;
diff --git a/dix/main.c b/dix/main.c
index c40dfdd..852cbcb 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -715,18 +715,28 @@ AddScreen(
 	xfree(pScreen);
 	return -1;
     }
+
+    /* must pre-allocate one private for the new devPrivates support */
+    pScreen->WindowPrivateLen = 1;
+    pScreen->WindowPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->totalWindowSize = PadToLong(sizeof(WindowRec)) + sizeof(DevUnion);
+    pScreen->GCPrivateLen = 1;
+    pScreen->GCPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->totalGCSize = PadToLong(sizeof(GC)) + sizeof(DevUnion);
+    pScreen->PixmapPrivateLen = 1;
+    pScreen->PixmapPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->totalPixmapSize = BitmapBytePad(8 * (sizeof(PixmapRec) +
+						  sizeof(DevUnion)));
+    if (pScreen->WindowPrivateSizes && pScreen->GCPrivateSizes &&
+	pScreen->PixmapPrivateSizes)
+	*pScreen->WindowPrivateSizes = *pScreen->GCPrivateSizes =
+	    *pScreen->PixmapPrivateSizes = 0;
+    else {
+	xfree(pScreen);
+	return -1;
+    }
+
     pScreen->myNum = i;
-    pScreen->WindowPrivateLen = 0;
-    pScreen->WindowPrivateSizes = (unsigned *)NULL;
-    pScreen->totalWindowSize =
-        ((sizeof(WindowRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
-    pScreen->GCPrivateLen = 0;
-    pScreen->GCPrivateSizes = (unsigned *)NULL;
-    pScreen->totalGCSize =
-        ((sizeof(GC) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
-    pScreen->PixmapPrivateLen = 0;
-    pScreen->PixmapPrivateSizes = (unsigned *)NULL;
-    pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
     
diff --git a/dix/privates.c b/dix/privates.c
index 48ba675..57da0fa 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -279,8 +279,8 @@ dixLookupPrivateOffset(RESTYPE type)
 /*
  * Called from the main loop to reset the subsystem.
  */
-static void ResetExtensionPrivates(void);
-static void ResetClientPrivates(void);
+static int ResetExtensionPrivates(void);
+static int ResetClientPrivates(void);
 static void ResetScreenPrivates(void);
 static void ResetWindowPrivates(void);
 static void ResetGCPrivates(void);
@@ -307,8 +307,8 @@ dixResetPrivates(void)
 	return FALSE;
 
     /* reset legacy devPrivates support */
-    ResetExtensionPrivates();
-    ResetClientPrivates();
+    if (!ResetExtensionPrivates() || !ResetClientPrivates())
+	return FALSE;
     ResetScreenPrivates();
     ResetWindowPrivates();
     ResetGCPrivates();
@@ -317,10 +317,14 @@ dixResetPrivates(void)
     ResetDevicePrivateIndex();
 
     /* register basic resource offsets */
-    if (!dixRegisterPrivateOffset(RT_WINDOW, offsetof(WindowRec,devPrivates)))
-	return FALSE;
-
-    return TRUE;
+    return dixRegisterPrivateOffset(RT_WINDOW,
+				    offsetof(WindowRec, devPrivates)) &&
+	dixRegisterPrivateOffset(RT_PIXMAP,
+				 offsetof(PixmapRec, devPrivates)) &&
+	dixRegisterPrivateOffset(RT_GC,
+				 offsetof(GC, devPrivates)) &&
+	dixRegisterPrivateOffset(RT_COLORMAP,
+				 offsetof(ColormapRec, devPrivates));
 }
 
 /*
@@ -343,15 +347,18 @@ int extensionPrivateLen;
 unsigned *extensionPrivateSizes;
 unsigned totalExtensionSize;
 
-static void
+static int
 ResetExtensionPrivates()
 {
-    extensionPrivateCount = 0;
-    extensionPrivateLen = 0;
+    extensionPrivateCount = 1;
+    extensionPrivateLen = 1;
     xfree(extensionPrivateSizes);
-    extensionPrivateSizes = (unsigned *)NULL;
-    totalExtensionSize =
-	((sizeof(ExtensionEntry) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
+    extensionPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    if (!extensionPrivateSizes)
+	return FALSE;
+    *extensionPrivateSizes = 0;
+    totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
+    return TRUE;
 }
 
 _X_EXPORT int
@@ -400,15 +407,18 @@ int clientPrivateLen;
 unsigned *clientPrivateSizes;
 unsigned totalClientSize;
 
-static void
+static int
 ResetClientPrivates()
 {
-    clientPrivateCount = 0;
-    clientPrivateLen = 0;
+    clientPrivateCount = 1;
+    clientPrivateLen = 1;
     xfree(clientPrivateSizes);
-    clientPrivateSizes = (unsigned *)NULL;
-    totalClientSize =
-	((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
+    clientPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    if (!clientPrivateSizes)
+	return FALSE;
+    *clientPrivateSizes = 0;
+    totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
+    return TRUE;
 }
 
 _X_EXPORT int
@@ -457,7 +467,7 @@ int  screenPrivateCount;
 static void
 ResetScreenPrivates()
 {
-    screenPrivateCount = 0;
+    screenPrivateCount = 1;
 }
 
 /* this can be called after some screens have been created,
@@ -499,7 +509,7 @@ static int  windowPrivateCount;
 static void
 ResetWindowPrivates()
 {
-    windowPrivateCount = 0;
+    windowPrivateCount = 1;
 }
 
 _X_EXPORT int
@@ -549,7 +559,7 @@ static int  gcPrivateCount;
 static void
 ResetGCPrivates()
 {
-    gcPrivateCount = 0;
+    gcPrivateCount = 1;
 }
 
 _X_EXPORT int
@@ -598,7 +608,7 @@ static int  pixmapPrivateCount;
 static void
 ResetPixmapPrivates()
 {
-    pixmapPrivateCount = 0;
+    pixmapPrivateCount = 1;
 }
 
 _X_EXPORT int
@@ -649,7 +659,7 @@ int  colormapPrivateCount;
 static void
 ResetColormapPrivates()
 {
-    colormapPrivateCount = 0;
+    colormapPrivateCount = 1;
 }
 
 
@@ -734,5 +744,5 @@ AllocateDevicePrivate(DeviceIntPtr device, int index)
 static void
 ResetDevicePrivateIndex(void)
 {
-    devicePrivateIndex = 0;
+    devicePrivateIndex = 1;
 }
diff --git a/include/privates.h b/include/privates.h
index 898fdd9..9c95350 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -31,6 +31,13 @@ typedef struct _Private {
 } PrivateRec;
 
 /*
+ * Backwards compatibility macro.  Use to get the proper PrivateRec
+ * reference from any of the structure types that supported the old
+ * devPrivates mechanism.
+ */
+#define DEVPRIV_PTR(foo) ((PrivateRec **)(&(foo)->devPrivates[0].ptr))
+
+/*
  * Request pre-allocated private space for your driver/module.
  * A non-null pScreen argument restricts to objects on a given screen.
  */
@@ -156,4 +163,7 @@ dixLookupPrivateOffset(RESTYPE type);
 extern int
 dixRegisterPrivateOffset(RESTYPE type, unsigned offset);
 
+/* Used by the legacy support, don't rely on this being here */
+#define PadToLong(w) ((((w) + sizeof(long)-1) / sizeof(long)) * sizeof(long))
+
 #endif /* PRIVATES_H */
commit aaef4d6a4121d9341b670a0ce8fabc3b491049cf
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 7 09:57:02 2007 -0500

    devPrivates rework: move reset functions into a single call.

diff --git a/dix/main.c b/dix/main.c
index eb75cf5..c40dfdd 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -359,15 +359,7 @@ main(int argc, char *argv[], char *envp[])
 	InitGlyphCaching();
 	if (!dixResetPrivates())
 	    FatalError("couldn't init private data storage");
-	ResetExtensionPrivates();
-	ResetClientPrivates();
-	ResetScreenPrivates();
-	ResetWindowPrivates();
-	ResetGCPrivates();
-	ResetPixmapPrivates();
-	ResetColormapPrivates();
 	ResetFontPrivateIndex();
-	ResetDevicePrivateIndex();
 	InitCallbackManager();
 	InitVisualWrap();
 	InitOutput(&screenInfo, argc, argv);
diff --git a/dix/privates.c b/dix/privates.c
index 0722d9f..48ba675 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -279,6 +279,15 @@ dixLookupPrivateOffset(RESTYPE type)
 /*
  * Called from the main loop to reset the subsystem.
  */
+static void ResetExtensionPrivates(void);
+static void ResetClientPrivates(void);
+static void ResetScreenPrivates(void);
+static void ResetWindowPrivates(void);
+static void ResetGCPrivates(void);
+static void ResetPixmapPrivates(void);
+static void ResetColormapPrivates(void);
+static void ResetDevicePrivateIndex(void);
+
 int
 dixResetPrivates(void)
 {
@@ -297,6 +306,16 @@ dixResetPrivates(void)
     if (!offsets)
 	return FALSE;
 
+    /* reset legacy devPrivates support */
+    ResetExtensionPrivates();
+    ResetClientPrivates();
+    ResetScreenPrivates();
+    ResetWindowPrivates();
+    ResetGCPrivates();
+    ResetPixmapPrivates();
+    ResetColormapPrivates();
+    ResetDevicePrivateIndex();
+
     /* register basic resource offsets */
     if (!dixRegisterPrivateOffset(RT_WINDOW, offsetof(WindowRec,devPrivates)))
 	return FALSE;
@@ -324,7 +343,7 @@ int extensionPrivateLen;
 unsigned *extensionPrivateSizes;
 unsigned totalExtensionSize;
 
-void
+static void
 ResetExtensionPrivates()
 {
     extensionPrivateCount = 0;
@@ -381,7 +400,7 @@ int clientPrivateLen;
 unsigned *clientPrivateSizes;
 unsigned totalClientSize;
 
-void
+static void
 ResetClientPrivates()
 {
     clientPrivateCount = 0;
@@ -435,7 +454,7 @@ AllocateClientPrivate(int index2, unsigned amount)
 
 int  screenPrivateCount;
 
-void
+static void
 ResetScreenPrivates()
 {
     screenPrivateCount = 0;
@@ -477,7 +496,7 @@ AllocateScreenPrivateIndex()
 
 static int  windowPrivateCount;
 
-void
+static void
 ResetWindowPrivates()
 {
     windowPrivateCount = 0;
@@ -527,7 +546,7 @@ AllocateWindowPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
 
 static int  gcPrivateCount;
 
-void
+static void
 ResetGCPrivates()
 {
     gcPrivateCount = 0;
@@ -576,7 +595,7 @@ AllocateGCPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
  */
 static int  pixmapPrivateCount;
 
-void
+static void
 ResetPixmapPrivates()
 {
     pixmapPrivateCount = 0;
@@ -627,7 +646,7 @@ AllocatePixmapPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
 
 int  colormapPrivateCount;
 
-void
+static void
 ResetColormapPrivates()
 {
     colormapPrivateCount = 0;
@@ -712,7 +731,7 @@ AllocateDevicePrivate(DeviceIntPtr device, int index)
     }
 }
 
-void
+static void
 ResetDevicePrivateIndex(void)
 {
     devicePrivateIndex = 0;
diff --git a/include/dix.h b/include/dix.h
index 5c2c5b8..13f3c05 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -591,8 +591,6 @@ void
 ScreenRestructured (ScreenPtr pScreen);
 #endif
 
-extern void ResetClientPrivates(void);
-
 extern int AllocateClientPrivateIndex(void);
 
 extern Bool AllocateClientPrivate(
diff --git a/include/extension.h b/include/extension.h
index 74975c5..27decc1 100644
--- a/include/extension.h
+++ b/include/extension.h
@@ -58,8 +58,6 @@ extern Bool EnableDisableExtension(char *name, Bool enable);
 
 extern void EnableDisableExtensionError(char *name, Bool enable);
 
-extern void ResetExtensionPrivates(void);
-
 extern int AllocateExtensionPrivateIndex(void);
 
 extern Bool AllocateExtensionPrivate(
diff --git a/include/input.h b/include/input.h
index fc607d3..2350a24 100644
--- a/include/input.h
+++ b/include/input.h
@@ -160,7 +160,6 @@ typedef struct {
 
 extern int AllocateDevicePrivateIndex(void);
 extern Bool AllocateDevicePrivate(DeviceIntPtr device, int index);
-extern void ResetDevicePrivateIndex(void);
 
 extern KeybdCtrl	defaultKeyboardControl;
 extern PtrCtrl		defaultPointerControl;
diff --git a/include/screenint.h b/include/screenint.h
index 1f1434a..bf8da44 100644
--- a/include/screenint.h
+++ b/include/screenint.h
@@ -55,12 +55,8 @@ typedef struct _Visual *VisualPtr;
 typedef struct _Depth  *DepthPtr;
 typedef struct _Screen *ScreenPtr;
 
-extern void ResetScreenPrivates(void);
-
 extern int AllocateScreenPrivateIndex(void);
 
-extern void ResetWindowPrivates(void);
-
 extern int AllocateWindowPrivateIndex(void);
 
 extern Bool AllocateWindowPrivate(
@@ -68,8 +64,6 @@ extern Bool AllocateWindowPrivate(
     int /* index */,
     unsigned /* amount */);
 
-extern void ResetGCPrivates(void);
-
 extern int AllocateGCPrivateIndex(void);
 
 extern Bool AllocateGCPrivate(
@@ -86,8 +80,6 @@ extern int AddScreen(
     int /*argc*/,
     char** /*argv*/);
 
-extern void ResetPixmapPrivates(void);
-
 extern int AllocatePixmapPrivateIndex(void);
 
 extern Bool AllocatePixmapPrivate(
@@ -95,8 +87,6 @@ extern Bool AllocatePixmapPrivate(
     int /* index */,
     unsigned /* amount */);
 
-extern void ResetColormapPrivates(void);
-
 
 typedef struct _ColormapRec *ColormapPtr;
 typedef int (*InitCmapPrivFunc)(ColormapPtr, int);
commit bb111291d854b4329e47367ce3c67e8a2785e6e9
Merge: 74175e0... e9bfb2b...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Mar 7 09:03:46 2007 -0500

    Merge branch 'master' into XACE-SELINUX

commit 74175e0af74c530cb712a6772d3c5d61d1be9748
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 5 12:34:37 2007 -0500

    devPrivates rework: remove some debugging code from dixFreePrivates.

diff --git a/dix/privates.c b/dix/privates.c
index c4ecf6a..a12c8bf 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -215,9 +215,6 @@ dixFreePrivates(PrivateRec *privates)
 	    ptr = next;
 	}
     }
-
-    /* no more use of privates permitted */
-    *privates = NULL;
 }
 
 /*
commit 23fc429aad5b2721911862617772c314e1036bb0
Merge: e684824... fe7b8f4...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Mon Mar 5 12:18:54 2007 -0500

    Merge branch 'master' into XACE-SELINUX

diff --cc configure.ac
index 3631576,fe77709..a7d5c6f
--- a/configure.ac
+++ b/configure.ac
@@@ -1244,39 -1255,8 +1269,8 @@@ if test "x$XORG" = xyes -o "x$XGL" = xy
  	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
  	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
  	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
 -	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $OS_LIB"
 +	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB $OS_LIB"
  
- 	if test "x$DGA" = xauto; then
- 		PKG_CHECK_MODULES(DGA, xf86dgaproto, [DGA=yes], [DGA=no])
- 	fi
- 	if test "x$DGA" = xyes; then
- 		XORG_MODULES="$XORG_MODULES xf86dgaproto"
- 		AC_DEFINE(DGA, 1, [Support DGA extension])
- 		AC_DEFINE(XFreeXDGA, 1, [Build XDGA support])
- 	fi
- 
- 	if test "x$XF86MISC" = xauto; then
- 		PKG_CHECK_MODULES(XF86MISC, xf86miscproto, [XF86MISC=yes], [XF86MISC=no])
- 	fi
- 	if test "x$XF86MISC" = xyes; then
- 		XORG_MODULES="$XORG_MODULES xf86miscproto"
- 		AC_DEFINE(XF86MISC, 1, [Support XFree86 miscellaneous extensions])
- 	fi
- 
- 	if test "x$XF86VIDMODE" = xauto; then
- 		PKG_CHECK_MODULES(XF86VIDMODE, xf86vidmodeproto, [XF86VIDMODE=yes], [XF86VIDMODE=no])
- 	fi
- 	if test "x$XF86VIDMODE" = xyes; then
- 		XORG_MODULES="$XORG_MODULES xf86vidmodeproto"
- 		AC_DEFINE(XF86VIDMODE, 1, [Support XFree86 Video Mode extension])
- 	fi
- 
- 	if test -n "$XORG_MODULES"; then
- 	        PKG_CHECK_MODULES(XORG_MODULES, [$XORG_MODULES])
- 	        XORG_CFLAGS="$XORG_CFLAGS $XORG_MODULES_CFLAGS"
- 	        XORG_LIBS="$XORG_LIBS $XORG_MODULES_LIBS"
- 	fi
- 
  dnl Check to see if dlopen is in default libraries (like Solaris, which
  dnl has it in libc), or if libdl is needed to get it.
  	AC_CHECK_FUNC([dlopen], [], 
commit e684824709fa8ffe03dde3c8dfbc58c267515a4f
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 1 15:00:02 2007 -0500

    devPrivates rework: redo interface and implementation.

diff --git a/dix/main.c b/dix/main.c
index b5954af..ed5e358 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -357,7 +357,8 @@ main(int argc, char *argv[], char *envp[])
 	InitAtoms();
 	InitEvents();
 	InitGlyphCaching();
-	dixResetPrivates();
+	if (!dixResetPrivates())
+	    FatalError("couldn't init private data storage");
 	ResetExtensionPrivates();
 	ResetClientPrivates();
 	ResetScreenPrivates();
diff --git a/dix/privates.c b/dix/privates.c
index feab867..c4ecf6a 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -31,6 +31,7 @@ from The Open Group.
 #endif
 
 #include <X11/X.h>
+#include <stddef.h>
 #include "scrnintstr.h"
 #include "misc.h"
 #include "os.h"
@@ -45,315 +46,265 @@ from The Open Group.
 #include "inputstr.h"
 #include "extnsionst.h"
 
-typedef struct _PrivateDescItem {
-    int index;
+typedef struct _PrivateDesc {
+    devprivate_key_t *key;
     RESTYPE type;
     pointer parent;
     unsigned size;
     CallbackListPtr initfuncs;
     CallbackListPtr deletefuncs;
-} PrivateDescItemRec, *PrivateDescItemPtr;
-
-/* keeps track of whether resource objects have been created */
-static char *instances = NULL;
-static RESTYPE instancesSize = 0;
-static char anyInstances = 0;
+    struct _PrivateDesc *next;
+} PrivateDescRec;
 
 /* list of all allocated privates */
-static PrivateDescItemPtr items = NULL;
-static unsigned itemsSize = 0;
-static unsigned nextPrivateIndex = 0;
-
-/* number of extra slots to add when resizing the tables */
-#define PRIV_TAB_INCREMENT 48
-/* set in index value for privates registered after resources were created */
-#define PRIV_DYN_MASK (1<<30)
-/* descriptor item lookup convenience macro */
-#define GET_DESCRIPTOR(index) (items + ((index) & (PRIV_DYN_MASK - 1)))
-/* type mask convenience macro */
-#define TYPE_BITS(type) ((type) & TypeMask)
+static PrivateDescRec *items = NULL;
 
-static _X_INLINE ResourcePtr
-findResourceBucket(RESTYPE type, pointer instance) {
-    ResourcePtr res = *((ResourcePtr *)instance);
-
-    while (res->type != type)
-	res = res->nexttype;
-    return res;
+static _X_INLINE PrivateDescRec *
+findItem(devprivate_key_t *const key)
+{
+    PrivateDescRec *item = items;
+    while (item) {
+	if (item->key == key)
+	    return item;
+	item = item->next;
+    }
+    return NULL;
 }
 
 /*
- * Request functions; the latter calls the former internally.
+ * Request pre-allocated space in resources of a given type.
  */
 _X_EXPORT int
-dixRequestPrivate(RESTYPE type, unsigned size, pointer parent)
-{
-    int index = nextPrivateIndex;
+dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
+		  unsigned size, pointer parent)
+{
+    PrivateDescRec *item = findItem(key);
+    if (item) {
+	assert(item->type == type);
+	if (size > item->size)
+	    item->size = size;
+    } else {
+	item = (PrivateDescRec *)xalloc(sizeof(PrivateDescRec));
+	if (!item)
+	    return FALSE;
+	memset(item, 0, sizeof(PrivateDescRec));
+
+	/* add privates descriptor */
+	item->key = key;
+	item->type = type;
+	item->parent = parent;
+	item->size = size;
+	item->next = items;
+	items = item;
+    }
+    return TRUE;
+}
 
-    /* check if privates descriptor table needs to be resized */
-    if (nextPrivateIndex >= itemsSize) {
-	unsigned bytes;
-	unsigned size = itemsSize;
+/*
+ * Allocate a private and attach it to an existing object.
+ */
+_X_EXPORT pointer *
+dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
+{
+    PrivateDescRec *item = findItem(key);
+    PrivateRec *ptr;
+    unsigned size = sizeof(PrivateRec);
+    
+    if (item)
+	size += item->size;
 
-	while (nextPrivateIndex >= size)
-	    size += PRIV_TAB_INCREMENT;
+    ptr = (PrivateRec *)xalloc(size);
+    if (!ptr)
+	return NULL;
+    memset(ptr, 0, size);
+    ptr->key = key;
+    ptr->value = (size > sizeof(PrivateRec)) ? (ptr + 1) : NULL;
+    ptr->next = *privates;
+    *privates = ptr;
 
-	bytes = size * sizeof(PrivateDescItemRec);
-	items = (PrivateDescItemPtr)xrealloc(items, bytes);
-	if (!items) {
-	    itemsSize = nextPrivateIndex = 0;
-	    return -1;
-	}
-	memset(items + itemsSize, 0,
-	       (size - itemsSize) * sizeof(PrivateDescItemRec));
+    /* call any init funcs and return */
+    if (item) {
+	PrivateCallbackRec calldata = { key, ptr->value };
+	CallCallbacks(&item->initfuncs, &calldata);
     }
-
-    /* figure out if resource instances already exist */
-    if ((type != RC_ANY && instances[TYPE_BITS(type)]) ||
-	(type == RC_ANY && anyInstances))
-	index |= PRIV_DYN_MASK;
-
-    /* add privates descriptor */
-    items[nextPrivateIndex].index = index;
-    items[nextPrivateIndex].type = type;
-    items[nextPrivateIndex].parent = parent;
-    items[nextPrivateIndex].size = size;
-    nextPrivateIndex++;
-    return index;
+    return &ptr->value;
 }
 
-_X_EXPORT int
-dixRequestSinglePrivate(RESTYPE type, unsigned size, pointer instance)
+/*
+ * Allocates pre-requested privates in a single chunk.
+ */
+_X_EXPORT PrivateRec *
+dixAllocatePrivates(RESTYPE type, pointer parent)
 {
-    PrivatePtr ptr;
-    ResourcePtr res = findResourceBucket(type, instance);
-    int index = dixRequestPrivate(type, size, instance);
-    if (index < 0)
-	return index;
+    unsigned count = 0, size = 0;
+    PrivateCallbackRec calldata;
+    PrivateDescRec *item;
+    PrivateRec *ptr;
+    char *value;
+
+    /* first pass figures out total size */
+    for (item = items; item; item = item->next)
+	if ((item->type == type || item->type == RC_ANY) &&
+	    (item->parent == NULL || item->parent == parent)) {
+
+	    size += sizeof(PrivateRec) + item->size;
+	    count++;
+	}
 
-    ptr = (PrivatePtr)xalloc(sizeof(PrivateRec) + size);
+    /* allocate one chunk of memory for everything */
+    ptr = (PrivateRec *)xalloc(size);
     if (!ptr)
-	return -1;
-    ptr->index = index;
-    ptr->value = ptr + 1;
-    ptr->next = res->privates;
-    res->privates = ptr;
-    return index;
+	return NULL;
+    memset(ptr, 0, size);
+    value = (char *)(ptr + count);
+
+    /* second pass sets up records and calls init funcs */
+    count = 0;
+    for (item = items; item; item = item->next)
+	if ((item->type == type || item->type == RC_ANY) &&
+	    (item->parent == NULL || item->parent == parent)) {
+
+	    ptr[count].key = calldata.key = item->key;
+	    ptr[count].dontfree = (count > 0);
+	    ptr[count].value = calldata.value = (items->size ? value : NULL);
+	    ptr[count].next = ptr + (count + 1);
+
+	    CallCallbacks(&item->initfuncs, &calldata);
+
+	    count++;
+	    value += item->size;
+	}
+
+    if (count > 0)
+	ptr[count-1].next = NULL;
+
+    return ptr;
 }
 
 /*
- * Lookup function (some of this could be static inlined)
+ * Called to free privates at object deletion time.
  */
-_X_EXPORT pointer
-dixLookupPrivate(RESTYPE type, int index, pointer instance)
+_X_EXPORT void
+dixFreePrivates(PrivateRec *privates)
 {
-    ResourcePtr res = findResourceBucket(type, instance);
-    PrivatePtr ptr = res->privates;
-    PrivateDescItemPtr item;
+    PrivateRec *ptr, *next;
+    PrivateDescRec *item;
     PrivateCallbackRec calldata;
 
-    /* see if private has already been allocated (likely) */
+    /* first pass calls the delete callbacks */
+    for (ptr = privates; ptr; ptr = ptr->next) {
+	item = findItem(ptr->key);
+	if (item) {
+	    calldata.key = ptr->key;
+	    calldata.value = ptr->value;
+	    CallCallbacks(&item->deletefuncs, &calldata);
+	}
+    }
+	
+    /* second pass frees the memory */
+    ptr = privates;
     while (ptr) {
-	if (ptr->index == index)
-	    return ptr->value;
-	ptr = ptr->next;
+	if (ptr->dontfree)
+	    ptr = ptr->next;
+	else {
+	    next = ptr->next;
+	    while (next && next->dontfree)
+		next = next->next;
+
+	    xfree(ptr);
+	    ptr = next;
+	}
     }
 
-    /* past this point, need to create private on the fly */
-    /* create the new private */
-    item = GET_DESCRIPTOR(index);
-    ptr = (PrivatePtr)xalloc(sizeof(PrivateRec) + item->size);
-    if (!ptr)
-	return NULL;
-    memset(ptr, 0, sizeof(PrivateRec) + item->size);
-    ptr->index = index;
-    ptr->value = ptr + 1;
-    ptr->next = res->privates;
-    res->privates = ptr;
-
-    /* call any init funcs and return */
-    calldata.value = ptr->value;
-    calldata.index = index;
-    calldata.resource = res;
-    CallCallbacks(&item->initfuncs, &calldata);
-    return ptr->value;
+    /* no more use of privates permitted */
+    *privates = NULL;
 }
 
 /*
  * Callback registration
  */
 _X_EXPORT int
-dixRegisterPrivateInitFunc(RESTYPE type, int index,
+dixRegisterPrivateInitFunc(devprivate_key_t *const key,
 			   CallbackProcPtr callback, pointer data)
 {
-    return AddCallback(&GET_DESCRIPTOR(index)->initfuncs, callback, data);
+    PrivateDescRec *item = findItem(key);
+    if (!item)
+	return FALSE;
+    return AddCallback(&item->initfuncs, callback, data);
 }
 
 _X_EXPORT int
-dixRegisterPrivateDeleteFunc(RESTYPE type, int index,
+dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 			     CallbackProcPtr callback, pointer data)
 {
-    return AddCallback(&GET_DESCRIPTOR(index)->deletefuncs, callback, data);
+    PrivateDescRec *item = findItem(key);
+    if (!item)
+	return FALSE;
+    return AddCallback(&item->deletefuncs, callback, data);
 }
 
-/*
- * Internal function called from the main loop to reset the subsystem.
- */
-void
-dixResetPrivates(void)
-{
-    if (items)
-	xfree(items);
-    items = NULL;
-    itemsSize = 0;
-    nextPrivateIndex = 0;
-    
-    if (instances)
-	xfree(instances);
-    instances = NULL;
-    instancesSize = 0;
-    anyInstances = 0;
-}
+/* Table of devPrivates offsets */
+static unsigned *offsets = NULL;
+static unsigned offsetsSize = 0;
 
 /*
- * Internal function called from CreateNewResourceType.
+ * Specify where the devPrivates field is located in a structure type
  */
-int
-dixUpdatePrivates(void)
+_X_EXPORT int
+dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
 {
-    RESTYPE next = lastResourceType + 1;
-
-    /* check if instances table needs to be resized */
-    if (next >= instancesSize) {
-	RESTYPE size = instancesSize;
-
-	while (next >= size)
-	    size += PRIV_TAB_INCREMENT;
+    type = type & TypeMask;
 
-	instances = (char *)xrealloc(instances, size);
-	if (!instances) {
-	    instancesSize = 0;
+    /* resize offsets table if necessary */
+    while (type >= offsetsSize) {
+	offsets = (unsigned *)xrealloc(offsets,
+				       offsetsSize * 2 * sizeof(unsigned));
+	if (!offsets) {
+	    offsetsSize = 0;
 	    return FALSE;
 	}
-	memset(instances + instancesSize, 0, size - instancesSize);
-	instancesSize = size;
+	offsetsSize *= 2;
     }
+
+    offsets[type] = offset;
     return TRUE;
 }
 
-/*
- * Internal function called from dixAddResource.
- * Allocates a ResourceRec along with any private space all in one chunk.
- */
-ResourcePtr
-dixAllocateResourceRec(RESTYPE type, pointer instance, pointer parent)
+_X_EXPORT unsigned
+dixLookupPrivateOffset(RESTYPE type)
 {
-    unsigned i, count = 0, size = sizeof(ResourceRec);
-    ResourcePtr res;
-    PrivatePtr ptr;
-    char *value;
-    
-    /* first pass figures out total size */
-    for (i=0; i<nextPrivateIndex; i++)
-	if (items[i].type == type &&
-	    (items[i].parent == NULL || items[i].parent == parent)) {
-
-	    size += sizeof(PrivateRec) + items[i].size;
-	    count++;
-	}
-
-    /* allocate resource bucket */
-    res = (ResourcePtr)xalloc(size);
-    if (!res)
-	return res;
-    memset(res, 0, size);
-    ptr = (PrivatePtr)(res + 1);
-    value = (char *)(ptr + count);
-    res->privates = (count > 0) ? ptr : NULL;
-
-    /* second pass sets up privates records */
-    count = 0;
-    for (i=0; i<nextPrivateIndex; i++)
-	if (items[i].type == type &&
-	    (items[i].parent == NULL || items[i].parent == parent)) {
-
-	    ptr[count].index = items[i].index;
-	    ptr[count].value = value;
-	    ptr[count].next = ptr + (count + 1);
-	    count++;
-	    value += items[i].size;
-	}
-
-    if (count > 0)
-	ptr[count-1].next = NULL;
-
-    /* hook up back-pointer to resource record(s) */
-    if (type & RC_PRIVATES) {
-	res->nexttype = *((ResourcePtr *)instance);
-	*((ResourcePtr *)instance) = res;
-    }
-
-    instances[TYPE_BITS(type)] = anyInstances = 1;
-    return res;
+    assert(type & RC_PRIVATES);
+    type = type & TypeMask;
+    assert(type < offsetsSize);
+    return offsets[type];
 }
-    
+
 /*
- * Internal function called from dixAddResource.
- * Calls the init functions on a newly allocated resource.
+ * Called from the main loop to reset the subsystem.
  */
-void
-dixCallPrivateInitFuncs(ResourcePtr res)
+int
+dixResetPrivates(void)
 {
-    PrivatePtr ptr = res->privates;
-    PrivateCallbackRec calldata;
-
-    calldata.resource = res;
-    while (ptr) {
-	calldata.value = ptr->value;
-	calldata.index = ptr->index;
-	CallCallbacks(&GET_DESCRIPTOR(ptr->index)->initfuncs, &calldata);
-	ptr = ptr->next;
+    PrivateDescRec *next;
+    while (items) {
+	next = items->next;
+	xfree(items);
+	items = next;
     }
-}
 
-/*
- * Internal function called from the various delete resource functions.
- * Calls delete callbacks before freeing the ResourceRec and other bits.
- */
-void
-dixFreeResourceRec(ResourcePtr res)
-{
-    ResourcePtr *tmp;
-    PrivatePtr ptr, next, base;
-    PrivateCallbackRec calldata;
+    if (offsets)
+	xfree(offsets);
 
-    /* first pass calls the delete callbacks */
-    ptr = res->privates;
-    calldata.resource = res;
-    while (ptr) {
-	calldata.value = ptr->value;
-	calldata.index = ptr->index;
-	CallCallbacks(&GET_DESCRIPTOR(ptr->index)->deletefuncs, &calldata);
-	ptr = ptr->next;
-    }
+    offsetsSize = 16;
+    offsets = (unsigned *)xalloc(offsetsSize * sizeof(unsigned));
+    if (!offsets)
+	return FALSE;
 
-    /* second pass frees any off-struct private records */
-    ptr = res->privates;
-    base = (PrivatePtr)(res + 1);
-    while (ptr && ptr != base) {
-	next = ptr->next;
-	xfree(ptr);
-	ptr = next;
-    }
+    /* register basic resource offsets */
+    if (!dixRegisterPrivateOffset(RT_WINDOW, offsetof(WindowRec,devPrivates)))
+	return FALSE;
 
-    /* remove the record from the nexttype linked list and free it*/
-    if (res->type & RC_PRIVATES) {
-	tmp = (ResourcePtr *)res->value;
-	while (*tmp != res)
-	    tmp = &(*tmp)->nexttype;
-	*tmp = (*tmp)->nexttype;
-    }
-    xfree(res);
+    return TRUE;
 }
 
 /*
diff --git a/dix/resource.c b/dix/resource.c
index c568ed0..2cad7c0 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -169,6 +169,12 @@ static void RebuildTable(
 #define INITHASHSIZE 6
 #define MAXHASHSIZE 11
 
+typedef struct _Resource {
+    struct _Resource	*next;
+    XID			id;
+    RESTYPE		type;
+    pointer		value;
+} ResourceRec, *ResourcePtr;
 #define NullResource ((ResourcePtr)NULL)
 
 typedef struct _ClientResource {
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 9136351..5479ed0 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -261,10 +261,13 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(FreeScratchPixmapHeader)
     /* privates.c */
     SYMFUNC(dixRequestPrivate)
-    SYMFUNC(dixRequestSinglePrivate)
-    SYMFUNC(dixLookupPrivate)
     SYMFUNC(dixRegisterPrivateInitFunc)
     SYMFUNC(dixRegisterPrivateDeleteFunc)
+    SYMFUNC(dixAllocatePrivate)
+    SYMFUNC(dixAllocatePrivates)
+    SYMFUNC(dixFreePrivates)
+    SYMFUNC(dixRegisterPrivateOffset)
+    SYMFUNC(dixLookupPrivateOffset)
     SYMFUNC(AllocateExtensionPrivate)
     SYMFUNC(AllocateExtensionPrivateIndex)
     SYMFUNC(AllocateClientPrivate)
diff --git a/include/privates.h b/include/privates.h
index 8d74270..898fdd9 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -19,59 +19,141 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * STUFF FOR PRIVATES
  *****************************************************************/
 
+typedef struct _PrivateKey {
+    int unused;
+} devprivate_key_t;
+
+typedef struct _Private {
+    devprivate_key_t	*key;
+    int			dontfree;
+    pointer		value;
+    struct _Private	*next;
+} PrivateRec;
+
 /*
- * Request private space for your driver/module in all resources of a type.
- * A non-null pScreen argument restricts to resources on a given screen.
+ * Request pre-allocated private space for your driver/module.
+ * A non-null pScreen argument restricts to objects on a given screen.
  */
 extern int
-dixRequestPrivate(RESTYPE type, unsigned size, pointer pScreen);
+dixRequestPrivate(RESTYPE type, devprivate_key_t *const key,
+		  unsigned size, pointer pScreen);
 
 /*
- * Request private space in just one individual resource object.
+ * Allocates a new private and attaches it to an existing object.
  */
-extern int
-dixRequestSinglePrivate(RESTYPE type, unsigned size, pointer instance);
+extern pointer *
+dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key);
 
 /*
  * Look up a private pointer.
  */
-extern pointer
-dixLookupPrivate(RESTYPE type, int index, pointer instance);
+static _X_INLINE pointer
+dixLookupPrivate(PrivateRec **privates, devprivate_key_t *const key)
+{
+    PrivateRec *rec = *privates;
+    pointer *ptr;
+
+    while (rec) {
+	if (rec->key == key)
+	    return rec->value;
+	rec = rec->next;
+    }
+
+    ptr = dixAllocatePrivate(privates, key);
+    return ptr ? *ptr : NULL;
+}
+
+/*
+ * Look up the address of a private pointer.
+ */
+static _X_INLINE pointer *
+dixLookupPrivateAddr(PrivateRec **privates, devprivate_key_t *const key)
+{
+    PrivateRec *rec = *privates;
+
+    while (rec) {
+	if (rec->key == key)
+	    return &rec->value;
+	rec = rec->next;
+    }
+
+    return dixAllocatePrivate(privates, key);
+}
+
+/*
+ * Set a private pointer.
+ */
+static _X_INLINE int
+dixSetPrivate(PrivateRec **privates, devprivate_key_t *const key, pointer val)
+{
+    PrivateRec *rec;
+
+ top:
+    rec = *privates;
+    while (rec) {
+	if (rec->key == key) {
+	    rec->value = val;
+	    return TRUE;
+	}
+	rec = rec->next;
+    }
+
+    if (!dixAllocatePrivate(privates, key))
+	return FALSE;
+    goto top;
+}
 
 /*
  * Register callbacks to be called on private allocation/freeing.
  * The calldata argument to the callbacks is a PrivateCallbackPtr.
  */
 typedef struct _PrivateCallback {
+    devprivate_key_t *key;	/* private registration key */
     pointer value;		/* pointer to private */
-    int index;			/* registration index */
-    ResourcePtr resource;	/* resource record (do not modify!) */
-} PrivateCallbackRec, *PrivateCallbackPtr;
+} PrivateCallbackRec;
 
 extern int
-dixRegisterPrivateInitFunc(RESTYPE type, int index,
+dixRegisterPrivateInitFunc(devprivate_key_t *const key,
 			   CallbackProcPtr callback, pointer userdata);
 
 extern int
-dixRegisterPrivateDeleteFunc(RESTYPE type, int index,
+dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
 			     CallbackProcPtr callback, pointer userdata);
 
 /*
- * Internal functions
+ * Allocates all pre-requested private space in one chunk.
+ */
+extern PrivateRec *
+dixAllocatePrivates(RESTYPE type, pointer parent);
+
+/*
+ * Frees any private space that is not part of an object.
  */
 extern void
-dixResetPrivates(void);
+dixFreePrivates(PrivateRec *privates);
 
+/*
+ * Resets the subsystem, called from the main loop.
+ */
 extern int
-dixUpdatePrivates(void);
+dixResetPrivates(void);
 
-extern ResourcePtr
-dixAllocateResourceRec(RESTYPE type, pointer value, pointer parent);
+/*
+ * These next two functions are necessary because the position of
+ * the devPrivates field varies by structure and calling code might
+ * only know the resource type, not the structure definition.
+ */
 
-extern void
-dixCallPrivateInitFuncs(ResourcePtr res);
+/*
+ * Looks up the offset where the devPrivates field is located by type.
+ */
+extern unsigned
+dixLookupPrivateOffset(RESTYPE type);
 
-extern void
-dixFreeResourceRec(ResourcePtr res);
+/*
+ * Specifies the offset where the devPrivates field is located.
+ */
+extern int
+dixRegisterPrivateOffset(RESTYPE type, unsigned offset);
 
 #endif /* PRIVATES_H */
diff --git a/include/resource.h b/include/resource.h
index 9023058..40259ac 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -53,27 +53,10 @@ SOFTWARE.
  * STUFF FOR RESOURCES 
  *****************************************************************/
 
-/* Resource structures */
+/* classes for Resource routines */
 
 typedef unsigned long RESTYPE;
 
-typedef struct _Private {
-    int			index;
-    pointer		value;
-    struct _Private	*next;
-} PrivateRec, *PrivatePtr;
-
-typedef struct _Resource {
-    struct _Resource	*next;
-    struct _Resource	*nexttype;
-    XID			id;
-    RESTYPE		type;
-    pointer		value;
-    PrivatePtr		privates;
-} ResourceRec, *ResourcePtr;
-
-/* classes for Resource routines */
-
 #define RC_VANILLA	((RESTYPE)0)
 #define RC_CACHED	((RESTYPE)1<<31)
 #define RC_DRAWABLE	((RESTYPE)1<<30)
@@ -84,8 +67,8 @@ typedef struct _Resource {
  */
 #define RC_NEVERRETAIN	((RESTYPE)1<<29)
 /*  Use class RC_PRIVATES for resources that support extra private data.
- *  Resources having this class must provide a field of type ResourcePtr
- *  at the top of the resource structure, which must be initalized to NULL.
+ *  Resources having this class must provide a field of type PrivateRec *.
+ *  Refer to the X server documentation on devPrivates for the details.
  */
 #define RC_PRIVATES	((RESTYPE)1<<28)
 #define RC_LASTPREDEF	RC_PRIVATES
commit 74f1de1de9633119c2cf26086875717181c8a6f7
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Mar 1 12:07:33 2007 -0500

    devPrivates rework: unhook resource system; will try a different approach.

diff --git a/dix/resource.c b/dix/resource.c
index bddc18c..c568ed0 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -135,7 +135,6 @@ Equipment Corporation.
 #include "misc.h"
 #include "os.h"
 #include "resource.h"
-#include "privates.h"
 #include "dixstruct.h" 
 #include "opaque.h"
 #include "windowstr.h"
@@ -207,8 +206,6 @@ CreateNewResourceType(DeleteType deleteFunc)
 
     if (next & lastResourceClass)
 	return 0;
-    if (!dixUpdatePrivates())
-	return 0;
     funcs = (DeleteType *)xrealloc(DeleteFuncs,
 				   (next + 1) * sizeof(DeleteType));
     if (!funcs)
@@ -454,7 +451,7 @@ FakeClientID(register int client)
 }
 
 _X_EXPORT Bool
-dixAddResource(XID id, RESTYPE type, pointer value, pointer parent)
+AddResource(XID id, RESTYPE type, pointer value)
 {
     int client;
     register ClientResourceRec *rrec;
@@ -475,7 +472,7 @@ dixAddResource(XID id, RESTYPE type, pointer value, pointer parent)
 	(rrec->hashsize < MAXHASHSIZE))
 	RebuildTable(client);
     head = &rrec->resources[Hash(client, id)];
-    res = dixAllocateResourceRec(type, value, parent);
+    res = (ResourcePtr)xalloc(sizeof(ResourceRec));
     if (!res)
     {
 	(*DeleteFuncs[type & TypeMask])(value, id);
@@ -489,16 +486,9 @@ dixAddResource(XID id, RESTYPE type, pointer value, pointer parent)
     rrec->elements++;
     if (!(id & SERVER_BIT) && (id >= rrec->expectID))
 	rrec->expectID = id + 1;
-    dixCallPrivateInitFuncs(res);
     return TRUE;
 }
 
-_X_EXPORT Bool
-AddResource(XID id, RESTYPE type, pointer value)
-{
-    return dixAddResource(id, type, value, NULL);
-}
-
 static void
 RebuildTable(int client)
 {
@@ -580,7 +570,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
 		    FlushClientCaches(res->id);
 		if (rtype != skipDeleteFuncType)
 		    (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
-		dixFreeResourceRec(res);
+		xfree(res);
 		if (*eltptr != elements)
 		    prev = head; /* prev may no longer be valid */
 		gotOne = TRUE;
@@ -624,7 +614,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 		    FlushClientCaches(res->id);
 		if (!skipFree)
 		    (*DeleteFuncs[type & TypeMask])(res->value, res->id);
-		dixFreeResourceRec(res);
+		xfree(res);
 		break;
 	    }
 	    else
@@ -789,7 +779,7 @@ FreeClientNeverRetainResources(ClientPtr client)
 		if (rtype & RC_CACHED)
 		    FlushClientCaches(this->id);
 		(*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
-		dixFreeResourceRec(this);
+		xfree(this);
 	    }
 	    else
 		prev = &this->next;
@@ -839,7 +829,7 @@ FreeClientResources(ClientPtr client)
 	    if (rtype & RC_CACHED)
 		FlushClientCaches(this->id);
 	    (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
-	    dixFreeResourceRec(this);
+	    xfree(this);
 	}
     }
     xfree(clientTable[client->index].resources);
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 7735767..9136351 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -283,7 +283,6 @@ _X_HIDDEN void *dixLookupTab[] = {
 #endif
     /* resource.c */
     SYMFUNC(AddResource)
-    SYMFUNC(dixAddResource)
     SYMFUNC(ChangeResourceValue)
     SYMFUNC(CreateNewResourceClass)
     SYMFUNC(CreateNewResourceType)
diff --git a/include/resource.h b/include/resource.h
index 617afbf..9023058 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -183,12 +183,6 @@ extern Bool AddResource(
     RESTYPE /*type*/,
     pointer /*value*/);
 
-extern Bool dixAddResource(
-    XID /*id*/,
-    RESTYPE /*type*/,
-    pointer /*value*/,
-    pointer /*parent*/);
-
 extern void FreeResource(
     XID /*id*/,
     RESTYPE /*skipDeleteFuncType*/);
commit 81372f9096b952f4be545654b0b44ac37ef4f2c2
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 23 13:23:12 2007 -0500

    devPrivates rework: hook up new interface in resource system; add new
    resource-adding function that takes an additional ScreenPtr argument.

diff --git a/dix/main.c b/dix/main.c
index 3a77533..b5954af 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -89,6 +89,7 @@ Equipment Corporation.
 #include "os.h"
 #include "windowstr.h"
 #include "resource.h"
+#include "privates.h"
 #include "dixstruct.h"
 #include "gcstruct.h"
 #include "extension.h"
@@ -356,6 +357,7 @@ main(int argc, char *argv[], char *envp[])
 	InitAtoms();
 	InitEvents();
 	InitGlyphCaching();
+	dixResetPrivates();
 	ResetExtensionPrivates();
 	ResetClientPrivates();
 	ResetScreenPrivates();
diff --git a/dix/resource.c b/dix/resource.c
index 584ac94..bddc18c 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -135,6 +135,7 @@ Equipment Corporation.
 #include "misc.h"
 #include "os.h"
 #include "resource.h"
+#include "privates.h"
 #include "dixstruct.h" 
 #include "opaque.h"
 #include "windowstr.h"
@@ -206,6 +207,8 @@ CreateNewResourceType(DeleteType deleteFunc)
 
     if (next & lastResourceClass)
 	return 0;
+    if (!dixUpdatePrivates())
+	return 0;
     funcs = (DeleteType *)xrealloc(DeleteFuncs,
 				   (next + 1) * sizeof(DeleteType));
     if (!funcs)
@@ -451,7 +454,7 @@ FakeClientID(register int client)
 }
 
 _X_EXPORT Bool
-AddResource(XID id, RESTYPE type, pointer value)
+dixAddResource(XID id, RESTYPE type, pointer value, pointer parent)
 {
     int client;
     register ClientResourceRec *rrec;
@@ -472,7 +475,7 @@ AddResource(XID id, RESTYPE type, pointer value)
 	(rrec->hashsize < MAXHASHSIZE))
 	RebuildTable(client);
     head = &rrec->resources[Hash(client, id)];
-    res = (ResourcePtr)xalloc(sizeof(ResourceRec));
+    res = dixAllocateResourceRec(type, value, parent);
     if (!res)
     {
 	(*DeleteFuncs[type & TypeMask])(value, id);
@@ -486,9 +489,16 @@ AddResource(XID id, RESTYPE type, pointer value)
     rrec->elements++;
     if (!(id & SERVER_BIT) && (id >= rrec->expectID))
 	rrec->expectID = id + 1;
+    dixCallPrivateInitFuncs(res);
     return TRUE;
 }
 
+_X_EXPORT Bool
+AddResource(XID id, RESTYPE type, pointer value)
+{
+    return dixAddResource(id, type, value, NULL);
+}
+
 static void
 RebuildTable(int client)
 {
@@ -570,7 +580,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
 		    FlushClientCaches(res->id);
 		if (rtype != skipDeleteFuncType)
 		    (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
-		xfree(res);
+		dixFreeResourceRec(res);
 		if (*eltptr != elements)
 		    prev = head; /* prev may no longer be valid */
 		gotOne = TRUE;
@@ -614,7 +624,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 		    FlushClientCaches(res->id);
 		if (!skipFree)
 		    (*DeleteFuncs[type & TypeMask])(res->value, res->id);
-		xfree(res);
+		dixFreeResourceRec(res);
 		break;
 	    }
 	    else
@@ -779,7 +789,7 @@ FreeClientNeverRetainResources(ClientPtr client)
 		if (rtype & RC_CACHED)
 		    FlushClientCaches(this->id);
 		(*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
-		xfree(this);	    
+		dixFreeResourceRec(this);
 	    }
 	    else
 		prev = &this->next;
@@ -829,7 +839,7 @@ FreeClientResources(ClientPtr client)
 	    if (rtype & RC_CACHED)
 		FlushClientCaches(this->id);
 	    (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
-	    xfree(this);	    
+	    dixFreeResourceRec(this);
 	}
     }
     xfree(clientTable[client->index].resources);
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 9136351..7735767 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -283,6 +283,7 @@ _X_HIDDEN void *dixLookupTab[] = {
 #endif
     /* resource.c */
     SYMFUNC(AddResource)
+    SYMFUNC(dixAddResource)
     SYMFUNC(ChangeResourceValue)
     SYMFUNC(CreateNewResourceClass)
     SYMFUNC(CreateNewResourceType)
diff --git a/include/resource.h b/include/resource.h
index 9023058..617afbf 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -183,6 +183,12 @@ extern Bool AddResource(
     RESTYPE /*type*/,
     pointer /*value*/);
 
+extern Bool dixAddResource(
+    XID /*id*/,
+    RESTYPE /*type*/,
+    pointer /*value*/,
+    pointer /*parent*/);
+
 extern void FreeResource(
     XID /*id*/,
     RESTYPE /*skipDeleteFuncType*/);
commit 16f2b8892d9ebcef6410a675d10549043223f617
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 23 13:20:43 2007 -0500

    devPrivates rework: add new interface implementation.

diff --git a/dix/privates.c b/dix/privates.c
index b20a1db..feab867 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -36,6 +36,7 @@ from The Open Group.
 #include "os.h"
 #include "windowstr.h"
 #include "resource.h"
+#include "privates.h"
 #include "dixstruct.h"
 #include "gcstruct.h"
 #include "colormapst.h"
@@ -44,6 +45,322 @@ from The Open Group.
 #include "inputstr.h"
 #include "extnsionst.h"
 
+typedef struct _PrivateDescItem {
+    int index;
+    RESTYPE type;
+    pointer parent;
+    unsigned size;
+    CallbackListPtr initfuncs;
+    CallbackListPtr deletefuncs;
+} PrivateDescItemRec, *PrivateDescItemPtr;
+
+/* keeps track of whether resource objects have been created */
+static char *instances = NULL;
+static RESTYPE instancesSize = 0;
+static char anyInstances = 0;
+
+/* list of all allocated privates */
+static PrivateDescItemPtr items = NULL;
+static unsigned itemsSize = 0;
+static unsigned nextPrivateIndex = 0;
+
+/* number of extra slots to add when resizing the tables */
+#define PRIV_TAB_INCREMENT 48
+/* set in index value for privates registered after resources were created */
+#define PRIV_DYN_MASK (1<<30)
+/* descriptor item lookup convenience macro */
+#define GET_DESCRIPTOR(index) (items + ((index) & (PRIV_DYN_MASK - 1)))
+/* type mask convenience macro */
+#define TYPE_BITS(type) ((type) & TypeMask)
+
+static _X_INLINE ResourcePtr
+findResourceBucket(RESTYPE type, pointer instance) {
+    ResourcePtr res = *((ResourcePtr *)instance);
+
+    while (res->type != type)
+	res = res->nexttype;
+    return res;
+}
+
+/*
+ * Request functions; the latter calls the former internally.
+ */
+_X_EXPORT int
+dixRequestPrivate(RESTYPE type, unsigned size, pointer parent)
+{
+    int index = nextPrivateIndex;
+
+    /* check if privates descriptor table needs to be resized */
+    if (nextPrivateIndex >= itemsSize) {
+	unsigned bytes;
+	unsigned size = itemsSize;
+
+	while (nextPrivateIndex >= size)
+	    size += PRIV_TAB_INCREMENT;
+
+	bytes = size * sizeof(PrivateDescItemRec);
+	items = (PrivateDescItemPtr)xrealloc(items, bytes);
+	if (!items) {
+	    itemsSize = nextPrivateIndex = 0;
+	    return -1;
+	}
+	memset(items + itemsSize, 0,
+	       (size - itemsSize) * sizeof(PrivateDescItemRec));
+    }
+
+    /* figure out if resource instances already exist */
+    if ((type != RC_ANY && instances[TYPE_BITS(type)]) ||
+	(type == RC_ANY && anyInstances))
+	index |= PRIV_DYN_MASK;
+
+    /* add privates descriptor */
+    items[nextPrivateIndex].index = index;
+    items[nextPrivateIndex].type = type;
+    items[nextPrivateIndex].parent = parent;
+    items[nextPrivateIndex].size = size;
+    nextPrivateIndex++;
+    return index;
+}
+
+_X_EXPORT int
+dixRequestSinglePrivate(RESTYPE type, unsigned size, pointer instance)
+{
+    PrivatePtr ptr;
+    ResourcePtr res = findResourceBucket(type, instance);
+    int index = dixRequestPrivate(type, size, instance);
+    if (index < 0)
+	return index;
+
+    ptr = (PrivatePtr)xalloc(sizeof(PrivateRec) + size);
+    if (!ptr)
+	return -1;
+    ptr->index = index;
+    ptr->value = ptr + 1;
+    ptr->next = res->privates;
+    res->privates = ptr;
+    return index;
+}
+
+/*
+ * Lookup function (some of this could be static inlined)
+ */
+_X_EXPORT pointer
+dixLookupPrivate(RESTYPE type, int index, pointer instance)
+{
+    ResourcePtr res = findResourceBucket(type, instance);
+    PrivatePtr ptr = res->privates;
+    PrivateDescItemPtr item;
+    PrivateCallbackRec calldata;
+
+    /* see if private has already been allocated (likely) */
+    while (ptr) {
+	if (ptr->index == index)
+	    return ptr->value;
+	ptr = ptr->next;
+    }
+
+    /* past this point, need to create private on the fly */
+    /* create the new private */
+    item = GET_DESCRIPTOR(index);
+    ptr = (PrivatePtr)xalloc(sizeof(PrivateRec) + item->size);
+    if (!ptr)
+	return NULL;
+    memset(ptr, 0, sizeof(PrivateRec) + item->size);
+    ptr->index = index;
+    ptr->value = ptr + 1;
+    ptr->next = res->privates;
+    res->privates = ptr;
+
+    /* call any init funcs and return */
+    calldata.value = ptr->value;
+    calldata.index = index;
+    calldata.resource = res;
+    CallCallbacks(&item->initfuncs, &calldata);
+    return ptr->value;
+}
+
+/*
+ * Callback registration
+ */
+_X_EXPORT int
+dixRegisterPrivateInitFunc(RESTYPE type, int index,
+			   CallbackProcPtr callback, pointer data)
+{
+    return AddCallback(&GET_DESCRIPTOR(index)->initfuncs, callback, data);
+}
+
+_X_EXPORT int
+dixRegisterPrivateDeleteFunc(RESTYPE type, int index,
+			     CallbackProcPtr callback, pointer data)
+{
+    return AddCallback(&GET_DESCRIPTOR(index)->deletefuncs, callback, data);
+}
+
+/*
+ * Internal function called from the main loop to reset the subsystem.
+ */
+void
+dixResetPrivates(void)
+{
+    if (items)
+	xfree(items);
+    items = NULL;
+    itemsSize = 0;
+    nextPrivateIndex = 0;
+    
+    if (instances)
+	xfree(instances);
+    instances = NULL;
+    instancesSize = 0;
+    anyInstances = 0;
+}
+
+/*
+ * Internal function called from CreateNewResourceType.
+ */
+int
+dixUpdatePrivates(void)
+{
+    RESTYPE next = lastResourceType + 1;
+
+    /* check if instances table needs to be resized */
+    if (next >= instancesSize) {
+	RESTYPE size = instancesSize;
+
+	while (next >= size)
+	    size += PRIV_TAB_INCREMENT;
+
+	instances = (char *)xrealloc(instances, size);
+	if (!instances) {
+	    instancesSize = 0;
+	    return FALSE;
+	}
+	memset(instances + instancesSize, 0, size - instancesSize);
+	instancesSize = size;
+    }
+    return TRUE;
+}
+
+/*
+ * Internal function called from dixAddResource.
+ * Allocates a ResourceRec along with any private space all in one chunk.
+ */
+ResourcePtr
+dixAllocateResourceRec(RESTYPE type, pointer instance, pointer parent)
+{
+    unsigned i, count = 0, size = sizeof(ResourceRec);
+    ResourcePtr res;
+    PrivatePtr ptr;
+    char *value;
+    
+    /* first pass figures out total size */
+    for (i=0; i<nextPrivateIndex; i++)
+	if (items[i].type == type &&
+	    (items[i].parent == NULL || items[i].parent == parent)) {
+
+	    size += sizeof(PrivateRec) + items[i].size;
+	    count++;
+	}
+
+    /* allocate resource bucket */
+    res = (ResourcePtr)xalloc(size);
+    if (!res)
+	return res;
+    memset(res, 0, size);
+    ptr = (PrivatePtr)(res + 1);
+    value = (char *)(ptr + count);
+    res->privates = (count > 0) ? ptr : NULL;
+
+    /* second pass sets up privates records */
+    count = 0;
+    for (i=0; i<nextPrivateIndex; i++)
+	if (items[i].type == type &&
+	    (items[i].parent == NULL || items[i].parent == parent)) {
+
+	    ptr[count].index = items[i].index;
+	    ptr[count].value = value;
+	    ptr[count].next = ptr + (count + 1);
+	    count++;
+	    value += items[i].size;
+	}
+
+    if (count > 0)
+	ptr[count-1].next = NULL;
+
+    /* hook up back-pointer to resource record(s) */
+    if (type & RC_PRIVATES) {
+	res->nexttype = *((ResourcePtr *)instance);
+	*((ResourcePtr *)instance) = res;
+    }
+
+    instances[TYPE_BITS(type)] = anyInstances = 1;
+    return res;
+}
+    
+/*
+ * Internal function called from dixAddResource.
+ * Calls the init functions on a newly allocated resource.
+ */
+void
+dixCallPrivateInitFuncs(ResourcePtr res)
+{
+    PrivatePtr ptr = res->privates;
+    PrivateCallbackRec calldata;
+
+    calldata.resource = res;
+    while (ptr) {
+	calldata.value = ptr->value;
+	calldata.index = ptr->index;
+	CallCallbacks(&GET_DESCRIPTOR(ptr->index)->initfuncs, &calldata);
+	ptr = ptr->next;
+    }
+}
+
+/*
+ * Internal function called from the various delete resource functions.
+ * Calls delete callbacks before freeing the ResourceRec and other bits.
+ */
+void
+dixFreeResourceRec(ResourcePtr res)
+{
+    ResourcePtr *tmp;
+    PrivatePtr ptr, next, base;
+    PrivateCallbackRec calldata;
+
+    /* first pass calls the delete callbacks */
+    ptr = res->privates;
+    calldata.resource = res;
+    while (ptr) {
+	calldata.value = ptr->value;
+	calldata.index = ptr->index;
+	CallCallbacks(&GET_DESCRIPTOR(ptr->index)->deletefuncs, &calldata);
+	ptr = ptr->next;
+    }
+
+    /* second pass frees any off-struct private records */
+    ptr = res->privates;
+    base = (PrivatePtr)(res + 1);
+    while (ptr && ptr != base) {
+	next = ptr->next;
+	xfree(ptr);
+	ptr = next;
+    }
+
+    /* remove the record from the nexttype linked list and free it*/
+    if (res->type & RC_PRIVATES) {
+	tmp = (ResourcePtr *)res->value;
+	while (*tmp != res)
+	    tmp = &(*tmp)->nexttype;
+	*tmp = (*tmp)->nexttype;
+    }
+    xfree(res);
+}
+
+/*
+ *  Following is the old devPrivates support.  These functions and variables
+ *  are deprecated, and should no longer be used.
+ */
+
 /*
  *  See the Wrappers and devPrivates section in "Definition of the
  *  Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c
index 32e0e4f..9136351 100644
--- a/hw/xfree86/loader/dixsym.c
+++ b/hw/xfree86/loader/dixsym.c
@@ -63,6 +63,7 @@
 #include "globals.h"
 #include "os.h"
 #include "osdep.h"
+#include "privates.h"
 #include "resource.h"
 #include "servermd.h"
 #include "scrnintstr.h"
@@ -259,6 +260,11 @@ _X_HIDDEN void *dixLookupTab[] = {
     SYMFUNC(GetScratchPixmapHeader)
     SYMFUNC(FreeScratchPixmapHeader)
     /* privates.c */
+    SYMFUNC(dixRequestPrivate)
+    SYMFUNC(dixRequestSinglePrivate)
+    SYMFUNC(dixLookupPrivate)
+    SYMFUNC(dixRegisterPrivateInitFunc)
+    SYMFUNC(dixRegisterPrivateDeleteFunc)
     SYMFUNC(AllocateExtensionPrivate)
     SYMFUNC(AllocateExtensionPrivateIndex)
     SYMFUNC(AllocateClientPrivate)
commit 779faccfb78648a9f7e70b77dcfa9f6e19559772
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 23 13:19:53 2007 -0500

    devPrivates rework: add dix header file containing new interface.

diff --git a/include/Makefile.am b/include/Makefile.am
index 4289b81..4d8910b 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -31,6 +31,7 @@ sdk_HEADERS =		\
 	os.h		\
 	pixmap.h	\
 	pixmapstr.h	\
+	privates.h	\
 	property.h	\
 	propertyst.h	\
 	region.h	\
diff --git a/include/privates.h b/include/privates.h
new file mode 100644
index 0000000..8d74270
--- /dev/null
+++ b/include/privates.h
@@ -0,0 +1,77 @@
+/***********************************************************
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************/
+
+#ifndef PRIVATES_H
+#define PRIVATES_H 1
+
+#include "dix.h"
+#include "resource.h"
+
+/*****************************************************************
+ * STUFF FOR PRIVATES
+ *****************************************************************/
+
+/*
+ * Request private space for your driver/module in all resources of a type.
+ * A non-null pScreen argument restricts to resources on a given screen.
+ */
+extern int
+dixRequestPrivate(RESTYPE type, unsigned size, pointer pScreen);
+
+/*
+ * Request private space in just one individual resource object.
+ */
+extern int
+dixRequestSinglePrivate(RESTYPE type, unsigned size, pointer instance);
+
+/*
+ * Look up a private pointer.
+ */
+extern pointer
+dixLookupPrivate(RESTYPE type, int index, pointer instance);
+
+/*
+ * Register callbacks to be called on private allocation/freeing.
+ * The calldata argument to the callbacks is a PrivateCallbackPtr.
+ */
+typedef struct _PrivateCallback {
+    pointer value;		/* pointer to private */
+    int index;			/* registration index */
+    ResourcePtr resource;	/* resource record (do not modify!) */
+} PrivateCallbackRec, *PrivateCallbackPtr;
+
+extern int
+dixRegisterPrivateInitFunc(RESTYPE type, int index,
+			   CallbackProcPtr callback, pointer userdata);
+
+extern int
+dixRegisterPrivateDeleteFunc(RESTYPE type, int index,
+			     CallbackProcPtr callback, pointer userdata);
+
+/*
+ * Internal functions
+ */
+extern void
+dixResetPrivates(void);
+
+extern int
+dixUpdatePrivates(void);
+
+extern ResourcePtr
+dixAllocateResourceRec(RESTYPE type, pointer value, pointer parent);
+
+extern void
+dixCallPrivateInitFuncs(ResourcePtr res);
+
+extern void
+dixFreeResourceRec(ResourcePtr res);
+
+#endif /* PRIVATES_H */
commit 9a3eb0357e779d5d5f76858f23667956c4c5d721
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 16 19:30:03 2007 -0500

    devPrivates rework: add RC_PRIVATES class, make ResourceRec visible in
    the API, and add extra fields and structure supporting private storage.

diff --git a/dix/resource.c b/dix/resource.c
index 4468f45..584ac94 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -169,12 +169,6 @@ static void RebuildTable(
 #define INITHASHSIZE 6
 #define MAXHASHSIZE 11
 
-typedef struct _Resource {
-    struct _Resource	*next;
-    XID			id;
-    RESTYPE		type;
-    pointer		value;
-} ResourceRec, *ResourcePtr;
 #define NullResource ((ResourcePtr)NULL)
 
 typedef struct _ClientResource {
diff --git a/include/resource.h b/include/resource.h
index 3231e8c..9023058 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -53,10 +53,27 @@ SOFTWARE.
  * STUFF FOR RESOURCES 
  *****************************************************************/
 
-/* classes for Resource routines */
+/* Resource structures */
 
 typedef unsigned long RESTYPE;
 
+typedef struct _Private {
+    int			index;
+    pointer		value;
+    struct _Private	*next;
+} PrivateRec, *PrivatePtr;
+
+typedef struct _Resource {
+    struct _Resource	*next;
+    struct _Resource	*nexttype;
+    XID			id;
+    RESTYPE		type;
+    pointer		value;
+    PrivatePtr		privates;
+} ResourceRec, *ResourcePtr;
+
+/* classes for Resource routines */
+
 #define RC_VANILLA	((RESTYPE)0)
 #define RC_CACHED	((RESTYPE)1<<31)
 #define RC_DRAWABLE	((RESTYPE)1<<30)
@@ -66,7 +83,12 @@ typedef unsigned long RESTYPE;
  *  Extensions can use this too!
  */
 #define RC_NEVERRETAIN	((RESTYPE)1<<29)
-#define RC_LASTPREDEF	RC_NEVERRETAIN
+/*  Use class RC_PRIVATES for resources that support extra private data.
+ *  Resources having this class must provide a field of type ResourcePtr
+ *  at the top of the resource structure, which must be initalized to NULL.
+ */
+#define RC_PRIVATES	((RESTYPE)1<<28)
+#define RC_LASTPREDEF	RC_PRIVATES
 #define RC_ANY		(~(RESTYPE)0)
 
 /* types for Resource routines */
commit 2534f5a9027c196f677923aaa38fa9ed9917f73d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Feb 16 15:33:48 2007 -0500

    Remove nasty function pointer type from DevUnion, return to documented type.

diff --git a/include/miscstruct.h b/include/miscstruct.h
index c39f03c..f784587 100644
--- a/include/miscstruct.h
+++ b/include/miscstruct.h
@@ -50,7 +50,6 @@ SOFTWARE.
 
 #include "misc.h"
 #include <X11/Xprotostr.h>
-#include "gc.h"
 
 typedef xPoint DDXPointRec;
 
@@ -62,17 +61,7 @@ typedef union _DevUnion {
     pointer		ptr;
     long		val;
     unsigned long	uval;
-    RegionPtr   	(*fptr)(
-        DrawablePtr         /* pSrcDrawable */,
-        DrawablePtr         /* pDstDrawable */,
-        GCPtr               /* pGC */,
-        int                 /* srcx */,
-        int                 /* srcy */,
-        int                 /* width */,
-        int                 /* height */,
-        int                 /* dstx */,
-        int                 /* dsty */,
-        unsigned long       /* bitPlane */);
+    pointer		(*fptr)(void);
 } DevUnion;
 
 #endif /* MISCSTRUCT_H */
diff --git a/mfb/mfbbitblt.c b/mfb/mfbbitblt.c
index 0f84df3..270fd96 100644
--- a/mfb/mfbbitblt.c
+++ b/mfb/mfbbitblt.c
@@ -400,20 +400,22 @@ int dstx, dsty;
 static unsigned long	copyPlaneGeneration;
 static int		copyPlaneScreenIndex = -1;
 
+typedef RegionPtr (*CopyPlaneFuncPtr)(
+    DrawablePtr         /* pSrcDrawable */,
+    DrawablePtr         /* pDstDrawable */,
+    GCPtr               /* pGC */,
+    int                 /* srcx */,
+    int                 /* srcy */,
+    int                 /* width */,
+    int                 /* height */,
+    int                 /* dstx */,
+    int                 /* dsty */,
+    unsigned long       /* bitPlane */);
+
 Bool
 mfbRegisterCopyPlaneProc (pScreen, proc)
     ScreenPtr	pScreen;
-    RegionPtr	(*proc)(
-        DrawablePtr         /* pSrcDrawable */,
-        DrawablePtr         /* pDstDrawable */,
-        GCPtr               /* pGC */,
-        int                 /* srcx */,
-        int                 /* srcy */,
-        int                 /* width */,
-        int                 /* height */,
-        int                 /* dstx */,
-        int                 /* dsty */,
-        unsigned long       /* bitPlane */);
+    CopyPlaneFuncPtr proc;
 {
     if (copyPlaneGeneration != serverGeneration)
     {
@@ -422,7 +424,7 @@ mfbRegisterCopyPlaneProc (pScreen, proc)
 	    return FALSE;
 	copyPlaneGeneration = serverGeneration;
     }
-    pScreen->devPrivates[copyPlaneScreenIndex].fptr = proc;
+    pScreen->devPrivates[copyPlaneScreenIndex].fptr = (CopyPlaneFuncPtr)proc;
     return TRUE;
 }
 
@@ -468,7 +470,7 @@ unsigned long plane;
     if (pSrcDrawable->depth != 1)
     {
 	if (copyPlaneScreenIndex >= 0 &&
-	    (copyPlane =
+	    (copyPlane = (CopyPlaneFuncPtr)
 		pSrcDrawable->pScreen->devPrivates[copyPlaneScreenIndex].fptr)
 	    )
 	{
commit f452507ca9209598401d15da0039aaa4e1fed1a3
Merge: 0463283... 8116757...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 15 09:47:20 2007 -0500

    Merge branch 'master' into my-XACE-SELINUX

commit 04632835b7402456fdcf6c8fa01970cd2804e27c
Merge: 88f89b9... 9ecf79c...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Feb 15 09:27:05 2007 -0500

    Merge branch 'master' into my-XACE-SELINUX

commit 88f89b9ac1b92a0916c46488350ff68c3ffdd490
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 19 19:15:49 2007 -0500

    Policy updates: use x prefix in property and ext types.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index e45fdcc..38b7831 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -19,58 +19,58 @@ nonlocal_context			system_u:object_r:remote_xclient_t:s0
 # any position (it need not be the last property rule listed).
 #
 # Properties set by typical clients: WM, _NET_WM, etc.
-property WM_NAME			client_property_t
-property WM_CLASS			client_property_t
-property WM_ICON_NAME			client_property_t
-property WM_HINTS			client_property_t
-property WM_NORMAL_HINTS		client_property_t
-property WM_COMMAND			client_property_t
-property WM_CLIENT_MACHINE		client_property_t
-property WM_LOCALE_NAME			client_property_t
-property WM_CLIENT_LEADER		client_property_t
-property WM_STATE			client_property_t
-property WM_PROTOCOLS			client_property_t
-property WM_WINDOW_ROLE			client_property_t
-property WM_TRANSIENT_FOR		client_property_t
-property _NET_WM_NAME			client_property_t
-property _NET_WM_ICON			client_property_t
-property _NET_WM_ICON_NAME		client_property_t
-property _NET_WM_PID			client_property_t
-property _NET_WM_STATE			client_property_t
-property _NET_WM_DESKTOP		client_property_t
-property _NET_WM_SYNC_REQUEST_COUNTER	client_property_t
-property _NET_WM_WINDOW_TYPE		client_property_t
-property _NET_WM_USER_TIME		client_property_t
-property _MOTIF_DRAG_RECEIVER_INFO	client_property_t
-property XdndAware			client_property_t
+property WM_NAME			client_xproperty_t
+property WM_CLASS			client_xproperty_t
+property WM_ICON_NAME			client_xproperty_t
+property WM_HINTS			client_xproperty_t
+property WM_NORMAL_HINTS		client_xproperty_t
+property WM_COMMAND			client_xproperty_t
+property WM_CLIENT_MACHINE		client_xproperty_t
+property WM_LOCALE_NAME			client_xproperty_t
+property WM_CLIENT_LEADER		client_xproperty_t
+property WM_STATE			client_xproperty_t
+property WM_PROTOCOLS			client_xproperty_t
+property WM_WINDOW_ROLE			client_xproperty_t
+property WM_TRANSIENT_FOR		client_xproperty_t
+property _NET_WM_NAME			client_xproperty_t
+property _NET_WM_ICON			client_xproperty_t
+property _NET_WM_ICON_NAME		client_xproperty_t
+property _NET_WM_PID			client_xproperty_t
+property _NET_WM_STATE			client_xproperty_t
+property _NET_WM_DESKTOP		client_xproperty_t
+property _NET_WM_SYNC_REQUEST_COUNTER	client_xproperty_t
+property _NET_WM_WINDOW_TYPE		client_xproperty_t
+property _NET_WM_USER_TIME		client_xproperty_t
+property _MOTIF_DRAG_RECEIVER_INFO	client_xproperty_t
+property XdndAware			client_xproperty_t
 
 # Properties written by xrdb
-property RESOURCE_MANAGER		rm_property_t
-property SCREEN_RESOURCES		rm_property_t
+property RESOURCE_MANAGER		rm_xproperty_t
+property SCREEN_RESOURCES		rm_xproperty_t
 
 # Properties written by window managers
-property _MIT_PRIORITY_COLORS		wm_property_t
+property _MIT_PRIORITY_COLORS		wm_xproperty_t
 
 # Properties used for security labeling
-property _SELINUX_CLIENT_CONTEXT	seclabel_property_t
+property _SELINUX_CLIENT_CONTEXT	seclabel_xproperty_t
 
 # Properties used to communicate screen information
-property XFree86_VT			info_property_t
-property XFree86_DDC_EDID1_RAWDATA	info_property_t
+property XFree86_VT			info_xproperty_t
+property XFree86_DDC_EDID1_RAWDATA	info_xproperty_t
 
 # Clipboard and selection properties
-property CUT_BUFFER0			clipboard_property_t
-property CUT_BUFFER1			clipboard_property_t
-property CUT_BUFFER2			clipboard_property_t
-property CUT_BUFFER3			clipboard_property_t
-property CUT_BUFFER4			clipboard_property_t
-property CUT_BUFFER5			clipboard_property_t
-property CUT_BUFFER6			clipboard_property_t
-property CUT_BUFFER7			clipboard_property_t
-property _XT_SELECTION_0		clipboard_property_t
+property CUT_BUFFER0			clipboard_xproperty_t
+property CUT_BUFFER1			clipboard_xproperty_t
+property CUT_BUFFER2			clipboard_xproperty_t
+property CUT_BUFFER3			clipboard_xproperty_t
+property CUT_BUFFER4			clipboard_xproperty_t
+property CUT_BUFFER5			clipboard_xproperty_t
+property CUT_BUFFER6			clipboard_xproperty_t
+property CUT_BUFFER7			clipboard_xproperty_t
+property _XT_SELECTION_0		clipboard_xproperty_t
 
 # Default fallback type
-property default			unknown_property_t
+property default			unknown_xproperty_t
 
 #
 # Extension rules map an extension name to a SELinux type.  The type must
@@ -81,63 +81,63 @@ property default			unknown_property_t
 # any position (it need not be the last extension rule listed).
 #
 # Standard extensions
-extension BIG-REQUESTS			std_ext_t
-extension DOUBLE-BUFFER			std_ext_t
-extension Extended-Visual-Information	std_ext_t
-extension MIT-SUNDRY-NONSTANDARD	std_ext_t
-extension SHAPE				std_ext_t
-extension SYNC				std_ext_t
-extension XC-MISC			std_ext_t
-extension XFIXES			std_ext_t
-extension XFree86-Misc			std_ext_t
-extension XpExtension                   std_ext_t
+extension BIG-REQUESTS			std_xext_t
+extension DOUBLE-BUFFER			std_xext_t
+extension Extended-Visual-Information	std_xext_t
+extension MIT-SUNDRY-NONSTANDARD	std_xext_t
+extension SHAPE				std_xext_t
+extension SYNC				std_xext_t
+extension XC-MISC			std_xext_t
+extension XFIXES			std_xext_t
+extension XFree86-Misc			std_xext_t
+extension XpExtension                   std_xext_t
 
 # Screen management and multihead extensions
-extension RANDR				output_ext_t
-extension XINERAMA			std_ext_t
+extension RANDR				output_xext_t
+extension XINERAMA			std_xext_t
 
 # Input extensions
-extension XInputExtension		input_ext_t
-extension XKEYBOARD			input_ext_t
+extension XInputExtension		input_xext_t
+extension XKEYBOARD			input_xext_t
 
 # Screensaver, power management extensions
-extension DPMS				screensaver_ext_t
-extension MIT-SCREEN-SAVER		screensaver_ext_t
+extension DPMS				screensaver_xext_t
+extension MIT-SCREEN-SAVER		screensaver_xext_t
 
 # Fonting extensions
-extension FontCache			font_ext_t
-extension XFree86-Bigfont		font_ext_t
+extension FontCache			font_xext_t
+extension XFree86-Bigfont		font_xext_t
 
 # Shared memory extensions
-extension MIT-SHM			shmem_ext_t
+extension MIT-SHM			shmem_xext_t
 
 # Accelerated graphics, OpenGL, direct rendering extensions
-extension DAMAGE			accelgraphics_ext_t
-extension GLX				accelgraphics_ext_t
-extension NV-CONTROL			accelgraphics_ext_t
-extension NV-GLX			accelgraphics_ext_t
-extension NVIDIA-GLX			accelgraphics_ext_t
-extension RENDER			std_ext_t
-extension XFree86-DGA			accelgraphics_ext_t
+extension DAMAGE			accelgraphics_xext_t
+extension GLX				accelgraphics_xext_t
+extension NV-CONTROL			accelgraphics_xext_t
+extension NV-GLX			accelgraphics_xext_t
+extension NVIDIA-GLX			accelgraphics_xext_t
+extension RENDER			std_xext_t
+extension XFree86-DGA			accelgraphics_xext_t
 
 # Debugging, testing, and recording extensions
-extension RECORD			debug_ext_t
-extension X-Resource			debug_ext_t
-extension XTEST				debug_ext_t
+extension RECORD			debug_xext_t
+extension X-Resource			debug_xext_t
+extension XTEST				debug_xext_t
 
 # Extensions just for window managers
-extension TOG-CUP			windowmgr_ext_t
+extension TOG-CUP			windowmgr_xext_t
 
 # Security-related extensions
-extension SECURITY			security_ext_t
-extension SELinux			security_ext_t
-extension XAccessControlExtension	security_ext_t
-extension XC-APPGROUP			security_ext_t
+extension SECURITY			security_xext_t
+extension SELinux			security_xext_t
+extension XAccessControlExtension	security_xext_t
+extension XC-APPGROUP			security_xext_t
 
 # Video extensions
-extension XFree86-VidModeExtension	video_ext_t
-extension XVideo			video_ext_t
-extension XVideo-MotionCompensation	video_ext_t
+extension XFree86-VidModeExtension	video_xext_t
+extension XVideo			video_xext_t
+extension XVideo-MotionCompensation	video_xext_t
 
 # Default fallback type
-extension default			unknown_ext_t
+extension default			unknown_xext_t
commit 2fb8b7f8199c35ae0870cb54b40ee28a4e01d479
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 19 19:14:51 2007 -0500

    Split ObjectSIDByLabel into two functions since property labeling now
    involves an additional compute_create lookup.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index a6e0213..5b77269 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -314,36 +314,75 @@ IDPerm(ClientPtr sclient,
 }
 
 /*
- * ObjectSIDByLabel - get SID for an extension or property.
+ * GetPropertySID - compute SID for a property object.
  *
  * Arguments:
- * class: should be SECCLASS_XEXTENSION or SECCLASS_PROPERTY.
- * name: name of the extension or property.
+ * basecontext: context of client owning the property.
+ * name: name of the property.
  *
  * Returns: proper SID for the object or NULL on error.
  */
 static security_id_t
-ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
-                 const char *name)
+GetPropertySID(security_context_t base, const char *name)
+{
+    security_context_t new, result;
+    context_t con;
+    security_id_t sid = NULL;
+    char **ptr, *type = NULL;
+
+    /* make a new context-manipulation object */
+    con = context_new(base);
+    if (!con)
+	goto out;
+
+    /* look in the mappings of names to types */
+    for (ptr = propertyTypes; *ptr; ptr+=2)
+	if (!strcmp(*ptr, name))
+	    break;
+    type = ptr[1];
+
+    /* set the role and type in the context (user unchanged) */
+    if (context_type_set(con, type) ||
+	context_role_set(con, "object_r"))
+	goto out2;
+
+    /* get a context string from the context-manipulation object */
+    new = context_str(con);
+    if (!new)
+	goto out2;
+
+    /* perform a transition to obtain the final context */
+    if (security_compute_create(base, new, SECCLASS_PROPERTY, &result) < 0)
+	goto out2;
+
+    /* get a SID for the context */
+    avc_context_to_sid(result, &sid);
+    freecon(result);
+  out2:
+    context_free(con);
+  out:
+    return sid;
+}
+
+/*
+ * GetExtensionSID - compute SID for an extension object.
+ *
+ * Arguments:
+ * name: name of the extension.
+ *
+ * Returns: proper SID for the object or NULL on error.
+ */
+static security_id_t
+GetExtensionSID(const char *name)
 {
     security_context_t base, new;
     context_t con;
     security_id_t sid = NULL;
     char **ptr, *type = NULL;
 
-    if (basecontext != NULL)
-    {
-        /* use the supplied context */
-        base = strdup(basecontext);
-        if (base == NULL)
-            goto out;
-    }
-    else
-    {
-        /* get server context */
-        if (getcon(&base) < 0)
-            goto out;
-    }
+    /* get server context */
+    if (getcon(&base) < 0)
+	goto out;
 
     /* make a new context-manipulation object */
     con = context_new(base);
@@ -351,8 +390,7 @@ ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
 	goto out2;
 
     /* look in the mappings of names to types */
-    ptr = (class == SECCLASS_PROPERTY) ? propertyTypes : extensionTypes;
-    for (; *ptr; ptr+=2)
+    for (ptr = extensionTypes; *ptr; ptr+=2)
 	if (!strcmp(*ptr, name))
 	    break;
     type = ptr[1];
@@ -368,8 +406,7 @@ ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
 	goto out3;
 
     /* get a SID for the context */
-    if (avc_context_to_sid(new, &sid) < 0)
-	goto out3;
+    avc_context_to_sid(new, &sid);
 
   out3:
     context_free(con);
@@ -1028,7 +1065,7 @@ CALLBACK(XSELinuxExtDispatch)
     /* XXX there should be a separate callback for this */
     if (!EXTENSIONSID(ext))
     {
-	extsid = ObjectSIDByLabel(NULL, SECCLASS_XEXTENSION, ext->name);
+	extsid = GetExtensionSID(ext->name);
 	if (!extsid)
 	    return;
 	EXTENSIONSID(ext) = extsid;
@@ -1071,7 +1108,7 @@ CALLBACK(XSELinuxProperty)
     if (!tclient || !HAVESTATE(tclient))
         return;
 
-    propsid = ObjectSIDByLabel(SID(tclient)->ctx, SECCLASS_PROPERTY, propname);
+    propsid = GetPropertySID(SID(tclient)->ctx, propname);
     if (!propsid)
 	return;
 
commit 700fccf863593cbea1691789f1f1cafc08a32fee
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 19 14:56:38 2007 -0500

    Remove the root window context line from the configuration file.
    This context will be derived through a type_transition rule instead.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index 4958264..e45fdcc 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -9,7 +9,6 @@
 # security policy.  Only one nonlocal_context rule may be defined.
 #
 nonlocal_context			system_u:object_r:remote_xclient_t:s0
-root_window_context			system_u:object_r:root_window_t:s0
 
 #
 # Property rules map a property name to a SELinux type.  The type must
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 9b5ee10..a6e0213 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -128,9 +128,6 @@ Atom atom_client_ctx;
 /* security context for non-local clients */
 static char *XSELinuxNonlocalContextDefault = NULL;
 
-/* security context for the root window */
-static char *XSELinuxRootWindowContext = NULL;
-
 /* Selection stuff from dix */
 extern Selection *CurrentSelections;
 extern int NumCurrentSelections;
@@ -1241,9 +1238,7 @@ static char *XSELinuxKeywords[] = {
     "extension",
 #define XSELinuxKeywordNonlocalContext 3
     "nonlocal_context",
-#define XSELinuxKeywordRootWindowContext 4
-    "root_window_context",
-#define XSELinuxKeywordDefault 5
+#define XSELinuxKeywordDefault 4
     "default"
 };
 
@@ -1582,39 +1577,6 @@ XSELinuxParseNonlocalContext(char *p)
 } /* XSELinuxParseNonlocalContext */
 
 static Bool
-XSELinuxParseRootWindowContext(char *p)
-{
-    char *context;
-
-    context = XSELinuxParseString(&p);
-    if (!context || (strlen(context) == 0))
-    {
-        return FALSE;
-    }
-
-    if (XSELinuxRootWindowContext != NULL)
-    {
-        return FALSE;
-    }
-
-    /* validate the context */
-    if (security_check_context(context))
-    {
-        return FALSE;
-    }
-
-    XSELinuxRootWindowContext = (char *)xalloc(strlen(context)+1);
-    if (!XSELinuxRootWindowContext)
-    {
-        ErrorF("XSELinux: out of memory\n");
-        return FALSE;
-    }
-    strcpy(XSELinuxRootWindowContext, context);
-
-    return TRUE;
-} /* XSELinuxParseRootWindowContext */
-
-static Bool
 XSELinuxLoadConfigFile(void)
 {
     FILE *f;
@@ -1630,7 +1592,6 @@ XSELinuxLoadConfigFile(void)
     propertyTypes = extensionTypes = NULL;
     XSELinuxPropertyTypeDefault = XSELinuxExtensionTypeDefault = NULL;
     XSELinuxNonlocalContextDefault = NULL;
-    XSELinuxRootWindowContext = NULL;
 
 #ifndef __UNIXOS2__
     f = fopen(XSELINUXCONFIGFILE, "r");
@@ -1671,10 +1632,6 @@ XSELinuxLoadConfigFile(void)
                 validLine = XSELinuxParseNonlocalContext(p);
                 break;
 
-            case XSELinuxKeywordRootWindowContext:
-                validLine = XSELinuxParseRootWindowContext(p);
-                break;
-
             default:
                 validLine = (*p == '\0');
                 break;
@@ -1706,11 +1663,6 @@ XSELinuxLoadConfigFile(void)
         ErrorF("XSELinux: No default context for non-local clients specified\n");
         goto out;
     }
-    else if (XSELinuxRootWindowContext == NULL)
-    {
-        ErrorF("XSELinux: No context specified for the root window\n");
-        goto out;
-    }
 
     /* Finally, append the default property and extension types to the
      * bottoms of the propertyTypes and extensionTypes arrays, respectively.
@@ -1780,10 +1732,6 @@ XSELinuxFreeConfigData(void)
     /* finally, take care of the context for non-local connections */
     xfree(XSELinuxNonlocalContextDefault);
     XSELinuxNonlocalContextDefault = NULL;
-
-    /* ... and for the root window */
-    xfree(XSELinuxRootWindowContext);
-    XSELinuxRootWindowContext = NULL;
 } /* XSELinuxFreeConfigData */
 
 /* Extension dispatch functions */
@@ -1890,10 +1838,6 @@ XSELinuxExtensionInit(INITARGS)
 
     /* Load the config file.  If this fails, shut down the server,
      * since an unknown security status is worse than no security.
-     *
-     * Note that this must come before we assign a security state
-     * for the serverClient, because the serverClient's root windows
-     * are assigned a context based on data in the config file.
      */
     if (XSELinuxLoadConfigFile() != TRUE)
     {
commit 3a9791b456f35adb252a9059b19265c6c447f1ba
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Jan 19 14:53:09 2007 -0500

    Policy updates.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index 1c5016e..4958264 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -59,15 +59,16 @@ property _SELINUX_CLIENT_CONTEXT	seclabel_property_t
 property XFree86_VT			info_property_t
 property XFree86_DDC_EDID1_RAWDATA	info_property_t
 
-# Cut buffers
-property CUT_BUFFER0			cut_buffer_property_t
-property CUT_BUFFER1			cut_buffer_property_t
-property CUT_BUFFER2			cut_buffer_property_t
-property CUT_BUFFER3			cut_buffer_property_t
-property CUT_BUFFER4			cut_buffer_property_t
-property CUT_BUFFER5			cut_buffer_property_t
-property CUT_BUFFER6			cut_buffer_property_t
-property CUT_BUFFER7			cut_buffer_property_t
+# Clipboard and selection properties
+property CUT_BUFFER0			clipboard_property_t
+property CUT_BUFFER1			clipboard_property_t
+property CUT_BUFFER2			clipboard_property_t
+property CUT_BUFFER3			clipboard_property_t
+property CUT_BUFFER4			clipboard_property_t
+property CUT_BUFFER5			clipboard_property_t
+property CUT_BUFFER6			clipboard_property_t
+property CUT_BUFFER7			clipboard_property_t
+property _XT_SELECTION_0		clipboard_property_t
 
 # Default fallback type
 property default			unknown_property_t
commit 43a4376bd72ef1b6486cddb60ad57b2d6169292a
Merge: 4b1c9ac... d9e079d...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 22 13:53:55 2006 -0500

    Merge branch 'master' into my-XACE-SELINUX

commit 4b1c9ac3d13767e395b47e76b37f9f3a569e7be1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Dec 22 13:04:50 2006 -0500

    Policy updates.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index 65f4015..1c5016e 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -19,13 +19,47 @@ root_window_context			system_u:object_r:root_window_t:s0
 # property type may not be omitted.  The default rule may appear in
 # any position (it need not be the last property rule listed).
 #
-property WM_NAME			wm_property_t
-property WM_CLASS			wm_property_t
-property WM_ICON_NAME			wm_property_t
-property WM_HINTS			wm_property_t
-property WM_NORMAL_HINTS		wm_property_t
-property WM_COMMAND			wm_property_t
+# Properties set by typical clients: WM, _NET_WM, etc.
+property WM_NAME			client_property_t
+property WM_CLASS			client_property_t
+property WM_ICON_NAME			client_property_t
+property WM_HINTS			client_property_t
+property WM_NORMAL_HINTS		client_property_t
+property WM_COMMAND			client_property_t
+property WM_CLIENT_MACHINE		client_property_t
+property WM_LOCALE_NAME			client_property_t
+property WM_CLIENT_LEADER		client_property_t
+property WM_STATE			client_property_t
+property WM_PROTOCOLS			client_property_t
+property WM_WINDOW_ROLE			client_property_t
+property WM_TRANSIENT_FOR		client_property_t
+property _NET_WM_NAME			client_property_t
+property _NET_WM_ICON			client_property_t
+property _NET_WM_ICON_NAME		client_property_t
+property _NET_WM_PID			client_property_t
+property _NET_WM_STATE			client_property_t
+property _NET_WM_DESKTOP		client_property_t
+property _NET_WM_SYNC_REQUEST_COUNTER	client_property_t
+property _NET_WM_WINDOW_TYPE		client_property_t
+property _NET_WM_USER_TIME		client_property_t
+property _MOTIF_DRAG_RECEIVER_INFO	client_property_t
+property XdndAware			client_property_t
 
+# Properties written by xrdb
+property RESOURCE_MANAGER		rm_property_t
+property SCREEN_RESOURCES		rm_property_t
+
+# Properties written by window managers
+property _MIT_PRIORITY_COLORS		wm_property_t
+
+# Properties used for security labeling
+property _SELINUX_CLIENT_CONTEXT	seclabel_property_t
+
+# Properties used to communicate screen information
+property XFree86_VT			info_property_t
+property XFree86_DDC_EDID1_RAWDATA	info_property_t
+
+# Cut buffers
 property CUT_BUFFER0			cut_buffer_property_t
 property CUT_BUFFER1			cut_buffer_property_t
 property CUT_BUFFER2			cut_buffer_property_t
@@ -35,6 +69,7 @@ property CUT_BUFFER5			cut_buffer_property_t
 property CUT_BUFFER6			cut_buffer_property_t
 property CUT_BUFFER7			cut_buffer_property_t
 
+# Default fallback type
 property default			unknown_property_t
 
 #
@@ -45,40 +80,64 @@ property default			unknown_property_t
 # extension type may not be omitted.  The default rule may appear in
 # any position (it need not be the last extension rule listed).
 #
+# Standard extensions
 extension BIG-REQUESTS			std_ext_t
 extension DOUBLE-BUFFER			std_ext_t
-extension DPMS				screensaver_ext_t
 extension Extended-Visual-Information	std_ext_t
-extension FontCache			font_ext_t
-extension GLX				std_ext_t
-extension LBX				std_ext_t
+extension MIT-SUNDRY-NONSTANDARD	std_ext_t
+extension SHAPE				std_ext_t
+extension SYNC				std_ext_t
+extension XC-MISC			std_ext_t
+extension XFIXES			std_ext_t
+extension XFree86-Misc			std_ext_t
+extension XpExtension                   std_ext_t
+
+# Screen management and multihead extensions
+extension RANDR				output_ext_t
+extension XINERAMA			std_ext_t
+
+# Input extensions
+extension XInputExtension		input_ext_t
+extension XKEYBOARD			input_ext_t
+
+# Screensaver, power management extensions
+extension DPMS				screensaver_ext_t
 extension MIT-SCREEN-SAVER		screensaver_ext_t
+
+# Fonting extensions
+extension FontCache			font_ext_t
+extension XFree86-Bigfont		font_ext_t
+
+# Shared memory extensions
 extension MIT-SHM			shmem_ext_t
-extension MIT-SUNDRY-NONSTANDARD	std_ext_t
+
+# Accelerated graphics, OpenGL, direct rendering extensions
+extension DAMAGE			accelgraphics_ext_t
+extension GLX				accelgraphics_ext_t
 extension NV-CONTROL			accelgraphics_ext_t
 extension NV-GLX			accelgraphics_ext_t
 extension NVIDIA-GLX			accelgraphics_ext_t
-extension RANDR				std_ext_t
-extension RECORD			debug_ext_t
 extension RENDER			std_ext_t
+extension XFree86-DGA			accelgraphics_ext_t
+
+# Debugging, testing, and recording extensions
+extension RECORD			debug_ext_t
+extension X-Resource			debug_ext_t
+extension XTEST				debug_ext_t
+
+# Extensions just for window managers
+extension TOG-CUP			windowmgr_ext_t
+
+# Security-related extensions
 extension SECURITY			security_ext_t
 extension SELinux			security_ext_t
-extension SHAPE				std_ext_t
-extension SYNC				sync_ext_t
-extension TOG-CUP			windowmgr_ext_t
-extension X-Resource			debug_ext_t
 extension XAccessControlExtension	security_ext_t
-extension XACEUSR			security_ext_t
 extension XC-APPGROUP			security_ext_t
-extension XC-MISC			std_ext_t
-extension XFree86-Bigfont		font_ext_t
-extension XFree86-DGA			accelgraphics_ext_t
-extension XFree86-Misc			std_ext_t
+
+# Video extensions
 extension XFree86-VidModeExtension	video_ext_t
-extension XInputExtension		input_ext_t
-extension XKEYBOARD			input_ext_t
-extension XpExtension                   std_ext_t
-extension XTEST				debug_ext_t
 extension XVideo			video_ext_t
 extension XVideo-MotionCompensation	video_ext_t
+
+# Default fallback type
 extension default			unknown_ext_t
commit cd71e861830081807e5b93ae89c73c17986c6330
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Dec 20 13:45:24 2006 -0500

    Naming change: Security*Access -> Dix*Access.
    Clarify some error message strings.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 41d01e4..9b5ee10 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -403,18 +403,18 @@ AssignServerState(void)
 
     /* get a SID from the context */
     if (avc_context_to_sid(basectx, &state->sid) < 0)
-	FatalError("Client %d: couldn't get security ID for client\n", 0);
+	FatalError("Client %d: context_to_sid(%s) failed\n", 0, basectx);
 
     /* get contexts and then SIDs for each resource type */
     for (i=0; i<NRES; i++) {
 	if (security_compute_create(basectx, basectx, sClasses[i],
 				    &objctx) < 0)
-	    FatalError("Client %d: couldn't get context for class %x\n", 0,
-		       sClasses[i]);
+	    FatalError("Client %d: compute_create(base=%s, cls=%d) failed\n",
+		       0, basectx, sClasses[i]);
 
 	if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
-	    FatalError("Client %d: couldn't get SID for class %x\n", 0,
-		       sClasses[i]);
+	    FatalError("Client %d: context_to_sid(%s) failed\n",
+		       0, objctx);
 
 	freecon(objctx);
     }
@@ -455,19 +455,19 @@ AssignClientState(ClientPtr client)
 
     /* get a SID from the context */
     if (avc_context_to_sid(basectx, &state->sid) < 0)
-	FatalError("Client %d: couldn't get security ID for client\n",
-		   client->index);
+	FatalError("Client %d: context_to_sid(%s) failed\n",
+		   client->index, basectx);
 
     /* get contexts and then SIDs for each resource type */
     for (i=0; i<NRES; i++) {
 	if (security_compute_create(basectx, basectx, sClasses[i],
 				    &objctx) < 0)
-	    FatalError("Client %d: couldn't get context for class %x\n",
-		       client->index, sClasses[i]);
+	    FatalError("Client %d: compute_create(base=%s, cls=%d) failed\n",
+		       client->index, basectx, sClasses[i]);
 
 	if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
-	    FatalError("Client %d: couldn't get SID for class %x\n",
-		       client->index, sClasses[i]);
+	    FatalError("Client %d: context_to_sid(%s) failed\n",
+		       client->index, objctx);
 
 	freecon(objctx);
     }
@@ -1078,11 +1078,11 @@ CALLBACK(XSELinuxProperty)
     if (!propsid)
 	return;
 
-    if (rec->access_mode & SecurityReadAccess)
+    if (rec->access_mode & DixReadAccess)
 	perm |= PROPERTY__READ;
-    if (rec->access_mode & SecurityWriteAccess)
+    if (rec->access_mode & DixWriteAccess)
 	perm |= PROPERTY__WRITE;
-    if (rec->access_mode & SecurityDestroyAccess)
+    if (rec->access_mode & DixDestroyAccess)
 	perm |= PROPERTY__FREE;
     if (!rec->access_mode)
 	perm = PROPERTY__READ | PROPERTY__WRITE | PROPERTY__FREE;
@@ -1176,7 +1176,7 @@ CALLBACK(XSELinuxDrawable)
 CALLBACK(XSELinuxHostlist)
 {
     XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
-    access_vector_t perm = (rec->access_mode == SecurityReadAccess) ?
+    access_vector_t perm = (rec->access_mode == DixReadAccess) ?
 	XSERVER__GETHOSTLIST : XSERVER__SETHOSTLIST;
 
     if (!ServerPerm(rec->client, SECCLASS_XSERVER, perm))
commit a81dbaae0597492f0245080c6f5af7158e05e2d0
Merge: fb6d676... d442998...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Dec 19 16:11:19 2006 -0500

    Merge branch 'master' into my-XACE-SELINUX

commit fb6d676de5aa606d943715437a12a68d9a41f386
Author: Eamon Walsh <ewalsh at moss-huskies.epoch.ncsc.mil>
Date:   Tue Dec 12 16:17:51 2006 -0500

    Add xserver object class to list of object classes.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 0de209d..41d01e4 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -152,7 +152,8 @@ static security_class_t sClasses[] = {
     SECCLASS_COLORMAP,
     SECCLASS_PROPERTY,
     SECCLASS_XCLIENT,
-    SECCLASS_XINPUT
+    SECCLASS_XINPUT,
+    SECCLASS_XSERVER
 };
 #define NRES (sizeof(sClasses)/sizeof(sClasses[0]))
 
commit 7b90944258eba66b61328480759833ad7589bcca
Author: Eamon Walsh <ewalsh at moss-huskies.epoch.ncsc.mil>
Date:   Tue Dec 12 15:59:38 2006 -0500

    Change MLS levels in config file contexts to more sane defaults.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index 9c953f5..65f4015 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -8,8 +8,8 @@
 # be defined, and it must be a valid context according to the SELinux
 # security policy.  Only one nonlocal_context rule may be defined.
 #
-nonlocal_context			system_u:object_r:remote_xclient_t:s1
-root_window_context			system_u:object_r:root_window_t:s1
+nonlocal_context			system_u:object_r:remote_xclient_t:s0
+root_window_context			system_u:object_r:root_window_t:s0
 
 #
 # Property rules map a property name to a SELinux type.  The type must
commit 568c09481e5d62091d032837171a36f409f39379
Author: Eamon Walsh <ewalsh at moss-huskies.epoch.ncsc.mil>
Date:   Tue Dec 12 15:59:08 2006 -0500

    Split AssignClientState() into two routines, new routine is server-specific.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 1c2b508..0de209d 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -382,6 +382,48 @@ ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
 }
 
 /*
+ * AssignServerState - set up server security state.
+ *
+ * Arguments:
+ */
+static void
+AssignServerState(void)
+{
+    int i;
+    security_context_t basectx, objctx;
+    XSELinuxClientStateRec *state;
+
+    state = (XSELinuxClientStateRec*)STATEPTR(serverClient);
+    avc_entry_ref_init(&state->aeref);
+
+    /* use the context of the X server process for the serverClient */
+    if (getcon(&basectx) < 0)
+	FatalError("Couldn't get context of X server process\n");
+
+    /* get a SID from the context */
+    if (avc_context_to_sid(basectx, &state->sid) < 0)
+	FatalError("Client %d: couldn't get security ID for client\n", 0);
+
+    /* get contexts and then SIDs for each resource type */
+    for (i=0; i<NRES; i++) {
+	if (security_compute_create(basectx, basectx, sClasses[i],
+				    &objctx) < 0)
+	    FatalError("Client %d: couldn't get context for class %x\n", 0,
+		       sClasses[i]);
+
+	if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
+	    FatalError("Client %d: couldn't get SID for class %x\n", 0,
+		       sClasses[i]);
+
+	freecon(objctx);
+    }
+
+    /* mark as set up, free base context, and return */
+    state->haveState = TRUE;
+    freecon(basectx);
+}
+
+/*
  * AssignClientState - set up client security state.
  *
  * Arguments:
@@ -392,75 +434,41 @@ AssignClientState(ClientPtr client)
 {
     int i, needToFree = 0;
     security_context_t basectx, objctx;
-    XSELinuxClientStateRec *state = (XSELinuxClientStateRec*)STATEPTR(client);
-    Bool isServerClient = FALSE;
+    XSELinuxClientStateRec *state;
 
+    state = (XSELinuxClientStateRec*)STATEPTR(client);
     avc_entry_ref_init(&state->aeref);
 
-    if (client->index > 0)
-    {
-	XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
-	if (_XSERVTransIsLocal(ci)) {
-	    /* for local clients, can get context from the socket */
-	    int fd = _XSERVTransGetConnectionNumber(ci);
-	    if (getpeercon(fd, &basectx) < 0)
-	    {
-		FatalError("Client %d: couldn't get context from socket\n",
-			   client->index);
-	    }
-	    needToFree = 1;
-	}
-        else
-        {
-	    /* for remote clients, need to use a default context */
-	    basectx = XSELinuxNonlocalContextDefault;
-	}
-    }
-    else
-    {
-        isServerClient = TRUE;
-
-	/* use the context of the X server process for the serverClient */
-	if (getcon(&basectx) < 0)
-	{
-	    FatalError("Couldn't get context of X server process\n");
-	}
+    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+    if (_XSERVTransIsLocal(ci)) {
+	/* for local clients, can get context from the socket */
+	int fd = _XSERVTransGetConnectionNumber(ci);
+	if (getpeercon(fd, &basectx) < 0)
+	    FatalError("Client %d: couldn't get context from socket\n",
+		       client->index);
 	needToFree = 1;
     }
+    else
+	/* for remote clients, need to use a default context */
+	basectx = XSELinuxNonlocalContextDefault;
 
     /* get a SID from the context */
     if (avc_context_to_sid(basectx, &state->sid) < 0)
-    {
 	FatalError("Client %d: couldn't get security ID for client\n",
 		   client->index);
-    }
 
     /* get contexts and then SIDs for each resource type */
-    for (i=0; i<NRES; i++)
-    {
+    for (i=0; i<NRES; i++) {
 	if (security_compute_create(basectx, basectx, sClasses[i],
 				    &objctx) < 0)
-	{
 	    FatalError("Client %d: couldn't get context for class %x\n",
 		       client->index, sClasses[i]);
-	}
-	else if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
-	{
+
+	if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
 	    FatalError("Client %d: couldn't get SID for class %x\n",
 		       client->index, sClasses[i]);
-	}
-	freecon(objctx);
-    }
 
-    /* special handling for serverClient windows (that is, root windows) */
-    if (isServerClient == TRUE)
-    {
-        i = IndexByClass(SECCLASS_WINDOW);
-        sidput(state->rsid[i]);
-        if (avc_context_to_sid(XSELinuxRootWindowContext, &state->rsid[i]))
-        {
-            FatalError("Failed to set SID for root window\n");
-        }
+	freecon(objctx);
     }
 
     /* mark as set up, free base context if necessary, and return */
@@ -1183,7 +1191,7 @@ CALLBACK(XSELinuxClientState)
     switch(client->clientState)
     {
     case ClientStateInitial:
-	AssignClientState(serverClient);
+	AssignServerState();
 	break;
 
 	case ClientStateRunning:
commit 62e7722ebd8d341a23eb56cb330eeb00e6a975a6
Merge: e124806... f3c6090...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Dec 12 13:54:33 2006 -0500

    Merge branch 'XACE-SELINUX' into my-XACE-SELINUX

commit e124806994675e16ca8e3937388f2cadeb529fc3
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Dec 12 13:35:22 2006 -0500

    Remove trailing whitespace (whitespace police).

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 8d710f6..1c2b508 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -135,8 +135,8 @@ static char *XSELinuxRootWindowContext = NULL;
 extern Selection *CurrentSelections;
 extern int NumCurrentSelections;
 
-/* 
- * list of classes corresponding to SIDs in the 
+/*
+ * list of classes corresponding to SIDs in the
  * rsid array of the security state structure (below).
  *
  * XXX SIDs should be stored in their native objects, not all
@@ -193,7 +193,7 @@ IndexByClass(security_class_t class)
 }
 
 /*
- * Does sanity checking on a resource ID.  This can be removed after 
+ * Does sanity checking on a resource ID.  This can be removed after
  * testing.
  */
 static void
@@ -351,7 +351,7 @@ ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
     con = context_new(base);
     if (!con)
 	goto out2;
-    
+
     /* look in the mappings of names to types */
     ptr = (class == SECCLASS_PROPERTY) ? propertyTypes : extensionTypes;
     for (; *ptr; ptr+=2)
@@ -564,14 +564,14 @@ CheckSendEventPerms(ClientPtr client)
 	swapl(&stuff->destination, n);
     return IDPerm(client, stuff->destination, SECCLASS_WINDOW, perm);
 }
-     
+
 static int
 CheckConvertSelectionPerms(ClientPtr client)
 {
     register char n;
     int rval = TRUE;
     REQUEST(xConvertSelectionReq);
-    
+
     if (!REQUEST_SIZE_CHECK(client, xConvertSelectionReq))
 	return FALSE;
 
@@ -620,11 +620,11 @@ CheckSetSelectionOwnerPerms(ClientPtr client)
 	    rval = rval && IDPerm(client, CurrentSelections[i].window,
 				  SECCLASS_WINDOW, WINDOW__CHSELECTION);
     }
-    rval = rval && IDPerm(client, stuff->window, 
+    rval = rval && IDPerm(client, stuff->window,
 			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
     return rval;
 }
-    
+
 CALLBACK(XSELinuxCoreDispatch)
 {
     XaceCoreDispatchRec *rec = (XaceCoreDispatchRec*)calldata;
@@ -678,7 +678,7 @@ CALLBACK(XSELinuxCoreDispatch)
     /* Window class control requirements */
     case X_ChangeProperty:
 	rval = IDPERM(client, xChangePropertyReq, window,
-		      SECCLASS_WINDOW, 
+		      SECCLASS_WINDOW,
 		      WINDOW__CHPROPLIST | WINDOW__CHPROP |
 		      WINDOW__LISTPROP);
 	break;
@@ -914,7 +914,7 @@ CALLBACK(XSELinuxCoreDispatch)
 	    && IDPERM(client, xPolyTextReq, drawable,
 		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
 	break;
-	
+
     /* Pixmap class control requirements */
     case X_CreatePixmap:
 	rval = IDPERM(client, xCreatePixmapReq, pid,
@@ -950,7 +950,7 @@ CALLBACK(XSELinuxCoreDispatch)
 	rval = IDPERM(client, xResourceReq, id,
 		      SECCLASS_CURSOR, CURSOR__FREE);
 	break;
-	    
+
     /* GC class control requirements */
     case X_CreateGC:
 	rval = IDPERM(client, xCreateGCReq, gc,
@@ -1018,7 +1018,7 @@ CALLBACK(XSELinuxExtDispatch)
     security_id_t extsid;
     access_vector_t perm;
     REQUEST(xReq);
-    
+
     /* XXX there should be a separate callback for this */
     if (!EXTENSIONSID(ext))
     {
@@ -1215,7 +1215,7 @@ CALLBACK(XSELinuxWindowInit)
 	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, strlen(ctx), ctx, FALSE);
 	freecon(ctx);
-    } 
+    }
     else
 	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, 10, "UNLABELED!", FALSE);
@@ -1441,7 +1441,7 @@ XSELinuxParsePropertyTypeRule(char *p)
 
     newTypes[propertyTypesCount*2 - 2] = propcopy;
     newTypes[propertyTypesCount*2 - 1] = typecopy;
-    
+
     propertyTypes = newTypes;
 
     return TRUE;
@@ -1612,7 +1612,7 @@ XSELinuxLoadConfigFile(void)
     int lineNumber = 0;
     char **newTypes;
     Bool ret = FALSE;
-    
+
     if (!XSELINUXCONFIGFILE)
         return FALSE;
 
@@ -1837,7 +1837,7 @@ XSELinuxExtensionSetup(INITARGS)
 {
     /* Allocate the client private index */
     clientPrivateIndex = AllocateClientPrivateIndex();
-    if (!AllocateClientPrivate(clientPrivateIndex, 
+    if (!AllocateClientPrivate(clientPrivateIndex,
 			       sizeof (XSELinuxClientStateRec)))
 	FatalError("XSELinux: Failed to allocate client private.\n");
 
commit ca77c121075a9de1f47d42f6aaf91c20185231de
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Dec 12 13:26:52 2006 -0500

    Naming change: Security*Operation -> Xace*Operation

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 2f960d1..8d710f6 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1090,7 +1090,7 @@ CALLBACK(XSELinuxProperty)
 	{
 	    if (errno != EACCES)
 		ErrorF("Property: unexpected error %d\n", errno);
-	    rec->rval = SecurityIgnoreOperation;
+	    rec->rval = XaceIgnoreOperation;
 	}
     } else
 	ErrorF("No client state in property callback!\n");
commit a60da1db7cced28c07960a713eb18deb45beb432
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Nov 29 22:19:57 2006 -0500

    Add required root window context to config file.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index faf815e..9c953f5 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -9,6 +9,7 @@
 # security policy.  Only one nonlocal_context rule may be defined.
 #
 nonlocal_context			system_u:object_r:remote_xclient_t:s1
+root_window_context			system_u:object_r:root_window_t:s1
 
 #
 # Property rules map a property name to a SELinux type.  The type must
commit 5719afe6d3a246985709e6f045617c1e16a7da51
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 26 20:20:57 2006 -0400

    Change symbol in libaudit library test.

diff --git a/configure.ac b/configure.ac
index 7e931ce..7306463 100644
--- a/configure.ac
+++ b/configure.ac
@@ -685,7 +685,7 @@ if test "x$XSELINUX" = xyes; then
 	AC_CHECK_HEADERS([selinux/selinux.h selinux/avc.h], [], AC_MSG_ERROR([SELinux include files not found]))
 	AC_CHECK_LIB(selinux, avc_init, [], AC_MSG_ERROR([SELinux library not found])) 
 	AC_CHECK_HEADERS([libaudit.h], [], AC_MSG_ERROR([SELinux extension requires audit system headers]))
-	AC_CHECK_LIB(audit, audit_log_avc, [], AC_MSG_ERROR([SELinux extension requires audit system library]))
+	AC_CHECK_LIB(audit, audit_open, [], AC_MSG_ERROR([SELinux extension requires audit system library]))
 	AC_DEFINE(XSELINUX, 1, [Build SELinux extension])
 	SELINUX_LIB="-lselinux -laudit"
 fi
commit 354c80da66af141e8ba6d75fed75a0f482987956
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 5 16:07:26 2006 -0400

    Improve error handling, messages during initialization.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index df19e5d..2f960d1 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1211,7 +1211,7 @@ CALLBACK(XSELinuxWindowInit)
     if (HAVESTATE(rec->client)) {
 	rc = avc_sid_to_context(SID(rec->client), &ctx);
 	if (rc < 0)
-	    FatalError("Failed to get security context!\n");
+	    FatalError("XSELinux: Failed to get security context!\n");
 	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, strlen(ctx), ctx, FALSE);
 	freecon(ctx);
@@ -1220,7 +1220,7 @@ CALLBACK(XSELinuxWindowInit)
 	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, 10, "UNLABELED!", FALSE);
     if (rc != Success)
-	FatalError("Failed to set context property on window!\n");
+	FatalError("XSELinux: Failed to set context property on window!\n");
 } /* XSELinuxWindowInit */
 
 static char *XSELinuxKeywords[] = {
@@ -1859,13 +1859,13 @@ XSELinuxExtensionInit(INITARGS)
 
     if (!is_selinux_enabled())
     {
-        ErrorF("SELinux Extension failed to load: SELinux not enabled\n");
+        ErrorF("XSELinux: Extension failed to load: SELinux not enabled\n");
         return;
     }
 
     if (avc_init("xserver", NULL, &alc, NULL, NULL) < 0)
     {
-	FatalError("couldn't initialize SELinux userspace AVC\n");
+	FatalError("XSELinux: Couldn't initialize SELinux userspace AVC\n");
     }
 
     if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
@@ -1874,10 +1874,10 @@ XSELinuxExtensionInit(INITARGS)
     /* Create atoms for doing window labeling */
     atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1);
     if (atom_ctx == BAD_RESOURCE)
-	return;
+	FatalError("XSELinux: Failed to create atom\n");
     atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, 1);
     if (atom_client_ctx == BAD_RESOURCE)
-	return;
+	FatalError("XSELinux: Failed to create atom\n");
 
     /* Load the config file.  If this fails, shut down the server,
      * since an unknown security status is worse than no security.
commit 3714d9149928754afcd6b2466a1371ca32e17985
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 4 16:23:35 2006 -0400

    Experimental window property holding security context.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 5a6d2ef..df19e5d 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #include <X11/X.h>
+#include <X11/Xatom.h>
 #include <X11/Xproto.h>
 #include <X11/Xfuncproto.h>
 #include "dixstruct.h"
@@ -120,6 +121,10 @@ static char **extensionTypes = NULL;
 static int extensionTypesCount = 0;
 static char *XSELinuxExtensionTypeDefault = NULL;
 
+/* Atoms for SELinux window labeling properties */
+Atom atom_ctx;
+Atom atom_client_ctx;
+
 /* security context for non-local clients */
 static char *XSELinuxNonlocalContextDefault = NULL;
 
@@ -1196,6 +1201,28 @@ CALLBACK(XSELinuxClientState)
     }
 } /* XSELinuxClientState */
 
+/* Labeling callbacks */
+CALLBACK(XSELinuxWindowInit)
+{
+    XaceWindowRec *rec = (XaceWindowRec*)calldata;
+    security_context_t ctx;
+    int rc;
+
+    if (HAVESTATE(rec->client)) {
+	rc = avc_sid_to_context(SID(rec->client), &ctx);
+	if (rc < 0)
+	    FatalError("Failed to get security context!\n");
+	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
+				  PropModeReplace, strlen(ctx), ctx, FALSE);
+	freecon(ctx);
+    } 
+    else
+	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
+				  PropModeReplace, 10, "UNLABELED!", FALSE);
+    if (rc != Success)
+	FatalError("Failed to set context property on window!\n");
+} /* XSELinuxWindowInit */
+
 static char *XSELinuxKeywords[] = {
 #define XSELinuxKeywordComment 0
     "#",
@@ -1844,6 +1871,14 @@ XSELinuxExtensionInit(INITARGS)
     if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
 	return;
 
+    /* Create atoms for doing window labeling */
+    atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1);
+    if (atom_ctx == BAD_RESOURCE)
+	return;
+    atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, 1);
+    if (atom_client_ctx == BAD_RESOURCE)
+	return;
+
     /* Load the config file.  If this fails, shut down the server,
      * since an unknown security status is worse than no security.
      *
@@ -1873,6 +1908,7 @@ XSELinuxExtensionInit(INITARGS)
     XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
     XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
     XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
+    XaceRegisterCallback(XACE_WINDOW_INIT, XSELinuxWindowInit, NULL);
     /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
     XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
 
commit 7f16c38ae2b47b195609d8fedefb7b28f612b2d4
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:31:18 2006 -0400

    Add SELinux extension configure-time support.

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 6ea3d74..be04c84 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -76,6 +76,16 @@ if XACE
 BUILTIN_SRCS += $(XACE_SRCS)
 endif
 
+# SELinux extension: provides SELinux policy support for X objects
+# requires X-ACE extension
+XSELINUX_SRCS = xselinux.c xselinux.h
+if XSELINUX
+BUILTIN_SRCS += $(XSELINUX_SRCS)
+
+SERVERCONFIG_DATA += XSELinuxConfig
+AM_CFLAGS += -DXSELINUXCONFIGFILE=\"$(SERVERCONFIGdir)/XSELinuxConfig\"
+endif
+
 # Security extension: multi-level security to protect clients from each other
 XCSECURITY_SRCS = security.c securitysrv.h
 if XCSECURITY   
commit a7f4bbea87ada1d699bfd9e3b6a98f06191650f6
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:17:01 2006 -0400

    Add SELinux extension to the module/extension loader.

diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 41f060b..131b9e6 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -129,6 +129,11 @@ extern void ShmRegisterFuncs(
 extern void XaceExtensionInit(INITARGS);
 #endif
 
+#ifdef XSELINUX
+extern void XSELinuxExtensionSetup(INITARGS);
+extern void XSELinuxExtensionInit(INITARGS);
+#endif
+
 #if 1
 extern void SecurityExtensionSetup(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index cb34473..e270bc6 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -248,6 +248,9 @@ typedef void (*InitExtension)(INITARGS);
 #include "securitysrv.h"
 #include <X11/extensions/securstr.h>
 #endif
+#ifdef XSELINUX
+#include "xselinux.h"
+#endif
 #ifdef PANORAMIX
 #include <X11/extensions/panoramiXproto.h>
 #endif
@@ -321,6 +324,10 @@ extern void XaceExtensionInit(INITARGS);
 extern void SecurityExtensionSetup(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
 #endif
+#ifdef XSELINUX
+extern void XSELinuxExtensionSetup(INITARGS);
+extern void XSELinuxExtensionInit(INITARGS);
+#endif
 #ifdef XPRINT
 extern void XpExtensionInit(INITARGS);
 #endif
@@ -532,6 +539,9 @@ InitExtensions(argc, argv)
 #ifdef XCSECURITY
     SecurityExtensionSetup();
 #endif
+#ifdef XSELINUX
+    XSELinuxExtensionSetup();
+#endif
 #ifdef PANORAMIX
 # if !defined(PRINT_ONLY_SERVER) && !defined(NO_PANORAMIX)
   if (!noPanoramiXExtension) PanoramiXExtensionInit();
@@ -600,6 +610,9 @@ InitExtensions(argc, argv)
 #ifdef XCSECURITY
     if (!noSecurityExtension) SecurityExtensionInit();
 #endif
+#ifdef XSELINUX
+    XSELinuxExtensionInit();
+#endif
 #ifdef XPRINT
     XpExtensionInit(); /* server-specific extension, cannot be disabled */
 #endif
@@ -705,6 +718,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef XCSECURITY
     { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, SecurityExtensionSetup, NULL },
 #endif
+#ifdef XSELINUX
+    { XSELinuxExtensionInit, XSELINUX_EXTENSION_NAME, NULL, XSELinuxExtensionSetup, NULL },
+#endif
 #ifdef XPRINT
     { XpExtensionInit, XP_PRINTNAME, NULL, NULL, NULL },
 #endif
commit 28e80cd65b1207b123c02f895851bb6d207aa3c1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:15:19 2006 -0400

    Add SELinux extension configure-time support.

diff --git a/configure.ac b/configure.ac
index 002be62..7e931ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -442,6 +442,7 @@ AC_ARG_ENABLE(xinerama,	      AS_HELP_STRING([--disable-xinerama], [Build Xinera
 AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: auto)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=auto])
 AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: auto)]), [XF86MISC=$enableval], [XF86MISC=auto])
 AC_ARG_ENABLE(xace,     AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
+AC_ARG_ENABLE(xselinux,     AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: enabled)]), [XSELINUX=$enableval], [XSELINUX=$XACE])
 AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (default: enabled)]), [XCSECURITY=$enableval], [XCSECURITY=$XACE])
 AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
 AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
@@ -676,6 +677,19 @@ if test "x$XACE" = xyes; then
 	AC_DEFINE(XACE, 1, [Build X-ACE extension])
 fi
 
+AM_CONDITIONAL(XSELINUX, [test "x$XSELINUX" = xyes])
+if test "x$XSELINUX" = xyes; then
+	if test "x$XACE" != xyes; then
+		AC_MSG_ERROR([cannot build SELinux extension without X-ACE])
+	fi
+	AC_CHECK_HEADERS([selinux/selinux.h selinux/avc.h], [], AC_MSG_ERROR([SELinux include files not found]))
+	AC_CHECK_LIB(selinux, avc_init, [], AC_MSG_ERROR([SELinux library not found])) 
+	AC_CHECK_HEADERS([libaudit.h], [], AC_MSG_ERROR([SELinux extension requires audit system headers]))
+	AC_CHECK_LIB(audit, audit_log_avc, [], AC_MSG_ERROR([SELinux extension requires audit system library]))
+	AC_DEFINE(XSELINUX, 1, [Build SELinux extension])
+	SELINUX_LIB="-lselinux -laudit"
+fi
+
 AM_CONDITIONAL(XCSECURITY, [test "x$XCSECURITY" = xyes])
 if test "x$XCSECURITY" = xyes; then
 	if test "x$XACE" != xyes; then
@@ -1162,7 +1176,7 @@ if test "x$XORG" = xyes -o "x$XGL" = xyes; then
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $OS_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB $OS_LIB"
 
 	if test "x$DGA" = xauto; then
 		PKG_CHECK_MODULES(DGA, xf86dgaproto, [DGA=yes], [DGA=no])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 7aabae2..4a0b128 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -317,6 +317,9 @@
 /* Build X-ACE extension */
 #undef XACE
 
+/* Build SELinux extension */
+#undef XSELINUX
+
 /* Support XCMisc extension */
 #undef XCMISC
 
commit 83aad2be8a80890f349c2f9caf84786333f7cc8c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:11:04 2006 -0400

    Add SELinux extension source files.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
new file mode 100644
index 0000000..faf815e
--- /dev/null
+++ b/Xext/XSELinuxConfig
@@ -0,0 +1,83 @@
+#
+# Config file for XSELinux extension
+#
+
+#
+# The nonlocal_context rule defines a context to be used for all clients
+# connecting to the server from a remote host.  The nonlocal context must
+# be defined, and it must be a valid context according to the SELinux
+# security policy.  Only one nonlocal_context rule may be defined.
+#
+nonlocal_context			system_u:object_r:remote_xclient_t:s1
+
+#
+# Property rules map a property name to a SELinux type.  The type must
+# be valid according to the SELinux security policy.  There can be any
+# number of property rules.  Additionally, a default property type can be
+# defined for all properties not explicitly listed.  The default
+# property type may not be omitted.  The default rule may appear in
+# any position (it need not be the last property rule listed).
+#
+property WM_NAME			wm_property_t
+property WM_CLASS			wm_property_t
+property WM_ICON_NAME			wm_property_t
+property WM_HINTS			wm_property_t
+property WM_NORMAL_HINTS		wm_property_t
+property WM_COMMAND			wm_property_t
+
+property CUT_BUFFER0			cut_buffer_property_t
+property CUT_BUFFER1			cut_buffer_property_t
+property CUT_BUFFER2			cut_buffer_property_t
+property CUT_BUFFER3			cut_buffer_property_t
+property CUT_BUFFER4			cut_buffer_property_t
+property CUT_BUFFER5			cut_buffer_property_t
+property CUT_BUFFER6			cut_buffer_property_t
+property CUT_BUFFER7			cut_buffer_property_t
+
+property default			unknown_property_t
+
+#
+# Extension rules map an extension name to a SELinux type.  The type must
+# be valid according to the SELinux security policy.  There can be any
+# number of extension rules.  Additionally, a default extension type can
+# be defined for all extensions not explicitly listed.  The default
+# extension type may not be omitted.  The default rule may appear in
+# any position (it need not be the last extension rule listed).
+#
+extension BIG-REQUESTS			std_ext_t
+extension DOUBLE-BUFFER			std_ext_t
+extension DPMS				screensaver_ext_t
+extension Extended-Visual-Information	std_ext_t
+extension FontCache			font_ext_t
+extension GLX				std_ext_t
+extension LBX				std_ext_t
+extension MIT-SCREEN-SAVER		screensaver_ext_t
+extension MIT-SHM			shmem_ext_t
+extension MIT-SUNDRY-NONSTANDARD	std_ext_t
+extension NV-CONTROL			accelgraphics_ext_t
+extension NV-GLX			accelgraphics_ext_t
+extension NVIDIA-GLX			accelgraphics_ext_t
+extension RANDR				std_ext_t
+extension RECORD			debug_ext_t
+extension RENDER			std_ext_t
+extension SECURITY			security_ext_t
+extension SELinux			security_ext_t
+extension SHAPE				std_ext_t
+extension SYNC				sync_ext_t
+extension TOG-CUP			windowmgr_ext_t
+extension X-Resource			debug_ext_t
+extension XAccessControlExtension	security_ext_t
+extension XACEUSR			security_ext_t
+extension XC-APPGROUP			security_ext_t
+extension XC-MISC			std_ext_t
+extension XFree86-Bigfont		font_ext_t
+extension XFree86-DGA			accelgraphics_ext_t
+extension XFree86-Misc			std_ext_t
+extension XFree86-VidModeExtension	video_ext_t
+extension XInputExtension		input_ext_t
+extension XKEYBOARD			input_ext_t
+extension XpExtension                   std_ext_t
+extension XTEST				debug_ext_t
+extension XVideo			video_ext_t
+extension XVideo-MotionCompensation	video_ext_t
+extension default			unknown_ext_t
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
new file mode 100644
index 0000000..5a6d2ef
--- /dev/null
+++ b/Xext/xselinux.c
@@ -0,0 +1,1884 @@
+/************************************************************
+
+Author: Eamon Walsh <ewalsh at epoch.ncsc.mil>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+this permission notice appear in supporting documentation.  This permission
+notice shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+********************************************************/
+
+/*
+ * Portions of this code copyright (c) 2005 by Trusted Computer Solutions, Inc.
+ * All rights reserved.
+ */
+
+#include <selinux/flask.h>
+#include <selinux/av_permissions.h>
+#include <selinux/selinux.h>
+#include <selinux/context.h>
+#include <selinux/avc.h>
+
+#include <libaudit.h>
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/Xfuncproto.h>
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "resource.h"
+#include "selection.h"
+#include "xacestr.h"
+#include "xselinux.h"
+#define XSERV_t
+#define TRANS_SERVER
+#include <X11/Xtrans/Xtrans.h>
+#include "../os/osdep.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "modinit.h"
+
+#ifndef XSELINUXCONFIGFILE
+#warning "XSELinux Policy file is not defined"
+#define XSELINUXCONFIGFILE  NULL
+#endif
+
+
+/* Make sure a locally connecting client has a valid context.  The context
+ * for this client is retrieved again later on in AssignClientState(), but
+ * by that point it's too late to reject the client.
+ */
+static char *
+XSELinuxValidContext (ClientPtr client)
+{
+    security_context_t ctx = NULL;
+    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+    char reason[256];
+    char *ret = (char *)NULL;
+
+    if (_XSERVTransIsLocal(ci))
+    {
+        int fd = _XSERVTransGetConnectionNumber(ci);
+        if (getpeercon(fd, &ctx) < 0)
+        {
+            snprintf(reason, sizeof(reason), "Failed to retrieve SELinux context from socket");
+            ret = reason;
+            goto out;
+        }
+        if (security_check_context(ctx))
+        {
+            snprintf(reason, sizeof(reason), "Client's SELinux context is invalid: %s", ctx);
+            ret = reason;
+        }
+
+        freecon(ctx);
+    }
+
+out:
+    return ret;
+}
+
+
+/* devPrivates in client and extension */
+static int clientPrivateIndex;
+static int extnsnPrivateIndex;
+
+/* audit file descriptor */
+static int audit_fd;
+
+/* structure passed to auditing callback */
+typedef struct {
+    ClientPtr client;	/* client */
+    char *property;	/* property name, if any */
+    char *extension;	/* extension name, if any */
+} XSELinuxAuditRec;
+
+/*
+ * Table of SELinux types for property names.
+ */
+static char **propertyTypes = NULL;
+static int propertyTypesCount = 0;
+char *XSELinuxPropertyTypeDefault = NULL;
+
+/*
+ * Table of SELinux types for each extension.
+ */
+static char **extensionTypes = NULL;
+static int extensionTypesCount = 0;
+static char *XSELinuxExtensionTypeDefault = NULL;
+
+/* security context for non-local clients */
+static char *XSELinuxNonlocalContextDefault = NULL;
+
+/* security context for the root window */
+static char *XSELinuxRootWindowContext = NULL;
+
+/* Selection stuff from dix */
+extern Selection *CurrentSelections;
+extern int NumCurrentSelections;
+
+/* 
+ * list of classes corresponding to SIDs in the 
+ * rsid array of the security state structure (below).
+ *
+ * XXX SIDs should be stored in their native objects, not all
+ * bunched together in the client structure.  However, this will
+ * require modification to the resource manager.
+ */
+static security_class_t sClasses[] = {
+    SECCLASS_WINDOW,
+    SECCLASS_DRAWABLE,
+    SECCLASS_GC,
+    SECCLASS_CURSOR,
+    SECCLASS_FONT,
+    SECCLASS_COLORMAP,
+    SECCLASS_PROPERTY,
+    SECCLASS_XCLIENT,
+    SECCLASS_XINPUT
+};
+#define NRES (sizeof(sClasses)/sizeof(sClasses[0]))
+
+/* This is what we store for client security state */
+typedef struct {
+    int haveState;
+    security_id_t sid;
+    security_id_t rsid[NRES];
+    struct avc_entry_ref aeref;
+} XSELinuxClientStateRec;
+
+/* Convenience macros for accessing security state fields */
+#define STATEPTR(client) \
+    ((client)->devPrivates[clientPrivateIndex].ptr)
+#define HAVESTATE(client) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->haveState)
+#define SID(client) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->sid)
+#define RSID(client,n) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->rsid[n])
+#define AEREF(client) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->aeref)
+#define EXTENSIONSID(ext) \
+    ((ext)->devPrivates[extnsnPrivateIndex].ptr)
+
+/*
+ * Returns the index into the rsid array where the SID for the
+ * given class is stored.
+ */
+static int
+IndexByClass(security_class_t class)
+{
+    int i;
+    for (i=0; i<NRES; i++)
+	if (class == sClasses[i])
+	    return i;
+    return 0;
+}
+
+/*
+ * Does sanity checking on a resource ID.  This can be removed after 
+ * testing.
+ */
+static void
+CheckXID(XID id)
+{
+    /*
+    XID c = CLIENT_ID(id);
+
+    if (c > 10)
+	ErrorF("Warning: possibly mangled ID %x\n", id);
+
+    c = id & RESOURCE_ID_MASK;
+    if (c > 100)
+	ErrorF("Warning: possibly mangled ID %x\n", id);
+        */
+}
+
+/*
+ * Byte-swap a CARD32 id if necessary.
+ */
+static XID
+SwapXID(ClientPtr client, XID id)
+{
+    register char n;
+    if (client->swapped)
+	swapl(&id, n);
+    return id;
+}
+
+/*
+ * ServerPerm - check access permissions on a server-owned object.
+ *
+ * Arguments:
+ * client: Client doing the request.
+ * class: Security class of the server object being accessed.
+ * perm: Permissions required on the object.
+ *
+ * Returns: boolean TRUE=allowed, FALSE=denied.
+ */
+static int
+ServerPerm(ClientPtr client,
+	   security_class_t class,
+	   access_vector_t perm)
+{
+    int idx = IndexByClass(class);
+    if (HAVESTATE(client))
+    {
+	XSELinuxAuditRec auditdata;
+	auditdata.client = client;
+	auditdata.property = NULL;
+	auditdata.extension = NULL;
+	errno = 0;
+        if (avc_has_perm(SID(client), RSID(serverClient,idx), class,
+                         perm, &AEREF(client), &auditdata) < 0)
+        {
+            if (errno != EACCES)
+                ErrorF("ServerPerm: unexpected error %d\n", errno);
+            return FALSE;
+        }
+    }
+    else
+    {
+	ErrorF("No client state in server-perm check!\n");
+        return TRUE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * IDPerm - check access permissions on a resource.
+ *
+ * Arguments:
+ * client: Client doing the request.
+ * id: resource id of the resource being accessed.
+ * class: Security class of the resource being accessed.
+ * perm: Permissions required on the resource.
+ *
+ * Returns: boolean TRUE=allowed, FALSE=denied.
+ */
+static int
+IDPerm(ClientPtr sclient,
+	 XID id,
+	 security_class_t class,
+	 access_vector_t perm)
+{
+    ClientPtr tclient;
+    int idx = IndexByClass(class);
+    XSELinuxAuditRec auditdata;
+
+    if (id == None)
+	return TRUE;
+
+    CheckXID(id);
+    tclient = clients[CLIENT_ID(id)];
+
+    /*
+     * This happens in the case where a client has
+     * disconnected.  XXX might want to make the server
+     * own orphaned resources...
+     */
+    if (!tclient || !HAVESTATE(tclient) || !HAVESTATE(sclient))
+    {
+	return TRUE;
+    }
+
+    auditdata.client = sclient;
+    auditdata.property = NULL;
+    auditdata.extension = NULL;
+    errno = 0;
+    if (avc_has_perm(SID(sclient), RSID(tclient,idx), class,
+		     perm, &AEREF(sclient), &auditdata) < 0)
+    {
+	if (errno != EACCES)
+	    ErrorF("IDPerm: unexpected error %d\n", errno);
+	return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * ObjectSIDByLabel - get SID for an extension or property.
+ *
+ * Arguments:
+ * class: should be SECCLASS_XEXTENSION or SECCLASS_PROPERTY.
+ * name: name of the extension or property.
+ *
+ * Returns: proper SID for the object or NULL on error.
+ */
+static security_id_t
+ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
+                 const char *name)
+{
+    security_context_t base, new;
+    context_t con;
+    security_id_t sid = NULL;
+    char **ptr, *type = NULL;
+
+    if (basecontext != NULL)
+    {
+        /* use the supplied context */
+        base = strdup(basecontext);
+        if (base == NULL)
+            goto out;
+    }
+    else
+    {
+        /* get server context */
+        if (getcon(&base) < 0)
+            goto out;
+    }
+
+    /* make a new context-manipulation object */
+    con = context_new(base);
+    if (!con)
+	goto out2;
+    
+    /* look in the mappings of names to types */
+    ptr = (class == SECCLASS_PROPERTY) ? propertyTypes : extensionTypes;
+    for (; *ptr; ptr+=2)
+	if (!strcmp(*ptr, name))
+	    break;
+    type = ptr[1];
+
+    /* set the role and type in the context (user unchanged) */
+    if (context_type_set(con, type) ||
+	context_role_set(con, "object_r"))
+	goto out3;
+
+    /* get a context string from the context-manipulation object */
+    new = context_str(con);
+    if (!new)
+	goto out3;
+
+    /* get a SID for the context */
+    if (avc_context_to_sid(new, &sid) < 0)
+	goto out3;
+
+  out3:
+    context_free(con);
+  out2:
+    freecon(base);
+  out:
+    return sid;
+}
+
+/*
+ * AssignClientState - set up client security state.
+ *
+ * Arguments:
+ * client: client to set up (can be serverClient).
+ */
+static void
+AssignClientState(ClientPtr client)
+{
+    int i, needToFree = 0;
+    security_context_t basectx, objctx;
+    XSELinuxClientStateRec *state = (XSELinuxClientStateRec*)STATEPTR(client);
+    Bool isServerClient = FALSE;
+
+    avc_entry_ref_init(&state->aeref);
+
+    if (client->index > 0)
+    {
+	XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+	if (_XSERVTransIsLocal(ci)) {
+	    /* for local clients, can get context from the socket */
+	    int fd = _XSERVTransGetConnectionNumber(ci);
+	    if (getpeercon(fd, &basectx) < 0)
+	    {
+		FatalError("Client %d: couldn't get context from socket\n",
+			   client->index);
+	    }
+	    needToFree = 1;
+	}
+        else
+        {
+	    /* for remote clients, need to use a default context */
+	    basectx = XSELinuxNonlocalContextDefault;
+	}
+    }
+    else
+    {
+        isServerClient = TRUE;
+
+	/* use the context of the X server process for the serverClient */
+	if (getcon(&basectx) < 0)
+	{
+	    FatalError("Couldn't get context of X server process\n");
+	}
+	needToFree = 1;
+    }
+
+    /* get a SID from the context */
+    if (avc_context_to_sid(basectx, &state->sid) < 0)
+    {
+	FatalError("Client %d: couldn't get security ID for client\n",
+		   client->index);
+    }
+
+    /* get contexts and then SIDs for each resource type */
+    for (i=0; i<NRES; i++)
+    {
+	if (security_compute_create(basectx, basectx, sClasses[i],
+				    &objctx) < 0)
+	{
+	    FatalError("Client %d: couldn't get context for class %x\n",
+		       client->index, sClasses[i]);
+	}
+	else if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
+	{
+	    FatalError("Client %d: couldn't get SID for class %x\n",
+		       client->index, sClasses[i]);
+	}
+	freecon(objctx);
+    }
+
+    /* special handling for serverClient windows (that is, root windows) */
+    if (isServerClient == TRUE)
+    {
+        i = IndexByClass(SECCLASS_WINDOW);
+        sidput(state->rsid[i]);
+        if (avc_context_to_sid(XSELinuxRootWindowContext, &state->rsid[i]))
+        {
+            FatalError("Failed to set SID for root window\n");
+        }
+    }
+
+    /* mark as set up, free base context if necessary, and return */
+    state->haveState = TRUE;
+    if (needToFree)
+	freecon(basectx);
+}
+
+/*
+ * FreeClientState - tear down client security state.
+ *
+ * Arguments:
+ * client: client to release (can be serverClient).
+ */
+static void
+FreeClientState(ClientPtr client)
+{
+    int i;
+    XSELinuxClientStateRec *state = (XSELinuxClientStateRec*)STATEPTR(client);
+
+    /* client state may not be set up if its auth was rejected */
+    if (state->haveState) {
+	state = (XSELinuxClientStateRec*)STATEPTR(client);
+	sidput(state->sid);
+	for (i=0; i<NRES; i++)
+	    sidput(state->rsid[i]);
+	state->haveState = FALSE;
+    }
+}
+
+#define REQUEST_SIZE_CHECK(client, req) \
+    (client->req_len >= (sizeof(req) >> 2))
+#define IDPERM(client, req, field, class, perm) \
+    (REQUEST_SIZE_CHECK(client,req) && \
+    IDPerm(client, SwapXID(client,((req*)stuff)->field), class, perm))
+#define CALLBACK(name) static void \
+name(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
+
+static int
+CheckSendEventPerms(ClientPtr client)
+{
+    register char n;
+    access_vector_t perm = 0;
+    REQUEST(xSendEventReq);
+
+    /* might need type bounds checking here */
+    if (!REQUEST_SIZE_CHECK(client, xSendEventReq))
+	return FALSE;
+
+    switch (stuff->event.u.u.type) {
+	case SelectionClear:
+	case SelectionNotify:
+	case SelectionRequest:
+	case ClientMessage:
+	case PropertyNotify:
+	    perm = WINDOW__CLIENTCOMEVENT;
+	    break;
+	case ButtonPress:
+	case ButtonRelease:
+	case KeyPress:
+	case KeyRelease:
+	case KeymapNotify:
+	case MotionNotify:
+	case EnterNotify:
+	case LeaveNotify:
+	case FocusIn:
+	case FocusOut:
+	    perm = WINDOW__INPUTEVENT;
+	    break;
+	case Expose:
+	case GraphicsExpose:
+	case NoExpose:
+	case VisibilityNotify:
+	    perm = WINDOW__DRAWEVENT;
+	    break;
+	case CirculateNotify:
+	case ConfigureNotify:
+	case CreateNotify:
+	case DestroyNotify:
+	case MapNotify:
+	case UnmapNotify:
+	case GravityNotify:
+	case ReparentNotify:
+	    perm = WINDOW__WINDOWCHANGEEVENT;
+	    break;
+	case CirculateRequest:
+	case ConfigureRequest:
+	case MapRequest:
+	case ResizeRequest:
+	    perm = WINDOW__WINDOWCHANGEREQUEST;
+	    break;
+	case ColormapNotify:
+	case MappingNotify:
+	    perm = WINDOW__SERVERCHANGEEVENT;
+	    break;
+	default:
+	    perm = WINDOW__EXTENSIONEVENT;
+	    break;
+    }
+    if (client->swapped)
+	swapl(&stuff->destination, n);
+    return IDPerm(client, stuff->destination, SECCLASS_WINDOW, perm);
+}
+     
+static int
+CheckConvertSelectionPerms(ClientPtr client)
+{
+    register char n;
+    int rval = TRUE;
+    REQUEST(xConvertSelectionReq);
+    
+    if (!REQUEST_SIZE_CHECK(client, xConvertSelectionReq))
+	return FALSE;
+
+    if (client->swapped)
+    {
+	swapl(&stuff->selection, n);
+	swapl(&stuff->requestor, n);
+    }
+
+    if (ValidAtom(stuff->selection))
+    {
+	int i = 0;
+	while ((i < NumCurrentSelections) &&
+	       CurrentSelections[i].selection != stuff->selection) i++;
+	if (i < NumCurrentSelections)
+	    rval = rval && IDPerm(client, CurrentSelections[i].window,
+				  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
+    }
+    rval = rval && IDPerm(client, stuff->requestor,
+			  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
+    return rval;
+}
+
+static int
+CheckSetSelectionOwnerPerms(ClientPtr client)
+{
+    register char n;
+    int rval = TRUE;
+    REQUEST(xSetSelectionOwnerReq);
+
+    if (!REQUEST_SIZE_CHECK(client, xSetSelectionOwnerReq))
+	return FALSE;
+
+    if (client->swapped)
+    {
+	swapl(&stuff->selection, n);
+	swapl(&stuff->window, n);
+    }
+
+    if (ValidAtom(stuff->selection))
+    {
+	int i = 0;
+	while ((i < NumCurrentSelections) &&
+	       CurrentSelections[i].selection != stuff->selection) i++;
+	if (i < NumCurrentSelections)
+	    rval = rval && IDPerm(client, CurrentSelections[i].window,
+				  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+    }
+    rval = rval && IDPerm(client, stuff->window, 
+			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+    return rval;
+}
+    
+CALLBACK(XSELinuxCoreDispatch)
+{
+    XaceCoreDispatchRec *rec = (XaceCoreDispatchRec*)calldata;
+    ClientPtr client = rec->client;
+    REQUEST(xReq);
+    Bool rval;
+
+    switch(stuff->reqType) {
+    /* Drawable class control requirements */
+    case X_ClearArea:
+	rval = IDPERM(client, xClearAreaReq, window,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_PolySegment:
+    case X_PolyRectangle:
+    case X_PolyArc:
+    case X_PolyFillRectangle:
+    case X_PolyFillArc:
+	rval = IDPERM(client, xPolySegmentReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_PolyPoint:
+    case X_PolyLine:
+	rval = IDPERM(client, xPolyPointReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_FillPoly:
+	rval = IDPERM(client, xFillPolyReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_PutImage:
+	rval = IDPERM(client, xPutImageReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_CopyArea:
+    case X_CopyPlane:
+	rval = IDPERM(client, xCopyAreaReq, srcDrawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY)
+	    && IDPERM(client, xCopyAreaReq, dstDrawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_GetImage:
+	rval = IDPERM(client, xGetImageReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
+	break;
+    case X_GetGeometry:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_DRAWABLE, DRAWABLE__GETATTR);
+	break;
+
+    /* Window class control requirements */
+    case X_ChangeProperty:
+	rval = IDPERM(client, xChangePropertyReq, window,
+		      SECCLASS_WINDOW, 
+		      WINDOW__CHPROPLIST | WINDOW__CHPROP |
+		      WINDOW__LISTPROP);
+	break;
+    case X_ChangeSaveSet:
+	rval = IDPERM(client, xChangeSaveSetReq, window,
+		      SECCLASS_WINDOW,
+		      WINDOW__CTRLLIFE | WINDOW__CHPARENT);
+	break;
+    case X_ChangeWindowAttributes:
+	rval = IDPERM(client, xChangeWindowAttributesReq, window,
+		      SECCLASS_WINDOW, WINDOW__SETATTR);
+	break;
+    case X_CirculateWindow:
+	rval = IDPERM(client, xCirculateWindowReq, window,
+		      SECCLASS_WINDOW, WINDOW__CHSTACK);
+	break;
+    case X_ConfigureWindow:
+	rval = IDPERM(client, xConfigureWindowReq, window,
+		      SECCLASS_WINDOW,
+		      WINDOW__SETATTR | WINDOW__MOVE | WINDOW__CHSTACK);
+	break;
+    case X_ConvertSelection:
+	rval = CheckConvertSelectionPerms(client);
+	break;
+    case X_CreateWindow:
+	rval = IDPERM(client, xCreateWindowReq, wid,
+		      SECCLASS_WINDOW,
+		      WINDOW__CREATE | WINDOW__SETATTR | WINDOW__MOVE)
+	    && IDPERM(client, xCreateWindowReq, parent,
+		      SECCLASS_WINDOW,
+		      WINDOW__CHSTACK | WINDOW__ADDCHILD)
+	    && IDPERM(client, xCreateWindowReq, wid,
+		      SECCLASS_DRAWABLE, DRAWABLE__CREATE);
+	break;
+    case X_DeleteProperty:
+	rval = IDPERM(client, xDeletePropertyReq, window,
+		      SECCLASS_WINDOW,
+		      WINDOW__CHPROP | WINDOW__CHPROPLIST);
+	break;
+    case X_DestroyWindow:
+    case X_DestroySubwindows:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW,
+		      WINDOW__ENUMERATE | WINDOW__UNMAP | WINDOW__DESTROY)
+	    && IDPERM(client, xResourceReq, id,
+		      SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
+	break;
+    case X_GetMotionEvents:
+	rval = IDPERM(client, xGetMotionEventsReq, window,
+		      SECCLASS_WINDOW, WINDOW__MOUSEMOTION);
+	break;
+    case X_GetProperty:
+	rval = IDPERM(client, xGetPropertyReq, window,
+		      SECCLASS_WINDOW, WINDOW__LISTPROP);
+	break;
+    case X_GetWindowAttributes:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW, WINDOW__GETATTR);
+	break;
+    case X_KillClient:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_XCLIENT, XCLIENT__KILL);
+	break;
+    case X_ListProperties:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW, WINDOW__LISTPROP);
+	break;
+    case X_MapWindow:
+    case X_MapSubwindows:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW,
+		      WINDOW__ENUMERATE | WINDOW__GETATTR | WINDOW__MAP);
+	break;
+    case X_QueryTree:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW, WINDOW__ENUMERATE | WINDOW__GETATTR);
+	break;
+    case X_RotateProperties:
+	rval = IDPERM(client, xRotatePropertiesReq, window,
+		      SECCLASS_WINDOW, WINDOW__CHPROP | WINDOW__CHPROPLIST);
+	break;
+    case X_ReparentWindow:
+	rval = IDPERM(client, xReparentWindowReq, window,
+		      SECCLASS_WINDOW, WINDOW__CHPARENT | WINDOW__MOVE)
+	    && IDPERM(client, xReparentWindowReq, parent,
+		      SECCLASS_WINDOW, WINDOW__CHSTACK | WINDOW__ADDCHILD);
+	break;
+    case X_SendEvent:
+	rval = CheckSendEventPerms(client);
+	break;
+    case X_SetInputFocus:
+	rval = IDPERM(client, xSetInputFocusReq, focus,
+		      SECCLASS_WINDOW, WINDOW__SETFOCUS)
+	    && ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETFOCUS);
+	break;
+    case X_SetSelectionOwner:
+	rval = CheckSetSelectionOwnerPerms(client);
+	break;
+    case X_TranslateCoords:
+	rval = IDPERM(client, xTranslateCoordsReq, srcWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR)
+	    && IDPERM(client, xTranslateCoordsReq, dstWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR);
+	break;
+    case X_UnmapWindow:
+    case X_UnmapSubwindows:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW,
+		      WINDOW__ENUMERATE | WINDOW__GETATTR |
+		      WINDOW__UNMAP);
+	break;
+    case X_WarpPointer:
+	rval = IDPERM(client, xWarpPointerReq, srcWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR)
+	    && IDPERM(client, xWarpPointerReq, dstWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR)
+	    && ServerPerm(client, SECCLASS_XINPUT, XINPUT__WARPPOINTER);
+	break;
+
+    /* Input class control requirements */
+    case X_GrabButton:
+    case X_GrabKey:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__PASSIVEGRAB);
+	break;
+    case X_GrabKeyboard:
+    case X_GrabPointer:
+    case X_ChangeActivePointerGrab:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__ACTIVEGRAB);
+	break;
+    case X_AllowEvents:
+    case X_UngrabButton:
+    case X_UngrabKey:
+    case X_UngrabKeyboard:
+    case X_UngrabPointer:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__UNGRAB);
+	break;
+    case X_GetKeyboardControl:
+    case X_GetKeyboardMapping:
+    case X_GetPointerControl:
+    case X_GetPointerMapping:
+    case X_GetModifierMapping:
+    case X_QueryKeymap:
+    case X_QueryPointer:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__GETATTR);
+	break;
+    case X_ChangeKeyboardControl:
+    case X_ChangePointerControl:
+    case X_ChangeKeyboardMapping:
+    case X_SetModifierMapping:
+    case X_SetPointerMapping:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETATTR);
+	break;
+    case X_Bell:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__BELL);
+	break;
+
+    /* Colormap class control requirements */
+    case X_AllocColor:
+    case X_AllocColorCells:
+    case X_AllocColorPlanes:
+    case X_AllocNamedColor:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP,
+		      COLORMAP__READ | COLORMAP__STORE);
+	break;
+    case X_CopyColormapAndFree:
+	rval = IDPERM(client, xCopyColormapAndFreeReq, mid,
+		      SECCLASS_COLORMAP, COLORMAP__CREATE)
+	    && IDPERM(client, xCopyColormapAndFreeReq, srcCmap,
+		      SECCLASS_COLORMAP,
+		      COLORMAP__READ | COLORMAP__FREE);
+	break;
+    case X_CreateColormap:
+	rval = IDPERM(client, xCreateColormapReq, mid,
+		      SECCLASS_COLORMAP, COLORMAP__CREATE)
+	    && IDPERM(client, xCreateColormapReq, window,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_FreeColormap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__FREE);
+	break;
+    case X_FreeColors:
+	rval = IDPERM(client, xFreeColorsReq, cmap,
+		      SECCLASS_COLORMAP, COLORMAP__STORE);
+	break;
+    case X_InstallColormap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__INSTALL)
+	    && ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__INSTALL);
+	break;
+    case X_ListInstalledColormaps:
+	rval = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__LIST);
+	break;
+    case X_LookupColor:
+    case X_QueryColors:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__READ);
+	break;
+    case X_StoreColors:
+    case X_StoreNamedColor:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__STORE);
+	break;
+    case X_UninstallColormap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__UNINSTALL)
+	    && ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
+	break;
+
+    /* Font class control requirements */
+    case X_CloseFont:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_FONT, FONT__FREE);
+	break;
+    case X_ImageText8:
+    case X_ImageText16:
+	/* Font accesses checked through the resource manager */
+	rval = IDPERM(client, xImageTextReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_OpenFont:
+	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD)
+	    && IDPERM(client, xOpenFontReq, fid,
+		      SECCLASS_FONT, FONT__USE);
+	break;
+    case X_PolyText8:
+    case X_PolyText16:
+	/* Font accesses checked through the resource manager */
+	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD)
+	    && IDPERM(client, xPolyTextReq, gc,
+		      SECCLASS_GC, GC__SETATTR)
+	    && IDPERM(client, xPolyTextReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+	
+    /* Pixmap class control requirements */
+    case X_CreatePixmap:
+	rval = IDPERM(client, xCreatePixmapReq, pid,
+		      SECCLASS_DRAWABLE, DRAWABLE__CREATE);
+	break;
+    case X_FreePixmap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
+	break;
+
+    /* Cursor class control requirements */
+    case X_CreateCursor:
+	rval = IDPERM(client, xCreateCursorReq, cid,
+		      SECCLASS_CURSOR, CURSOR__CREATE)
+	    && IDPERM(client, xCreateCursorReq, source,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW)
+	    && IDPERM(client, xCreateCursorReq, mask,
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
+	break;
+    case X_CreateGlyphCursor:
+	rval = IDPERM(client, xCreateGlyphCursorReq, cid,
+		      SECCLASS_CURSOR, CURSOR__CREATEGLYPH)
+	    && IDPERM(client, xCreateGlyphCursorReq, source,
+		      SECCLASS_FONT, FONT__USE)
+	    && IDPERM(client, xCreateGlyphCursorReq, mask,
+		      SECCLASS_FONT, FONT__USE);
+	break;
+    case X_RecolorCursor:
+	rval = IDPERM(client, xRecolorCursorReq, cursor,
+		      SECCLASS_CURSOR, CURSOR__SETATTR);
+	break;
+    case X_FreeCursor:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_CURSOR, CURSOR__FREE);
+	break;
+	    
+    /* GC class control requirements */
+    case X_CreateGC:
+	rval = IDPERM(client, xCreateGCReq, gc,
+		      SECCLASS_GC, GC__CREATE | GC__SETATTR);
+	break;
+    case X_ChangeGC:
+    case X_SetDashes:
+    case X_SetClipRectangles:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_GC, GC__SETATTR);
+	break;
+    case X_CopyGC:
+	rval = IDPERM(client, xCopyGCReq, srcGC,
+		      SECCLASS_GC, GC__GETATTR)
+	    && IDPERM(client, xCopyGCReq, dstGC,
+		      SECCLASS_GC, GC__SETATTR);
+	break;
+    case X_FreeGC:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_GC, GC__FREE);
+	break;
+
+    /* Server class control requirements */
+    case X_GrabServer:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GRAB);
+	break;
+    case X_UngrabServer:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__UNGRAB);
+	break;
+    case X_ForceScreenSaver:
+    case X_GetScreenSaver:
+    case X_SetScreenSaver:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SCREENSAVER);
+	break;
+    case X_ListHosts:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETHOSTLIST);
+	break;
+    case X_ChangeHosts:
+    case X_SetAccessControl:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SETHOSTLIST);
+	break;
+    case X_GetFontPath:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETFONTPATH);
+	break;
+    case X_SetFontPath:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SETFONTPATH);
+	break;
+    case X_QueryBestSize:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETATTR);
+	break;
+
+    default:
+	rval = TRUE;
+	break;
+    }
+    if (!rval)
+	rec->rval = FALSE;
+}
+
+CALLBACK(XSELinuxExtDispatch)
+{
+    XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
+    ClientPtr client = rec->client;
+    ExtensionEntry *ext = rec->ext;
+    security_id_t extsid;
+    access_vector_t perm;
+    REQUEST(xReq);
+    
+    /* XXX there should be a separate callback for this */
+    if (!EXTENSIONSID(ext))
+    {
+	extsid = ObjectSIDByLabel(NULL, SECCLASS_XEXTENSION, ext->name);
+	if (!extsid)
+	    return;
+	EXTENSIONSID(ext) = extsid;
+    }
+
+    extsid = (security_id_t)EXTENSIONSID(ext);
+    perm = ((stuff->reqType == X_QueryExtension) ||
+	    (stuff->reqType == X_ListExtensions)) ?
+	XEXTENSION__QUERY : XEXTENSION__USE;
+
+    if (HAVESTATE(client))
+    {
+	XSELinuxAuditRec auditdata;
+	auditdata.client = client;
+	auditdata.property = NULL;
+	auditdata.extension = ext->name;
+	errno = 0;
+	if (avc_has_perm(SID(client), extsid, SECCLASS_XEXTENSION,
+			 perm, &AEREF(client), &auditdata) < 0)
+	{
+	    if (errno != EACCES)
+		ErrorF("ExtDispatch: unexpected error %d\n", errno);
+	    rec->rval = FALSE;
+	}
+    } else
+	ErrorF("No client state in extension dispatcher!\n");
+} /* XSELinuxExtDispatch */
+
+CALLBACK(XSELinuxProperty)
+{
+    XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
+    WindowPtr pWin = rec->pWin;
+    ClientPtr client = rec->client;
+    ClientPtr tclient;
+    access_vector_t perm = 0;
+    security_id_t propsid;
+    char *propname = NameForAtom(rec->propertyName);
+
+    tclient = wClient(pWin);
+    if (!tclient || !HAVESTATE(tclient))
+        return;
+
+    propsid = ObjectSIDByLabel(SID(tclient)->ctx, SECCLASS_PROPERTY, propname);
+    if (!propsid)
+	return;
+
+    if (rec->access_mode & SecurityReadAccess)
+	perm |= PROPERTY__READ;
+    if (rec->access_mode & SecurityWriteAccess)
+	perm |= PROPERTY__WRITE;
+    if (rec->access_mode & SecurityDestroyAccess)
+	perm |= PROPERTY__FREE;
+    if (!rec->access_mode)
+	perm = PROPERTY__READ | PROPERTY__WRITE | PROPERTY__FREE;
+
+    if (HAVESTATE(client))
+    {
+	XSELinuxAuditRec auditdata;
+	auditdata.client = client;
+	auditdata.property = propname;
+	auditdata.extension = NULL;
+	errno = 0;
+	if (avc_has_perm(SID(client), propsid, SECCLASS_PROPERTY,
+			 perm, &AEREF(client), &auditdata) < 0)
+	{
+	    if (errno != EACCES)
+		ErrorF("Property: unexpected error %d\n", errno);
+	    rec->rval = SecurityIgnoreOperation;
+	}
+    } else
+	ErrorF("No client state in property callback!\n");
+
+    /* XXX this should be saved in the property structure */
+    sidput(propsid);
+} /* XSELinuxProperty */
+
+CALLBACK(XSELinuxResLookup)
+{
+    XaceResourceAccessRec *rec = (XaceResourceAccessRec*)calldata;
+    ClientPtr client = rec->client;
+    REQUEST(xReq);
+    access_vector_t perm = 0;
+    Bool rval = TRUE;
+
+    /* serverClient requests OK */
+    if (client->index == 0)
+	return;
+
+    switch(rec->rtype) {
+	case RT_FONT: {
+	    switch(stuff->reqType) {
+		case X_ImageText8:
+		case X_ImageText16:
+		case X_PolyText8:
+		case X_PolyText16:
+		    perm = FONT__USE;
+		    break;
+		case X_ListFonts:
+		case X_ListFontsWithInfo:
+		case X_QueryFont:
+		case X_QueryTextExtents:
+		    perm = FONT__GETATTR;
+		    break;
+		default:
+		    break;
+	    }
+	    if (perm)
+		rval = IDPerm(client, rec->id, SECCLASS_FONT, perm);
+	    break;
+	}
+	default:
+	    break;
+    }
+    if (!rval)
+	rec->rval = FALSE;
+} /* XSELinuxResLookup */
+
+CALLBACK(XSELinuxMap)
+{
+    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
+    if (!IDPerm(rec->client, rec->pWin->drawable.id,
+		SECCLASS_WINDOW, WINDOW__MAP))
+	rec->rval = FALSE;
+} /* XSELinuxMap */
+
+CALLBACK(XSELinuxBackgrnd)
+{
+    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
+    if (!IDPerm(rec->client, rec->pWin->drawable.id,
+		SECCLASS_WINDOW, WINDOW__TRANSPARENT))
+	rec->rval = FALSE;
+} /* XSELinuxBackgrnd */
+
+CALLBACK(XSELinuxDrawable)
+{
+    XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
+    if (!IDPerm(rec->client, rec->pDraw->id,
+		SECCLASS_DRAWABLE, DRAWABLE__COPY))
+	rec->rval = FALSE;
+} /* XSELinuxDrawable */
+
+CALLBACK(XSELinuxHostlist)
+{
+    XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
+    access_vector_t perm = (rec->access_mode == SecurityReadAccess) ?
+	XSERVER__GETHOSTLIST : XSERVER__SETHOSTLIST;
+
+    if (!ServerPerm(rec->client, SECCLASS_XSERVER, perm))
+	rec->rval = FALSE;
+} /* XSELinuxHostlist */
+
+/* Extension callbacks */
+CALLBACK(XSELinuxClientState)
+{
+    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
+    ClientPtr client = pci->client;
+
+    switch(client->clientState)
+    {
+    case ClientStateInitial:
+	AssignClientState(serverClient);
+	break;
+
+	case ClientStateRunning:
+	{
+	    AssignClientState(client);
+	    break;
+	}
+	case ClientStateGone:
+	case ClientStateRetained:
+	{
+	    FreeClientState(client);
+	    break;
+	}
+	default: break;
+    }
+} /* XSELinuxClientState */
+
+static char *XSELinuxKeywords[] = {
+#define XSELinuxKeywordComment 0
+    "#",
+#define XSELinuxKeywordProperty 1
+    "property",
+#define XSELinuxKeywordExtension 2
+    "extension",
+#define XSELinuxKeywordNonlocalContext 3
+    "nonlocal_context",
+#define XSELinuxKeywordRootWindowContext 4
+    "root_window_context",
+#define XSELinuxKeywordDefault 5
+    "default"
+};
+
+#define NUMKEYWORDS (sizeof(XSELinuxKeywords) / sizeof(char *))
+
+#ifndef __UNIXOS2__
+#define XSELinuxIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') )
+#else
+#define XSELinuxIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') )
+#endif
+
+static char *
+XSELinuxSkipWhitespace(
+    char *p)
+{
+    while (XSELinuxIsWhitespace(*p))
+	p++;
+    return p;
+} /* XSELinuxSkipWhitespace */
+
+static char *
+XSELinuxParseString(
+    char **rest)
+{
+    char *startOfString;
+    char *s = *rest;
+    char endChar = 0;
+
+    s = XSELinuxSkipWhitespace(s);
+
+    if (*s == '"' || *s == '\'')
+    {
+	endChar = *s++;
+	startOfString = s;
+	while (*s && (*s != endChar))
+	    s++;
+    }
+    else
+    {
+	startOfString = s;
+	while (*s && !XSELinuxIsWhitespace(*s))
+	    s++;
+    }
+    if (*s)
+    {
+	*s = '\0';
+	*rest = s + 1;
+	return startOfString;
+    }
+    else
+    {
+	*rest = s;
+	return (endChar) ? NULL : startOfString;
+    }
+} /* XSELinuxParseString */
+
+static int
+XSELinuxParseKeyword(
+    char **p)
+{
+    int i;
+    char *s = *p;
+    s = XSELinuxSkipWhitespace(s);
+    for (i = 0; i < NUMKEYWORDS; i++)
+    {
+	int len = strlen(XSELinuxKeywords[i]);
+	if (strncmp(s, XSELinuxKeywords[i], len) == 0)
+	{
+	    *p = s + len;
+	    return (i);
+	}
+    }
+    *p = s;
+    return -1;
+} /* XSELinuxParseKeyword */
+
+static Bool
+XSELinuxTypeIsValid(char *typename)
+{
+    security_context_t base, new;
+    context_t con;
+    Bool ret = FALSE;
+
+    /* get the server's context */
+    if (getcon(&base) < 0)
+        goto out;
+
+    /* make a new context-manipulation object */
+    con = context_new(base);
+    if (!con)
+        goto out_free;
+
+    /* set the role */
+    if (context_role_set(con, "object_r"))
+        goto out_free2;
+
+    /* set the type */
+    if (context_type_set(con, typename))
+        goto out_free2;
+
+    /* get a context string - note: context_str() returns a pointer
+     * to the string inside the context; the returned pointer should
+     * not be freed
+     */
+    new = context_str(con);
+    if (!new)
+        goto out_free2;
+
+    /* finally, check to see if it's valid */
+    if (security_check_context(new) == 0)
+        ret = TRUE;
+
+out_free2:
+    context_free(con);
+out_free:
+    freecon(base);
+out:
+    return ret;
+}
+
+static Bool
+XSELinuxParsePropertyTypeRule(char *p)
+{
+    int keyword;
+    char *propname = NULL, *propcopy = NULL;
+    char *typename = NULL, *typecopy = NULL;
+    char **newTypes;
+    Bool defaultPropertyType = FALSE;
+
+    /* get property name */
+    keyword = XSELinuxParseKeyword(&p);
+    if (keyword == XSELinuxKeywordDefault)
+    {
+        defaultPropertyType = TRUE;
+    }
+    else
+    {
+        propname = XSELinuxParseString(&p);
+        if (!propname || (strlen(propname) == 0))
+        {
+            return FALSE;
+        }
+    }
+
+    /* get the SELinux type corresponding to the property */
+    typename = XSELinuxParseString(&p);
+    if (!typename || (strlen(typename) == 0))
+        return FALSE;
+
+    /* validate the type */
+    if (XSELinuxTypeIsValid(typename) != TRUE)
+        return FALSE;
+
+    /* if it's the default property, save it to append to the end of the
+     * property types list
+     */
+    if (defaultPropertyType == TRUE)
+    {
+        if (XSELinuxPropertyTypeDefault != NULL)
+        {
+            return FALSE;
+        }
+        else
+        {
+            XSELinuxPropertyTypeDefault = (char *)xalloc(strlen(typename)+1);
+            if (!XSELinuxPropertyTypeDefault)
+            {
+                ErrorF("XSELinux: out of memory\n");
+                return FALSE;
+            }
+            strcpy(XSELinuxPropertyTypeDefault, typename);
+            return TRUE;
+        }
+    }
+
+    /* insert the property and type into the propertyTypes array */
+    propcopy = (char *)xalloc(strlen(propname)+1);
+    if (!propcopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(propcopy, propname);
+
+    typecopy = (char *)xalloc(strlen(typename)+1);
+    if (!typecopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(propcopy);
+        return FALSE;
+    }
+    strcpy(typecopy, typename);
+
+    newTypes = (char **)xrealloc(propertyTypes, sizeof (char *) * ((propertyTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(propcopy);
+        xfree(typecopy);
+        return FALSE;
+    }
+
+    propertyTypesCount++;
+
+    newTypes[propertyTypesCount*2 - 2] = propcopy;
+    newTypes[propertyTypesCount*2 - 1] = typecopy;
+    
+    propertyTypes = newTypes;
+
+    return TRUE;
+} /* XSELinuxParsePropertyTypeRule */
+
+static Bool
+XSELinuxParseExtensionTypeRule(char *p)
+{
+    int keyword;
+    char *extname = NULL, *extcopy = NULL;
+    char *typename = NULL, *typecopy = NULL;
+    char **newTypes;
+    Bool defaultExtensionType = FALSE;
+
+    /* get extension name */
+    keyword = XSELinuxParseKeyword(&p);
+    if (keyword == XSELinuxKeywordDefault)
+    {
+        defaultExtensionType = TRUE;
+    }
+    else
+    {
+        extname = XSELinuxParseString(&p);
+        if (!extname || (strlen(extname) == 0))
+        {
+            return FALSE;
+        }
+    }
+
+    /* get the SELinux type corresponding to the extension */
+    typename = XSELinuxParseString(&p);
+    if (!typename || (strlen(typename) == 0))
+        return FALSE;
+
+    /* validate the type */
+    if (XSELinuxTypeIsValid(typename) != TRUE)
+        return FALSE;
+
+    /* if it's the default extension, save it to append to the end of the
+     * extension types list
+     */
+    if (defaultExtensionType == TRUE)
+    {
+        if (XSELinuxExtensionTypeDefault != NULL)
+        {
+            return FALSE;
+        }
+        else
+        {
+            XSELinuxExtensionTypeDefault = (char *)xalloc(strlen(typename)+1);
+            if (!XSELinuxExtensionTypeDefault)
+            {
+                ErrorF("XSELinux: out of memory\n");
+                return FALSE;
+            }
+            strcpy(XSELinuxExtensionTypeDefault, typename);
+            return TRUE;
+        }
+    }
+
+    /* insert the extension and type into the extensionTypes array */
+    extcopy = (char *)xalloc(strlen(extname)+1);
+    if (!extcopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(extcopy, extname);
+
+    typecopy = (char *)xalloc(strlen(typename)+1);
+    if (!typecopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(extcopy);
+        return FALSE;
+    }
+    strcpy(typecopy, typename);
+
+    newTypes = (char **)xrealloc(extensionTypes, sizeof(char *) *( (extensionTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(extcopy);
+        xfree(typecopy);
+        return FALSE;
+    }
+
+    extensionTypesCount++;
+
+    newTypes[extensionTypesCount*2 - 2] = extcopy;
+    newTypes[extensionTypesCount*2 - 1] = typecopy;
+
+    extensionTypes = newTypes;
+
+    return TRUE;
+} /* XSELinuxParseExtensionTypeRule */
+
+static Bool
+XSELinuxParseNonlocalContext(char *p)
+{
+    char *context;
+
+    context = XSELinuxParseString(&p);
+    if (!context || (strlen(context) == 0))
+    {
+        return FALSE;
+    }
+
+    if (XSELinuxNonlocalContextDefault != NULL)
+    {
+        return FALSE;
+    }
+
+    /* validate the context */
+    if (security_check_context(context))
+    {
+        return FALSE;
+    }
+
+    XSELinuxNonlocalContextDefault = (char *)xalloc(strlen(context)+1);
+    if (!XSELinuxNonlocalContextDefault)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(XSELinuxNonlocalContextDefault, context);
+
+    return TRUE;
+} /* XSELinuxParseNonlocalContext */
+
+static Bool
+XSELinuxParseRootWindowContext(char *p)
+{
+    char *context;
+
+    context = XSELinuxParseString(&p);
+    if (!context || (strlen(context) == 0))
+    {
+        return FALSE;
+    }
+
+    if (XSELinuxRootWindowContext != NULL)
+    {
+        return FALSE;
+    }
+
+    /* validate the context */
+    if (security_check_context(context))
+    {
+        return FALSE;
+    }
+
+    XSELinuxRootWindowContext = (char *)xalloc(strlen(context)+1);
+    if (!XSELinuxRootWindowContext)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(XSELinuxRootWindowContext, context);
+
+    return TRUE;
+} /* XSELinuxParseRootWindowContext */
+
+static Bool
+XSELinuxLoadConfigFile(void)
+{
+    FILE *f;
+    int lineNumber = 0;
+    char **newTypes;
+    Bool ret = FALSE;
+    
+    if (!XSELINUXCONFIGFILE)
+        return FALSE;
+
+    /* some initial bookkeeping */
+    propertyTypesCount = extensionTypesCount = 0;
+    propertyTypes = extensionTypes = NULL;
+    XSELinuxPropertyTypeDefault = XSELinuxExtensionTypeDefault = NULL;
+    XSELinuxNonlocalContextDefault = NULL;
+    XSELinuxRootWindowContext = NULL;
+
+#ifndef __UNIXOS2__
+    f = fopen(XSELINUXCONFIGFILE, "r");
+#else
+    f = fopen((char*)__XOS2RedirRoot(XSELINUXCONFIGFILE), "r");
+#endif
+    if (!f)
+    {
+        ErrorF("Error opening XSELinux policy file %s\n", XSELINUXCONFIGFILE);
+        return FALSE;
+    }
+
+    while (!feof(f))
+    {
+        char buf[200];
+        Bool validLine;
+        char *p;
+
+        if (!(p = fgets(buf, sizeof(buf), f)))
+            break;
+        lineNumber++;
+
+        switch (XSELinuxParseKeyword(&p))
+        {
+            case XSELinuxKeywordComment:
+                validLine = TRUE;
+                break;
+
+            case XSELinuxKeywordProperty:
+                validLine = XSELinuxParsePropertyTypeRule(p);
+                break;
+
+            case XSELinuxKeywordExtension:
+                validLine = XSELinuxParseExtensionTypeRule(p);
+                break;
+
+            case XSELinuxKeywordNonlocalContext:
+                validLine = XSELinuxParseNonlocalContext(p);
+                break;
+
+            case XSELinuxKeywordRootWindowContext:
+                validLine = XSELinuxParseRootWindowContext(p);
+                break;
+
+            default:
+                validLine = (*p == '\0');
+                break;
+        }
+
+        if (!validLine)
+        {
+            ErrorF("XSELinux: Line %d of %s is invalid\n",
+                   lineNumber, XSELINUXCONFIGFILE);
+            goto out;
+        }
+    }
+
+    /* check to make sure the default types and the nonlocal context
+     * were specified
+     */
+    if (XSELinuxPropertyTypeDefault == NULL)
+    {
+        ErrorF("XSELinux: No default property type specified\n");
+        goto out;
+    }
+    else if (XSELinuxExtensionTypeDefault == NULL)
+    {
+        ErrorF("XSELinux: No default extension type specified\n");
+        goto out;
+    }
+    else if (XSELinuxNonlocalContextDefault == NULL)
+    {
+        ErrorF("XSELinux: No default context for non-local clients specified\n");
+        goto out;
+    }
+    else if (XSELinuxRootWindowContext == NULL)
+    {
+        ErrorF("XSELinux: No context specified for the root window\n");
+        goto out;
+    }
+
+    /* Finally, append the default property and extension types to the
+     * bottoms of the propertyTypes and extensionTypes arrays, respectively.
+     * The 'name' of the property / extension is NULL.
+     */
+    newTypes = (char **)xrealloc(propertyTypes, sizeof(char *) *((propertyTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        goto out;
+    }
+    propertyTypesCount++;
+    newTypes[propertyTypesCount*2 - 2] = NULL;
+    newTypes[propertyTypesCount*2 - 1] = XSELinuxPropertyTypeDefault;
+    propertyTypes = newTypes;
+
+    newTypes = (char **)xrealloc(extensionTypes, sizeof(char *) *((extensionTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        goto out;
+    }
+    extensionTypesCount++;
+    newTypes[extensionTypesCount*2 - 2] = NULL;
+    newTypes[extensionTypesCount*2 - 1] = XSELinuxExtensionTypeDefault;
+    extensionTypes = newTypes;
+
+    ret = TRUE;
+
+out:
+    fclose(f);
+    return ret;
+} /* XSELinuxLoadConfigFile */
+
+static void
+XSELinuxFreeConfigData(void)
+{
+    char **ptr;
+
+    /* Free all the memory in the table until we reach the NULL, then
+     * skip one past the NULL and free the default type.  Then take care
+     * of some bookkeeping.
+     */
+    for (ptr = propertyTypes; *ptr; ptr++)
+        xfree(*ptr);
+    ptr++;
+    xfree(*ptr);
+
+    XSELinuxPropertyTypeDefault = NULL;
+    propertyTypesCount = 0;
+
+    xfree(propertyTypes);
+    propertyTypes = NULL;
+
+    /* ... and the same for the extension type table */
+    for (ptr = extensionTypes; *ptr; ptr++)
+        xfree(*ptr);
+    ptr++;
+    xfree(*ptr);
+
+    XSELinuxExtensionTypeDefault = NULL;
+    extensionTypesCount = 0;
+
+    xfree(extensionTypes);
+    extensionTypes = NULL;
+
+    /* finally, take care of the context for non-local connections */
+    xfree(XSELinuxNonlocalContextDefault);
+    XSELinuxNonlocalContextDefault = NULL;
+
+    /* ... and for the root window */
+    xfree(XSELinuxRootWindowContext);
+    XSELinuxRootWindowContext = NULL;
+} /* XSELinuxFreeConfigData */
+
+/* Extension dispatch functions */
+static int
+ProcXSELinuxDispatch(ClientPtr client)
+{
+    return BadRequest;
+} /* ProcXSELinuxDispatch */
+
+static void
+XSELinuxResetProc(ExtensionEntry *extEntry)
+{
+    FreeClientState(serverClient);
+
+    XSELinuxFreeConfigData();
+
+    audit_close(audit_fd);
+
+    avc_destroy();
+} /* XSELinuxResetProc */
+
+static void
+XSELinuxAVCAudit(void *auditdata,
+		 security_class_t class,
+		 char *msgbuf,
+		 size_t msgbufsize)
+{
+    XSELinuxAuditRec *audit = (XSELinuxAuditRec*)auditdata;
+    ClientPtr client = audit->client;
+    char requestNum[8];
+    REQUEST(xReq);
+
+    if (stuff)
+	snprintf(requestNum, 8, "%d", stuff->reqType);
+
+    snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s",
+	     stuff ? "request=" : "",
+	     stuff ? requestNum : "",
+	     audit->property ? " property=" : "",
+	     audit->property ? audit->property : "",
+	     audit->extension ? " extension=" : "",
+	     audit->extension ? audit->extension : "");
+}
+
+static void
+XSELinuxAVCLog(const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    VErrorF(fmt, ap);
+    va_end(ap);
+}
+
+/* XSELinuxExtensionSetup
+ *
+ * Set up the XSELinux Extension (pre-init)
+ */
+void
+XSELinuxExtensionSetup(INITARGS)
+{
+    /* Allocate the client private index */
+    clientPrivateIndex = AllocateClientPrivateIndex();
+    if (!AllocateClientPrivate(clientPrivateIndex, 
+			       sizeof (XSELinuxClientStateRec)))
+	FatalError("XSELinux: Failed to allocate client private.\n");
+
+    /* Allocate the extension private index */
+    extnsnPrivateIndex = AllocateExtensionPrivateIndex();
+    if (!AllocateExtensionPrivate(extnsnPrivateIndex, 0))
+	FatalError("XSELinux: Failed to allocate extension private.\n");
+}
+
+/* XSELinuxExtensionInit
+ *
+ * Initialize the XSELinux Extension
+ */
+void
+XSELinuxExtensionInit(INITARGS)
+{
+    ExtensionEntry	*extEntry;
+    struct avc_log_callback alc = {XSELinuxAVCLog, XSELinuxAVCAudit};
+
+    if (!is_selinux_enabled())
+    {
+        ErrorF("SELinux Extension failed to load: SELinux not enabled\n");
+        return;
+    }
+
+    if (avc_init("xserver", NULL, &alc, NULL, NULL) < 0)
+    {
+	FatalError("couldn't initialize SELinux userspace AVC\n");
+    }
+
+    if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
+	return;
+
+    /* Load the config file.  If this fails, shut down the server,
+     * since an unknown security status is worse than no security.
+     *
+     * Note that this must come before we assign a security state
+     * for the serverClient, because the serverClient's root windows
+     * are assigned a context based on data in the config file.
+     */
+    if (XSELinuxLoadConfigFile() != TRUE)
+    {
+	FatalError("XSELinux: Failed to load security policy\n");
+    }
+
+    /* prepare for auditing */
+    audit_fd = audit_open();
+    if (audit_fd < 0)
+    {
+        FatalError("XSELinux: Failed to open the system audit log\n");
+    }
+
+    /* register security callbacks */
+    XaceRegisterCallback(XACE_CORE_DISPATCH, XSELinuxCoreDispatch, NULL);
+    XaceRegisterCallback(XACE_EXT_ACCESS, XSELinuxExtDispatch, NULL);
+    XaceRegisterCallback(XACE_EXT_DISPATCH, XSELinuxExtDispatch, NULL);
+    XaceRegisterCallback(XACE_RESOURCE_ACCESS, XSELinuxResLookup, NULL);
+    XaceRegisterCallback(XACE_MAP_ACCESS, XSELinuxMap, NULL);
+    XaceRegisterCallback(XACE_HOSTLIST_ACCESS, XSELinuxHostlist, NULL);
+    XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
+    XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
+    XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
+    /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
+    XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
+
+    /* register extension with server */
+    extEntry = AddExtension(XSELINUX_EXTENSION_NAME,
+			    XSELinuxNumberEvents, XSELinuxNumberErrors,
+			    ProcXSELinuxDispatch, ProcXSELinuxDispatch,
+			    XSELinuxResetProc, StandardMinorOpcode);
+}
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
new file mode 100644
index 0000000..eff6db5
--- /dev/null
+++ b/Xext/xselinux.h
@@ -0,0 +1,29 @@
+/************************************************************
+
+Author: Eamon Walsh <ewalsh at epoch.ncsc.mil>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+this permission notice appear in supporting documentation.  This permission
+notice shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+********************************************************/
+
+#ifndef _XSELINUX_H
+#define _XSELINUX_H
+
+#define XSELINUX_EXTENSION_NAME		"SELinux"
+#define XSELINUX_MAJOR_VERSION		1
+#define XSELINUX_MINOR_VERSION		0
+#define XSELinuxNumberEvents		0
+#define XSELinuxNumberErrors		0
+
+#endif /* _XSELINUX_H */
commit f3c60900e575e65254cd2576cc6c90b97c8f63ae
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Nov 29 22:19:57 2006 -0500

    Add required root window context to config file.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
index faf815e..9c953f5 100644
--- a/Xext/XSELinuxConfig
+++ b/Xext/XSELinuxConfig
@@ -9,6 +9,7 @@
 # security policy.  Only one nonlocal_context rule may be defined.
 #
 nonlocal_context			system_u:object_r:remote_xclient_t:s1
+root_window_context			system_u:object_r:root_window_t:s1
 
 #
 # Property rules map a property name to a SELinux type.  The type must
commit 143558500a89a5c887c75c03798bae68c953cac9
Merge: e3d3d29... ee9bdd3...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Nov 29 20:41:41 2006 -0500

    Merge branch 'master' into my-XACE-SELINUX

diff --cc configure.ac
index 2d2f299,db2234f..3731204
--- a/configure.ac
+++ b/configure.ac
@@@ -412,10 -439,9 +439,10 @@@ AC_ARG_ENABLE(aiglx,          AS_HELP_S
  AC_ARG_ENABLE(glx-tls,        AS_HELP_STRING([--enable-glx-tls], [Build GLX with TLS support (default: disabled)]), [GLX_USE_TLS=$enableval], [GLX_USE_TLS=no])
  AC_ARG_ENABLE(dri,            AS_HELP_STRING([--enable-dri], [Build DRI extension (default: auto)]), [DRI=$enableval])
  AC_ARG_ENABLE(xinerama,	      AS_HELP_STRING([--disable-xinerama], [Build Xinerama extension (default: enabled)]), [XINERAMA=$enableval], [XINERAMA=yes])
- AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: enabled)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=yes])
- AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: enabled)]), [XF86MISC=$enableval], [XF86MISC=yes])
+ AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: auto)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=auto])
+ AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: auto)]), [XF86MISC=$enableval], [XF86MISC=auto])
  AC_ARG_ENABLE(xace,     AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
 +AC_ARG_ENABLE(xselinux,     AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: enabled)]), [XSELINUX=$enableval], [XSELINUX=$XACE])
  AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (default: enabled)]), [XCSECURITY=$enableval], [XCSECURITY=$XACE])
  AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
  AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
@@@ -1105,8 -1162,39 +1176,39 @@@ if test "x$XORG" = xyes -o "x$XGL" = xy
  	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
  	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
  	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
 -	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $OS_LIB"
 +	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB $OS_LIB"
  
+ 	if test "x$DGA" = xauto; then
+ 		PKG_CHECK_MODULES(DGA, xf86dgaproto, [DGA=yes], [DGA=no])
+ 	fi
+ 	if test "x$DGA" = xyes; then
+ 		XORG_MODULES="$XORG_MODULES xf86dgaproto"
+ 		AC_DEFINE(DGA, 1, [Support DGA extension])
+ 		AC_DEFINE(XFreeXDGA, 1, [Build XDGA support])
+ 	fi
+ 
+ 	if test "x$XF86MISC" = xauto; then
+ 		PKG_CHECK_MODULES(XF86MISC, xf86miscproto, [XF86MISC=yes], [XF86MISC=no])
+ 	fi
+ 	if test "x$XF86MISC" = xyes; then
+ 		XORG_MODULES="$XORG_MODULES xf86miscproto"
+ 		AC_DEFINE(XF86MISC, 1, [Support XFree86 miscellaneous extensions])
+ 	fi
+ 
+ 	if test "x$XF86VIDMODE" = xauto; then
+ 		PKG_CHECK_MODULES(XF86VIDMODE, xf86vidmodeproto, [XF86VIDMODE=yes], [XF86VIDMODE=no])
+ 	fi
+ 	if test "x$XF86VIDMODE" = xyes; then
+ 		XORG_MODULES="$XORG_MODULES xf86vidmodeproto"
+ 		AC_DEFINE(XF86VIDMODE, 1, [Support XFree86 Video Mode extension])
+ 	fi
+ 
+ 	if test -n "$XORG_MODULES"; then
+ 	        PKG_CHECK_MODULES(XORG_MODULES, [$XORG_MODULES])
+ 	        XORG_CFLAGS="$XORG_CFLAGS $XORG_MODULES_CFLAGS"
+ 	        XORG_LIBS="$XORG_LIBS $XORG_MODULES_LIBS"
+ 	fi
+ 
  dnl Check to see if dlopen is in default libraries (like Solaris, which
  dnl has it in libc), or if libdl is needed to get it.
  	AC_CHECK_FUNC([dlopen], [], 
commit e3d3d29db5eef057b4e8294377c9c3147436bc2f
Merge: 92387e9... 004d00e...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 26 20:21:16 2006 -0400

    Merge branch 'master' into my-XACE-SELINUX

commit 92387e99d085b0b081fcedb2f20304eb0ac536b1
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 26 20:20:57 2006 -0400

    Change symbol in libaudit library test.

diff --git a/configure.ac b/configure.ac
index fe48e4f..1fd4a1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -642,7 +642,7 @@ if test "x$XSELINUX" = xyes; then
 	AC_CHECK_HEADERS([selinux/selinux.h selinux/avc.h], [], AC_MSG_ERROR([SELinux include files not found]))
 	AC_CHECK_LIB(selinux, avc_init, [], AC_MSG_ERROR([SELinux library not found])) 
 	AC_CHECK_HEADERS([libaudit.h], [], AC_MSG_ERROR([SELinux extension requires audit system headers]))
-	AC_CHECK_LIB(audit, audit_log_avc, [], AC_MSG_ERROR([SELinux extension requires audit system library]))
+	AC_CHECK_LIB(audit, audit_open, [], AC_MSG_ERROR([SELinux extension requires audit system library]))
 	AC_DEFINE(XSELINUX, 1, [Build SELinux extension])
 	SELINUX_LIB="-lselinux -laudit"
 fi
commit 4b53a5e4b147ab748b28dffc1d330b7148d8efa6
Merge: 23f6f08... 042d4a4...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 11 20:50:31 2006 -0400

    Merge branch 'master' into my-XACE-SELINUX

commit 23f6f08b7b5c9a4297fd223d232a7e9f45376550
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Thu Oct 5 16:07:26 2006 -0400

    Improve error handling, messages during initialization.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index df19e5d..2f960d1 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -1211,7 +1211,7 @@ CALLBACK(XSELinuxWindowInit)
     if (HAVESTATE(rec->client)) {
 	rc = avc_sid_to_context(SID(rec->client), &ctx);
 	if (rc < 0)
-	    FatalError("Failed to get security context!\n");
+	    FatalError("XSELinux: Failed to get security context!\n");
 	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, strlen(ctx), ctx, FALSE);
 	freecon(ctx);
@@ -1220,7 +1220,7 @@ CALLBACK(XSELinuxWindowInit)
 	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
 				  PropModeReplace, 10, "UNLABELED!", FALSE);
     if (rc != Success)
-	FatalError("Failed to set context property on window!\n");
+	FatalError("XSELinux: Failed to set context property on window!\n");
 } /* XSELinuxWindowInit */
 
 static char *XSELinuxKeywords[] = {
@@ -1859,13 +1859,13 @@ XSELinuxExtensionInit(INITARGS)
 
     if (!is_selinux_enabled())
     {
-        ErrorF("SELinux Extension failed to load: SELinux not enabled\n");
+        ErrorF("XSELinux: Extension failed to load: SELinux not enabled\n");
         return;
     }
 
     if (avc_init("xserver", NULL, &alc, NULL, NULL) < 0)
     {
-	FatalError("couldn't initialize SELinux userspace AVC\n");
+	FatalError("XSELinux: Couldn't initialize SELinux userspace AVC\n");
     }
 
     if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
@@ -1874,10 +1874,10 @@ XSELinuxExtensionInit(INITARGS)
     /* Create atoms for doing window labeling */
     atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1);
     if (atom_ctx == BAD_RESOURCE)
-	return;
+	FatalError("XSELinux: Failed to create atom\n");
     atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, 1);
     if (atom_client_ctx == BAD_RESOURCE)
-	return;
+	FatalError("XSELinux: Failed to create atom\n");
 
     /* Load the config file.  If this fails, shut down the server,
      * since an unknown security status is worse than no security.
commit df351f1efbcc95f94c719fcf993c480155c511e9
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Wed Oct 4 16:23:35 2006 -0400

    Experimental window property holding security context.

diff --git a/Xext/xselinux.c b/Xext/xselinux.c
index 5a6d2ef..df19e5d 100644
--- a/Xext/xselinux.c
+++ b/Xext/xselinux.c
@@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #include <X11/X.h>
+#include <X11/Xatom.h>
 #include <X11/Xproto.h>
 #include <X11/Xfuncproto.h>
 #include "dixstruct.h"
@@ -120,6 +121,10 @@ static char **extensionTypes = NULL;
 static int extensionTypesCount = 0;
 static char *XSELinuxExtensionTypeDefault = NULL;
 
+/* Atoms for SELinux window labeling properties */
+Atom atom_ctx;
+Atom atom_client_ctx;
+
 /* security context for non-local clients */
 static char *XSELinuxNonlocalContextDefault = NULL;
 
@@ -1196,6 +1201,28 @@ CALLBACK(XSELinuxClientState)
     }
 } /* XSELinuxClientState */
 
+/* Labeling callbacks */
+CALLBACK(XSELinuxWindowInit)
+{
+    XaceWindowRec *rec = (XaceWindowRec*)calldata;
+    security_context_t ctx;
+    int rc;
+
+    if (HAVESTATE(rec->client)) {
+	rc = avc_sid_to_context(SID(rec->client), &ctx);
+	if (rc < 0)
+	    FatalError("Failed to get security context!\n");
+	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
+				  PropModeReplace, strlen(ctx), ctx, FALSE);
+	freecon(ctx);
+    } 
+    else
+	rc = ChangeWindowProperty(rec->pWin, atom_client_ctx, XA_STRING, 8,
+				  PropModeReplace, 10, "UNLABELED!", FALSE);
+    if (rc != Success)
+	FatalError("Failed to set context property on window!\n");
+} /* XSELinuxWindowInit */
+
 static char *XSELinuxKeywords[] = {
 #define XSELinuxKeywordComment 0
     "#",
@@ -1844,6 +1871,14 @@ XSELinuxExtensionInit(INITARGS)
     if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
 	return;
 
+    /* Create atoms for doing window labeling */
+    atom_ctx = MakeAtom("_SELINUX_CONTEXT", 16, 1);
+    if (atom_ctx == BAD_RESOURCE)
+	return;
+    atom_client_ctx = MakeAtom("_SELINUX_CLIENT_CONTEXT", 23, 1);
+    if (atom_client_ctx == BAD_RESOURCE)
+	return;
+
     /* Load the config file.  If this fails, shut down the server,
      * since an unknown security status is worse than no security.
      *
@@ -1873,6 +1908,7 @@ XSELinuxExtensionInit(INITARGS)
     XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
     XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
     XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
+    XaceRegisterCallback(XACE_WINDOW_INIT, XSELinuxWindowInit, NULL);
     /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
     XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
 
commit 75e0cc41b201b9ceb2615e7cec0dd5b4c136b343
Merge: 6926776... 20c0cee...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Tue Oct 3 13:58:03 2006 -0400

    Merge branch 'my-XACE-modular' into my-XACE-SELINUX

commit 20c0ceedfbce9ae5c70703900b52973917ac4cd0
Merge: 49a70c8... 84eb2c0...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 29 15:37:00 2006 -0400

    Merge branch 'master' into my-XACE-modular

commit 6926776f0ecd1e8e81c5c40ccd3a97227bc44dcb
Merge: 6950267... 49a70c8...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 15 15:28:13 2006 -0400

    Merge branch 'my-XACE-modular' into my-XACE-SELINUX

commit 6950267dd690ef8e29b1c32a157dd64c9b79c06d
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:31:18 2006 -0400

    Add SELinux extension configure-time support.

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 6ea3d74..be04c84 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -76,6 +76,16 @@ if XACE
 BUILTIN_SRCS += $(XACE_SRCS)
 endif
 
+# SELinux extension: provides SELinux policy support for X objects
+# requires X-ACE extension
+XSELINUX_SRCS = xselinux.c xselinux.h
+if XSELINUX
+BUILTIN_SRCS += $(XSELINUX_SRCS)
+
+SERVERCONFIG_DATA += XSELinuxConfig
+AM_CFLAGS += -DXSELINUXCONFIGFILE=\"$(SERVERCONFIGdir)/XSELinuxConfig\"
+endif
+
 # Security extension: multi-level security to protect clients from each other
 XCSECURITY_SRCS = security.c securitysrv.h
 if XCSECURITY   
commit fb34c02861ab3629c1c85c156e73b158518db7c7
Merge: 9c503f0... d1110c5...
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:30:12 2006 -0400

    Merge branch 'my-XACE-modular' into my-XACE-SELINUX

commit 9c503f09ce78d952d0ece77c424e42b6df3fa9ad
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:17:01 2006 -0400

    Add SELinux extension to the module/extension loader.

diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
index 41f060b..131b9e6 100644
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ b/hw/xfree86/dixmods/extmod/modinit.h
@@ -129,6 +129,11 @@ extern void ShmRegisterFuncs(
 extern void XaceExtensionInit(INITARGS);
 #endif
 
+#ifdef XSELINUX
+extern void XSELinuxExtensionSetup(INITARGS);
+extern void XSELinuxExtensionInit(INITARGS);
+#endif
+
 #if 1
 extern void SecurityExtensionSetup(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
diff --git a/mi/miinitext.c b/mi/miinitext.c
index aafd014..bab45cd 100644
--- a/mi/miinitext.c
+++ b/mi/miinitext.c
@@ -248,6 +248,9 @@ typedef void (*InitExtension)(INITARGS);
 #include "securitysrv.h"
 #include <X11/extensions/securstr.h>
 #endif
+#ifdef XSELINUX
+#include "xselinux.h"
+#endif
 #ifdef PANORAMIX
 #include <X11/extensions/panoramiXproto.h>
 #endif
@@ -321,6 +324,10 @@ extern void XaceExtensionInit(INITARGS);
 extern void SecurityExtensionSetup(INITARGS);
 extern void SecurityExtensionInit(INITARGS);
 #endif
+#ifdef XSELINUX
+extern void XSELinuxExtensionSetup(INITARGS);
+extern void XSELinuxExtensionInit(INITARGS);
+#endif
 #ifdef XPRINT
 extern void XpExtensionInit(INITARGS);
 #endif
@@ -532,6 +539,9 @@ InitExtensions(argc, argv)
 #ifdef XCSECURITY
     SecurityExtensionSetup();
 #endif
+#ifdef XSELINUX
+    XSELinuxExtensionSetup();
+#endif
 #ifdef PANORAMIX
 # if !defined(PRINT_ONLY_SERVER) && !defined(NO_PANORAMIX)
   if (!noPanoramiXExtension) PanoramiXExtensionInit();
@@ -600,6 +610,9 @@ InitExtensions(argc, argv)
 #ifdef XCSECURITY
     if (!noSecurityExtension) SecurityExtensionInit();
 #endif
+#ifdef XSELINUX
+    XSELinuxExtensionInit();
+#endif
 #ifdef XPRINT
     XpExtensionInit(); /* server-specific extension, cannot be disabled */
 #endif
@@ -705,6 +718,9 @@ static ExtensionModule staticExtensions[] = {
 #ifdef XCSECURITY
     { SecurityExtensionInit, SECURITY_EXTENSION_NAME, &noSecurityExtension, SecurityExtensionSetup, NULL },
 #endif
+#ifdef XSELINUX
+    { XSELinuxExtensionInit, XSELINUX_EXTENSION_NAME, NULL, XSELinuxExtensionSetup, NULL },
+#endif
 #ifdef XPRINT
     { XpExtensionInit, XP_PRINTNAME, NULL, NULL, NULL },
 #endif
commit 9aa44e3e4c321f42d8e64f83c7f0932470593c26
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:15:19 2006 -0400

    Add SELinux extension configure-time support.

diff --git a/configure.ac b/configure.ac
index 49dfad2..cf838b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -414,6 +414,7 @@ AC_ARG_ENABLE(xinerama,	      AS_HELP_STRING([--disable-xinerama], [Build Xinera
 AC_ARG_ENABLE(xf86vidmode,    AS_HELP_STRING([--disable-xf86vidmode], [Build XF86VidMode extension (default: enabled)]), [XF86VIDMODE=$enableval], [XF86VIDMODE=yes])
 AC_ARG_ENABLE(xf86misc,       AS_HELP_STRING([--disable-xf86misc], [Build XF86Misc extension (default: enabled)]), [XF86MISC=$enableval], [XF86MISC=yes])
 AC_ARG_ENABLE(xace,     AS_HELP_STRING([--disable-xace], [Build X-ACE extension (default: enabled)]), [XACE=$enableval], [XACE=yes])
+AC_ARG_ENABLE(xselinux,     AS_HELP_STRING([--disable-xselinux], [Build SELinux extension (default: enabled)]), [XSELINUX=$enableval], [XSELINUX=$XACE])
 AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Security extension (default: enabled)]), [XCSECURITY=$enableval], [XCSECURITY=$XACE])
 AC_ARG_ENABLE(appgroup,       AS_HELP_STRING([--disable-appgroup], [Build XC-APPGROUP extension (default: enabled)]), [APPGROUP=$enableval], [APPGROUP=$XCSECURITY])
 AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
@@ -627,6 +628,19 @@ if test "x$XACE" = xyes; then
 	AC_DEFINE(XACE, 1, [Build X-ACE extension])
 fi
 
+AM_CONDITIONAL(XSELINUX, [test "x$XSELINUX" = xyes])
+if test "x$XSELINUX" = xyes; then
+	if test "x$XACE" != xyes; then
+		AC_MSG_ERROR([cannot build SELinux extension without X-ACE])
+	fi
+	AC_CHECK_HEADERS([selinux/selinux.h selinux/avc.h], [], AC_MSG_ERROR([SELinux include files not found]))
+	AC_CHECK_LIB(selinux, avc_init, [], AC_MSG_ERROR([SELinux library not found])) 
+	AC_CHECK_HEADERS([libaudit.h], [], AC_MSG_ERROR([SELinux extension requires audit system headers]))
+	AC_CHECK_LIB(audit, audit_log_avc, [], AC_MSG_ERROR([SELinux extension requires audit system library]))
+	AC_DEFINE(XSELINUX, 1, [Build SELinux extension])
+	SELINUX_LIB="-lselinux -laudit"
+fi
+
 AM_CONDITIONAL(XCSECURITY, [test "x$XCSECURITY" = xyes])
 if test "x$XCSECURITY" = xyes; then
 	if test "x$XACE" != xyes; then
@@ -1042,7 +1056,7 @@ if test "x$XORG" = xyes -o "x$XGL" = xyes; then
 	XORG_OSINCS='-I$(top_srcdir)/hw/xfree86/os-support -I$(top_srcdir)/hw/xfree86/os-support/bus -I$(top_srcdir)/os'
 	XORG_INCS="$XORG_DDXINCS $XORG_OSINCS"
 	XORG_CFLAGS="$XORGSERVER_CFLAGS -DHAVE_XORG_CONFIG_H"
-	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $OS_LIB"
+	XORG_LIBS="$COMPOSITE_LIB $MI_LIB $FIXES_LIB $XEXTXORG_LIB $GLX_LIBS $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XPSTUBS_LIB $SELINUX_LIB $OS_LIB"
 
 dnl Check to see if dlopen is in default libraries (like Solaris, which
 dnl has it in libc), or if libdl is needed to get it.
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 571a867..f664548 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -311,6 +311,9 @@
 /* Build X-ACE extension */
 #undef XACE
 
+/* Build SELinux extension */
+#undef XSELINUX
+
 /* Support XCMisc extension */
 #undef XCMISC
 
commit 150eabc4c8a08c81c48493583f922a1240b7e91c
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date:   Fri Sep 8 15:11:04 2006 -0400

    Add SELinux extension source files.

diff --git a/Xext/XSELinuxConfig b/Xext/XSELinuxConfig
new file mode 100644
index 0000000..faf815e
--- /dev/null
+++ b/Xext/XSELinuxConfig
@@ -0,0 +1,83 @@
+#
+# Config file for XSELinux extension
+#
+
+#
+# The nonlocal_context rule defines a context to be used for all clients
+# connecting to the server from a remote host.  The nonlocal context must
+# be defined, and it must be a valid context according to the SELinux
+# security policy.  Only one nonlocal_context rule may be defined.
+#
+nonlocal_context			system_u:object_r:remote_xclient_t:s1
+
+#
+# Property rules map a property name to a SELinux type.  The type must
+# be valid according to the SELinux security policy.  There can be any
+# number of property rules.  Additionally, a default property type can be
+# defined for all properties not explicitly listed.  The default
+# property type may not be omitted.  The default rule may appear in
+# any position (it need not be the last property rule listed).
+#
+property WM_NAME			wm_property_t
+property WM_CLASS			wm_property_t
+property WM_ICON_NAME			wm_property_t
+property WM_HINTS			wm_property_t
+property WM_NORMAL_HINTS		wm_property_t
+property WM_COMMAND			wm_property_t
+
+property CUT_BUFFER0			cut_buffer_property_t
+property CUT_BUFFER1			cut_buffer_property_t
+property CUT_BUFFER2			cut_buffer_property_t
+property CUT_BUFFER3			cut_buffer_property_t
+property CUT_BUFFER4			cut_buffer_property_t
+property CUT_BUFFER5			cut_buffer_property_t
+property CUT_BUFFER6			cut_buffer_property_t
+property CUT_BUFFER7			cut_buffer_property_t
+
+property default			unknown_property_t
+
+#
+# Extension rules map an extension name to a SELinux type.  The type must
+# be valid according to the SELinux security policy.  There can be any
+# number of extension rules.  Additionally, a default extension type can
+# be defined for all extensions not explicitly listed.  The default
+# extension type may not be omitted.  The default rule may appear in
+# any position (it need not be the last extension rule listed).
+#
+extension BIG-REQUESTS			std_ext_t
+extension DOUBLE-BUFFER			std_ext_t
+extension DPMS				screensaver_ext_t
+extension Extended-Visual-Information	std_ext_t
+extension FontCache			font_ext_t
+extension GLX				std_ext_t
+extension LBX				std_ext_t
+extension MIT-SCREEN-SAVER		screensaver_ext_t
+extension MIT-SHM			shmem_ext_t
+extension MIT-SUNDRY-NONSTANDARD	std_ext_t
+extension NV-CONTROL			accelgraphics_ext_t
+extension NV-GLX			accelgraphics_ext_t
+extension NVIDIA-GLX			accelgraphics_ext_t
+extension RANDR				std_ext_t
+extension RECORD			debug_ext_t
+extension RENDER			std_ext_t
+extension SECURITY			security_ext_t
+extension SELinux			security_ext_t
+extension SHAPE				std_ext_t
+extension SYNC				sync_ext_t
+extension TOG-CUP			windowmgr_ext_t
+extension X-Resource			debug_ext_t
+extension XAccessControlExtension	security_ext_t
+extension XACEUSR			security_ext_t
+extension XC-APPGROUP			security_ext_t
+extension XC-MISC			std_ext_t
+extension XFree86-Bigfont		font_ext_t
+extension XFree86-DGA			accelgraphics_ext_t
+extension XFree86-Misc			std_ext_t
+extension XFree86-VidModeExtension	video_ext_t
+extension XInputExtension		input_ext_t
+extension XKEYBOARD			input_ext_t
+extension XpExtension                   std_ext_t
+extension XTEST				debug_ext_t
+extension XVideo			video_ext_t
+extension XVideo-MotionCompensation	video_ext_t
+extension default			unknown_ext_t
diff --git a/Xext/xselinux.c b/Xext/xselinux.c
new file mode 100644
index 0000000..5a6d2ef
--- /dev/null
+++ b/Xext/xselinux.c
@@ -0,0 +1,1884 @@
+/************************************************************
+
+Author: Eamon Walsh <ewalsh at epoch.ncsc.mil>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+this permission notice appear in supporting documentation.  This permission
+notice shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+********************************************************/
+
+/*
+ * Portions of this code copyright (c) 2005 by Trusted Computer Solutions, Inc.
+ * All rights reserved.
+ */
+
+#include <selinux/flask.h>
+#include <selinux/av_permissions.h>
+#include <selinux/selinux.h>
+#include <selinux/context.h>
+#include <selinux/avc.h>
+
+#include <libaudit.h>
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/Xfuncproto.h>
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "resource.h"
+#include "selection.h"
+#include "xacestr.h"
+#include "xselinux.h"
+#define XSERV_t
+#define TRANS_SERVER
+#include <X11/Xtrans/Xtrans.h>
+#include "../os/osdep.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "modinit.h"
+
+#ifndef XSELINUXCONFIGFILE
+#warning "XSELinux Policy file is not defined"
+#define XSELINUXCONFIGFILE  NULL
+#endif
+
+
+/* Make sure a locally connecting client has a valid context.  The context
+ * for this client is retrieved again later on in AssignClientState(), but
+ * by that point it's too late to reject the client.
+ */
+static char *
+XSELinuxValidContext (ClientPtr client)
+{
+    security_context_t ctx = NULL;
+    XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+    char reason[256];
+    char *ret = (char *)NULL;
+
+    if (_XSERVTransIsLocal(ci))
+    {
+        int fd = _XSERVTransGetConnectionNumber(ci);
+        if (getpeercon(fd, &ctx) < 0)
+        {
+            snprintf(reason, sizeof(reason), "Failed to retrieve SELinux context from socket");
+            ret = reason;
+            goto out;
+        }
+        if (security_check_context(ctx))
+        {
+            snprintf(reason, sizeof(reason), "Client's SELinux context is invalid: %s", ctx);
+            ret = reason;
+        }
+
+        freecon(ctx);
+    }
+
+out:
+    return ret;
+}
+
+
+/* devPrivates in client and extension */
+static int clientPrivateIndex;
+static int extnsnPrivateIndex;
+
+/* audit file descriptor */
+static int audit_fd;
+
+/* structure passed to auditing callback */
+typedef struct {
+    ClientPtr client;	/* client */
+    char *property;	/* property name, if any */
+    char *extension;	/* extension name, if any */
+} XSELinuxAuditRec;
+
+/*
+ * Table of SELinux types for property names.
+ */
+static char **propertyTypes = NULL;
+static int propertyTypesCount = 0;
+char *XSELinuxPropertyTypeDefault = NULL;
+
+/*
+ * Table of SELinux types for each extension.
+ */
+static char **extensionTypes = NULL;
+static int extensionTypesCount = 0;
+static char *XSELinuxExtensionTypeDefault = NULL;
+
+/* security context for non-local clients */
+static char *XSELinuxNonlocalContextDefault = NULL;
+
+/* security context for the root window */
+static char *XSELinuxRootWindowContext = NULL;
+
+/* Selection stuff from dix */
+extern Selection *CurrentSelections;
+extern int NumCurrentSelections;
+
+/* 
+ * list of classes corresponding to SIDs in the 
+ * rsid array of the security state structure (below).
+ *
+ * XXX SIDs should be stored in their native objects, not all
+ * bunched together in the client structure.  However, this will
+ * require modification to the resource manager.
+ */
+static security_class_t sClasses[] = {
+    SECCLASS_WINDOW,
+    SECCLASS_DRAWABLE,
+    SECCLASS_GC,
+    SECCLASS_CURSOR,
+    SECCLASS_FONT,
+    SECCLASS_COLORMAP,
+    SECCLASS_PROPERTY,
+    SECCLASS_XCLIENT,
+    SECCLASS_XINPUT
+};
+#define NRES (sizeof(sClasses)/sizeof(sClasses[0]))
+
+/* This is what we store for client security state */
+typedef struct {
+    int haveState;
+    security_id_t sid;
+    security_id_t rsid[NRES];
+    struct avc_entry_ref aeref;
+} XSELinuxClientStateRec;
+
+/* Convenience macros for accessing security state fields */
+#define STATEPTR(client) \
+    ((client)->devPrivates[clientPrivateIndex].ptr)
+#define HAVESTATE(client) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->haveState)
+#define SID(client) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->sid)
+#define RSID(client,n) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->rsid[n])
+#define AEREF(client) \
+    (((XSELinuxClientStateRec*)STATEPTR(client))->aeref)
+#define EXTENSIONSID(ext) \
+    ((ext)->devPrivates[extnsnPrivateIndex].ptr)
+
+/*
+ * Returns the index into the rsid array where the SID for the
+ * given class is stored.
+ */
+static int
+IndexByClass(security_class_t class)
+{
+    int i;
+    for (i=0; i<NRES; i++)
+	if (class == sClasses[i])
+	    return i;
+    return 0;
+}
+
+/*
+ * Does sanity checking on a resource ID.  This can be removed after 
+ * testing.
+ */
+static void
+CheckXID(XID id)
+{
+    /*
+    XID c = CLIENT_ID(id);
+
+    if (c > 10)
+	ErrorF("Warning: possibly mangled ID %x\n", id);
+
+    c = id & RESOURCE_ID_MASK;
+    if (c > 100)
+	ErrorF("Warning: possibly mangled ID %x\n", id);
+        */
+}
+
+/*
+ * Byte-swap a CARD32 id if necessary.
+ */
+static XID
+SwapXID(ClientPtr client, XID id)
+{
+    register char n;
+    if (client->swapped)
+	swapl(&id, n);
+    return id;
+}
+
+/*
+ * ServerPerm - check access permissions on a server-owned object.
+ *
+ * Arguments:
+ * client: Client doing the request.
+ * class: Security class of the server object being accessed.
+ * perm: Permissions required on the object.
+ *
+ * Returns: boolean TRUE=allowed, FALSE=denied.
+ */
+static int
+ServerPerm(ClientPtr client,
+	   security_class_t class,
+	   access_vector_t perm)
+{
+    int idx = IndexByClass(class);
+    if (HAVESTATE(client))
+    {
+	XSELinuxAuditRec auditdata;
+	auditdata.client = client;
+	auditdata.property = NULL;
+	auditdata.extension = NULL;
+	errno = 0;
+        if (avc_has_perm(SID(client), RSID(serverClient,idx), class,
+                         perm, &AEREF(client), &auditdata) < 0)
+        {
+            if (errno != EACCES)
+                ErrorF("ServerPerm: unexpected error %d\n", errno);
+            return FALSE;
+        }
+    }
+    else
+    {
+	ErrorF("No client state in server-perm check!\n");
+        return TRUE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * IDPerm - check access permissions on a resource.
+ *
+ * Arguments:
+ * client: Client doing the request.
+ * id: resource id of the resource being accessed.
+ * class: Security class of the resource being accessed.
+ * perm: Permissions required on the resource.
+ *
+ * Returns: boolean TRUE=allowed, FALSE=denied.
+ */
+static int
+IDPerm(ClientPtr sclient,
+	 XID id,
+	 security_class_t class,
+	 access_vector_t perm)
+{
+    ClientPtr tclient;
+    int idx = IndexByClass(class);
+    XSELinuxAuditRec auditdata;
+
+    if (id == None)
+	return TRUE;
+
+    CheckXID(id);
+    tclient = clients[CLIENT_ID(id)];
+
+    /*
+     * This happens in the case where a client has
+     * disconnected.  XXX might want to make the server
+     * own orphaned resources...
+     */
+    if (!tclient || !HAVESTATE(tclient) || !HAVESTATE(sclient))
+    {
+	return TRUE;
+    }
+
+    auditdata.client = sclient;
+    auditdata.property = NULL;
+    auditdata.extension = NULL;
+    errno = 0;
+    if (avc_has_perm(SID(sclient), RSID(tclient,idx), class,
+		     perm, &AEREF(sclient), &auditdata) < 0)
+    {
+	if (errno != EACCES)
+	    ErrorF("IDPerm: unexpected error %d\n", errno);
+	return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*
+ * ObjectSIDByLabel - get SID for an extension or property.
+ *
+ * Arguments:
+ * class: should be SECCLASS_XEXTENSION or SECCLASS_PROPERTY.
+ * name: name of the extension or property.
+ *
+ * Returns: proper SID for the object or NULL on error.
+ */
+static security_id_t
+ObjectSIDByLabel(security_context_t basecontext, security_class_t class,
+                 const char *name)
+{
+    security_context_t base, new;
+    context_t con;
+    security_id_t sid = NULL;
+    char **ptr, *type = NULL;
+
+    if (basecontext != NULL)
+    {
+        /* use the supplied context */
+        base = strdup(basecontext);
+        if (base == NULL)
+            goto out;
+    }
+    else
+    {
+        /* get server context */
+        if (getcon(&base) < 0)
+            goto out;
+    }
+
+    /* make a new context-manipulation object */
+    con = context_new(base);
+    if (!con)
+	goto out2;
+    
+    /* look in the mappings of names to types */
+    ptr = (class == SECCLASS_PROPERTY) ? propertyTypes : extensionTypes;
+    for (; *ptr; ptr+=2)
+	if (!strcmp(*ptr, name))
+	    break;
+    type = ptr[1];
+
+    /* set the role and type in the context (user unchanged) */
+    if (context_type_set(con, type) ||
+	context_role_set(con, "object_r"))
+	goto out3;
+
+    /* get a context string from the context-manipulation object */
+    new = context_str(con);
+    if (!new)
+	goto out3;
+
+    /* get a SID for the context */
+    if (avc_context_to_sid(new, &sid) < 0)
+	goto out3;
+
+  out3:
+    context_free(con);
+  out2:
+    freecon(base);
+  out:
+    return sid;
+}
+
+/*
+ * AssignClientState - set up client security state.
+ *
+ * Arguments:
+ * client: client to set up (can be serverClient).
+ */
+static void
+AssignClientState(ClientPtr client)
+{
+    int i, needToFree = 0;
+    security_context_t basectx, objctx;
+    XSELinuxClientStateRec *state = (XSELinuxClientStateRec*)STATEPTR(client);
+    Bool isServerClient = FALSE;
+
+    avc_entry_ref_init(&state->aeref);
+
+    if (client->index > 0)
+    {
+	XtransConnInfo ci = ((OsCommPtr)client->osPrivate)->trans_conn;
+	if (_XSERVTransIsLocal(ci)) {
+	    /* for local clients, can get context from the socket */
+	    int fd = _XSERVTransGetConnectionNumber(ci);
+	    if (getpeercon(fd, &basectx) < 0)
+	    {
+		FatalError("Client %d: couldn't get context from socket\n",
+			   client->index);
+	    }
+	    needToFree = 1;
+	}
+        else
+        {
+	    /* for remote clients, need to use a default context */
+	    basectx = XSELinuxNonlocalContextDefault;
+	}
+    }
+    else
+    {
+        isServerClient = TRUE;
+
+	/* use the context of the X server process for the serverClient */
+	if (getcon(&basectx) < 0)
+	{
+	    FatalError("Couldn't get context of X server process\n");
+	}
+	needToFree = 1;
+    }
+
+    /* get a SID from the context */
+    if (avc_context_to_sid(basectx, &state->sid) < 0)
+    {
+	FatalError("Client %d: couldn't get security ID for client\n",
+		   client->index);
+    }
+
+    /* get contexts and then SIDs for each resource type */
+    for (i=0; i<NRES; i++)
+    {
+	if (security_compute_create(basectx, basectx, sClasses[i],
+				    &objctx) < 0)
+	{
+	    FatalError("Client %d: couldn't get context for class %x\n",
+		       client->index, sClasses[i]);
+	}
+	else if (avc_context_to_sid(objctx, &state->rsid[i]) < 0)
+	{
+	    FatalError("Client %d: couldn't get SID for class %x\n",
+		       client->index, sClasses[i]);
+	}
+	freecon(objctx);
+    }
+
+    /* special handling for serverClient windows (that is, root windows) */
+    if (isServerClient == TRUE)
+    {
+        i = IndexByClass(SECCLASS_WINDOW);
+        sidput(state->rsid[i]);
+        if (avc_context_to_sid(XSELinuxRootWindowContext, &state->rsid[i]))
+        {
+            FatalError("Failed to set SID for root window\n");
+        }
+    }
+
+    /* mark as set up, free base context if necessary, and return */
+    state->haveState = TRUE;
+    if (needToFree)
+	freecon(basectx);
+}
+
+/*
+ * FreeClientState - tear down client security state.
+ *
+ * Arguments:
+ * client: client to release (can be serverClient).
+ */
+static void
+FreeClientState(ClientPtr client)
+{
+    int i;
+    XSELinuxClientStateRec *state = (XSELinuxClientStateRec*)STATEPTR(client);
+
+    /* client state may not be set up if its auth was rejected */
+    if (state->haveState) {
+	state = (XSELinuxClientStateRec*)STATEPTR(client);
+	sidput(state->sid);
+	for (i=0; i<NRES; i++)
+	    sidput(state->rsid[i]);
+	state->haveState = FALSE;
+    }
+}
+
+#define REQUEST_SIZE_CHECK(client, req) \
+    (client->req_len >= (sizeof(req) >> 2))
+#define IDPERM(client, req, field, class, perm) \
+    (REQUEST_SIZE_CHECK(client,req) && \
+    IDPerm(client, SwapXID(client,((req*)stuff)->field), class, perm))
+#define CALLBACK(name) static void \
+name(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
+
+static int
+CheckSendEventPerms(ClientPtr client)
+{
+    register char n;
+    access_vector_t perm = 0;
+    REQUEST(xSendEventReq);
+
+    /* might need type bounds checking here */
+    if (!REQUEST_SIZE_CHECK(client, xSendEventReq))
+	return FALSE;
+
+    switch (stuff->event.u.u.type) {
+	case SelectionClear:
+	case SelectionNotify:
+	case SelectionRequest:
+	case ClientMessage:
+	case PropertyNotify:
+	    perm = WINDOW__CLIENTCOMEVENT;
+	    break;
+	case ButtonPress:
+	case ButtonRelease:
+	case KeyPress:
+	case KeyRelease:
+	case KeymapNotify:
+	case MotionNotify:
+	case EnterNotify:
+	case LeaveNotify:
+	case FocusIn:
+	case FocusOut:
+	    perm = WINDOW__INPUTEVENT;
+	    break;
+	case Expose:
+	case GraphicsExpose:
+	case NoExpose:
+	case VisibilityNotify:
+	    perm = WINDOW__DRAWEVENT;
+	    break;
+	case CirculateNotify:
+	case ConfigureNotify:
+	case CreateNotify:
+	case DestroyNotify:
+	case MapNotify:
+	case UnmapNotify:
+	case GravityNotify:
+	case ReparentNotify:
+	    perm = WINDOW__WINDOWCHANGEEVENT;
+	    break;
+	case CirculateRequest:
+	case ConfigureRequest:
+	case MapRequest:
+	case ResizeRequest:
+	    perm = WINDOW__WINDOWCHANGEREQUEST;
+	    break;
+	case ColormapNotify:
+	case MappingNotify:
+	    perm = WINDOW__SERVERCHANGEEVENT;
+	    break;
+	default:
+	    perm = WINDOW__EXTENSIONEVENT;
+	    break;
+    }
+    if (client->swapped)
+	swapl(&stuff->destination, n);
+    return IDPerm(client, stuff->destination, SECCLASS_WINDOW, perm);
+}
+     
+static int
+CheckConvertSelectionPerms(ClientPtr client)
+{
+    register char n;
+    int rval = TRUE;
+    REQUEST(xConvertSelectionReq);
+    
+    if (!REQUEST_SIZE_CHECK(client, xConvertSelectionReq))
+	return FALSE;
+
+    if (client->swapped)
+    {
+	swapl(&stuff->selection, n);
+	swapl(&stuff->requestor, n);
+    }
+
+    if (ValidAtom(stuff->selection))
+    {
+	int i = 0;
+	while ((i < NumCurrentSelections) &&
+	       CurrentSelections[i].selection != stuff->selection) i++;
+	if (i < NumCurrentSelections)
+	    rval = rval && IDPerm(client, CurrentSelections[i].window,
+				  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
+    }
+    rval = rval && IDPerm(client, stuff->requestor,
+			  SECCLASS_WINDOW, WINDOW__CLIENTCOMEVENT);
+    return rval;
+}
+
+static int
+CheckSetSelectionOwnerPerms(ClientPtr client)
+{
+    register char n;
+    int rval = TRUE;
+    REQUEST(xSetSelectionOwnerReq);
+
+    if (!REQUEST_SIZE_CHECK(client, xSetSelectionOwnerReq))
+	return FALSE;
+
+    if (client->swapped)
+    {
+	swapl(&stuff->selection, n);
+	swapl(&stuff->window, n);
+    }
+
+    if (ValidAtom(stuff->selection))
+    {
+	int i = 0;
+	while ((i < NumCurrentSelections) &&
+	       CurrentSelections[i].selection != stuff->selection) i++;
+	if (i < NumCurrentSelections)
+	    rval = rval && IDPerm(client, CurrentSelections[i].window,
+				  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+    }
+    rval = rval && IDPerm(client, stuff->window, 
+			  SECCLASS_WINDOW, WINDOW__CHSELECTION);
+    return rval;
+}
+    
+CALLBACK(XSELinuxCoreDispatch)
+{
+    XaceCoreDispatchRec *rec = (XaceCoreDispatchRec*)calldata;
+    ClientPtr client = rec->client;
+    REQUEST(xReq);
+    Bool rval;
+
+    switch(stuff->reqType) {
+    /* Drawable class control requirements */
+    case X_ClearArea:
+	rval = IDPERM(client, xClearAreaReq, window,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_PolySegment:
+    case X_PolyRectangle:
+    case X_PolyArc:
+    case X_PolyFillRectangle:
+    case X_PolyFillArc:
+	rval = IDPERM(client, xPolySegmentReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_PolyPoint:
+    case X_PolyLine:
+	rval = IDPERM(client, xPolyPointReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_FillPoly:
+	rval = IDPERM(client, xFillPolyReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_PutImage:
+	rval = IDPERM(client, xPutImageReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_CopyArea:
+    case X_CopyPlane:
+	rval = IDPERM(client, xCopyAreaReq, srcDrawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY)
+	    && IDPERM(client, xCopyAreaReq, dstDrawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_GetImage:
+	rval = IDPERM(client, xGetImageReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
+	break;
+    case X_GetGeometry:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_DRAWABLE, DRAWABLE__GETATTR);
+	break;
+
+    /* Window class control requirements */
+    case X_ChangeProperty:
+	rval = IDPERM(client, xChangePropertyReq, window,
+		      SECCLASS_WINDOW, 
+		      WINDOW__CHPROPLIST | WINDOW__CHPROP |
+		      WINDOW__LISTPROP);
+	break;
+    case X_ChangeSaveSet:
+	rval = IDPERM(client, xChangeSaveSetReq, window,
+		      SECCLASS_WINDOW,
+		      WINDOW__CTRLLIFE | WINDOW__CHPARENT);
+	break;
+    case X_ChangeWindowAttributes:
+	rval = IDPERM(client, xChangeWindowAttributesReq, window,
+		      SECCLASS_WINDOW, WINDOW__SETATTR);
+	break;
+    case X_CirculateWindow:
+	rval = IDPERM(client, xCirculateWindowReq, window,
+		      SECCLASS_WINDOW, WINDOW__CHSTACK);
+	break;
+    case X_ConfigureWindow:
+	rval = IDPERM(client, xConfigureWindowReq, window,
+		      SECCLASS_WINDOW,
+		      WINDOW__SETATTR | WINDOW__MOVE | WINDOW__CHSTACK);
+	break;
+    case X_ConvertSelection:
+	rval = CheckConvertSelectionPerms(client);
+	break;
+    case X_CreateWindow:
+	rval = IDPERM(client, xCreateWindowReq, wid,
+		      SECCLASS_WINDOW,
+		      WINDOW__CREATE | WINDOW__SETATTR | WINDOW__MOVE)
+	    && IDPERM(client, xCreateWindowReq, parent,
+		      SECCLASS_WINDOW,
+		      WINDOW__CHSTACK | WINDOW__ADDCHILD)
+	    && IDPERM(client, xCreateWindowReq, wid,
+		      SECCLASS_DRAWABLE, DRAWABLE__CREATE);
+	break;
+    case X_DeleteProperty:
+	rval = IDPERM(client, xDeletePropertyReq, window,
+		      SECCLASS_WINDOW,
+		      WINDOW__CHPROP | WINDOW__CHPROPLIST);
+	break;
+    case X_DestroyWindow:
+    case X_DestroySubwindows:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW,
+		      WINDOW__ENUMERATE | WINDOW__UNMAP | WINDOW__DESTROY)
+	    && IDPERM(client, xResourceReq, id,
+		      SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
+	break;
+    case X_GetMotionEvents:
+	rval = IDPERM(client, xGetMotionEventsReq, window,
+		      SECCLASS_WINDOW, WINDOW__MOUSEMOTION);
+	break;
+    case X_GetProperty:
+	rval = IDPERM(client, xGetPropertyReq, window,
+		      SECCLASS_WINDOW, WINDOW__LISTPROP);
+	break;
+    case X_GetWindowAttributes:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW, WINDOW__GETATTR);
+	break;
+    case X_KillClient:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_XCLIENT, XCLIENT__KILL);
+	break;
+    case X_ListProperties:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW, WINDOW__LISTPROP);
+	break;
+    case X_MapWindow:
+    case X_MapSubwindows:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW,
+		      WINDOW__ENUMERATE | WINDOW__GETATTR | WINDOW__MAP);
+	break;
+    case X_QueryTree:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW, WINDOW__ENUMERATE | WINDOW__GETATTR);
+	break;
+    case X_RotateProperties:
+	rval = IDPERM(client, xRotatePropertiesReq, window,
+		      SECCLASS_WINDOW, WINDOW__CHPROP | WINDOW__CHPROPLIST);
+	break;
+    case X_ReparentWindow:
+	rval = IDPERM(client, xReparentWindowReq, window,
+		      SECCLASS_WINDOW, WINDOW__CHPARENT | WINDOW__MOVE)
+	    && IDPERM(client, xReparentWindowReq, parent,
+		      SECCLASS_WINDOW, WINDOW__CHSTACK | WINDOW__ADDCHILD);
+	break;
+    case X_SendEvent:
+	rval = CheckSendEventPerms(client);
+	break;
+    case X_SetInputFocus:
+	rval = IDPERM(client, xSetInputFocusReq, focus,
+		      SECCLASS_WINDOW, WINDOW__SETFOCUS)
+	    && ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETFOCUS);
+	break;
+    case X_SetSelectionOwner:
+	rval = CheckSetSelectionOwnerPerms(client);
+	break;
+    case X_TranslateCoords:
+	rval = IDPERM(client, xTranslateCoordsReq, srcWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR)
+	    && IDPERM(client, xTranslateCoordsReq, dstWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR);
+	break;
+    case X_UnmapWindow:
+    case X_UnmapSubwindows:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_WINDOW,
+		      WINDOW__ENUMERATE | WINDOW__GETATTR |
+		      WINDOW__UNMAP);
+	break;
+    case X_WarpPointer:
+	rval = IDPERM(client, xWarpPointerReq, srcWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR)
+	    && IDPERM(client, xWarpPointerReq, dstWid,
+		      SECCLASS_WINDOW, WINDOW__GETATTR)
+	    && ServerPerm(client, SECCLASS_XINPUT, XINPUT__WARPPOINTER);
+	break;
+
+    /* Input class control requirements */
+    case X_GrabButton:
+    case X_GrabKey:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__PASSIVEGRAB);
+	break;
+    case X_GrabKeyboard:
+    case X_GrabPointer:
+    case X_ChangeActivePointerGrab:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__ACTIVEGRAB);
+	break;
+    case X_AllowEvents:
+    case X_UngrabButton:
+    case X_UngrabKey:
+    case X_UngrabKeyboard:
+    case X_UngrabPointer:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__UNGRAB);
+	break;
+    case X_GetKeyboardControl:
+    case X_GetKeyboardMapping:
+    case X_GetPointerControl:
+    case X_GetPointerMapping:
+    case X_GetModifierMapping:
+    case X_QueryKeymap:
+    case X_QueryPointer:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__GETATTR);
+	break;
+    case X_ChangeKeyboardControl:
+    case X_ChangePointerControl:
+    case X_ChangeKeyboardMapping:
+    case X_SetModifierMapping:
+    case X_SetPointerMapping:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__SETATTR);
+	break;
+    case X_Bell:
+	rval = ServerPerm(client, SECCLASS_XINPUT, XINPUT__BELL);
+	break;
+
+    /* Colormap class control requirements */
+    case X_AllocColor:
+    case X_AllocColorCells:
+    case X_AllocColorPlanes:
+    case X_AllocNamedColor:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP,
+		      COLORMAP__READ | COLORMAP__STORE);
+	break;
+    case X_CopyColormapAndFree:
+	rval = IDPERM(client, xCopyColormapAndFreeReq, mid,
+		      SECCLASS_COLORMAP, COLORMAP__CREATE)
+	    && IDPERM(client, xCopyColormapAndFreeReq, srcCmap,
+		      SECCLASS_COLORMAP,
+		      COLORMAP__READ | COLORMAP__FREE);
+	break;
+    case X_CreateColormap:
+	rval = IDPERM(client, xCreateColormapReq, mid,
+		      SECCLASS_COLORMAP, COLORMAP__CREATE)
+	    && IDPERM(client, xCreateColormapReq, window,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_FreeColormap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__FREE);
+	break;
+    case X_FreeColors:
+	rval = IDPERM(client, xFreeColorsReq, cmap,
+		      SECCLASS_COLORMAP, COLORMAP__STORE);
+	break;
+    case X_InstallColormap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__INSTALL)
+	    && ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__INSTALL);
+	break;
+    case X_ListInstalledColormaps:
+	rval = ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__LIST);
+	break;
+    case X_LookupColor:
+    case X_QueryColors:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__READ);
+	break;
+    case X_StoreColors:
+    case X_StoreNamedColor:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__STORE);
+	break;
+    case X_UninstallColormap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_COLORMAP, COLORMAP__UNINSTALL)
+	    && ServerPerm(client, SECCLASS_COLORMAP, COLORMAP__UNINSTALL);
+	break;
+
+    /* Font class control requirements */
+    case X_CloseFont:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_FONT, FONT__FREE);
+	break;
+    case X_ImageText8:
+    case X_ImageText16:
+	/* Font accesses checked through the resource manager */
+	rval = IDPERM(client, xImageTextReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+    case X_OpenFont:
+	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD)
+	    && IDPERM(client, xOpenFontReq, fid,
+		      SECCLASS_FONT, FONT__USE);
+	break;
+    case X_PolyText8:
+    case X_PolyText16:
+	/* Font accesses checked through the resource manager */
+	rval = ServerPerm(client, SECCLASS_FONT, FONT__LOAD)
+	    && IDPERM(client, xPolyTextReq, gc,
+		      SECCLASS_GC, GC__SETATTR)
+	    && IDPERM(client, xPolyTextReq, drawable,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW);
+	break;
+	
+    /* Pixmap class control requirements */
+    case X_CreatePixmap:
+	rval = IDPERM(client, xCreatePixmapReq, pid,
+		      SECCLASS_DRAWABLE, DRAWABLE__CREATE);
+	break;
+    case X_FreePixmap:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_DRAWABLE, DRAWABLE__DESTROY);
+	break;
+
+    /* Cursor class control requirements */
+    case X_CreateCursor:
+	rval = IDPERM(client, xCreateCursorReq, cid,
+		      SECCLASS_CURSOR, CURSOR__CREATE)
+	    && IDPERM(client, xCreateCursorReq, source,
+		      SECCLASS_DRAWABLE, DRAWABLE__DRAW)
+	    && IDPERM(client, xCreateCursorReq, mask,
+		      SECCLASS_DRAWABLE, DRAWABLE__COPY);
+	break;
+    case X_CreateGlyphCursor:
+	rval = IDPERM(client, xCreateGlyphCursorReq, cid,
+		      SECCLASS_CURSOR, CURSOR__CREATEGLYPH)
+	    && IDPERM(client, xCreateGlyphCursorReq, source,
+		      SECCLASS_FONT, FONT__USE)
+	    && IDPERM(client, xCreateGlyphCursorReq, mask,
+		      SECCLASS_FONT, FONT__USE);
+	break;
+    case X_RecolorCursor:
+	rval = IDPERM(client, xRecolorCursorReq, cursor,
+		      SECCLASS_CURSOR, CURSOR__SETATTR);
+	break;
+    case X_FreeCursor:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_CURSOR, CURSOR__FREE);
+	break;
+	    
+    /* GC class control requirements */
+    case X_CreateGC:
+	rval = IDPERM(client, xCreateGCReq, gc,
+		      SECCLASS_GC, GC__CREATE | GC__SETATTR);
+	break;
+    case X_ChangeGC:
+    case X_SetDashes:
+    case X_SetClipRectangles:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_GC, GC__SETATTR);
+	break;
+    case X_CopyGC:
+	rval = IDPERM(client, xCopyGCReq, srcGC,
+		      SECCLASS_GC, GC__GETATTR)
+	    && IDPERM(client, xCopyGCReq, dstGC,
+		      SECCLASS_GC, GC__SETATTR);
+	break;
+    case X_FreeGC:
+	rval = IDPERM(client, xResourceReq, id,
+		      SECCLASS_GC, GC__FREE);
+	break;
+
+    /* Server class control requirements */
+    case X_GrabServer:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GRAB);
+	break;
+    case X_UngrabServer:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__UNGRAB);
+	break;
+    case X_ForceScreenSaver:
+    case X_GetScreenSaver:
+    case X_SetScreenSaver:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SCREENSAVER);
+	break;
+    case X_ListHosts:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETHOSTLIST);
+	break;
+    case X_ChangeHosts:
+    case X_SetAccessControl:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SETHOSTLIST);
+	break;
+    case X_GetFontPath:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETFONTPATH);
+	break;
+    case X_SetFontPath:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__SETFONTPATH);
+	break;
+    case X_QueryBestSize:
+	rval = ServerPerm(client, SECCLASS_XSERVER, XSERVER__GETATTR);
+	break;
+
+    default:
+	rval = TRUE;
+	break;
+    }
+    if (!rval)
+	rec->rval = FALSE;
+}
+
+CALLBACK(XSELinuxExtDispatch)
+{
+    XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata;
+    ClientPtr client = rec->client;
+    ExtensionEntry *ext = rec->ext;
+    security_id_t extsid;
+    access_vector_t perm;
+    REQUEST(xReq);
+    
+    /* XXX there should be a separate callback for this */
+    if (!EXTENSIONSID(ext))
+    {
+	extsid = ObjectSIDByLabel(NULL, SECCLASS_XEXTENSION, ext->name);
+	if (!extsid)
+	    return;
+	EXTENSIONSID(ext) = extsid;
+    }
+
+    extsid = (security_id_t)EXTENSIONSID(ext);
+    perm = ((stuff->reqType == X_QueryExtension) ||
+	    (stuff->reqType == X_ListExtensions)) ?
+	XEXTENSION__QUERY : XEXTENSION__USE;
+
+    if (HAVESTATE(client))
+    {
+	XSELinuxAuditRec auditdata;
+	auditdata.client = client;
+	auditdata.property = NULL;
+	auditdata.extension = ext->name;
+	errno = 0;
+	if (avc_has_perm(SID(client), extsid, SECCLASS_XEXTENSION,
+			 perm, &AEREF(client), &auditdata) < 0)
+	{
+	    if (errno != EACCES)
+		ErrorF("ExtDispatch: unexpected error %d\n", errno);
+	    rec->rval = FALSE;
+	}
+    } else
+	ErrorF("No client state in extension dispatcher!\n");
+} /* XSELinuxExtDispatch */
+
+CALLBACK(XSELinuxProperty)
+{
+    XacePropertyAccessRec *rec = (XacePropertyAccessRec*)calldata;
+    WindowPtr pWin = rec->pWin;
+    ClientPtr client = rec->client;
+    ClientPtr tclient;
+    access_vector_t perm = 0;
+    security_id_t propsid;
+    char *propname = NameForAtom(rec->propertyName);
+
+    tclient = wClient(pWin);
+    if (!tclient || !HAVESTATE(tclient))
+        return;
+
+    propsid = ObjectSIDByLabel(SID(tclient)->ctx, SECCLASS_PROPERTY, propname);
+    if (!propsid)
+	return;
+
+    if (rec->access_mode & SecurityReadAccess)
+	perm |= PROPERTY__READ;
+    if (rec->access_mode & SecurityWriteAccess)
+	perm |= PROPERTY__WRITE;
+    if (rec->access_mode & SecurityDestroyAccess)
+	perm |= PROPERTY__FREE;
+    if (!rec->access_mode)
+	perm = PROPERTY__READ | PROPERTY__WRITE | PROPERTY__FREE;
+
+    if (HAVESTATE(client))
+    {
+	XSELinuxAuditRec auditdata;
+	auditdata.client = client;
+	auditdata.property = propname;
+	auditdata.extension = NULL;
+	errno = 0;
+	if (avc_has_perm(SID(client), propsid, SECCLASS_PROPERTY,
+			 perm, &AEREF(client), &auditdata) < 0)
+	{
+	    if (errno != EACCES)
+		ErrorF("Property: unexpected error %d\n", errno);
+	    rec->rval = SecurityIgnoreOperation;
+	}
+    } else
+	ErrorF("No client state in property callback!\n");
+
+    /* XXX this should be saved in the property structure */
+    sidput(propsid);
+} /* XSELinuxProperty */
+
+CALLBACK(XSELinuxResLookup)
+{
+    XaceResourceAccessRec *rec = (XaceResourceAccessRec*)calldata;
+    ClientPtr client = rec->client;
+    REQUEST(xReq);
+    access_vector_t perm = 0;
+    Bool rval = TRUE;
+
+    /* serverClient requests OK */
+    if (client->index == 0)
+	return;
+
+    switch(rec->rtype) {
+	case RT_FONT: {
+	    switch(stuff->reqType) {
+		case X_ImageText8:
+		case X_ImageText16:
+		case X_PolyText8:
+		case X_PolyText16:
+		    perm = FONT__USE;
+		    break;
+		case X_ListFonts:
+		case X_ListFontsWithInfo:
+		case X_QueryFont:
+		case X_QueryTextExtents:
+		    perm = FONT__GETATTR;
+		    break;
+		default:
+		    break;
+	    }
+	    if (perm)
+		rval = IDPerm(client, rec->id, SECCLASS_FONT, perm);
+	    break;
+	}
+	default:
+	    break;
+    }
+    if (!rval)
+	rec->rval = FALSE;
+} /* XSELinuxResLookup */
+
+CALLBACK(XSELinuxMap)
+{
+    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
+    if (!IDPerm(rec->client, rec->pWin->drawable.id,
+		SECCLASS_WINDOW, WINDOW__MAP))
+	rec->rval = FALSE;
+} /* XSELinuxMap */
+
+CALLBACK(XSELinuxBackgrnd)
+{
+    XaceMapAccessRec *rec = (XaceMapAccessRec*)calldata;
+    if (!IDPerm(rec->client, rec->pWin->drawable.id,
+		SECCLASS_WINDOW, WINDOW__TRANSPARENT))
+	rec->rval = FALSE;
+} /* XSELinuxBackgrnd */
+
+CALLBACK(XSELinuxDrawable)
+{
+    XaceDrawableAccessRec *rec = (XaceDrawableAccessRec*)calldata;
+    if (!IDPerm(rec->client, rec->pDraw->id,
+		SECCLASS_DRAWABLE, DRAWABLE__COPY))
+	rec->rval = FALSE;
+} /* XSELinuxDrawable */
+
+CALLBACK(XSELinuxHostlist)
+{
+    XaceHostlistAccessRec *rec = (XaceHostlistAccessRec*)calldata;
+    access_vector_t perm = (rec->access_mode == SecurityReadAccess) ?
+	XSERVER__GETHOSTLIST : XSERVER__SETHOSTLIST;
+
+    if (!ServerPerm(rec->client, SECCLASS_XSERVER, perm))
+	rec->rval = FALSE;
+} /* XSELinuxHostlist */
+
+/* Extension callbacks */
+CALLBACK(XSELinuxClientState)
+{
+    NewClientInfoRec *pci = (NewClientInfoRec *)calldata;
+    ClientPtr client = pci->client;
+
+    switch(client->clientState)
+    {
+    case ClientStateInitial:
+	AssignClientState(serverClient);
+	break;
+
+	case ClientStateRunning:
+	{
+	    AssignClientState(client);
+	    break;
+	}
+	case ClientStateGone:
+	case ClientStateRetained:
+	{
+	    FreeClientState(client);
+	    break;
+	}
+	default: break;
+    }
+} /* XSELinuxClientState */
+
+static char *XSELinuxKeywords[] = {
+#define XSELinuxKeywordComment 0
+    "#",
+#define XSELinuxKeywordProperty 1
+    "property",
+#define XSELinuxKeywordExtension 2
+    "extension",
+#define XSELinuxKeywordNonlocalContext 3
+    "nonlocal_context",
+#define XSELinuxKeywordRootWindowContext 4
+    "root_window_context",
+#define XSELinuxKeywordDefault 5
+    "default"
+};
+
+#define NUMKEYWORDS (sizeof(XSELinuxKeywords) / sizeof(char *))
+
+#ifndef __UNIXOS2__
+#define XSELinuxIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') )
+#else
+#define XSELinuxIsWhitespace(c) ( (c == ' ') || (c == '\t') || (c == '\n') || (c == '\r') )
+#endif
+
+static char *
+XSELinuxSkipWhitespace(
+    char *p)
+{
+    while (XSELinuxIsWhitespace(*p))
+	p++;
+    return p;
+} /* XSELinuxSkipWhitespace */
+
+static char *
+XSELinuxParseString(
+    char **rest)
+{
+    char *startOfString;
+    char *s = *rest;
+    char endChar = 0;
+
+    s = XSELinuxSkipWhitespace(s);
+
+    if (*s == '"' || *s == '\'')
+    {
+	endChar = *s++;
+	startOfString = s;
+	while (*s && (*s != endChar))
+	    s++;
+    }
+    else
+    {
+	startOfString = s;
+	while (*s && !XSELinuxIsWhitespace(*s))
+	    s++;
+    }
+    if (*s)
+    {
+	*s = '\0';
+	*rest = s + 1;
+	return startOfString;
+    }
+    else
+    {
+	*rest = s;
+	return (endChar) ? NULL : startOfString;
+    }
+} /* XSELinuxParseString */
+
+static int
+XSELinuxParseKeyword(
+    char **p)
+{
+    int i;
+    char *s = *p;
+    s = XSELinuxSkipWhitespace(s);
+    for (i = 0; i < NUMKEYWORDS; i++)
+    {
+	int len = strlen(XSELinuxKeywords[i]);
+	if (strncmp(s, XSELinuxKeywords[i], len) == 0)
+	{
+	    *p = s + len;
+	    return (i);
+	}
+    }
+    *p = s;
+    return -1;
+} /* XSELinuxParseKeyword */
+
+static Bool
+XSELinuxTypeIsValid(char *typename)
+{
+    security_context_t base, new;
+    context_t con;
+    Bool ret = FALSE;
+
+    /* get the server's context */
+    if (getcon(&base) < 0)
+        goto out;
+
+    /* make a new context-manipulation object */
+    con = context_new(base);
+    if (!con)
+        goto out_free;
+
+    /* set the role */
+    if (context_role_set(con, "object_r"))
+        goto out_free2;
+
+    /* set the type */
+    if (context_type_set(con, typename))
+        goto out_free2;
+
+    /* get a context string - note: context_str() returns a pointer
+     * to the string inside the context; the returned pointer should
+     * not be freed
+     */
+    new = context_str(con);
+    if (!new)
+        goto out_free2;
+
+    /* finally, check to see if it's valid */
+    if (security_check_context(new) == 0)
+        ret = TRUE;
+
+out_free2:
+    context_free(con);
+out_free:
+    freecon(base);
+out:
+    return ret;
+}
+
+static Bool
+XSELinuxParsePropertyTypeRule(char *p)
+{
+    int keyword;
+    char *propname = NULL, *propcopy = NULL;
+    char *typename = NULL, *typecopy = NULL;
+    char **newTypes;
+    Bool defaultPropertyType = FALSE;
+
+    /* get property name */
+    keyword = XSELinuxParseKeyword(&p);
+    if (keyword == XSELinuxKeywordDefault)
+    {
+        defaultPropertyType = TRUE;
+    }
+    else
+    {
+        propname = XSELinuxParseString(&p);
+        if (!propname || (strlen(propname) == 0))
+        {
+            return FALSE;
+        }
+    }
+
+    /* get the SELinux type corresponding to the property */
+    typename = XSELinuxParseString(&p);
+    if (!typename || (strlen(typename) == 0))
+        return FALSE;
+
+    /* validate the type */
+    if (XSELinuxTypeIsValid(typename) != TRUE)
+        return FALSE;
+
+    /* if it's the default property, save it to append to the end of the
+     * property types list
+     */
+    if (defaultPropertyType == TRUE)
+    {
+        if (XSELinuxPropertyTypeDefault != NULL)
+        {
+            return FALSE;
+        }
+        else
+        {
+            XSELinuxPropertyTypeDefault = (char *)xalloc(strlen(typename)+1);
+            if (!XSELinuxPropertyTypeDefault)
+            {
+                ErrorF("XSELinux: out of memory\n");
+                return FALSE;
+            }
+            strcpy(XSELinuxPropertyTypeDefault, typename);
+            return TRUE;
+        }
+    }
+
+    /* insert the property and type into the propertyTypes array */
+    propcopy = (char *)xalloc(strlen(propname)+1);
+    if (!propcopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(propcopy, propname);
+
+    typecopy = (char *)xalloc(strlen(typename)+1);
+    if (!typecopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(propcopy);
+        return FALSE;
+    }
+    strcpy(typecopy, typename);
+
+    newTypes = (char **)xrealloc(propertyTypes, sizeof (char *) * ((propertyTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(propcopy);
+        xfree(typecopy);
+        return FALSE;
+    }
+
+    propertyTypesCount++;
+
+    newTypes[propertyTypesCount*2 - 2] = propcopy;
+    newTypes[propertyTypesCount*2 - 1] = typecopy;
+    
+    propertyTypes = newTypes;
+
+    return TRUE;
+} /* XSELinuxParsePropertyTypeRule */
+
+static Bool
+XSELinuxParseExtensionTypeRule(char *p)
+{
+    int keyword;
+    char *extname = NULL, *extcopy = NULL;
+    char *typename = NULL, *typecopy = NULL;
+    char **newTypes;
+    Bool defaultExtensionType = FALSE;
+
+    /* get extension name */
+    keyword = XSELinuxParseKeyword(&p);
+    if (keyword == XSELinuxKeywordDefault)
+    {
+        defaultExtensionType = TRUE;
+    }
+    else
+    {
+        extname = XSELinuxParseString(&p);
+        if (!extname || (strlen(extname) == 0))
+        {
+            return FALSE;
+        }
+    }
+
+    /* get the SELinux type corresponding to the extension */
+    typename = XSELinuxParseString(&p);
+    if (!typename || (strlen(typename) == 0))
+        return FALSE;
+
+    /* validate the type */
+    if (XSELinuxTypeIsValid(typename) != TRUE)
+        return FALSE;
+
+    /* if it's the default extension, save it to append to the end of the
+     * extension types list
+     */
+    if (defaultExtensionType == TRUE)
+    {
+        if (XSELinuxExtensionTypeDefault != NULL)
+        {
+            return FALSE;
+        }
+        else
+        {
+            XSELinuxExtensionTypeDefault = (char *)xalloc(strlen(typename)+1);
+            if (!XSELinuxExtensionTypeDefault)
+            {
+                ErrorF("XSELinux: out of memory\n");
+                return FALSE;
+            }
+            strcpy(XSELinuxExtensionTypeDefault, typename);
+            return TRUE;
+        }
+    }
+
+    /* insert the extension and type into the extensionTypes array */
+    extcopy = (char *)xalloc(strlen(extname)+1);
+    if (!extcopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(extcopy, extname);
+
+    typecopy = (char *)xalloc(strlen(typename)+1);
+    if (!typecopy)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(extcopy);
+        return FALSE;
+    }
+    strcpy(typecopy, typename);
+
+    newTypes = (char **)xrealloc(extensionTypes, sizeof(char *) *( (extensionTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        xfree(extcopy);
+        xfree(typecopy);
+        return FALSE;
+    }
+
+    extensionTypesCount++;
+
+    newTypes[extensionTypesCount*2 - 2] = extcopy;
+    newTypes[extensionTypesCount*2 - 1] = typecopy;
+
+    extensionTypes = newTypes;
+
+    return TRUE;
+} /* XSELinuxParseExtensionTypeRule */
+
+static Bool
+XSELinuxParseNonlocalContext(char *p)
+{
+    char *context;
+
+    context = XSELinuxParseString(&p);
+    if (!context || (strlen(context) == 0))
+    {
+        return FALSE;
+    }
+
+    if (XSELinuxNonlocalContextDefault != NULL)
+    {
+        return FALSE;
+    }
+
+    /* validate the context */
+    if (security_check_context(context))
+    {
+        return FALSE;
+    }
+
+    XSELinuxNonlocalContextDefault = (char *)xalloc(strlen(context)+1);
+    if (!XSELinuxNonlocalContextDefault)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(XSELinuxNonlocalContextDefault, context);
+
+    return TRUE;
+} /* XSELinuxParseNonlocalContext */
+
+static Bool
+XSELinuxParseRootWindowContext(char *p)
+{
+    char *context;
+
+    context = XSELinuxParseString(&p);
+    if (!context || (strlen(context) == 0))
+    {
+        return FALSE;
+    }
+
+    if (XSELinuxRootWindowContext != NULL)
+    {
+        return FALSE;
+    }
+
+    /* validate the context */
+    if (security_check_context(context))
+    {
+        return FALSE;
+    }
+
+    XSELinuxRootWindowContext = (char *)xalloc(strlen(context)+1);
+    if (!XSELinuxRootWindowContext)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        return FALSE;
+    }
+    strcpy(XSELinuxRootWindowContext, context);
+
+    return TRUE;
+} /* XSELinuxParseRootWindowContext */
+
+static Bool
+XSELinuxLoadConfigFile(void)
+{
+    FILE *f;
+    int lineNumber = 0;
+    char **newTypes;
+    Bool ret = FALSE;
+    
+    if (!XSELINUXCONFIGFILE)
+        return FALSE;
+
+    /* some initial bookkeeping */
+    propertyTypesCount = extensionTypesCount = 0;
+    propertyTypes = extensionTypes = NULL;
+    XSELinuxPropertyTypeDefault = XSELinuxExtensionTypeDefault = NULL;
+    XSELinuxNonlocalContextDefault = NULL;
+    XSELinuxRootWindowContext = NULL;
+
+#ifndef __UNIXOS2__
+    f = fopen(XSELINUXCONFIGFILE, "r");
+#else
+    f = fopen((char*)__XOS2RedirRoot(XSELINUXCONFIGFILE), "r");
+#endif
+    if (!f)
+    {
+        ErrorF("Error opening XSELinux policy file %s\n", XSELINUXCONFIGFILE);
+        return FALSE;
+    }
+
+    while (!feof(f))
+    {
+        char buf[200];
+        Bool validLine;
+        char *p;
+
+        if (!(p = fgets(buf, sizeof(buf), f)))
+            break;
+        lineNumber++;
+
+        switch (XSELinuxParseKeyword(&p))
+        {
+            case XSELinuxKeywordComment:
+                validLine = TRUE;
+                break;
+
+            case XSELinuxKeywordProperty:
+                validLine = XSELinuxParsePropertyTypeRule(p);
+                break;
+
+            case XSELinuxKeywordExtension:
+                validLine = XSELinuxParseExtensionTypeRule(p);
+                break;
+
+            case XSELinuxKeywordNonlocalContext:
+                validLine = XSELinuxParseNonlocalContext(p);
+                break;
+
+            case XSELinuxKeywordRootWindowContext:
+                validLine = XSELinuxParseRootWindowContext(p);
+                break;
+
+            default:
+                validLine = (*p == '\0');
+                break;
+        }
+
+        if (!validLine)
+        {
+            ErrorF("XSELinux: Line %d of %s is invalid\n",
+                   lineNumber, XSELINUXCONFIGFILE);
+            goto out;
+        }
+    }
+
+    /* check to make sure the default types and the nonlocal context
+     * were specified
+     */
+    if (XSELinuxPropertyTypeDefault == NULL)
+    {
+        ErrorF("XSELinux: No default property type specified\n");
+        goto out;
+    }
+    else if (XSELinuxExtensionTypeDefault == NULL)
+    {
+        ErrorF("XSELinux: No default extension type specified\n");
+        goto out;
+    }
+    else if (XSELinuxNonlocalContextDefault == NULL)
+    {
+        ErrorF("XSELinux: No default context for non-local clients specified\n");
+        goto out;
+    }
+    else if (XSELinuxRootWindowContext == NULL)
+    {
+        ErrorF("XSELinux: No context specified for the root window\n");
+        goto out;
+    }
+
+    /* Finally, append the default property and extension types to the
+     * bottoms of the propertyTypes and extensionTypes arrays, respectively.
+     * The 'name' of the property / extension is NULL.
+     */
+    newTypes = (char **)xrealloc(propertyTypes, sizeof(char *) *((propertyTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        goto out;
+    }
+    propertyTypesCount++;
+    newTypes[propertyTypesCount*2 - 2] = NULL;
+    newTypes[propertyTypesCount*2 - 1] = XSELinuxPropertyTypeDefault;
+    propertyTypes = newTypes;
+
+    newTypes = (char **)xrealloc(extensionTypes, sizeof(char *) *((extensionTypesCount+1) * 2));
+    if (!newTypes)
+    {
+        ErrorF("XSELinux: out of memory\n");
+        goto out;
+    }
+    extensionTypesCount++;
+    newTypes[extensionTypesCount*2 - 2] = NULL;
+    newTypes[extensionTypesCount*2 - 1] = XSELinuxExtensionTypeDefault;
+    extensionTypes = newTypes;
+
+    ret = TRUE;
+
+out:
+    fclose(f);
+    return ret;
+} /* XSELinuxLoadConfigFile */
+
+static void
+XSELinuxFreeConfigData(void)
+{
+    char **ptr;
+
+    /* Free all the memory in the table until we reach the NULL, then
+     * skip one past the NULL and free the default type.  Then take care
+     * of some bookkeeping.
+     */
+    for (ptr = propertyTypes; *ptr; ptr++)
+        xfree(*ptr);
+    ptr++;
+    xfree(*ptr);
+
+    XSELinuxPropertyTypeDefault = NULL;
+    propertyTypesCount = 0;
+
+    xfree(propertyTypes);
+    propertyTypes = NULL;
+
+    /* ... and the same for the extension type table */
+    for (ptr = extensionTypes; *ptr; ptr++)
+        xfree(*ptr);
+    ptr++;
+    xfree(*ptr);
+
+    XSELinuxExtensionTypeDefault = NULL;
+    extensionTypesCount = 0;
+
+    xfree(extensionTypes);
+    extensionTypes = NULL;
+
+    /* finally, take care of the context for non-local connections */
+    xfree(XSELinuxNonlocalContextDefault);
+    XSELinuxNonlocalContextDefault = NULL;
+
+    /* ... and for the root window */
+    xfree(XSELinuxRootWindowContext);
+    XSELinuxRootWindowContext = NULL;
+} /* XSELinuxFreeConfigData */
+
+/* Extension dispatch functions */
+static int
+ProcXSELinuxDispatch(ClientPtr client)
+{
+    return BadRequest;
+} /* ProcXSELinuxDispatch */
+
+static void
+XSELinuxResetProc(ExtensionEntry *extEntry)
+{
+    FreeClientState(serverClient);
+
+    XSELinuxFreeConfigData();
+
+    audit_close(audit_fd);
+
+    avc_destroy();
+} /* XSELinuxResetProc */
+
+static void
+XSELinuxAVCAudit(void *auditdata,
+		 security_class_t class,
+		 char *msgbuf,
+		 size_t msgbufsize)
+{
+    XSELinuxAuditRec *audit = (XSELinuxAuditRec*)auditdata;
+    ClientPtr client = audit->client;
+    char requestNum[8];
+    REQUEST(xReq);
+
+    if (stuff)
+	snprintf(requestNum, 8, "%d", stuff->reqType);
+
+    snprintf(msgbuf, msgbufsize, "%s%s%s%s%s%s",
+	     stuff ? "request=" : "",
+	     stuff ? requestNum : "",
+	     audit->property ? " property=" : "",
+	     audit->property ? audit->property : "",
+	     audit->extension ? " extension=" : "",
+	     audit->extension ? audit->extension : "");
+}
+
+static void
+XSELinuxAVCLog(const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    VErrorF(fmt, ap);
+    va_end(ap);
+}
+
+/* XSELinuxExtensionSetup
+ *
+ * Set up the XSELinux Extension (pre-init)
+ */
+void
+XSELinuxExtensionSetup(INITARGS)
+{
+    /* Allocate the client private index */
+    clientPrivateIndex = AllocateClientPrivateIndex();
+    if (!AllocateClientPrivate(clientPrivateIndex, 
+			       sizeof (XSELinuxClientStateRec)))
+	FatalError("XSELinux: Failed to allocate client private.\n");
+
+    /* Allocate the extension private index */
+    extnsnPrivateIndex = AllocateExtensionPrivateIndex();
+    if (!AllocateExtensionPrivate(extnsnPrivateIndex, 0))
+	FatalError("XSELinux: Failed to allocate extension private.\n");
+}
+
+/* XSELinuxExtensionInit
+ *
+ * Initialize the XSELinux Extension
+ */
+void
+XSELinuxExtensionInit(INITARGS)
+{
+    ExtensionEntry	*extEntry;
+    struct avc_log_callback alc = {XSELinuxAVCLog, XSELinuxAVCAudit};
+
+    if (!is_selinux_enabled())
+    {
+        ErrorF("SELinux Extension failed to load: SELinux not enabled\n");
+        return;
+    }
+
+    if (avc_init("xserver", NULL, &alc, NULL, NULL) < 0)
+    {
+	FatalError("couldn't initialize SELinux userspace AVC\n");
+    }
+
+    if (!AddCallback(&ClientStateCallback, XSELinuxClientState, NULL))
+	return;
+
+    /* Load the config file.  If this fails, shut down the server,
+     * since an unknown security status is worse than no security.
+     *
+     * Note that this must come before we assign a security state
+     * for the serverClient, because the serverClient's root windows
+     * are assigned a context based on data in the config file.
+     */
+    if (XSELinuxLoadConfigFile() != TRUE)
+    {
+	FatalError("XSELinux: Failed to load security policy\n");
+    }
+
+    /* prepare for auditing */
+    audit_fd = audit_open();
+    if (audit_fd < 0)
+    {
+        FatalError("XSELinux: Failed to open the system audit log\n");
+    }
+
+    /* register security callbacks */
+    XaceRegisterCallback(XACE_CORE_DISPATCH, XSELinuxCoreDispatch, NULL);
+    XaceRegisterCallback(XACE_EXT_ACCESS, XSELinuxExtDispatch, NULL);
+    XaceRegisterCallback(XACE_EXT_DISPATCH, XSELinuxExtDispatch, NULL);
+    XaceRegisterCallback(XACE_RESOURCE_ACCESS, XSELinuxResLookup, NULL);
+    XaceRegisterCallback(XACE_MAP_ACCESS, XSELinuxMap, NULL);
+    XaceRegisterCallback(XACE_HOSTLIST_ACCESS, XSELinuxHostlist, NULL);
+    XaceRegisterCallback(XACE_BACKGRND_ACCESS, XSELinuxBackgrnd, NULL);
+    XaceRegisterCallback(XACE_DRAWABLE_ACCESS, XSELinuxDrawable, NULL);
+    XaceRegisterCallback(XACE_PROPERTY_ACCESS, XSELinuxProperty, NULL);
+    /* XaceRegisterCallback(XACE_DECLARE_EXT_SECURE, XSELinuxDeclare, NULL);
+    XaceRegisterCallback(XACE_DEVICE_ACCESS, XSELinuxDevice, NULL); */
+
+    /* register extension with server */
+    extEntry = AddExtension(XSELINUX_EXTENSION_NAME,
+			    XSELinuxNumberEvents, XSELinuxNumberErrors,
+			    ProcXSELinuxDispatch, ProcXSELinuxDispatch,
+			    XSELinuxResetProc, StandardMinorOpcode);
+}
diff --git a/Xext/xselinux.h b/Xext/xselinux.h
new file mode 100644
index 0000000..eff6db5
--- /dev/null
+++ b/Xext/xselinux.h
@@ -0,0 +1,29 @@
+/************************************************************
+
+Author: Eamon Walsh <ewalsh at epoch.ncsc.mil>
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+this permission notice appear in supporting documentation.  This permission
+notice shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+********************************************************/
+
+#ifndef _XSELINUX_H
+#define _XSELINUX_H
+
+#define XSELINUX_EXTENSION_NAME		"SELinux"
+#define XSELINUX_MAJOR_VERSION		1
+#define XSELINUX_MINOR_VERSION		0
+#define XSELinuxNumberEvents		0
+#define XSELinuxNumberErrors		0
+
+#endif /* _XSELINUX_H */


More information about the xorg-commit mailing list