| 150 | } |
| 151 | |
| 152 | void NSHandler::parseNSSwitch() |
| 153 | { |
| 154 | USBGUARD_LOG(Info) << "Loading nsswitch from " << _nsswitch_path; |
| 155 | std::ifstream nss(_nsswitch_path); |
| 156 | |
| 157 | if (!nss.is_open()) { |
| 158 | USBGUARD_LOG(Info) << "Error when opening nsswitch file: " << _nsswitch_path << ": " << ErrnoException::reasonFromErrno(errno); |
| 159 | USBGUARD_LOG(Info) << "Using default value FILES"; |
| 160 | _source = SourceType::LOCAL; |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | _parser.parseStream(nss); |
| 165 | _parsedOptions = _parser.getMap(); |
| 166 | nss.close(); |
| 167 | USBGUARD_LOG(Debug) << "Map contains:"; |
| 168 | |
| 169 | for (auto x: _parsedOptions) { |
| 170 | USBGUARD_LOG(Debug) << "--> " << x.first << " -> " << x.second << " <--"; |
| 171 | } |
| 172 | |
| 173 | std::locale loc; |
| 174 | |
| 175 | for (unsigned i = 0 ; i < _parsedOptions["USBGUARD"].length() ; i++) { |
| 176 | _parsedOptions["USBGUARD"][i] = std::toupper(_parsedOptions["USBGUARD"][i], loc); |
| 177 | } |
| 178 | |
| 179 | USBGUARD_LOG(Info) << "Fetched value is -> " << _parsedOptions["USBGUARD"] << " <-"; |
| 180 | |
| 181 | if (_parsedOptions["USBGUARD"] == "FILES") { |
| 182 | _source = SourceType::LOCAL; |
| 183 | } |
| 184 | else if (_parsedOptions["USBGUARD"] == "LDAP") { |
| 185 | #ifdef HAVE_LDAP |
| 186 | _source = SourceType::LDAP; |
| 187 | #else |
| 188 | USBGUARD_LOG(Info) << "USBGuard has been compiled without LDAP support"; |
| 189 | USBGUARD_LOG(Info) << "Using default value FILES"; |
| 190 | _source = SourceType::LOCAL; |
| 191 | #endif |
| 192 | } |
| 193 | else { |
| 194 | USBGUARD_LOG(Info) << "Value is not valid or not set, using default FILES"; |
| 195 | _source = SourceType::LOCAL; |
| 196 | } |
| 197 | } |
| 198 | } /* namespace usbguard */ |
| 199 | |
| 200 | /* vim: set ts=2 sw=2 et */ |
no test coverage detected