Subject: Bug#1145: x2godbadmin + postgres + non-existent home directory = wrong ownerships

From: Stefan Baur <[email-masked]>
Date: Tue, 7 Feb 2017 14:10:44 +0100

package: x2goserver

When x2godbadmin is used with a postgres database, and the user name
given doesn't yet have a home directory, it creates this home directory.
(see line 368 and following of /usr/sbin/x2godbadmin).

However, it fails to set the proper UID/GID ownerships for
/home/<username> - only the files below it have the proper ownership.

The proper way how to determine the correct UID for /home/<username> is
simple - use the UID that has been determined previously and that is
used as $uid within /usr/sbin/x2godbadmin.

The proper way how to determine the correct *GID* is more tricky, I
believe.  I can only speak for Debian here - this may be
distribution-specific:

You need to check if /etc/default/useradd contains a line
USERGROUPS_ENAB=yes
(which might also be "yes", or 'yes', or Yes, YES, ... you get the idea)

Check if that value is set to any variant of yes, or not set at all:
If yes: Check if the user already has a group named after them:
        If yes, use the GID of that group.
        If no, create a new group with a name matching the username,
        and assign the GID of that group.

If no (meaning the value is set to any variant of no, "no", 'no', No, etc.):
      Check if /etc/default/useradd contains a valid GID value for
      a variable named GROUP:
      If it does, assign that GID.
      If it doesn't, assign GID 100.

This pseudocode builds on the documentation found in "man useradd" on
Debian Jessie, after confirming the default value of USERGROUPS_ENAB is,
in fact, "unset".

Kind Regards,
Stefan Baur

-- 
BAUR-ITCS UG (haftungsbeschränkt)
Geschäftsführer: Stefan Baur
Eichenäckerweg 10, 89081 Ulm | Registergericht Ulm, HRB 724364
Fon/Fax 0731 40 34 66-36/-35 | USt-IdNr.: DE268653243