Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Commit

Permalink
Merge branch '0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
leonnnn committed Aug 25, 2013
2 parents 9f8fef7 + 5d4fed0 commit dce8dd0
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release 0.1:
• [#8] Security: Fixed a typo that could in some circumstances lead to a
crash after multiple failed authentication attempts. Thanks,
Paul Lhussiez.
56 changes: 44 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ mechanism, hence it also works on Fedora. Also, it's mostly written using
interaction is still necessary. As soon as XCB can provide the required
services of Xlib, the remaining code will be ported to XCB.

Usage
-----
Since pyxtrlock uses PAM authentication, it can be run as the normal user and
doesn't need special privileges.

Description
-----------
pyxtrlock, like its predecessor, is a very minimal X display lock program. While
pyxtrlock is running, it doesn't obscure the screen, only the mouse and keyboard
are grabbed and the mouse cursor becomes a padlock. Output displayed by X
Expand All @@ -26,27 +29,56 @@ pressing Escape or Clear clears anything that has been entered.
Like xtrlock, pyxtrlock will ignore further keystrokes until a timeout has
expired after too many attempts have been made in too short time.

Installation
------------
pyxtrlock requires [python3-pam](https://github.com/leonnnn/python3-pam). Make
sure to install this package before installing pyxtrlock.
Installation and Usage
----------------------
Install [python3-simplepam](https://github.com/leonnnn/python3-simplepam) for
dependencies:

$ git clone git://github.com/leonnnn/python3-simplepam.git
$ cd python3-simplepam
$ sudo python3 setup.py install

Clone and install pyxtrlock:

$ git clone git://github.com/leonnnn/pyxtrlock.git
$ cd pyxtrlock
$ sudo python3 setup.py install

After that, [download pyxtrlock from github](https://github.com/leonnnn/pyxtrlock),
and run ``python3 setup.py install`` as root. Once this is done, you should be
able to simply lock your display by running
Once this is done, you should be able to simply lock your display by running

$ pyxtrlock
$ pyxtrlock

If you would like to automatically lock your screen after some idle time,
we recommend the ``xautolock`` tool. Just add something like

xautolock -locker pyxtrlock -time 5

to your X autostart file to lock the screen with ``pyxtrlock`` after
5 minutes idle time. ``xautolock`` has many other useful features, see
its documentation. Most distributions provide an ``xautolock`` package
with a man page.

Bugs
----
Additional input devices other than the keyboard and mouse are not disabled.

Although this is not a bug, please note that pyxtrlock does not prevent a
user from switching to a virtual terminal, so be advised to always leave your
terminals locked.

Please report any new bugs you may find to our [Github issue tracker](https://github.com/leonnnn/pyxtrlock/issues).

Requirements
------------
* [python3-pam](https://github.com/leonnnn/python3-pam)
* Python >= 3.0
* [python3-simplepam](https://github.com/leonnnn/python3-simplepam)
* Python ≥ 3.0
* libxcb
* libX11 ≥ 1.4, or libX11 ≥ 1.2 compiled with XCB backend

These requirements are met at least on
* Debian wheezy and sid, and probably on Debian squeeze (untested; please report your experience)
* Ubuntu ≥ 11.10, and probably 10.04 (untested; please report your experience)
* Fedora ≥ 16

Authors
-------
Expand Down
5 changes: 3 additions & 2 deletions lib/X.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import pyxtrlock.xcb as xcb

libx = cdll.LoadLibrary(find_library('X11-xcb'))
libx_xcb = cdll.LoadLibrary(find_library('X11-xcb'))
libx = cdll.LoadLibrary(find_library('X11'))


class Display(Structure):
Expand Down Expand Up @@ -51,7 +52,7 @@ class KeyEvent(Structure):
close_window.argtypes = [POINTER(Display)]
close_window.restype = c_int

get_xcb_connection = libx.XGetXCBConnection
get_xcb_connection = libx_xcb.XGetXCBConnection
get_xcb_connection.argtypes = [POINTER(Display)]
get_xcb_connection.restype = POINTER(xcb.Connection)

Expand Down
19 changes: 12 additions & 7 deletions pyxtrlock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getpass
from ctypes import byref, cast, sizeof
from ctypes import POINTER, c_int, c_uint32, c_char

import pam
import simplepam as pam

import pyxtrlock.xcb as xcb
import pyxtrlock.X as X
Expand Down Expand Up @@ -54,6 +54,13 @@ mask_bits = bytes([
0xff, 0xff, 0xff, 0x0f
])

if getpass.getuser() == 'root' and sys.argv[1:] != ['-f']:
msg = (
"pyxtrlock: refusing to run as root. Use -f to force. Warning: You "
"might not be able to unlock."
)
print(msg, file=sys.stderr)
sys.exit(1)

display = X.create_window(None)
conn = X.get_xcb_connection(display)
Expand All @@ -79,7 +86,7 @@ window = xcb.generate_id(conn)

attribs = (c_uint32 * 2)(1, xcb.EVENT_MASK_KEY_PRESS)
ret = xcb.create_window(conn, xcb.COPY_FROM_PARENT, window, screen.root,
0, 0, 100, 100, 0, xcb.WINDOW_CLASS_INPUT_ONLY,
0, 0, 1, 1, 0, xcb.WINDOW_CLASS_INPUT_ONLY,
xcb.VisualID(xcb.COPY_FROM_PARENT),
xcb.CW_OVERRIDE_REDIRECT | xcb.CW_EVENT_MASK,
cast(byref(attribs), POINTER(c_uint32)))
Expand Down Expand Up @@ -196,10 +203,8 @@ while True:
if status.value == X.BUFFER_OVERFLOW:
buf = bytearray(length)
buf_p = cast((c_char * length).from_buffer(buf), POINTER(c_char))
length = X.utf8_lookup_string(ic, byref(x_key_press_event),
buf_p,
length,
byref(keysym), byref(status))
length = X.utf8_lookup_string(ic, byref(x_key_press_event), buf_p,
length, byref(keysym), byref(status))

status = status.value
keysym = keysym.value
Expand All @@ -219,7 +224,7 @@ while True:
if timeout:
goodwill += time_stamp - timeout
if goodwill > MAXGOODWILL:
goodwill = MAXGODWILL
goodwill = MAXGOODWILL
timeout = -int(goodwill * GOODWILLPORTION)
goodwill += timeout
timeout += time_stamp + TIMEOUTPERATTEMPT
Expand Down
21 changes: 18 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
'The X transparent screen lock rewritten in Python, using XCB and PAM.'
)

long_desc = """
pyxtrlock -- The leightweight screen locker rewritten in Python
---------------------------------------------------------------
pyxtrlock is a very limited transparent X screen locker inspired by Ian
Jackson’s great xtrlock program. pyxtrlock uses modern libraries, most
importantly the obsolete direct passwd/shadow authentication has been replaced
by today’s PAM authentication mechanism, hence it also works on Fedora. Also,
it’s mostly written using XCB instead of Xlib.
"""


classifiers = [
'Development Status :: 3',
'Environment :: X11 Applications',
Expand All @@ -20,14 +33,16 @@
]

setup(name='pyxtrlock',
version='0.1beta',
version='0.1',
author=authors,
author_email='[email protected]',
requires=['pam'],
requires=['simplepam'],
package_dir={'pyxtrlock': 'lib'},
packages=['pyxtrlock'],
scripts=['pyxtrlock'],
license='GPLv3+',
url='https://github.com/leonnnn/pyxtrlock',
url='https://zombofant.net/hacking/pyxtrlock',
description=desc,
long_description=long_desc,
classifiers=classifiers
)

0 comments on commit dce8dd0

Please sign in to comment.