Duplicate low-level code from the original regserver.
Add license header.