From 011694ae838bf1ee9002c81f7db72f9b4ff8de6b Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Sun, 3 Dec 2017 10:35:22 +0000 Subject: [PATCH] migrations: Add 03_users_group_gid This migration will fix the dynamically assigned gid of `users` group from the 900 range to the static 100. Signed-off-by: Ikey Doherty --- src/cli/migrate.c | 1 + src/meson.build | 1 + src/migrations/03_users_group_gid.c | 42 +++++++++++++++++++++++++++++ src/migrations/declared.h | 12 +++++++++ src/migrations/shared.c | 25 +++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 src/migrations/03_users_group_gid.c diff --git a/src/cli/migrate.c b/src/cli/migrate.c index 121a318..6bb02d9 100644 --- a/src/cli/migrate.c +++ b/src/cli/migrate.c @@ -37,6 +37,7 @@ static QolMigration migration_table[] = { MIGRATION("Add users to scanner group", 01_scanner_group), MIGRATION("Add users to plugdev group", 02_plugdev_group), + MIGRATION("Set static gid for 'users' group", 03_users_group_gid), }; /** diff --git a/src/meson.build b/src/meson.build index 39036ca..64c2ddb 100644 --- a/src/meson.build +++ b/src/meson.build @@ -20,6 +20,7 @@ endif migrations = [ '01_scanner_group', '02_plugdev_group', + '03_users_group_gid', ] # Insert into sources diff --git a/src/migrations/03_users_group_gid.c b/src/migrations/03_users_group_gid.c new file mode 100644 index 0000000..702f297 --- /dev/null +++ b/src/migrations/03_users_group_gid.c @@ -0,0 +1,42 @@ +/* + * This file is part of qol-assist. + * + * Copyright © 2017 Solus Project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#define _GNU_SOURCE + +#include + +#include "declared.h" + +/** + * Fix the users group GID. + * + * Solus never used this group before, however by the time we needed it for + * SAMBA, a systemd update had created a 'users' group with a bogus GID in + * the 900 range, so we forcibly set it back to 100 here before using it + * for anything. + */ +bool qol_migration_03_users_group_gid(QolContext *context) +{ + return qol_migration_update_group_id(context, "users", 100); +} + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=8 tabstop=8 expandtab: + * :indentSize=8:tabSize=8:noTabs=true: + */ diff --git a/src/migrations/declared.h b/src/migrations/declared.h index 2a3bbf5..6f80b27 100644 --- a/src/migrations/declared.h +++ b/src/migrations/declared.h @@ -23,10 +23,22 @@ */ bool qol_migration_push_active_admin_group(QolContext *context, const char *group); +/** + * Update the group id for the given group name if it does not currently + * match the given ID + * + * @param context Pointer to a valid QolContext + * @param group Name for the group in question + * + * @returns True if the operation succeeded + */ +bool qol_migration_update_group_id(QolContext *context, const char *group, int gid); + /* Migrations follow */ bool qol_migration_01_scanner_group(QolContext *context); bool qol_migration_02_plugdev_group(QolContext *context); +bool qol_migration_03_users_group_gid(QolContext *context); /* * Editor modelines - https://www.wireshark.org/tools/modelines.html diff --git a/src/migrations/shared.c b/src/migrations/shared.c index 9b6e1b3..ec908fe 100644 --- a/src/migrations/shared.c +++ b/src/migrations/shared.c @@ -11,7 +11,9 @@ #define _GNU_SOURCE +#include #include +#include #include "declared.h" @@ -39,6 +41,29 @@ bool qol_migration_push_active_admin_group(QolContext *context, const char *grou return true; } +bool qol_migration_update_group_id(QolContext *context, const char *group, int gid) +{ + int current_id = 1; + + current_id = qol_user_manager_get_group_id(context->user_manager, group); + if (current_id < 0) { + fprintf(stderr, "Failed to find '%s' group: %s\n", group, strerror(errno)); + return false; + } + + /* No need to perform an update here, it's been done */ + if (current_id == gid) { + return true; + } + + fprintf(stderr, "Changing group '%s' ID from %d to %d\n", group, current_id, gid); + if (!qol_user_manager_change_group_id(context->user_manager, group, gid)) { + fprintf(stderr, "Failed to change group id: %s\n", strerror(errno)); + return false; + } + return true; +} + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html *