• [PATCH] Lookup users and groups in root directory instead of on host

    From Daan De Meyer@21:1/5 to All on Tue Mar 7 13:10:01 2023
    If a root directory is configured by the user, lookup users and groups
    in the /etc/passwd and /etc/group of that root directory instead of the
    host's /etc/passwd and /etc/group.

    This is especially important when building Debian chroots on distros
    that are not Debian based and where the host's /etc/passwd and /etc/group
    is using passwd and group entries that differ wildly from those shipped
    by Debian or its derivatives, causing dpkg stat-overrides to fail because
    a group or user cannot be found in the host's passwd or group entries.
    ---
    lib/dpkg/db-fsys-override.c | 64 +++++++++++++++++++++++++++++++------
    1 file changed, 54 insertions(+), 10 deletions(-)

    diff --git a/lib/dpkg/db-fsys-override.c b/lib/dpkg/db-fsys-override.c
    index e079c5ffb..29adaf134 100644
    --- a/lib/dpkg/db-fsys-override.c
    +++ b/lib/dpkg/db-fsys-override.c
    @@ -58,12 +58,34 @@ statdb_parse_uid(const char *str)
    ohshit(_("invalid statoverride uid %s"), str);
    uid = (uid_t)value;
    } else {
    - struct passwd *pw = getpwnam(str);
    + char *passwd;
    + FILE *file;
    +
    + uid = (uid_t)-1;
    + passwd = dpkg_fsys_get_path("etc/passwd");
    +
    + file = fopen(passwd, "r");
    + free(passwd);
    + if (!file) {
    + if (errno != ENOENT)
    + ohshite(_("failed to open etc/passwd file"));
    + } else {
    + struct passwd *pw;
    +
    + errno = 0;
    + while ((pw = fgetpwent(file))) {
    + if (strcmp(pw->pw_name, str) == 0)
    + break;
    + }

    - if (pw == NULL)
    - uid = (uid_t)-1;
    - else
    - uid = pw->pw_uid;
    + fclose(file);
    +
    + if (errno > 0)
    + oh
  • From Guillem Jover@21:1/5 to Daan De Meyer on Sat Apr 8 12:20:01 2023
    Hi!

    On Tue, 2023-03-07 at 13:05:51 +0100, Daan De Meyer wrote:
    If a root directory is configured by the user, lookup users and groups
    in the /etc/passwd and /etc/group of that root directory instead of the host's /etc/passwd and /etc/group.

    This is especially important when building Debian chroots on distros
    that are not Debian based and where the host's /etc/passwd and /etc/group
    is using passwd and group entries that differ wildly from those shipped
    by Debian or its derivatives, causing dpkg stat-overrides to fail because
    a group or user cannot be found in the host's passwd or group entries.

    Indeed, nice catch, and thanks for the patch (and for filing the bug
    report). While I don't quite like the hardcoding of the filenames, this
    is something that was already implicitly done by the system libc
    (including chroots and similar).

    I'll be queueing this as part of the greater refactoring for the
    dpkg sysusers support, and will probably add a way to override those
    pathnames externally to mitigate this hardcoding.

    Thanks,
    Guillem

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)