| Table | Column | Type | Value |
|---|---|---|---|
| bluetooth | state | int | 0 = off , 1 = on |
-| | desktop_connectivity | int | 0 = off , 1 = on |
+| | desktopConnectivity | int | 0 = off , 1 = on |
| | tethering | int | 0 = off , 1 = on |
| | pairing | int | 0 = off , 1 = on |
```sql
SELECT * FROM bluetooth
SELECT state FROM bluetooth
- SELECT desktop_connectivity FROM bluetooth
+ SELECT desktopConnectivity FROM bluetooth
SELECT pairing FROM bluetooth
SELECT tethering FROM bluetooth
```
## Set bluetooth policies
```sql
UPDATE bluetooth SET state = 1 # on
- UPDATE bluetooth SET desktop_connectivity = 0 # off
+ UPDATE bluetooth SET desktopConnectivity = 0 # off
UPDATE bluetooth SET pairing = 1 # on
UPDATE bluetooth SET tethering = 0 # off
UPDATE bluetooth SET state = 1, pairing = 0
int tethering;
DECLARE_COLUMN(State, "state", &Bluetooth::state);
- DECLARE_COLUMN(DesktopConnectivity, "desktop_connectivity", &Bluetooth::DesktopConnectivity);
+ DECLARE_COLUMN(DesktopConnectivity, "desktopConnectivity", &Bluetooth::DesktopConnectivity);
DECLARE_COLUMN(Pairing, "pairing", &Bluetooth::pairing);
DECLARE_COLUMN(Tethering, "tethering", &Bluetooth::tethering);
};
--- /dev/null
+table_name("bluetooth")
+description("The policies related bluetooth.")
+schema([
+ Column("bluetooth", INTEGER, "The policy value about bluetooth state"),
+ Column("bluetooth-desktop-connectivity", INTEGER, "The policy value about bt desktop connectivity"),
+ Column("bluetooth-pairing", INTEGER, "The policy value about bluetooth pairing"),
+ Column("bluetooth-tethering", INTEGER, "The policy value about bluetooth tethering"),
+])
+implementation("tizen/bluetooth@genBluetooth")
--- /dev/null
+/*
+ * Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include <string>
+#include <memory>
+#include <stdexcept>
+
+#include <osquery/sql.h>
+#include <osquery/tables.h>
+
+#include <vist/policy/api.hpp>
+#include <vist/exception.hpp>
+#include <vist/logger.hpp>
+
+namespace osquery {
+
+namespace {
+
+void getPolicy(Row& row, const std::string& name)
+{
+ int value = vist::policy::API::Get(name);
+ row[name] = std::to_string(value);
+}
+
+} // anonymous namespace
+
+namespace tables {
+
+using namespace vist;
+
+QueryData genBluetooth(QueryContext& context) try {
+ INFO(VIST) << "Select query about policy table.";
+
+ QueryData results;
+
+ Row row;
+ getPolicy(row, "bluetooth");
+ getPolicy(row, "bluetooth-desktop-connectivity");
+ getPolicy(row, "bluetooth-pairing");
+ getPolicy(row, "bluetooth-tethering");
+
+ results.emplace_back(std::move(row));
+
+ return results;
+} catch (const vist::Exception<ErrCode>& e) {
+ ERROR(VIST) << "Failed to query: " << e.what();
+ Row r;
+ return { r };
+} catch (...) {
+ ERROR(VIST) << "Failed to query with unknown exception.";
+ Row r;
+ return { r };
+}
+
+} // namespace tables
+} // namespace osquery
rmi::Remote remote(SOCK_ADDR);
auto query = REMOTE_METHOD(remote, &Vistd::query);
- return query.invoke<Rows>(statement);
+ auto rows = query.invoke<Rows>(statement);
+
+ DEBUG(VIST_CLIENT) << "Row's size: " << rows.size();
+ for (const auto& row : rows)
+ for (const auto& col : row)
+ DEBUG(VIST_CLIENT) << col.first << ", " << col.second;
+
+ return rows;
}
} // namespace vist
--- /dev/null
+/*
+ * Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#pragma once
+
+namespace vist {
+namespace schema {
+
+ struct Bluetooth {
+ int state;
+ int desktopConnectivity;
+ int pairing;
+ int tethering;
+
+ DECLARE_COLUMN(State, "state", &Bluetooth::state);
+ DECLARE_COLUMN(DesktopConnectivity, "desktopConnectivity", &Bluetooth::DesktopConnectivity);
+ DECLARE_COLUMN(Pairing, "pairing", &Bluetooth::pairing);
+ DECLARE_COLUMN(Tethering, "tethering", &Bluetooth::tethering);
+ };
+
+ DECLARE_TABLE(bluetoothTable, "bluetooth", Bluetooth::State,
+ Bluetooth::DesktopConnectivity,
+ Bluetooth::Pairing,
+ Bluetooth::Tethering);
+} // namesapce schema
+} // namesapce vist
if (!sql.ok())
THROW(ErrCode::RuntimeError) << "Faild to execute query: " << sql.getMessageString();
- return std::move(sql.rows());
+ return sql.rows();
}
} // namespace vist