Skip to content

Commit

Permalink
Add new 04_users_group_join migration
Browse files Browse the repository at this point in the history
For any existing users not in the `users` group, regardless of admin state,
add them all to the group. This will run **after** we update the gid from
the dynamic range to the new ID.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeydoherty committed Dec 3, 2017
1 parent 011694a commit b952421
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/cli/migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ migrations = [
'01_scanner_group',
'02_plugdev_group',
'03_users_group_gid',
'04_users_group_join',
]

# Insert into sources
Expand Down
37 changes: 37 additions & 0 deletions src/migrations/04_users_group_join.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

#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:
*/
13 changes: 13 additions & 0 deletions src/migrations/declared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
23 changes: 18 additions & 5 deletions src/migrations/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down

0 comments on commit b952421

Please sign in to comment.