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 <utility> |
| 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/callback.h" | 12 #include "base/callback.h" |
11 #include "base/environment.h" | 13 #include "base/environment.h" |
12 #include "remoting/base/logging.h" | 14 #include "remoting/base/logging.h" |
13 #include "remoting/host/username.h" | 15 #include "remoting/host/username.h" |
14 #include "remoting/protocol/channel_authenticator.h" | 16 #include "remoting/protocol/channel_authenticator.h" |
15 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | 17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
16 | 18 |
17 namespace remoting { | 19 namespace remoting { |
18 | 20 |
(...skipping 20 matching lines...) Expand all Loading... |
39 void OnMessageProcessed(const base::Closure& resume_callback); | 41 void OnMessageProcessed(const base::Closure& resume_callback); |
40 | 42 |
41 static int PamConversation(int num_messages, | 43 static int PamConversation(int num_messages, |
42 const struct pam_message** messages, | 44 const struct pam_message** messages, |
43 struct pam_response** responses, | 45 struct pam_response** responses, |
44 void* context); | 46 void* context); |
45 | 47 |
46 scoped_ptr<protocol::Authenticator> underlying_; | 48 scoped_ptr<protocol::Authenticator> underlying_; |
47 enum { NOT_CHECKED, ALLOWED, DISALLOWED } local_login_status_; | 49 enum { NOT_CHECKED, ALLOWED, DISALLOWED } local_login_status_; |
48 }; | 50 }; |
| 51 |
49 } // namespace | 52 } // namespace |
50 | 53 |
51 PamAuthorizer::PamAuthorizer(scoped_ptr<protocol::Authenticator> underlying) | 54 PamAuthorizer::PamAuthorizer(scoped_ptr<protocol::Authenticator> underlying) |
52 : underlying_(underlying.Pass()), | 55 : underlying_(std::move(underlying)), local_login_status_(NOT_CHECKED) {} |
53 local_login_status_(NOT_CHECKED) { | |
54 } | |
55 | 56 |
56 PamAuthorizer::~PamAuthorizer() { | 57 PamAuthorizer::~PamAuthorizer() {} |
57 } | |
58 | 58 |
59 protocol::Authenticator::State PamAuthorizer::state() const { | 59 protocol::Authenticator::State PamAuthorizer::state() const { |
60 if (local_login_status_ == DISALLOWED) { | 60 if (local_login_status_ == DISALLOWED) { |
61 return REJECTED; | 61 return REJECTED; |
62 } else { | 62 } else { |
63 return underlying_->state(); | 63 return underlying_->state(); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 bool PamAuthorizer::started() const { | 67 bool PamAuthorizer::started() const { |
(...skipping 18 matching lines...) Expand all Loading... |
86 } | 86 } |
87 | 87 |
88 void PamAuthorizer::OnMessageProcessed(const base::Closure& resume_callback) { | 88 void PamAuthorizer::OnMessageProcessed(const base::Closure& resume_callback) { |
89 MaybeCheckLocalLogin(); | 89 MaybeCheckLocalLogin(); |
90 resume_callback.Run(); | 90 resume_callback.Run(); |
91 } | 91 } |
92 | 92 |
93 scoped_ptr<buzz::XmlElement> PamAuthorizer::GetNextMessage() { | 93 scoped_ptr<buzz::XmlElement> PamAuthorizer::GetNextMessage() { |
94 scoped_ptr<buzz::XmlElement> result(underlying_->GetNextMessage()); | 94 scoped_ptr<buzz::XmlElement> result(underlying_->GetNextMessage()); |
95 MaybeCheckLocalLogin(); | 95 MaybeCheckLocalLogin(); |
96 return result.Pass(); | 96 return result; |
97 } | 97 } |
98 | 98 |
99 const std::string& PamAuthorizer::GetAuthKey() const { | 99 const std::string& PamAuthorizer::GetAuthKey() const { |
100 return underlying_->GetAuthKey(); | 100 return underlying_->GetAuthKey(); |
101 } | 101 } |
102 | 102 |
103 scoped_ptr<protocol::ChannelAuthenticator> | 103 scoped_ptr<protocol::ChannelAuthenticator> |
104 PamAuthorizer::CreateChannelAuthenticator() const { | 104 PamAuthorizer::CreateChannelAuthenticator() const { |
105 return underlying_->CreateChannelAuthenticator(); | 105 return underlying_->CreateChannelAuthenticator(); |
106 } | 106 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 HOST_LOG << "PAM conversation message: " << message->msg; | 153 HOST_LOG << "PAM conversation message: " << message->msg; |
154 break; | 154 break; |
155 default: | 155 default: |
156 LOG(FATAL) << "Unexpected PAM conversation response required: " | 156 LOG(FATAL) << "Unexpected PAM conversation response required: " |
157 << message->msg << "; msg_style = " << message->msg_style; | 157 << message->msg << "; msg_style = " << message->msg_style; |
158 } | 158 } |
159 } | 159 } |
160 return PAM_SUCCESS; | 160 return PAM_SUCCESS; |
161 } | 161 } |
162 | 162 |
163 | |
164 PamAuthorizationFactory::PamAuthorizationFactory( | 163 PamAuthorizationFactory::PamAuthorizationFactory( |
165 scoped_ptr<protocol::AuthenticatorFactory> underlying) | 164 scoped_ptr<protocol::AuthenticatorFactory> underlying) |
166 : underlying_(underlying.Pass()) { | 165 : underlying_(std::move(underlying)) {} |
167 } | |
168 | 166 |
169 PamAuthorizationFactory::~PamAuthorizationFactory() { | 167 PamAuthorizationFactory::~PamAuthorizationFactory() {} |
170 } | |
171 | 168 |
172 scoped_ptr<protocol::Authenticator> | 169 scoped_ptr<protocol::Authenticator> |
173 PamAuthorizationFactory::CreateAuthenticator( | 170 PamAuthorizationFactory::CreateAuthenticator( |
174 const std::string& local_jid, | 171 const std::string& local_jid, |
175 const std::string& remote_jid, | 172 const std::string& remote_jid, |
176 const buzz::XmlElement* first_message) { | 173 const buzz::XmlElement* first_message) { |
177 scoped_ptr<protocol::Authenticator> authenticator( | 174 scoped_ptr<protocol::Authenticator> authenticator( |
178 underlying_->CreateAuthenticator(local_jid, remote_jid, first_message)); | 175 underlying_->CreateAuthenticator(local_jid, remote_jid, first_message)); |
179 return make_scoped_ptr(new PamAuthorizer(authenticator.Pass())); | 176 return make_scoped_ptr(new PamAuthorizer(std::move(authenticator))); |
180 } | 177 } |
181 | 178 |
182 | |
183 } // namespace remoting | 179 } // namespace remoting |
OLD | NEW |