Merge lp:~aptdaemon-developers/aptdaemon/fail-on-no-auth into lp:aptdaemon

Proposed by Sebastian Heinlein
Status: Needs review
Proposed branch: lp:~aptdaemon-developers/aptdaemon/fail-on-no-auth
Merge into: lp:aptdaemon
Diff against target: 119 lines (+48/-11)
3 files modified
aptdaemon/core.py (+30/-10)
aptdaemon/enums.py (+14/-1)
aptdaemon/pkcompat.py (+4/-0)
To merge this branch: bzr merge lp:~aptdaemon-developers/aptdaemon/fail-on-no-auth
Reviewer Review Type Date Requested Status
Aptdaemon Developers Pending
Review via email: mp+99882@code.launchpad.net

Description of the change

This introduces a string change (new error messages)

To post a comment you must log in.

Unmerged revisions

787. By Sebastian Heinlein

core: if the run call fails also let the transaction fail (fixes LP #892215)

If the authorization fails the transaction will now also fail. This helps clients which dont catch errors in the run method. Furthermore all connected transaction will also fail.

786. By Sebastian Heinlein

enums: Add new transaction error enums to handle a not authorized user and a failed authorization process

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'aptdaemon/core.py'
2--- aptdaemon/core.py 2012-03-14 07:53:38 +0000
3+++ aptdaemon/core.py 2012-03-29 06:58:18 +0000
4@@ -47,6 +47,7 @@
5 import signal
6 import sys
7 import time
8+import traceback
9 import uuid
10
11 from gi.repository import GObject
12@@ -890,16 +891,35 @@
13
14 @inline_callbacks
15 def _run(self, sender):
16- yield self._check_foreign_user(sender)
17- yield self._check_auth()
18- yield self.queue.put(self.tid)
19- self.status = enums.STATUS_WAITING
20- next_trans = self.after
21- while next_trans:
22- yield next_trans._check_auth()
23- yield self.queue.put(next_trans.tid)
24- next_trans.status = enums.STATUS_WAITING
25- next_trans = next_trans.after
26+ trans = self
27+ while trans:
28+ try:
29+ yield self._check_foreign_user(sender)
30+ yield self._check_auth()
31+ yield self.queue.put(self.tid)
32+ except errors.AuthorizationFailed as excep:
33+ error = errors.TransactionFailed(enums.ERROR_AUTH_FAILED,
34+ str(excep))
35+ except errors.NotAuthorizedError as excep:
36+ error = errors.TransactionFailed(enums.ERROR_NOT_AUTHORIZED,
37+ str(excep))
38+ except Exception as excep:
39+ tbk = traceback.format_exc(excep)
40+ error = errors.TransactionFailed(enums.ERROR_UNKNOWN, tbk)
41+ else:
42+ self.status = enums.STATUS_WAITING
43+ trans = self.after
44+ continue
45+ trans.error = error
46+ trans.exit = enums.EXIT_FAILED
47+ # Also let all connected transactions fail
48+ next = self.after
49+ while next:
50+ next.error = error
51+ next.exit = enums.EXIT_FAILED
52+ next = next_trans.after
53+ # Need to re-raise the error
54+ raise error
55
56 @inline_callbacks
57 def _check_auth(self):
58
59=== modified file 'aptdaemon/enums.py'
60--- aptdaemon/enums.py 2011-12-13 21:32:43 +0000
61+++ aptdaemon/enums.py 2012-03-29 06:58:18 +0000
62@@ -38,7 +38,7 @@
63 "ERROR_SYSTEM_ALREADY_UPTODATE", "ERROR_NOT_SUPPORTED",
64 "ERROR_LICENSE_KEY_INSTALL_FAILED",
65 "ERROR_LICENSE_KEY_DOWNLOAD_FAILED",
66- "ERROR_UNKNOWN",
67+ "ERROR_NOT_AUTHORIZED", "ERROR_AUTH_FAILED", "ERROR_UNKNOWN",
68 "STATUS_SETTING_UP", "STATUS_WAITING", "STATUS_WAITING_MEDIUM",
69 "STATUS_WAITING_CONFIG_FILE_PROMPT", "STATUS_WAITING_LOCK",
70 "STATUS_RUNNING", "STATUS_LOADING_CACHE", "STATUS_DOWNLOADING",
71@@ -156,6 +156,11 @@
72 ERROR_LICENSE_KEY_INSTALL_FAILED = "error-license-key-install-failed"
73 #: The system is already up-to-date and don't needs any upgrades
74 ERROR_SYSTEM_ALREADY_UPTODATE = "error-system-already-uptodate"
75+#: The user could not authenticate to run the transaction
76+ERROR_NOT_AUTHORIZED = "error-not-authorized"
77+#: The authorization system is broken (e.g. there isn't any session policykit
78+#: agent running)
79+ERROR_AUTH_FAILED = "error-auth-failed"
80 #: An unknown error occured. In most cases these are programming ones.
81 ERROR_UNKNOWN = "error-unknown"
82
83@@ -547,6 +552,12 @@
84 "use this piece of software could not be "
85 "downloaded. Please check your "
86 "network connection."),
87+ ERROR_NOT_AUTHORIZED: _("Please check that you have entered the correct "
88+ "password and that you are allowed to perform "
89+ "this action. Contact your system administrator."),
90+ ERROR_AUTH_FAILED: _("The authorization system (PolicyKit) seems to be "
91+ "not correctly installed. Please make sure that a "
92+ "session agent is running."),
93 }
94
95 def get_error_description_from_enum(enum):
96@@ -586,6 +597,8 @@
97 ERROR_LICENSE_KEY_DOWNLOAD_FAILED: _("Failed to download the license key"),
98 ERROR_LICENSE_KEY_INSTALL_FAILED: _("Failed to install the license key"),
99 ERROR_SYSTEM_ALREADY_UPTODATE: _("The system is already up to date"),
100+ ERROR_NOT_AUTHORIZED: _("You are not allowed to perform this action"),
101+ ERROR_AUTH_FAILED: _("Failed to authorize you"),
102 ERROR_UNKNOWN : _("An unhandlable error occured")
103 }
104
105
106=== modified file 'aptdaemon/pkcompat.py'
107--- aptdaemon/pkcompat.py 2012-03-13 18:35:32 +0000
108+++ aptdaemon/pkcompat.py 2012-03-29 06:58:18 +0000
109@@ -203,6 +203,10 @@
110 pk_enums.ERROR_INVALID_PACKAGE_FILE,
111 aptd_enums.ERROR_SYSTEM_ALREADY_UPTODATE:
112 pk_enums.ERROR_NO_PACKAGES_TO_UPDATE,
113+ aptd_enums.ERROR_AUTH_FAILED:
114+ pk_enums.ERROR_NOT_AUTHORIZED,
115+ aptd_enums.ERROR_NOT_AUTHORIZED:
116+ pk_enums.ERROR_NOT_AUTHORIZED,
117 }
118
119 MAP_PACKAGE_ENUM = {

Subscribers

People subscribed via source and target branches

to status/vote changes: