possible fix for https://github.com/saltstack/salt/issues/5567

As discussed in [1].

The unittests did not pass cleanly, although it's difficult to tell if the failures are related to any of the changes that I did. I am also having massive problems getting debian packages to work correctly now (salt user doesn't seem to get created anymore), which is making testing difficult. For now, this pull request can be treated as informative only.

[1] https://github.com/saltstack/salt/issues/5567