Skip to content

Commit

Permalink
migrations: Add 03_users_group_gid
Browse files Browse the repository at this point in the history
This migration will fix the dynamically assigned gid of `users` group
from the 900 range to the static 100.

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

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

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

#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:
*/
12 changes: 12 additions & 0 deletions src/migrations/declared.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/migrations/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

#define _GNU_SOURCE

#include <errno.h>
#include <stdio.h>
#include <string.h>

#include "declared.h"

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 011694a

Please sign in to comment.