Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: remoting/host/pam_authorization_factory_posix.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/host/pam_authorization_factory_posix.h ('k') | remoting/host/policy_watcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/environment.h" 13 #include "base/environment.h"
14 #include "base/memory/ptr_util.h"
14 #include "remoting/base/logging.h" 15 #include "remoting/base/logging.h"
15 #include "remoting/host/username.h" 16 #include "remoting/host/username.h"
16 #include "remoting/protocol/channel_authenticator.h" 17 #include "remoting/protocol/channel_authenticator.h"
17 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" 18 #include "third_party/webrtc/libjingle/xmllite/xmlelement.h"
18 19
19 namespace remoting { 20 namespace remoting {
20 21
21 namespace { 22 namespace {
22 class PamAuthorizer : public protocol::Authenticator { 23 class PamAuthorizer : public protocol::Authenticator {
23 public: 24 public:
24 PamAuthorizer(scoped_ptr<protocol::Authenticator> underlying); 25 PamAuthorizer(std::unique_ptr<protocol::Authenticator> underlying);
25 ~PamAuthorizer() override; 26 ~PamAuthorizer() override;
26 27
27 // protocol::Authenticator interface. 28 // protocol::Authenticator interface.
28 State state() const override; 29 State state() const override;
29 bool started() const override; 30 bool started() const override;
30 RejectionReason rejection_reason() const override; 31 RejectionReason rejection_reason() const override;
31 void ProcessMessage(const buzz::XmlElement* message, 32 void ProcessMessage(const buzz::XmlElement* message,
32 const base::Closure& resume_callback) override; 33 const base::Closure& resume_callback) override;
33 scoped_ptr<buzz::XmlElement> GetNextMessage() override; 34 std::unique_ptr<buzz::XmlElement> GetNextMessage() override;
34 const std::string& GetAuthKey() const override; 35 const std::string& GetAuthKey() const override;
35 scoped_ptr<protocol::ChannelAuthenticator> CreateChannelAuthenticator() 36 std::unique_ptr<protocol::ChannelAuthenticator> CreateChannelAuthenticator()
36 const override; 37 const override;
37 38
38 private: 39 private:
39 void MaybeCheckLocalLogin(); 40 void MaybeCheckLocalLogin();
40 bool IsLocalLoginAllowed(); 41 bool IsLocalLoginAllowed();
41 void OnMessageProcessed(const base::Closure& resume_callback); 42 void OnMessageProcessed(const base::Closure& resume_callback);
42 43
43 static int PamConversation(int num_messages, 44 static int PamConversation(int num_messages,
44 const struct pam_message** messages, 45 const struct pam_message** messages,
45 struct pam_response** responses, 46 struct pam_response** responses,
46 void* context); 47 void* context);
47 48
48 scoped_ptr<protocol::Authenticator> underlying_; 49 std::unique_ptr<protocol::Authenticator> underlying_;
49 enum { NOT_CHECKED, ALLOWED, DISALLOWED } local_login_status_; 50 enum { NOT_CHECKED, ALLOWED, DISALLOWED } local_login_status_;
50 }; 51 };
51 52
52 } // namespace 53 } // namespace
53 54
54 PamAuthorizer::PamAuthorizer(scoped_ptr<protocol::Authenticator> underlying) 55 PamAuthorizer::PamAuthorizer(
56 std::unique_ptr<protocol::Authenticator> underlying)
55 : underlying_(std::move(underlying)), local_login_status_(NOT_CHECKED) {} 57 : underlying_(std::move(underlying)), local_login_status_(NOT_CHECKED) {}
56 58
57 PamAuthorizer::~PamAuthorizer() {} 59 PamAuthorizer::~PamAuthorizer() {}
58 60
59 protocol::Authenticator::State PamAuthorizer::state() const { 61 protocol::Authenticator::State PamAuthorizer::state() const {
60 if (local_login_status_ == DISALLOWED) { 62 if (local_login_status_ == DISALLOWED) {
61 return REJECTED; 63 return REJECTED;
62 } else { 64 } else {
63 return underlying_->state(); 65 return underlying_->state();
64 } 66 }
(...skipping 18 matching lines...) Expand all
83 underlying_->ProcessMessage(message, base::Bind( 85 underlying_->ProcessMessage(message, base::Bind(
84 &PamAuthorizer::OnMessageProcessed, 86 &PamAuthorizer::OnMessageProcessed,
85 base::Unretained(this), resume_callback)); 87 base::Unretained(this), resume_callback));
86 } 88 }
87 89
88 void PamAuthorizer::OnMessageProcessed(const base::Closure& resume_callback) { 90 void PamAuthorizer::OnMessageProcessed(const base::Closure& resume_callback) {
89 MaybeCheckLocalLogin(); 91 MaybeCheckLocalLogin();
90 resume_callback.Run(); 92 resume_callback.Run();
91 } 93 }
92 94
93 scoped_ptr<buzz::XmlElement> PamAuthorizer::GetNextMessage() { 95 std::unique_ptr<buzz::XmlElement> PamAuthorizer::GetNextMessage() {
94 scoped_ptr<buzz::XmlElement> result(underlying_->GetNextMessage()); 96 std::unique_ptr<buzz::XmlElement> result(underlying_->GetNextMessage());
95 MaybeCheckLocalLogin(); 97 MaybeCheckLocalLogin();
96 return result; 98 return result;
97 } 99 }
98 100
99 const std::string& PamAuthorizer::GetAuthKey() const { 101 const std::string& PamAuthorizer::GetAuthKey() const {
100 return underlying_->GetAuthKey(); 102 return underlying_->GetAuthKey();
101 } 103 }
102 104
103 scoped_ptr<protocol::ChannelAuthenticator> 105 std::unique_ptr<protocol::ChannelAuthenticator>
104 PamAuthorizer::CreateChannelAuthenticator() const { 106 PamAuthorizer::CreateChannelAuthenticator() const {
105 return underlying_->CreateChannelAuthenticator(); 107 return underlying_->CreateChannelAuthenticator();
106 } 108 }
107 109
108 void PamAuthorizer::MaybeCheckLocalLogin() { 110 void PamAuthorizer::MaybeCheckLocalLogin() {
109 if (local_login_status_ == NOT_CHECKED && state() == ACCEPTED) { 111 if (local_login_status_ == NOT_CHECKED && state() == ACCEPTED) {
110 local_login_status_ = IsLocalLoginAllowed() ? ALLOWED : DISALLOWED; 112 local_login_status_ = IsLocalLoginAllowed() ? ALLOWED : DISALLOWED;
111 } 113 }
112 } 114 }
113 115
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 break; 156 break;
155 default: 157 default:
156 LOG(FATAL) << "Unexpected PAM conversation response required: " 158 LOG(FATAL) << "Unexpected PAM conversation response required: "
157 << message->msg << "; msg_style = " << message->msg_style; 159 << message->msg << "; msg_style = " << message->msg_style;
158 } 160 }
159 } 161 }
160 return PAM_SUCCESS; 162 return PAM_SUCCESS;
161 } 163 }
162 164
163 PamAuthorizationFactory::PamAuthorizationFactory( 165 PamAuthorizationFactory::PamAuthorizationFactory(
164 scoped_ptr<protocol::AuthenticatorFactory> underlying) 166 std::unique_ptr<protocol::AuthenticatorFactory> underlying)
165 : underlying_(std::move(underlying)) {} 167 : underlying_(std::move(underlying)) {}
166 168
167 PamAuthorizationFactory::~PamAuthorizationFactory() {} 169 PamAuthorizationFactory::~PamAuthorizationFactory() {}
168 170
169 scoped_ptr<protocol::Authenticator> 171 std::unique_ptr<protocol::Authenticator>
170 PamAuthorizationFactory::CreateAuthenticator(const std::string& local_jid, 172 PamAuthorizationFactory::CreateAuthenticator(const std::string& local_jid,
171 const std::string& remote_jid) { 173 const std::string& remote_jid) {
172 scoped_ptr<protocol::Authenticator> authenticator( 174 std::unique_ptr<protocol::Authenticator> authenticator(
173 underlying_->CreateAuthenticator(local_jid, remote_jid)); 175 underlying_->CreateAuthenticator(local_jid, remote_jid));
174 return make_scoped_ptr(new PamAuthorizer(std::move(authenticator))); 176 return base::WrapUnique(new PamAuthorizer(std::move(authenticator)));
175 } 177 }
176 178
177 } // namespace remoting 179 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/pam_authorization_factory_posix.h ('k') | remoting/host/policy_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698