diff --git a/src/cli/migrate.c b/src/cli/migrate.c index 6bb02d9..d6e4ca7 100644 --- a/src/cli/migrate.c +++ b/src/cli/migrate.c @@ -38,6 +38,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), + MIGRATION("Add users to 'users' group", 04_users_group_join), }; /** diff --git a/src/meson.build b/src/meson.build index 64c2ddb..f107695 100644 --- a/src/meson.build +++ b/src/meson.build @@ -21,6 +21,7 @@ migrations = [ '01_scanner_group', '02_plugdev_group', '03_users_group_gid', + '04_users_group_join', ] # Insert into sources diff --git a/src/migrations/04_users_group_join.c b/src/migrations/04_users_group_join.c new file mode 100644 index 0000000..53c3772 --- /dev/null +++ b/src/migrations/04_users_group_join.c @@ -0,0 +1,37 @@ +/* + * 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" + +/** + * Add all active users into the users group + */ +bool qol_migration_04_users_group_join(QolContext *context) +{ + return qol_migration_push_active_group(context, "users"); +} + +/* + * 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 6f80b27..1b890fd 100644 --- a/src/migrations/declared.h +++ b/src/migrations/declared.h @@ -23,6 +23,18 @@ */ bool qol_migration_push_active_admin_group(QolContext *context, const char *group); +/** + * Add any active users to the specified group if they're not in it already + * + * @note This will add for users *and* admins + * + * @param context Pointer to a valid QolContext + * @param group Name of the group for the users to join + * + * @returns True if the operation succeeded + */ +bool qol_migration_push_active_group(QolContext *context, const char *group); + /** * Update the group id for the given group name if it does not currently * match the given ID @@ -39,6 +51,7 @@ bool qol_migration_update_group_id(QolContext *context, const char *group, int g 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); +bool qol_migration_04_users_group_join(QolContext *context); /* * Editor modelines - https://www.wireshark.org/tools/modelines.html diff --git a/src/migrations/shared.c b/src/migrations/shared.c index ec908fe..7d06f93 100644 --- a/src/migrations/shared.c +++ b/src/migrations/shared.c @@ -17,13 +17,13 @@ #include "declared.h" -/** - * Shared code for our API.. - */ -bool qol_migration_push_active_admin_group(QolContext *context, const char *group) +static bool qol_migration_push(QolContext *context, const char *group, bool require_admin) { for (QolUser *user = context->user_manager->users; user; user = user->next) { - if (!qol_user_is_active(user) || !qol_user_is_admin(user)) { + if (!qol_user_is_active(user)) { + continue; + } + if (require_admin && !qol_user_is_admin(user)) { continue; } if (qol_user_in_group(user, group)) { @@ -41,6 +41,19 @@ bool qol_migration_push_active_admin_group(QolContext *context, const char *grou return true; } +/** + * Shared code for our API.. + */ +bool qol_migration_push_active_admin_group(QolContext *context, const char *group) +{ + return qol_migration_push(context, group, true); +} + +bool qol_migration_push_active_group(QolContext *context, const char *group) +{ + return qol_migration_push(context, group, false); +} + bool qol_migration_update_group_id(QolContext *context, const char *group, int gid) { int current_id = 1;