|
|
|
|
@ -103,67 +103,5 @@ std::vector<std::string> split(std::string text, char delim) {
|
|
|
|
|
vec.push_back(line);
|
|
|
|
|
}
|
|
|
|
|
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 <string> pars_users() {
|
|
|
|
|
vector <string> 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|