#include <string>
#include <climits>
-#include <klay/exception.h>
#include <klay/exception.h>
}
DeviceAdministratorManager::DeviceAdministratorManager(const std::string& path) :
- repository(path + "/.client.db")
+ repository(path + "/.dpm.db")
{
prepareRepository();
}
{
database::Connection connection(repository, database::Connection::ReadWrite);
- std::string selectQuery = "SELECT * FROM CLIENT WHERE PKG = ? AND UID = ?";
+ std::string selectQuery = "SELECT * FROM ADMIN WHERE PKG = ? AND UID = ?";
database::Statement stmt0(connection, selectQuery);
stmt0.bind(1, name);
stmt0.bind(2, static_cast<int>(uid));
std::string key = generateKey();
- std::string insertQuery = "INSERT INTO CLIENT (PKG, UID, KEY, VALID) VALUES (?, ?, ?, ?)";
+ std::string insertQuery = "INSERT INTO ADMIN (PKG, UID, KEY, REMOVABLE) VALUES (?, ?, ?, ?)";
database::Statement stmt(connection, insertQuery);
stmt.bind(1, name);
stmt.bind(2, static_cast<int>(uid));
{
database::Connection connection(repository, database::Connection::ReadWrite);
- std::string query = "DELETE FROM CLIENT WHERE PKG = ? AND UID = ?";
+ std::string query = "DELETE FROM ADMIN WHERE PKG = ? AND UID = ?";
database::Statement stmt(connection, query);
stmt.bind(1, name);
stmt.bind(2, static_cast<int>(uid));
database::Connection connection(repository, database::Connection::ReadWrite |
database::Connection::Create);
- std::string query = "CREATE TABLE IF NOT EXISTS CLIENT (" \
+ std::string query = "CREATE TABLE IF NOT EXISTS ADMIN (" \
"ID INTEGER PRIMARY KEY AUTOINCREMENT, " \
"PKG TEXT, " \
"UID INTEGER, " \
"KEY TEXT, " \
- "VALID INTEGER)";
+ "REMOVABLE INTEGER)";
connection.exec(query);
- database::Statement stmt(connection, "SELECT * FROM CLIENT");
+ database::Statement stmt(connection, "SELECT * FROM ADMIN");
while (stmt.step()) {
std::string name = stmt.getColumn(1).getText();
uid_t uid = static_cast<uid_t>(stmt.getColumn(2).getInt());
* limitations under the License
*/
-#include <fcntl.h>
-#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <functional>
char pkgid[PATH_MAX];
if (aul_app_get_pkgid_bypid_for_uid(pid, pkgid, PATH_MAX, uid) != 0) {
- throw runtime::Exception("Unknown PID");
+ int fd = ::open(std::string("/proc/" + std::to_string(pid) + "/cmdline").c_str(), O_RDONLY);
+ if (fd == -1) {
+ throw runtime::Exception("Unknown PID");
+ }
+
+ ssize_t ret, bytes = 0;
+ do {
+ ret = ::read(fd, &pkgid[bytes], PATH_MAX);
+ if (ret != -1) {
+ bytes += ret;
+ }
+ } while ((ret == -1) && (errno == EINTR));
+
+ if (ret == -1) {
+ throw runtime::Exception("Failed to get admin info");
+ }
+
+ pkgid[bytes] = '\0';
}
return pkgid;