From 373089f949ef374e24a0180ddee0c69c4e234a23 Mon Sep 17 00:00:00 2001 From: Igor Belitskiy Date: Fri, 10 Mar 2023 11:04:00 +0600 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D1=8B=20wheel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/ublexec.cc | 41 ++++++++++++++++++++++++++++++++++++----- source/ublexec.h | 3 +++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/source/ublexec.cc b/source/ublexec.cc index 538d7a8..f6c89cc 100644 --- a/source/ublexec.cc +++ b/source/ublexec.cc @@ -333,6 +333,7 @@ void MainWindow::settings() { lblTime4EpriorityHigh->set_text("0 (Высокий)"); scalePriority->set_inverted(true); this->pars_dir_bin(); + this->is_user_wheel(); this->pars_users(); this->activ_or_block_execute_epriority(); this->changed_user(); @@ -455,7 +456,7 @@ string MainWindow::start_cmd(string user_cmd) { string str_nice_cmd = ""; if (chbAnotherUser->get_active()) { if (rbPkexec->get_active()) { - str_variants_root = " pkexec --user " + cmbUser->get_active_text(); + str_variants_root = "pkexec --user " + cmbUser->get_active_text(); if (cbxExecuteEpriority->get_active()) { str_variants_root += " nice -n " + to_string(spinPriority->get_value_as_int()); } @@ -470,18 +471,19 @@ string MainWindow::start_cmd(string user_cmd) { else{ str_variants_root = "su "; } - str_variants_root += + " -c \" DISPLAY=$DISPLAY "; + str_variants_root += " -c \" DISPLAY=$DISPLAY "; if (cbxExecuteEpriority->get_active()) { str_variants_root += "nice -n " + to_string(spinPriority->get_value_as_int()) + " "; } } else if (rbSudo->get_active()) { chbTerminal->set_active(true); - if (getlogin()==cmbUser->get_active_text()) { - str_variants_root="sudo "; + //if (getlogin()==cmbUser->get_active_text()) { + if (user_exec_app==cmbUser->get_active_text()) { + str_variants_root = "sudo "; } else{ - str_variants_root="sudo -u " + cmbUser->get_active_text() + " "; + str_variants_root = "sudo -u " + cmbUser->get_active_text() + " "; } if (cbxExecuteEpriority->get_active()) { str_variants_root += " nice -n " + to_string(spinPriority->get_value_as_int()) + " "; @@ -562,6 +564,24 @@ void MainWindow::denamic_cmd() { } } +string MainWindow::call(string cmd) { + FILE *fp; + int status; + char path[PATH_MAX] = {0}; + fp = popen(cmd.c_str(), "r"); + if (fp == NULL) { + exit(1); + } + while (fgets(path, PATH_MAX, fp) != NULL) { + break; + } + status = pclose(fp); + if (status == -1) { + exit(1); + } + return path; +} + bool MainWindow::focus_out_txt_cmd(GdkEventFocus* event) { if (cmd_old != txtCmd->get_text()) { user_cmd = txtCmd->get_text(); @@ -645,6 +665,17 @@ void MainWindow::pars_dir_bin() { rbSudo->set_sensitive(flag_sudo); } +void MainWindow::is_user_wheel(){ + string response = this->call("id -Gn"); + if (response.find("wheel") == string::npos){ + rbSudo->set_sensitive(false); + } + size_t user_index = response.find(" "); + if (user_index!=string::npos){ + user_exec_app = response.substr(0, user_index); + } +} + void MainWindow::pars_users() { while (true) { errno = 0; diff --git a/source/ublexec.h b/source/ublexec.h index 8bd558c..9b2e3a9 100755 --- a/source/ublexec.h +++ b/source/ublexec.h @@ -86,10 +86,12 @@ public: void delete_cmd(const int &x,const int &y); void synopsis_show(); void denamic_cmd(); + void is_user_wheel(); bool focus_out_txt_cmd(GdkEventFocus* event); bool focus_in_txt_cmd(GdkEventFocus* event); void unselect_icon(Gtk::IconView *icon_entry); void str_remove(std::string& source, std::string & to_remove); + string call(string cmd); vector split(const std::string &s, char delim); public: class ModelColumns : public Gtk::TreeModel::ColumnRecord { @@ -194,6 +196,7 @@ public: public: string version_application = "1.0"; string cmd_old = ""; + string user_exec_app = ""; string user_cmd = ""; string user_cmd_old = ""; string name_app_old = "";