Merge lp:~azzar1/unity/fix-missing-entry-lockscreen into lp:unity
- fix-missing-entry-lockscreen
- Merge into trunk
Proposed by
Andrea Azzarone
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4257 |
Proposed branch: | lp:~azzar1/unity/fix-missing-entry-lockscreen |
Merge into: | lp:unity |
Diff against target: |
558 lines (+144/-86) 12 files modified
lockscreen/KylinUserPromptView.cpp (+15/-15) lockscreen/KylinUserPromptView.h (+2/-3) lockscreen/LockScreenAbstractPromptView.h (+5/-3) lockscreen/LockScreenController.cpp (+3/-1) lockscreen/LockScreenController.h (+2/-0) lockscreen/LockScreenPromptFactory.cpp (+4/-3) lockscreen/LockScreenPromptFactory.h (+3/-1) lockscreen/UserAuthenticator.h (+2/-0) lockscreen/UserAuthenticatorPam.cpp (+41/-33) lockscreen/UserAuthenticatorPam.h (+9/-8) lockscreen/UserPromptView.cpp (+51/-15) lockscreen/UserPromptView.h (+7/-4) |
To merge this branch: | bzr merge lp:~azzar1/unity/fix-missing-entry-lockscreen |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
Review via email:
|
Commit message
Refactor the way UserAuthenticator is created and passed around. Handle failures to create new threads and fallback to a "Switch to greeter..." button in case of failure.
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Marco Trevisan (Treviño) (3v1n0) : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lockscreen/KylinUserPromptView.cpp' | |||
2 | --- lockscreen/KylinUserPromptView.cpp 2016-03-31 05:57:11 +0000 | |||
3 | +++ lockscreen/KylinUserPromptView.cpp 2017-09-15 13:37:27 +0000 | |||
4 | @@ -79,9 +79,9 @@ | |||
5 | 79 | 79 | ||
6 | 80 | } | 80 | } |
7 | 81 | 81 | ||
11 | 82 | KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_manager) | 82 | KylinUserPromptView::KylinUserPromptView(session::Manager::Ptr const& session_manager, |
12 | 83 | : AbstractUserPromptView(session_manager) | 83 | UserAuthenticator::Ptr const& user_authenticator) |
13 | 84 | , session_manager_(session_manager) | 84 | : AbstractUserPromptView(session_manager, user_authenticator) |
14 | 85 | , username_(nullptr) | 85 | , username_(nullptr) |
15 | 86 | , msg_layout_(nullptr) | 86 | , msg_layout_(nullptr) |
16 | 87 | , prompt_layout_(nullptr) | 87 | , prompt_layout_(nullptr) |
17 | @@ -90,25 +90,25 @@ | |||
18 | 90 | , avatar_(nullptr) | 90 | , avatar_(nullptr) |
19 | 91 | , avatar_icon_file("") | 91 | , avatar_icon_file("") |
20 | 92 | { | 92 | { |
22 | 93 | user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ | 93 | user_authenticator_->echo_on_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){ |
23 | 94 | AddPrompt(message, true, promise); | 94 | AddPrompt(message, true, promise); |
25 | 95 | }); | 95 | }, *this)); |
26 | 96 | 96 | ||
28 | 97 | user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ | 97 | user_authenticator_->echo_off_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){ |
29 | 98 | AddPrompt(message, false, promise); | 98 | AddPrompt(message, false, promise); |
31 | 99 | }); | 99 | }, *this)); |
32 | 100 | 100 | ||
34 | 101 | user_authenticator_.message_requested.connect([this](std::string const& message){ | 101 | user_authenticator_->message_requested.connect(sigc::track_obj([this](std::string const& message){ |
35 | 102 | AddMessage(message, nux::color::White); | 102 | AddMessage(message, nux::color::White); |
37 | 103 | }); | 103 | }, *this)); |
38 | 104 | 104 | ||
40 | 105 | user_authenticator_.error_requested.connect([this](std::string const& message){ | 105 | user_authenticator_->error_requested.connect(sigc::track_obj([this](std::string const& message){ |
41 | 106 | AddMessage(message, nux::color::Red); | 106 | AddMessage(message, nux::color::Red); |
43 | 107 | }); | 107 | }, *this)); |
44 | 108 | 108 | ||
46 | 109 | user_authenticator_.clear_prompts.connect([this](){ | 109 | user_authenticator_->clear_prompts.connect(sigc::track_obj([this](){ |
47 | 110 | ResetLayout(); | 110 | ResetLayout(); |
49 | 111 | }); | 111 | }, *this)); |
50 | 112 | 112 | ||
51 | 113 | scale.changed.connect(sigc::hide(sigc::mem_fun(this, &KylinUserPromptView::UpdateSize))); | 113 | scale.changed.connect(sigc::hide(sigc::mem_fun(this, &KylinUserPromptView::UpdateSize))); |
52 | 114 | 114 | ||
53 | @@ -121,7 +121,7 @@ | |||
54 | 121 | ResetLayout(); | 121 | ResetLayout(); |
55 | 122 | 122 | ||
56 | 123 | TextureCache::GetDefault().themed_invalidated.connect(sigc::mem_fun(this, &KylinUserPromptView::ResetLayout)); | 123 | TextureCache::GetDefault().themed_invalidated.connect(sigc::mem_fun(this, &KylinUserPromptView::ResetLayout)); |
58 | 124 | user_authenticator_.AuthenticateStart(session_manager_->UserName(), | 124 | user_authenticator_->AuthenticateStart(session_manager_->UserName(), |
59 | 125 | sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb)); | 125 | sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb)); |
60 | 126 | } | 126 | } |
61 | 127 | 127 | ||
62 | @@ -244,7 +244,7 @@ | |||
63 | 244 | { | 244 | { |
64 | 245 | AddMessage(_("Invalid password, please try again"), nux::color::Red); | 245 | AddMessage(_("Invalid password, please try again"), nux::color::Red); |
65 | 246 | 246 | ||
67 | 247 | user_authenticator_.AuthenticateStart(session_manager_->UserName(), | 247 | user_authenticator_->AuthenticateStart(session_manager_->UserName(), |
68 | 248 | sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb)); | 248 | sigc::mem_fun(this, &KylinUserPromptView::AuthenticationCb)); |
69 | 249 | } | 249 | } |
70 | 250 | } | 250 | } |
71 | 251 | 251 | ||
72 | === modified file 'lockscreen/KylinUserPromptView.h' | |||
73 | --- lockscreen/KylinUserPromptView.h 2016-03-16 10:47:16 +0000 | |||
74 | +++ lockscreen/KylinUserPromptView.h 2017-09-15 13:37:27 +0000 | |||
75 | @@ -44,7 +44,8 @@ | |||
76 | 44 | class KylinUserPromptView : public AbstractUserPromptView | 44 | class KylinUserPromptView : public AbstractUserPromptView |
77 | 45 | { | 45 | { |
78 | 46 | public: | 46 | public: |
80 | 47 | KylinUserPromptView(session::Manager::Ptr const& session_manager); | 47 | KylinUserPromptView(session::Manager::Ptr const& session_manager, |
81 | 48 | UserAuthenticator::Ptr const& user_authenticator); | ||
82 | 48 | 49 | ||
83 | 49 | nux::View* focus_view(); | 50 | nux::View* focus_view(); |
84 | 50 | 51 | ||
85 | @@ -62,8 +63,6 @@ | |||
86 | 62 | nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(std::string const& icon_file, int icon_size); | 63 | nux::ObjectPtr<nux::BaseTexture> LoadUserIcon(std::string const& icon_file, int icon_size); |
87 | 63 | 64 | ||
88 | 64 | private: | 65 | private: |
89 | 65 | session::Manager::Ptr session_manager_; | ||
90 | 66 | UserAuthenticatorPam user_authenticator_; | ||
91 | 67 | StaticCairoText* username_; | 66 | StaticCairoText* username_; |
92 | 68 | nux::VLayout* msg_layout_; | 67 | nux::VLayout* msg_layout_; |
93 | 69 | nux::VLayout* prompt_layout_; | 68 | nux::VLayout* prompt_layout_; |
94 | 70 | 69 | ||
95 | === modified file 'lockscreen/LockScreenAbstractPromptView.h' | |||
96 | --- lockscreen/LockScreenAbstractPromptView.h 2016-03-31 09:51:33 +0000 | |||
97 | +++ lockscreen/LockScreenAbstractPromptView.h 2017-09-15 13:37:27 +0000 | |||
98 | @@ -29,7 +29,7 @@ | |||
99 | 29 | #include <Nux/VLayout.h> | 29 | #include <Nux/VLayout.h> |
100 | 30 | #include "UnityCore/SessionManager.h" | 30 | #include "UnityCore/SessionManager.h" |
101 | 31 | 31 | ||
103 | 32 | #include "UserAuthenticatorPam.h" | 32 | #include "UserAuthenticator.h" |
104 | 33 | #include "unity-shared/IMTextEntry.h" | 33 | #include "unity-shared/IMTextEntry.h" |
105 | 34 | 34 | ||
106 | 35 | namespace nux | 35 | namespace nux |
107 | @@ -48,10 +48,12 @@ | |||
108 | 48 | class AbstractUserPromptView : public nux::View | 48 | class AbstractUserPromptView : public nux::View |
109 | 49 | { | 49 | { |
110 | 50 | public: | 50 | public: |
112 | 51 | AbstractUserPromptView(session::Manager::Ptr const& session_manager) | 51 | AbstractUserPromptView(session::Manager::Ptr const& session_manager, |
113 | 52 | UserAuthenticator::Ptr const& user_authenticator) | ||
114 | 52 | : nux::View(NUX_TRACKER_LOCATION) | 53 | : nux::View(NUX_TRACKER_LOCATION) |
115 | 53 | , scale(1.0) | 54 | , scale(1.0) |
116 | 54 | , session_manager_(session_manager) | 55 | , session_manager_(session_manager) |
117 | 56 | , user_authenticator_(user_authenticator) | ||
118 | 55 | {} | 57 | {} |
119 | 56 | 58 | ||
120 | 57 | nux::Property<double> scale; | 59 | nux::Property<double> scale; |
121 | @@ -64,7 +66,7 @@ | |||
122 | 64 | 66 | ||
123 | 65 | protected: | 67 | protected: |
124 | 66 | session::Manager::Ptr session_manager_; | 68 | session::Manager::Ptr session_manager_; |
126 | 67 | UserAuthenticatorPam user_authenticator_; | 69 | UserAuthenticator::Ptr user_authenticator_; |
127 | 68 | std::shared_ptr<nux::AbstractPaintLayer> bg_layer_; | 70 | std::shared_ptr<nux::AbstractPaintLayer> bg_layer_; |
128 | 69 | StaticCairoText* username_; | 71 | StaticCairoText* username_; |
129 | 70 | nux::VLayout* msg_layout_; | 72 | nux::VLayout* msg_layout_; |
130 | 71 | 73 | ||
131 | === modified file 'lockscreen/LockScreenController.cpp' | |||
132 | --- lockscreen/LockScreenController.cpp 2016-11-11 16:00:53 +0000 | |||
133 | +++ lockscreen/LockScreenController.cpp 2017-09-15 13:37:27 +0000 | |||
134 | @@ -27,6 +27,7 @@ | |||
135 | 27 | #include "LockScreenPromptFactory.h" | 27 | #include "LockScreenPromptFactory.h" |
136 | 28 | #include "LockScreenShield.h" | 28 | #include "LockScreenShield.h" |
137 | 29 | #include "LockScreenSettings.h" | 29 | #include "LockScreenSettings.h" |
138 | 30 | #include "UserAuthenticatorPam.h" | ||
139 | 30 | #include "unity-shared/AnimationUtils.h" | 31 | #include "unity-shared/AnimationUtils.h" |
140 | 31 | #include "unity-shared/InputMonitor.h" | 32 | #include "unity-shared/InputMonitor.h" |
141 | 32 | #include "unity-shared/UnitySettings.h" | 33 | #include "unity-shared/UnitySettings.h" |
142 | @@ -70,6 +71,7 @@ | |||
143 | 70 | , upstart_wrapper_(upstart_wrapper) | 71 | , upstart_wrapper_(upstart_wrapper) |
144 | 71 | , shield_factory_(shield_factory) | 72 | , shield_factory_(shield_factory) |
145 | 72 | , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>()) | 73 | , suspend_inhibitor_manager_(std::make_shared<SuspendInhibitorManager>()) |
146 | 74 | , user_authenticator_(std::make_shared<UserAuthenticatorPam>()) | ||
147 | 73 | , fade_animator_(unity::Settings::Instance().low_gfx() ? 0 : LOCK_FADE_DURATION) | 75 | , fade_animator_(unity::Settings::Instance().low_gfx() ? 0 : LOCK_FADE_DURATION) |
148 | 74 | , blank_window_animator_(IDLE_FADE_DURATION) | 76 | , blank_window_animator_(IDLE_FADE_DURATION) |
149 | 75 | , test_mode_(test_mode) | 77 | , test_mode_(test_mode) |
150 | @@ -259,7 +261,7 @@ | |||
151 | 259 | 261 | ||
152 | 260 | if (!prompt_view) | 262 | if (!prompt_view) |
153 | 261 | { | 263 | { |
155 | 262 | prompt_view = test_mode_ ? nux::ObjectPtr<AbstractUserPromptView>() : PromptFactory::CreatePrompt(session_manager_); | 264 | prompt_view = test_mode_ ? nux::ObjectPtr<AbstractUserPromptView>() : PromptFactory::CreatePrompt(session_manager_, user_authenticator_); |
156 | 263 | prompt_view_ = prompt_view.GetPointer(); | 265 | prompt_view_ = prompt_view.GetPointer(); |
157 | 264 | } | 266 | } |
158 | 265 | 267 | ||
159 | 266 | 268 | ||
160 | === modified file 'lockscreen/LockScreenController.h' | |||
161 | --- lockscreen/LockScreenController.h 2016-11-11 16:00:53 +0000 | |||
162 | +++ lockscreen/LockScreenController.h 2017-09-15 13:37:27 +0000 | |||
163 | @@ -29,6 +29,7 @@ | |||
164 | 29 | #include "LockScreenAcceleratorController.h" | 29 | #include "LockScreenAcceleratorController.h" |
165 | 30 | #include "SuspendInhibitorManager.h" | 30 | #include "SuspendInhibitorManager.h" |
166 | 31 | #include "ScreenSaverDBusManager.h" | 31 | #include "ScreenSaverDBusManager.h" |
167 | 32 | #include "UserAuthenticator.h" | ||
168 | 32 | #include "unity-shared/BackgroundEffectHelper.h" | 33 | #include "unity-shared/BackgroundEffectHelper.h" |
169 | 33 | #include "unity-shared/SystemdWrapper.h" | 34 | #include "unity-shared/SystemdWrapper.h" |
170 | 34 | #include "unity-shared/UpstartWrapper.h" | 35 | #include "unity-shared/UpstartWrapper.h" |
171 | @@ -95,6 +96,7 @@ | |||
172 | 95 | UpstartWrapper::Ptr upstart_wrapper_; | 96 | UpstartWrapper::Ptr upstart_wrapper_; |
173 | 96 | ShieldFactoryInterface::Ptr shield_factory_; | 97 | ShieldFactoryInterface::Ptr shield_factory_; |
174 | 97 | SuspendInhibitorManager::Ptr suspend_inhibitor_manager_; | 98 | SuspendInhibitorManager::Ptr suspend_inhibitor_manager_; |
175 | 99 | UserAuthenticator::Ptr user_authenticator_; | ||
176 | 98 | 100 | ||
177 | 99 | nux::animation::AnimateValue<double> fade_animator_; | 101 | nux::animation::AnimateValue<double> fade_animator_; |
178 | 100 | nux::animation::AnimateValue<double> blank_window_animator_; | 102 | nux::animation::AnimateValue<double> blank_window_animator_; |
179 | 101 | 103 | ||
180 | === modified file 'lockscreen/LockScreenPromptFactory.cpp' | |||
181 | --- lockscreen/LockScreenPromptFactory.cpp 2015-12-04 08:17:46 +0000 | |||
182 | +++ lockscreen/LockScreenPromptFactory.cpp 2017-09-15 13:37:27 +0000 | |||
183 | @@ -26,14 +26,15 @@ | |||
184 | 26 | { | 26 | { |
185 | 27 | namespace lockscreen | 27 | namespace lockscreen |
186 | 28 | { | 28 | { |
188 | 29 | nux::ObjectPtr<AbstractUserPromptView> PromptFactory::CreatePrompt(session::Manager::Ptr const& sm) | 29 | nux::ObjectPtr<AbstractUserPromptView> PromptFactory::CreatePrompt(session::Manager::Ptr const& sm, |
189 | 30 | UserAuthenticator::Ptr const& ua) | ||
190 | 30 | { | 31 | { |
191 | 31 | nux::ObjectPtr<AbstractUserPromptView> prompt; | 32 | nux::ObjectPtr<AbstractUserPromptView> prompt; |
192 | 32 | 33 | ||
193 | 33 | if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN) | 34 | if (unity::Settings::Instance().desktop_type() == DesktopType::UBUNTUKYLIN) |
195 | 34 | prompt = new KylinUserPromptView(sm); | 35 | prompt = new KylinUserPromptView(sm, ua); |
196 | 35 | else | 36 | else |
198 | 36 | prompt = new UserPromptView(sm); | 37 | prompt = new UserPromptView(sm, ua); |
199 | 37 | 38 | ||
200 | 38 | return prompt; | 39 | return prompt; |
201 | 39 | } | 40 | } |
202 | 40 | 41 | ||
203 | === modified file 'lockscreen/LockScreenPromptFactory.h' | |||
204 | --- lockscreen/LockScreenPromptFactory.h 2016-03-31 09:51:33 +0000 | |||
205 | +++ lockscreen/LockScreenPromptFactory.h 2017-09-15 13:37:27 +0000 | |||
206 | @@ -22,6 +22,7 @@ | |||
207 | 22 | 22 | ||
208 | 23 | #include <NuxCore/NuxCore.h> | 23 | #include <NuxCore/NuxCore.h> |
209 | 24 | #include "UnityCore/SessionManager.h" | 24 | #include "UnityCore/SessionManager.h" |
210 | 25 | #include "UserAuthenticator.h" | ||
211 | 25 | 26 | ||
212 | 26 | namespace unity | 27 | namespace unity |
213 | 27 | { | 28 | { |
214 | @@ -33,7 +34,8 @@ | |||
215 | 33 | 34 | ||
216 | 34 | struct PromptFactory | 35 | struct PromptFactory |
217 | 35 | { | 36 | { |
219 | 36 | static nux::ObjectPtr<AbstractUserPromptView> CreatePrompt(session::Manager::Ptr const&); | 37 | static nux::ObjectPtr<AbstractUserPromptView> CreatePrompt(session::Manager::Ptr const&, |
220 | 38 | UserAuthenticator::Ptr const&); | ||
221 | 37 | }; | 39 | }; |
222 | 38 | 40 | ||
223 | 39 | } | 41 | } |
224 | 40 | 42 | ||
225 | === modified file 'lockscreen/UserAuthenticator.h' | |||
226 | --- lockscreen/UserAuthenticator.h 2014-03-05 04:09:13 +0000 | |||
227 | +++ lockscreen/UserAuthenticator.h 2017-09-15 13:37:27 +0000 | |||
228 | @@ -36,6 +36,7 @@ | |||
229 | 36 | class UserAuthenticator | 36 | class UserAuthenticator |
230 | 37 | { | 37 | { |
231 | 38 | public: | 38 | public: |
232 | 39 | typedef std::shared_ptr<UserAuthenticator> Ptr; | ||
233 | 39 | typedef std::function<void(bool)> AuthenticateEndCallback; | 40 | typedef std::function<void(bool)> AuthenticateEndCallback; |
234 | 40 | 41 | ||
235 | 41 | virtual ~UserAuthenticator() = default; | 42 | virtual ~UserAuthenticator() = default; |
236 | @@ -43,6 +44,7 @@ | |||
237 | 43 | // Authenticate the user in a background thread. | 44 | // Authenticate the user in a background thread. |
238 | 44 | virtual bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) = 0; | 45 | virtual bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) = 0; |
239 | 45 | 46 | ||
240 | 47 | sigc::signal<void> start_failed; | ||
241 | 46 | sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_on_requested; | 48 | sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_on_requested; |
242 | 47 | sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_off_requested; | 49 | sigc::signal<void, std::string, PromiseAuthCodePtr const&> echo_off_requested; |
243 | 48 | sigc::signal<void, std::string> message_requested; | 50 | sigc::signal<void, std::string> message_requested; |
244 | 49 | 51 | ||
245 | === modified file 'lockscreen/UserAuthenticatorPam.cpp' | |||
246 | --- lockscreen/UserAuthenticatorPam.cpp 2016-08-10 08:56:27 +0000 | |||
247 | +++ lockscreen/UserAuthenticatorPam.cpp 2017-09-15 13:37:27 +0000 | |||
248 | @@ -23,6 +23,7 @@ | |||
249 | 23 | 23 | ||
250 | 24 | #include "UserAuthenticatorPam.h" | 24 | #include "UserAuthenticatorPam.h" |
251 | 25 | #include "unity-shared/UnitySettings.h" | 25 | #include "unity-shared/UnitySettings.h" |
252 | 26 | #include "UnityCore/GLibWrapper.h" | ||
253 | 26 | 27 | ||
254 | 27 | #include <cstring> | 28 | #include <cstring> |
255 | 28 | #include <security/pam_appl.h> | 29 | #include <security/pam_appl.h> |
256 | @@ -36,42 +37,49 @@ | |||
257 | 36 | bool UserAuthenticatorPam::AuthenticateStart(std::string const& username, | 37 | bool UserAuthenticatorPam::AuthenticateStart(std::string const& username, |
258 | 37 | AuthenticateEndCallback const& authenticate_cb) | 38 | AuthenticateEndCallback const& authenticate_cb) |
259 | 38 | { | 39 | { |
260 | 40 | if (pam_handle_) | ||
261 | 41 | return false; | ||
262 | 42 | |||
263 | 39 | first_prompt_ = true; | 43 | first_prompt_ = true; |
264 | 40 | username_ = username; | 44 | username_ = username; |
265 | 41 | authenticate_cb_ = authenticate_cb; | 45 | authenticate_cb_ = authenticate_cb; |
299 | 42 | pam_handle_ = nullptr; | 46 | |
300 | 43 | 47 | glib::Error error; | |
301 | 44 | if (!InitPam() || !pam_handle_) | 48 | g_thread_try_new(nullptr, AuthenticationThreadFunc, this, &error); |
302 | 45 | return false; | 49 | |
303 | 46 | 50 | return !error; | |
304 | 47 | glib::Object<GTask> task(g_task_new(nullptr, cancellable_, [] (GObject*, GAsyncResult*, gpointer data) { | 51 | } |
305 | 48 | auto self = static_cast<UserAuthenticatorPam*>(data); | 52 | |
306 | 49 | pam_end(self->pam_handle_, self->status_); | 53 | gpointer UserAuthenticatorPam::AuthenticationThreadFunc(gpointer data) |
307 | 50 | self->authenticate_cb_(self->status_ == PAM_SUCCESS); | 54 | { |
308 | 51 | }, this)); | 55 | auto self = static_cast<UserAuthenticatorPam*>(data); |
309 | 52 | 56 | ||
310 | 53 | g_task_set_task_data(task, this, nullptr); | 57 | if (!self->InitPam() || !self->pam_handle_) |
311 | 54 | 58 | { | |
312 | 55 | g_task_run_in_thread(task, [] (GTask* task, gpointer, gpointer data, GCancellable*) { | 59 | self->pam_handle_ = nullptr; |
313 | 56 | auto self = static_cast<UserAuthenticatorPam*>(data); | 60 | self->source_manager_.AddTimeout(0, [self] { self->start_failed.emit(); return false; }); |
314 | 57 | 61 | return nullptr; | |
315 | 58 | self->status_ = pam_authenticate(self->pam_handle_, 0); | 62 | } |
316 | 59 | 63 | ||
317 | 60 | if (self->status_ == PAM_SUCCESS) | 64 | self->status_ = pam_authenticate(self->pam_handle_, 0); |
318 | 61 | { | 65 | |
319 | 62 | int status2 = pam_acct_mgmt(self->pam_handle_, 0); | 66 | if (self->status_ == PAM_SUCCESS) |
320 | 63 | 67 | { | |
321 | 64 | if (status2 == PAM_NEW_AUTHTOK_REQD) | 68 | int status2 = pam_acct_mgmt(self->pam_handle_, 0); |
322 | 65 | status2 = pam_chauthtok(self->pam_handle_, PAM_CHANGE_EXPIRED_AUTHTOK); | 69 | |
323 | 66 | 70 | if (status2 == PAM_NEW_AUTHTOK_REQD) | |
324 | 67 | if (unity::Settings::Instance().pam_check_account_type()) | 71 | status2 = pam_chauthtok(self->pam_handle_, PAM_CHANGE_EXPIRED_AUTHTOK); |
325 | 68 | self->status_ = status2; | 72 | |
326 | 69 | 73 | if (unity::Settings::Instance().pam_check_account_type()) | |
327 | 70 | pam_setcred(self->pam_handle_, PAM_REINITIALIZE_CRED); | 74 | self->status_ = status2; |
328 | 71 | } | 75 | |
329 | 72 | }); | 76 | pam_setcred(self->pam_handle_, PAM_REINITIALIZE_CRED); |
330 | 73 | 77 | } | |
331 | 74 | return true; | 78 | |
332 | 79 | pam_end(self->pam_handle_, self->status_); | ||
333 | 80 | self->pam_handle_ = nullptr; | ||
334 | 81 | self->source_manager_.AddTimeout(0, [self] { self->authenticate_cb_(self->status_ == PAM_SUCCESS); return false; }); | ||
335 | 82 | return nullptr; | ||
336 | 75 | } | 83 | } |
337 | 76 | 84 | ||
338 | 77 | bool UserAuthenticatorPam::InitPam() | 85 | bool UserAuthenticatorPam::InitPam() |
339 | 78 | 86 | ||
340 | === modified file 'lockscreen/UserAuthenticatorPam.h' | |||
341 | --- lockscreen/UserAuthenticatorPam.h 2014-03-05 04:09:13 +0000 | |||
342 | +++ lockscreen/UserAuthenticatorPam.h 2017-09-15 13:37:27 +0000 | |||
343 | @@ -20,8 +20,6 @@ | |||
344 | 20 | #ifndef UNITY_USER_AUTHENTICATOR_PAM_H | 20 | #ifndef UNITY_USER_AUTHENTICATOR_PAM_H |
345 | 21 | #define UNITY_USER_AUTHENTICATOR_PAM_H | 21 | #define UNITY_USER_AUTHENTICATOR_PAM_H |
346 | 22 | 22 | ||
347 | 23 | #include <boost/noncopyable.hpp> | ||
348 | 24 | #include <UnityCore/GLibWrapper.h> | ||
349 | 25 | #include <UnityCore/GLibSource.h> | 23 | #include <UnityCore/GLibSource.h> |
350 | 26 | 24 | ||
351 | 27 | #include "UserAuthenticator.h" | 25 | #include "UserAuthenticator.h" |
352 | @@ -36,13 +34,17 @@ | |||
353 | 36 | namespace lockscreen | 34 | namespace lockscreen |
354 | 37 | { | 35 | { |
355 | 38 | 36 | ||
357 | 39 | class UserAuthenticatorPam : public UserAuthenticator, private boost::noncopyable | 37 | class UserAuthenticatorPam : public UserAuthenticator |
358 | 40 | { | 38 | { |
359 | 41 | public: | 39 | public: |
360 | 40 | UserAuthenticatorPam() = default; | ||
361 | 42 | bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) override; | 41 | bool AuthenticateStart(std::string const& username, AuthenticateEndCallback const&) override; |
362 | 43 | 42 | ||
363 | 44 | private: | 43 | private: |
365 | 45 | // TODO (andy) move to pimpl | 44 | UserAuthenticatorPam(UserAuthenticatorPam const&) = delete; |
366 | 45 | UserAuthenticatorPam& operator=(UserAuthenticatorPam const&) = delete; | ||
367 | 46 | |||
368 | 47 | static gpointer AuthenticationThreadFunc(gpointer); | ||
369 | 46 | bool InitPam(); | 48 | bool InitPam(); |
370 | 47 | 49 | ||
371 | 48 | static int ConversationFunction(int num_msg, | 50 | static int ConversationFunction(int num_msg, |
372 | @@ -53,10 +55,9 @@ | |||
373 | 53 | std::string username_; | 55 | std::string username_; |
374 | 54 | AuthenticateEndCallback authenticate_cb_; | 56 | AuthenticateEndCallback authenticate_cb_; |
375 | 55 | 57 | ||
380 | 56 | int status_; | 58 | int status_ = 0; |
381 | 57 | bool first_prompt_; | 59 | bool first_prompt_ = true; |
382 | 58 | pam_handle* pam_handle_; | 60 | pam_handle* pam_handle_ = nullptr; |
379 | 59 | glib::Cancellable cancellable_; | ||
383 | 60 | glib::SourceManager source_manager_; | 61 | glib::SourceManager source_manager_; |
384 | 61 | }; | 62 | }; |
385 | 62 | 63 | ||
386 | 63 | 64 | ||
387 | === modified file 'lockscreen/UserPromptView.cpp' | |||
388 | --- lockscreen/UserPromptView.cpp 2016-06-23 14:51:42 +0000 | |||
389 | +++ lockscreen/UserPromptView.cpp 2017-09-15 13:37:27 +0000 | |||
390 | @@ -23,6 +23,7 @@ | |||
391 | 23 | #include <glib/gi18n-lib.h> | 23 | #include <glib/gi18n-lib.h> |
392 | 24 | 24 | ||
393 | 25 | #include <boost/algorithm/string/trim.hpp> | 25 | #include <boost/algorithm/string/trim.hpp> |
394 | 26 | #include <NuxCore/Logger.h> | ||
395 | 26 | #include <Nux/VLayout.h> | 27 | #include <Nux/VLayout.h> |
396 | 27 | 28 | ||
397 | 28 | #include "LockScreenSettings.h" | 29 | #include "LockScreenSettings.h" |
398 | @@ -38,6 +39,9 @@ | |||
399 | 38 | { | 39 | { |
400 | 39 | namespace | 40 | namespace |
401 | 40 | { | 41 | { |
402 | 42 | |||
403 | 43 | DECLARE_LOGGER(logger, "unity.lockscreen"); | ||
404 | 44 | |||
405 | 41 | const RawPixel PADDING = 10_em; | 45 | const RawPixel PADDING = 10_em; |
406 | 42 | const RawPixel LAYOUT_MARGIN = 10_em; | 46 | const RawPixel LAYOUT_MARGIN = 10_em; |
407 | 43 | const RawPixel MSG_LAYOUT_MARGIN = 15_em; | 47 | const RawPixel MSG_LAYOUT_MARGIN = 15_em; |
408 | @@ -101,41 +105,46 @@ | |||
409 | 101 | 105 | ||
410 | 102 | } | 106 | } |
411 | 103 | 107 | ||
415 | 104 | UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager) | 108 | UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager, |
416 | 105 | : AbstractUserPromptView(session_manager) | 109 | UserAuthenticator::Ptr const& user_authenticator) |
417 | 106 | , session_manager_(session_manager) | 110 | : AbstractUserPromptView(session_manager, user_authenticator) |
418 | 107 | , username_(nullptr) | 111 | , username_(nullptr) |
419 | 108 | , msg_layout_(nullptr) | 112 | , msg_layout_(nullptr) |
420 | 109 | , prompt_layout_(nullptr) | 113 | , prompt_layout_(nullptr) |
421 | 110 | , button_layout_(nullptr) | 114 | , button_layout_(nullptr) |
422 | 111 | , prompted_(false) | 115 | , prompted_(false) |
423 | 112 | , unacknowledged_messages_(false) | 116 | , unacknowledged_messages_(false) |
424 | 117 | , num_retry_auth_(0) | ||
425 | 113 | { | 118 | { |
427 | 114 | user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ | 119 | user_authenticator_->start_failed.connect(sigc::track_obj([this](){ |
428 | 120 | HandleAuthenticationStartFailure(); | ||
429 | 121 | }, *this)); | ||
430 | 122 | |||
431 | 123 | user_authenticator_->echo_on_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){ | ||
432 | 115 | prompted_ = true; | 124 | prompted_ = true; |
433 | 116 | unacknowledged_messages_ = false; | 125 | unacknowledged_messages_ = false; |
434 | 117 | AddPrompt(message, /* visible */ true, promise); | 126 | AddPrompt(message, /* visible */ true, promise); |
436 | 118 | }); | 127 | }, *this)); |
437 | 119 | 128 | ||
439 | 120 | user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ | 129 | user_authenticator_->echo_off_requested.connect(sigc::track_obj([this](std::string const& message, PromiseAuthCodePtr const& promise){ |
440 | 121 | prompted_ = true; | 130 | prompted_ = true; |
441 | 122 | unacknowledged_messages_ = false; | 131 | unacknowledged_messages_ = false; |
442 | 123 | AddPrompt(message, /* visible */ false, promise); | 132 | AddPrompt(message, /* visible */ false, promise); |
444 | 124 | }); | 133 | }, *this)); |
445 | 125 | 134 | ||
447 | 126 | user_authenticator_.message_requested.connect([this](std::string const& message){ | 135 | user_authenticator_->message_requested.connect(sigc::track_obj([this](std::string const& message){ |
448 | 127 | unacknowledged_messages_ = true; | 136 | unacknowledged_messages_ = true; |
449 | 128 | AddMessage(message, nux::color::White); | 137 | AddMessage(message, nux::color::White); |
451 | 129 | }); | 138 | }, *this)); |
452 | 130 | 139 | ||
454 | 131 | user_authenticator_.error_requested.connect([this](std::string const& message){ | 140 | user_authenticator_->error_requested.connect(sigc::track_obj([this](std::string const& message){ |
455 | 132 | unacknowledged_messages_ = true; | 141 | unacknowledged_messages_ = true; |
456 | 133 | AddMessage(message, nux::color::Red); | 142 | AddMessage(message, nux::color::Red); |
458 | 134 | }); | 143 | }, *this)); |
459 | 135 | 144 | ||
461 | 136 | user_authenticator_.clear_prompts.connect([this](){ | 145 | user_authenticator_->clear_prompts.connect(sigc::track_obj([this](){ |
462 | 137 | ResetLayout(); | 146 | ResetLayout(); |
464 | 138 | }); | 147 | }, *this)); |
465 | 139 | 148 | ||
466 | 140 | scale.changed.connect(sigc::hide(sigc::mem_fun(this, &UserPromptView::UpdateSize))); | 149 | scale.changed.connect(sigc::hide(sigc::mem_fun(this, &UserPromptView::UpdateSize))); |
467 | 141 | 150 | ||
468 | @@ -469,8 +478,11 @@ | |||
469 | 469 | prompted_ = false; | 478 | prompted_ = false; |
470 | 470 | unacknowledged_messages_ = false; | 479 | unacknowledged_messages_ = false; |
471 | 471 | 480 | ||
474 | 472 | user_authenticator_.AuthenticateStart(session_manager_->UserName(), | 481 | if(!user_authenticator_->AuthenticateStart(session_manager_->UserName(), |
475 | 473 | sigc::mem_fun(this, &UserPromptView::AuthenticationCb)); | 482 | sigc::mem_fun(this, &UserPromptView::AuthenticationCb))) |
476 | 483 | { | ||
477 | 484 | HandleAuthenticationStartFailure(); | ||
478 | 485 | } | ||
479 | 474 | } | 486 | } |
480 | 475 | 487 | ||
481 | 476 | void UserPromptView::DoUnlock() | 488 | void UserPromptView::DoUnlock() |
482 | @@ -478,5 +490,29 @@ | |||
483 | 478 | session_manager_->unlock_requested.emit(); | 490 | session_manager_->unlock_requested.emit(); |
484 | 479 | } | 491 | } |
485 | 480 | 492 | ||
486 | 493 | void UserPromptView::HandleAuthenticationStartFailure() | ||
487 | 494 | { | ||
488 | 495 | ++num_retry_auth_; | ||
489 | 496 | |||
490 | 497 | if (num_retry_auth_ <= 5) | ||
491 | 498 | { | ||
492 | 499 | LOG_WARNING(logger) << "Failed to start the authentication process. Retrying for " << num_retry_auth_ << " time."; | ||
493 | 500 | source_manager_.AddTimeout(100, [this] { | ||
494 | 501 | StartAuthentication(); | ||
495 | 502 | return false; | ||
496 | 503 | }); | ||
497 | 504 | } | ||
498 | 505 | else | ||
499 | 506 | { | ||
500 | 507 | num_retry_auth_ = 0; | ||
501 | 508 | |||
502 | 509 | AddMessage(_("Authentication failure"), nux::color::Red); | ||
503 | 510 | AddButton(_("Switch to greeter…"), [this] { | ||
504 | 511 | session_manager_->SwitchToGreeter(); | ||
505 | 512 | }); | ||
506 | 513 | GetLayout()->AddLayout(button_layout_); | ||
507 | 514 | } | ||
508 | 515 | } | ||
509 | 516 | |||
510 | 481 | } | 517 | } |
511 | 482 | } | 518 | } |
512 | 483 | 519 | ||
513 | === modified file 'lockscreen/UserPromptView.h' | |||
514 | --- lockscreen/UserPromptView.h 2016-06-23 14:51:42 +0000 | |||
515 | +++ lockscreen/UserPromptView.h 2017-09-15 13:37:27 +0000 | |||
516 | @@ -25,10 +25,10 @@ | |||
517 | 25 | 25 | ||
518 | 26 | #include <Nux/Nux.h> | 26 | #include <Nux/Nux.h> |
519 | 27 | #include <Nux/View.h> | 27 | #include <Nux/View.h> |
520 | 28 | #include "UnityCore/GLibSource.h" | ||
521 | 28 | #include "UnityCore/SessionManager.h" | 29 | #include "UnityCore/SessionManager.h" |
522 | 29 | 30 | ||
523 | 30 | #include "LockScreenAbstractPromptView.h" | 31 | #include "LockScreenAbstractPromptView.h" |
524 | 31 | #include "UserAuthenticatorPam.h" | ||
525 | 32 | #include "unity-shared/IMTextEntry.h" | 32 | #include "unity-shared/IMTextEntry.h" |
526 | 33 | 33 | ||
527 | 34 | namespace nux | 34 | namespace nux |
528 | @@ -48,7 +48,8 @@ | |||
529 | 48 | class UserPromptView : public AbstractUserPromptView | 48 | class UserPromptView : public AbstractUserPromptView |
530 | 49 | { | 49 | { |
531 | 50 | public: | 50 | public: |
533 | 51 | UserPromptView(session::Manager::Ptr const& session_manager); | 51 | UserPromptView(session::Manager::Ptr const& session_manager, |
534 | 52 | UserAuthenticator::Ptr const& user_authenticator); | ||
535 | 52 | 53 | ||
536 | 53 | nux::View* focus_view(); | 54 | nux::View* focus_view(); |
537 | 54 | 55 | ||
538 | @@ -70,9 +71,8 @@ | |||
539 | 70 | void ShowAuthenticated(bool successful); | 71 | void ShowAuthenticated(bool successful); |
540 | 71 | void StartAuthentication(); | 72 | void StartAuthentication(); |
541 | 72 | void DoUnlock(); | 73 | void DoUnlock(); |
542 | 74 | void HandleAuthenticationStartFailure(); | ||
543 | 73 | 75 | ||
544 | 74 | session::Manager::Ptr session_manager_; | ||
545 | 75 | UserAuthenticatorPam user_authenticator_; | ||
546 | 76 | std::shared_ptr<nux::AbstractPaintLayer> bg_layer_; | 76 | std::shared_ptr<nux::AbstractPaintLayer> bg_layer_; |
547 | 77 | StaticCairoText* username_; | 77 | StaticCairoText* username_; |
548 | 78 | nux::VLayout* msg_layout_; | 78 | nux::VLayout* msg_layout_; |
549 | @@ -84,6 +84,9 @@ | |||
550 | 84 | 84 | ||
551 | 85 | bool prompted_; | 85 | bool prompted_; |
552 | 86 | bool unacknowledged_messages_; | 86 | bool unacknowledged_messages_; |
553 | 87 | int num_retry_auth_ = 0; | ||
554 | 88 | |||
555 | 89 | glib::SourceManager source_manager_; | ||
556 | 87 | }; | 90 | }; |
557 | 88 | 91 | ||
558 | 89 | } | 92 | } |
Looks good, thanks