This repository has been archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,48 @@ | ||
|
||
import os | ||
import socket | ||
import sys | ||
|
||
from xdg.BaseDirectory import get_runtime_dir | ||
|
||
|
||
def panic(*message_parts, exit_code=1): | ||
"""Print an error message to stderr and exit""" | ||
print("pyxtrlock:", *message_parts, file=sys.stderr) | ||
sys.exit(exit_code) | ||
|
||
|
||
def require_x11_session(): | ||
""" | ||
Detect whether we're running in a Wayland session and abort if so. | ||
""" | ||
|
||
if os.environ.get("XDG_SESSION_TYPE") == "x11": | ||
return | ||
|
||
if os.environ.get("WAYLAND_DISPLAY"): | ||
panic( | ||
"WAYLAND_DISPLAY is set, suspecting Wayland session. " | ||
"Using pyxtrlock in a Wayland session is insecure. Aborting." | ||
) | ||
|
||
if os.environ.get("WAYLAND_SOCKET"): | ||
panic( | ||
"WAYLAND_SOCKET is set, suspecting Wayland session. " | ||
"Using pyxtrlock in a Wayland session is insecure. Aborting." | ||
) | ||
|
||
xdg_runtime_dir = get_runtime_dir(strict=True) | ||
wayland_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) | ||
|
||
try: | ||
wayland_socket.connect(os.path.join(xdg_runtime_dir, "wayland-0")) | ||
except OSError: | ||
return | ||
else: | ||
panic( | ||
"Successfully connected to Wayland socket, suspecting Wayland session. " | ||
"Using pyxtrlock in a Wayland session is insecure. Aborting." | ||
) | ||
finally: | ||
wayland_socket.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,14 +33,14 @@ | |
] | ||
|
||
setup(name='pyxtrlock', | ||
version='0.3', | ||
version='0.4', | ||
author=authors, | ||
author_email='[email protected]', | ||
requires=['simplepam', 'pyxdg'], | ||
packages=['pyxtrlock'], | ||
scripts=['bin/pyxtrlock'], | ||
license='GPLv3+', | ||
url='https://zombofant.net/hacking/pyxtrlock', | ||
url='https://github.com/leonnnn/pyxtrlock', | ||
description=desc, | ||
long_description=long_desc, | ||
classifiers=classifiers | ||
|