std string ObjectStore mangleName std string const name static constex

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
std::string ObjectStore::mangleName(std::string const &name) {
static constexpr zstring_view qas_config = "/etc/opt/quest/vas/vas.conf";
bool found = false;
if (fs::exists(qas_config.data())) {
auto hash = static_cast<int64_t>(hashfile(qas_config));
if (hash == qas_file_hash) {
writeLog(Debug, "Using precatched hostname: %s", domain);
found = true; // using precached
} else {
auto hostnames = getAllHostnames();
std::ifstream fin(qas_config.data());
for (std::string line; !found && std::getline(fin, line);) {
for (auto &&hostname : hostnames) {
auto pos = line.find(hostname);
if (pos == std::string::npos) {
continue;
}
if (! ((pos == 0 || isspace(line[pos - 1])) &&
(pos + hostname.length() == line.length() ||
isspace(line[pos + hostname.length()]) ||
line[pos + hostname.length()] == '='))) {
continue;
}
auto pos_equal = line.find("=", pos + 1);
if (pos_equal == std::string::npos) {
continue;
}
auto l_domain = line.substr(pos_equal + 1);
trim(l_domain);
domain = l_domain;
qas_file_hash = hash;
found = true;
writeLog(Debug, "Found domain from qas for hostname %s: %s", hostname, domain);
break;
}
}
}
}
if (!found) {
domain = getMachineName() + "_{" + guid + "}";
writeLog(Debug, "Using machine name for out of domain machine: %s", domain);
}
auto account_name = name + "@" + domain;
std::transform(account_name.begin(), account_name.end(), account_name.begin(), [](unsigned char c){ return std::tolower(c); });
return account_name;
}