Skip to content

Commit

Permalink
Merge pull request #13 from halcyonseeker/fixes_for_freebsd
Browse files Browse the repository at this point in the history
Fixes for FreBSD
  • Loading branch information
nullobsi authored Oct 19, 2023
2 parents 7220576 + efff7c5 commit 9bf333c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.15)

if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set (CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install to /usr" FORCE)
set (CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install to /usr/local" FORCE)
endif()

option(INSTALL_DBUS_SERVICE "Overwrite the gnome-keyring org.freedesktop.secrets.service file." ON)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cmake ..
make
```

You can then install with `sudo make install`. This will by default install a systemd user service that can be dbus-activated when enabled.
You can then install with `sudo make install` and uninstall with `sudo xargs < rm install_manifest.txt`. This will by default install a systemd user service that can be dbus-activated when enabled.

```
sudo make install
Expand All @@ -28,3 +28,14 @@ Alternatively, you can run it in the background in your bashrc/xinitrc.
/usr/local/bin/pass-secrets &
...
```

If you're running pass-secrets on a BSD, or possibly a non-systemd Linux system, you'll need to start a DBus session bus before starting pass-secrets. For instance, your ~/.bash_profile could contain:

```
if ! pgrep -qf -U ${USER:-$(id -u)} dbus.\*--session; then
dbus-daemon --session --fork --address=unix:runtime=yes 2>/dev/null
export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
fi
```

See [this issue](https://github.com/nullobsi/pass-secrets/issues/11) for more details.
21 changes: 15 additions & 6 deletions interop/PassStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,22 @@ PassStore::PassStore() {
pathEntries.push_back(token);
}
for (const auto &dirName : pathEntries) {
fs::directory_iterator i(dirName);
for (const auto &file : i) {
if (file.is_regular_file() && file.path().filename() == "pass") {
std::cout << "Found pass at " + file.path().string() << std::endl;
passLocation = file.path().string();
goto finish;
// Handle any potential errors in filesystem access.
try {
fs::directory_iterator i(dirName);
for (const auto &file : i) {
if (file.is_regular_file() && file.path().filename() == "pass") {
std::cout << "Found pass at " + file.path().string() << std::endl;
passLocation = file.path().string();
goto finish;
}
}
} catch (std::exception &error) {
cerr << "Error found while accessing " << dirName << " in path:" << endl;
// std::filesystem_error should include details in
// what()...
cerr << error.what() << endl;
continue;
}
}
throw std::runtime_error("Pass not found in path!");
Expand Down
27 changes: 17 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@
int
main() {

auto conn = sdbus::createSessionBusConnection();
std::unique_ptr<sdbus::IConnection> conn;
try {
conn = sdbus::createSessionBusConnection();
} catch (std::runtime_error &e) {
std::cerr << "There was an error creating DBus connection." << std::endl;
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
conn->requestName("org.freedesktop.secrets");

std::shared_ptr<SecretService> service;
try {
service = std::make_shared<SecretService>(*conn, "/org/freedesktop/secrets");
} catch(sdbus::Error &e) {
std::cerr << "There was an error registering to DBus." << std::endl;
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
std::shared_ptr<SecretService> service;
try {
service = std::make_shared<SecretService>(*conn, "/org/freedesktop/secrets");
} catch(sdbus::Error &e) {
std::cerr << "There was an error registering to DBus." << std::endl;
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}

service->InitCollections();
while (true) {
Expand All @@ -39,4 +46,4 @@ main() {
return 0;
}
}
}
}

0 comments on commit 9bf333c

Please sign in to comment.