Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gnome-keyring-yubikey-unlock
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
gnome-keyring-yubikey-unlock
Commits
7638d61c
There was an error fetching the commit references. Please try again later.
Commit
7638d61c
authored
7 months ago
by
Recolic
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
2162cab1
No related branches found
No related tags found
1 merge request
!2
Add standalone implementation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/impl-standalone.hpp
+54
-0
54 additions, 0 deletions
src/impl-standalone.hpp
with
54 additions
and
0 deletions
src/impl-standalone.hpp
+
54
−
0
View file @
7638d61c
...
...
@@ -10,6 +10,14 @@
#include
<string>
#include
<rlib/macro.hpp>
#include
<iostream>
#include
<stdexcept>
#include
<filesystem>
#include
<cstdlib>
#include
<sys/stat.h>
#include
<sys/socket.h>
constexpr
auto
GNOME_KEYRING_RESULT_OK
=
0
;
...
...
@@ -20,3 +28,49 @@ inline GnomeKeyringResult do_unlock(std::string keyring, std::string password) {
inline
std
::
string
keyringResultToString
(
GnomeKeyringResult
res
)
{
}
namespace
utils
{
inline
auto
get_control_socket
()
{
namespace
fs
=
std
::
filesystem
;
// Helper function to check if a path is a socket
auto
is_socket
=
[](
const
fs
::
path
&
path
)
{
struct
stat
s
;
return
stat
(
path
.
c_str
(),
&
s
)
==
0
&&
S_ISSOCK
(
s
.
st_mode
);
};
if
(
const
char
*
gnome_keyring_control
=
std
::
getenv
(
"GNOME_KEYRING_CONTROL"
))
{
fs
::
path
control_socket
=
fs
::
path
(
gnome_keyring_control
)
/
"control"
;
if
(
fs
::
exists
(
control_socket
)
&&
is_socket
(
control_socket
))
{
return
control_socket
;
}
}
if
(
const
char
*
xdg_runtime_dir
=
std
::
getenv
(
"XDG_RUNTIME_DIR"
))
{
fs
::
path
control_socket
=
fs
::
path
(
xdg_runtime_dir
)
/
"keyring/control"
;
if
(
fs
::
exists
(
control_socket
)
&&
is_socket
(
control_socket
))
{
return
control_socket
;
}
}
throw
std
::
runtime_error
(
"Unable to find control socket"
);
}
inline
int
connect_unix_socket
(
std
::
string
path
)
{
// Create a UNIX socket
int
sock_fd
=
socket
(
AF_UNIX
,
SOCK_STREAM
,
0
);
if
(
sock_fd
==
-
1
)
{
throw
std
::
runtime_error
(
"Unable to create unix socket"
);
}
// Set up socket address
struct
sockaddr_un
addr
{};
addr
.
sun_family
=
AF_UNIX
;
std
::
strncpy
(
addr
.
sun_path
,
path
.
c_str
(),
sizeof
(
addr
.
sun_path
)
-
1
);
// Connect to the socket
if
(
connect
(
sock_fd
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
addr
),
sizeof
(
addr
))
==
-
1
)
{
close
(
sock_fd
);
throw
std
::
runtime_error
(
"Unable to connect to unix socket"
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment