Custom/universal clamp/attachment for light on rear rack
Some hackish ideas I have:

Why not just use zip ties? If your rack doesn't have 3 posts, you can make 2 or so loops (one or two horizontal, and 1 or 2 vertical) to make a makeshift mount. Then, attach something like a binder clip or two to the light. Alternatively, you could cut a bit of the light's plastic and use something like a velcro loop on the back. _v_v___v_v_ where the _ denotes the back of the light and v denotes entry &amp; exit points of velcro (if it doesn't need to be removable, you can even use zip ties instead, and seal the light a bit with a little bit of caulk). 

If you want to be fancy, you can always take the mount of some manufacturer (e.g. Planet Bike), and then get a piece of plastic / other stiff material, and rabbet the appropriate thickness ridge to fit into the mount (or glue a thin piece of material to a thicker piece material) to get the rabbet-ing effect. So, the thin part would be thin enough to slide through the mount, and the thick part would be attached securely to the light (through some adhesive, or screws). Then, you'd make the top a bit too wide for it to slide straight down through the mount. If you have an arts and crafts store nearby, you can pick up some thin but rigid plastic, screw in / glue a block of some other material narrower than the ridge of the mount and then put a screw through the light into the block. Then, on top of the block, put a lip so the light doesn't jump out. If you cut the block so that it conforms to the notch in the light mount, that would help too. Alternatively, you can cut a slot in the light mount and thread some velcro through it. 

You can also cannibalize another light with matching mount by simply cutting off a bit of area around where the mount is, and then adjoining it to a new light (screws/adhesive). 

As for the general problem:

Typically, mounts are isolated between manufacturers (certainly, on front lights. on rear lights, it seems to primarily be a width thing). So a universal solution is going to be hard to find / doesn't exist. For cheap lights, I'd be inclined to just get a new light.