Добавлена проверка группы wheel

pull/13/head
Igor Belitskiy 3 years ago
parent 0d28917d4f
commit 373089f949

@ -333,6 +333,7 @@ void MainWindow::settings() {
lblTime4EpriorityHigh->set_text("0 (Высокий)"); lblTime4EpriorityHigh->set_text("0 (Высокий)");
scalePriority->set_inverted(true); scalePriority->set_inverted(true);
this->pars_dir_bin(); this->pars_dir_bin();
this->is_user_wheel();
this->pars_users(); this->pars_users();
this->activ_or_block_execute_epriority(); this->activ_or_block_execute_epriority();
this->changed_user(); this->changed_user();
@ -470,14 +471,15 @@ string MainWindow::start_cmd(string user_cmd) {
else{ else{
str_variants_root = "su "; str_variants_root = "su ";
} }
str_variants_root += + " -c \" DISPLAY=$DISPLAY "; str_variants_root += " -c \" DISPLAY=$DISPLAY ";
if (cbxExecuteEpriority->get_active()) { if (cbxExecuteEpriority->get_active()) {
str_variants_root += "nice -n " + to_string(spinPriority->get_value_as_int()) + " "; str_variants_root += "nice -n " + to_string(spinPriority->get_value_as_int()) + " ";
} }
} }
else if (rbSudo->get_active()) { else if (rbSudo->get_active()) {
chbTerminal->set_active(true); chbTerminal->set_active(true);
if (getlogin()==cmbUser->get_active_text()) { //if (getlogin()==cmbUser->get_active_text()) {
if (user_exec_app==cmbUser->get_active_text()) {
str_variants_root = "sudo "; str_variants_root = "sudo ";
} }
else{ else{
@ -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) { bool MainWindow::focus_out_txt_cmd(GdkEventFocus* event) {
if (cmd_old != txtCmd->get_text()) { if (cmd_old != txtCmd->get_text()) {
user_cmd = txtCmd->get_text(); user_cmd = txtCmd->get_text();
@ -645,6 +665,17 @@ void MainWindow::pars_dir_bin() {
rbSudo->set_sensitive(flag_sudo); 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() { void MainWindow::pars_users() {
while (true) { while (true) {
errno = 0; errno = 0;

@ -86,10 +86,12 @@ public:
void delete_cmd(const int &x,const int &y); void delete_cmd(const int &x,const int &y);
void synopsis_show(); void synopsis_show();
void denamic_cmd(); void denamic_cmd();
void is_user_wheel();
bool focus_out_txt_cmd(GdkEventFocus* event); bool focus_out_txt_cmd(GdkEventFocus* event);
bool focus_in_txt_cmd(GdkEventFocus* event); bool focus_in_txt_cmd(GdkEventFocus* event);
void unselect_icon(Gtk::IconView *icon_entry); void unselect_icon(Gtk::IconView *icon_entry);
void str_remove(std::string& source, std::string & to_remove); void str_remove(std::string& source, std::string & to_remove);
string call(string cmd);
vector<std::string> split(const std::string &s, char delim); vector<std::string> split(const std::string &s, char delim);
public: public:
class ModelColumns : public Gtk::TreeModel::ColumnRecord { class ModelColumns : public Gtk::TreeModel::ColumnRecord {
@ -194,6 +196,7 @@ public:
public: public:
string version_application = "1.0"; string version_application = "1.0";
string cmd_old = ""; string cmd_old = "";
string user_exec_app = "";
string user_cmd = ""; string user_cmd = "";
string user_cmd_old = ""; string user_cmd_old = "";
string name_app_old = ""; string name_app_old = "";

Loading…
Cancel
Save