OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/pam_authorization_factory_posix.h" | 5 #include "remoting/host/pam_authorization_factory_posix.h" |
6 | 6 |
7 #include <security/pam_appl.h> | 7 #include <security/pam_appl.h> |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/callback.h" |
9 #include "base/environment.h" | 11 #include "base/environment.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "remoting/protocol/channel_authenticator.h" | 13 #include "remoting/protocol/channel_authenticator.h" |
12 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
13 | 15 |
14 namespace remoting { | 16 namespace remoting { |
15 | 17 |
16 namespace { | 18 namespace { |
17 class PamAuthorizer : public protocol::Authenticator { | 19 class PamAuthorizer : public protocol::Authenticator { |
18 public: | 20 public: |
19 PamAuthorizer(scoped_ptr<protocol::Authenticator> underlying); | 21 PamAuthorizer(scoped_ptr<protocol::Authenticator> underlying); |
20 virtual ~PamAuthorizer(); | 22 virtual ~PamAuthorizer(); |
21 | 23 |
22 // protocol::Authenticator interface. | 24 // protocol::Authenticator interface. |
23 virtual State state() const OVERRIDE; | 25 virtual State state() const OVERRIDE; |
24 virtual RejectionReason rejection_reason() const OVERRIDE; | 26 virtual RejectionReason rejection_reason() const OVERRIDE; |
25 virtual void ProcessMessage(const buzz::XmlElement* message) OVERRIDE; | 27 virtual void ProcessMessage(const buzz::XmlElement* message, |
| 28 const base::Closure& resume_callback) OVERRIDE; |
26 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; | 29 virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; |
27 virtual scoped_ptr<protocol::ChannelAuthenticator> | 30 virtual scoped_ptr<protocol::ChannelAuthenticator> |
28 CreateChannelAuthenticator() const OVERRIDE; | 31 CreateChannelAuthenticator() const OVERRIDE; |
29 | 32 |
30 private: | 33 private: |
31 void MaybeCheckLocalLogin(); | 34 void MaybeCheckLocalLogin(); |
32 bool IsLocalLoginAllowed(); | 35 bool IsLocalLoginAllowed(); |
| 36 void OnMessageProcessed(const base::Closure& resume_callback); |
33 | 37 |
34 static int PamConversation(int num_messages, | 38 static int PamConversation(int num_messages, |
35 const struct pam_message** messages, | 39 const struct pam_message** messages, |
36 struct pam_response** responses, | 40 struct pam_response** responses, |
37 void* context); | 41 void* context); |
38 | 42 |
39 scoped_ptr<protocol::Authenticator> underlying_; | 43 scoped_ptr<protocol::Authenticator> underlying_; |
40 enum { NOT_CHECKED, ALLOWED, DISALLOWED } local_login_status_; | 44 enum { NOT_CHECKED, ALLOWED, DISALLOWED } local_login_status_; |
41 }; | 45 }; |
42 } // namespace | 46 } // namespace |
(...skipping 16 matching lines...) Expand all Loading... |
59 | 63 |
60 protocol::Authenticator::RejectionReason | 64 protocol::Authenticator::RejectionReason |
61 PamAuthorizer::rejection_reason() const { | 65 PamAuthorizer::rejection_reason() const { |
62 if (local_login_status_ == DISALLOWED) { | 66 if (local_login_status_ == DISALLOWED) { |
63 return INVALID_CREDENTIALS; | 67 return INVALID_CREDENTIALS; |
64 } else { | 68 } else { |
65 return underlying_->rejection_reason(); | 69 return underlying_->rejection_reason(); |
66 } | 70 } |
67 } | 71 } |
68 | 72 |
69 void PamAuthorizer::ProcessMessage(const buzz::XmlElement* message) { | 73 void PamAuthorizer::ProcessMessage(const buzz::XmlElement* message, |
70 underlying_->ProcessMessage(message); | 74 const base::Closure& resume_callback) { |
| 75 // |underlying_| is owned, so Unretained() is safe here. |
| 76 underlying_->ProcessMessage(message, base::Bind( |
| 77 &PamAuthorizer::OnMessageProcessed, |
| 78 base::Unretained(this), resume_callback)); |
| 79 } |
| 80 |
| 81 void PamAuthorizer::OnMessageProcessed(const base::Closure& resume_callback) { |
71 MaybeCheckLocalLogin(); | 82 MaybeCheckLocalLogin(); |
| 83 resume_callback.Run(); |
72 } | 84 } |
73 | 85 |
74 scoped_ptr<buzz::XmlElement> PamAuthorizer::GetNextMessage() { | 86 scoped_ptr<buzz::XmlElement> PamAuthorizer::GetNextMessage() { |
75 scoped_ptr<buzz::XmlElement> result (underlying_->GetNextMessage()); | 87 scoped_ptr<buzz::XmlElement> result(underlying_->GetNextMessage()); |
76 MaybeCheckLocalLogin(); | 88 MaybeCheckLocalLogin(); |
77 return result.Pass(); | 89 return result.Pass(); |
78 } | 90 } |
79 | 91 |
80 scoped_ptr<protocol::ChannelAuthenticator> | 92 scoped_ptr<protocol::ChannelAuthenticator> |
81 PamAuthorizer::CreateChannelAuthenticator() const { | 93 PamAuthorizer::CreateChannelAuthenticator() const { |
82 return underlying_->CreateChannelAuthenticator(); | 94 return underlying_->CreateChannelAuthenticator(); |
83 } | 95 } |
84 | 96 |
85 void PamAuthorizer::MaybeCheckLocalLogin() { | 97 void PamAuthorizer::MaybeCheckLocalLogin() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 const std::string& remote_jid, | 165 const std::string& remote_jid, |
154 const buzz::XmlElement* first_message) { | 166 const buzz::XmlElement* first_message) { |
155 scoped_ptr<protocol::Authenticator> authenticator( | 167 scoped_ptr<protocol::Authenticator> authenticator( |
156 underlying_->CreateAuthenticator(local_jid, remote_jid, first_message)); | 168 underlying_->CreateAuthenticator(local_jid, remote_jid, first_message)); |
157 return scoped_ptr<protocol::Authenticator>( | 169 return scoped_ptr<protocol::Authenticator>( |
158 new PamAuthorizer(authenticator.Pass())); | 170 new PamAuthorizer(authenticator.Pass())); |
159 } | 171 } |
160 | 172 |
161 | 173 |
162 } // namespace remoting | 174 } // namespace remoting |
OLD | NEW |