* openvpn3 session-auth command * * This command is used to list on-going VPN sessions requiring user * interaction for further authentication * */
| 120 | * |
| 121 | */ |
| 122 | static int cmd_session_auth(ParsedArgs::Ptr args) |
| 123 | { |
| 124 | |
| 125 | if (args->Present("auth-req")) |
| 126 | { |
| 127 | auto reqid = static_cast<pid_t>(std::atoi(args->GetLastValue("auth-req").c_str())); |
| 128 | return cmd_session_auth_complete(reqid); |
| 129 | } |
| 130 | |
| 131 | // |
| 132 | // List all running sessions requiring user authentication interaction |
| 133 | // |
| 134 | auto dbuscon = DBus::Connection::Create(DBus::BusType::SYSTEM); |
| 135 | auto smprx = SessionManager::Proxy::Manager::Create(dbuscon); |
| 136 | |
| 137 | // Retrieve a list of all sessions requiring user interaction |
| 138 | SessionManager::Proxy::Session::List session_list = {}; |
| 139 | for (const auto &sess : smprx->FetchAvailableSessions()) |
| 140 | { |
| 141 | Events::Status s = sess->GetLastStatus(); |
| 142 | if (s.Check(StatusMajor::CONNECTION, StatusMinor::CFG_REQUIRE_USER) |
| 143 | || s.Check(StatusMajor::SESSION, StatusMinor::SESS_AUTH_URL)) |
| 144 | { |
| 145 | session_list.push_back(sess); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | if (session_list.size() < 1) |
| 150 | { |
| 151 | std::cout << "No sessions requires authentication interaction" << std::endl; |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | // List all sessions found |
| 156 | std::cout << "-----------------------------------------------------------------------------" << std::endl; |
| 157 | bool first = true; |
| 158 | for (const auto &sess : session_list) |
| 159 | { |
| 160 | if (!first) |
| 161 | { |
| 162 | std::cout << std::endl; |
| 163 | } |
| 164 | first = false; |
| 165 | |
| 166 | // Retrieve the session start timestamp |
| 167 | std::string created{}; |
| 168 | try |
| 169 | { |
| 170 | created = sess->GetSessionCreated(); |
| 171 | } |
| 172 | catch (const DBus::Exception &) |
| 173 | { |
| 174 | created = "(Not available)"; |
| 175 | } |
| 176 | |
| 177 | std::cout << " Path: " << sess->GetPath() << std::endl; |
| 178 | std::cout << "Auth Request: " |
| 179 | << std::to_string(sess->GetBackendPid()) << std::endl; |
nothing calls this directly
no test coverage detected