Refactor function searching for organizational group and group names

Extracted from multitenancy pull request: https://github.com/openchange/openchange/pull/72