diff --git a/source/util.cc b/source/util.cc index cb05f5b..dcbdc95 100644 --- a/source/util.cc +++ b/source/util.cc @@ -122,87 +122,6 @@ std::vector split(std::string text, char delim) { } return vec; } -unsigned short read_uid_min_max(string filename, string search) { - std::string line; - int uid = 0; - string remove_tab = "\t"; - string remove_space = " "; - std::ifstream in(filename); // окрываем файл для чтения - if (in.is_open()){ - while (getline(in, line)){ - try{ - if (line.find(search) != string::npos && (line.find("SYS_"+search) == string::npos)) { - str_remove(line, search); - str_remove(line, remove_space); - str_remove(line, remove_tab); - uid = atoi(line.c_str()); - } - } - catch (int x) { - if (search == "UID_MIN"){ - uid = 1000; - } - else{ - uid = 65534; - } - - } - - } - } - else{ - if (search == "UID_MIN") { - uid = 1000; - } - else{ - uid = 65534; - } - } - in.close(); - return uid; - -} - -vector pars_users() { - vector vec_users; - unsigned short uid_min = read_uid_min_max("/etc/login.defs", "UID_MIN"); - unsigned short uid_max =read_uid_min_max("/etc/login.defs", "UID_MAX"); - while (true) { - errno = 0; - passwd* entry = getpwent(); - if (!entry) { - if (errno) { - break; - } - break; - } - if ((entry->pw_uid >= uid_min && entry->pw_uid < uid_max) || entry->pw_uid == 0) { - vec_users.push_back(string(entry->pw_name)); - } - } - endpwent(); - return vec_users; -} - -string read_passwd(string username) { - string passwd = ""; - std::string line; - std::ifstream in("/etc/shadow"); - if (in.is_open()) { - while (getline(in, line)) { - if (line.find(username) != string::npos) { - size_t index_start = line.find(":"); - if (index_start != string::npos) { - size_t index_end = line.find(":", index_start + 1); - passwd = line.substr(index_start+1, index_end - index_start-1); - break; - } - } - } - } - in.close(); - return passwd; -} int synopsis_show(string str_link) { // gettext("https://wiki.ublinux.com/ru/Программное_обеспечение/Программы_и_утилиты/Все/") diff --git a/source/util.h b/source/util.h index d857b72..90aebad 100644 --- a/source/util.h +++ b/source/util.h @@ -23,9 +23,7 @@ vector find_all(string &str_ntp, string substr); void str_remove(std::string& source, std::string to_remove); void str_replace_all(string &str_base, string str_find, string str_replace); std::vector split(std::string text, char delim); -unsigned short read_uid_min_max(string filename, string search); vector pars_users(); -string read_passwd(string username); int synopsis_show(string str_link); string file_read(string filename); }