srm: Clean up query operations

Addresses issues in choosing the correct error code,
producing good error messages, and also fixes a couple
of null pointer exceptions and other errors.

Target: trunk
Require-notes: yes
Require-book: no
Acked-by: Paul Millar <paul.millar@desy.de>
Patch: http://rb.dcache.org/r/6124/