Skip to content

Commit

Permalink
Merge pull request linuxmint#6567 from claudiux/mcsm_sudoers
Browse files Browse the repository at this point in the history
[multicore-sys-monitor@ccadeptic23] v1.9.8 - Determines whether the user is a sudoer
  • Loading branch information
claudiux authored Nov 13, 2024
2 parents 533509c + d2a25a7 commit aa5401a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Util = imports.misc.util;
const Main = imports.ui.main;
const Applet = imports.ui.applet;
const PopupMenu = imports.ui.popupMenu;
const Lang = imports.lang;
const {
reloadExtension,
Type
Expand Down Expand Up @@ -210,7 +211,25 @@ mcsm.prototype = {
__init: function() {
this.configSettings = new ConfigSettings(this.configFilePath);

this._initContextMenu();
// Is the user a sudoer?
var user = GLib.get_user_name();
const HOME_DIR = GLib.get_home_dir();
const APPLET_DIR = HOME_DIR + "/.local/share/cinnamon/applets/" + UUID;
const SCRIPTS_DIR = APPLET_DIR + "/scripts";
let command = SCRIPTS_DIR + "/get-sudoers.sh";
this.is_sudoer = false;
let sudoersProcess = Util.spawnCommandLineAsyncIO(command, Lang.bind(this, function(stdout, stderr, exitCode) {
if (exitCode == 0) {
let list = stdout.trim().split(",");
if (list.indexOf(user) > -1) {
this.is_sudoer = true;
}
this._initContextMenu();
} else {
this._initContextMenu();
}
sudoersProcess.send_signal(9);
}));

this.actor.connect('enter-event', () => {
this.hovered = true;
Expand Down Expand Up @@ -316,7 +335,7 @@ mcsm.prototype = {
});
this._applet_context_menu.addMenuItem(w_graphs_item);
}
if (GLib.find_program_in_path("pkexec") && GLib.find_program_in_path("sysctl")) {
if (this.is_sudoer && GLib.find_program_in_path("pkexec") && GLib.find_program_in_path("sysctl")) {
this._applet_context_menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
let drop_cache_item = new Applet.MenuItem(
_("Drop Memory Cache (needs root rights)"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
###
# Returns the comma-separated list of sudoers.
###

sudoers1=$(getent group sudo | sed -e "s/:/ /g" | awk '{print$4}')
sudoers2=$(getent group wheel | sed -e "s/:/ /g" | awk '{print$4}')

[ -z $sudoers2 ] && {
echo "$sudoers1"
exit 0
} || {
[ -z $sudoers1 ] && {
echo "$sudoers2"
exit 0
} || {
echo "$sudoers1,$sudoers2"
exit 0
}
}

exit 1

0 comments on commit aa5401a

Please sign in to comment.