FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/session/SessionPasswordManager.cpp at master · pearsonca/rstudio · GitHub
pearsonca
/
rstudio
Public
forked from
rstudio/rstudio
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
SessionPasswordManager.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
143 lines (127 loc) · 4.69 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
SessionPasswordManager.cpp
Copy path
File metadata and controls
143 lines (127 loc) · 4.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* SessionPasswordManager.cpp
*
* Copyright (C) 2009-17 by RStudio, PBC
*
* Unless you have received this program directly from RStudio pursuant
* to the terms of a commercial license agreement with RStudio, then
* this program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#
include
<
session/SessionPasswordManager.hpp
>
#
include
<
core/RegexUtils.hpp
>
using
namespace
rstudio
::core
;
namespace
rstudio
{
namespace
session
{
namespace
console_process
{
void
PasswordManager::attach
(
boost::shared_ptr<console_process::ConsoleProcess> pCP,
bool
showRememberOption)
{
pCP->
setPromptHandler
(
boost::bind
(&PasswordManager::handlePrompt,
this
,
pCP->
handle
(),
_1,
showRememberOption,
_2));
pCP->
onExit
().
connect
(
boost::bind
(&PasswordManager::onExit,
this
,
pCP->
handle
(),
_1));
}
bool
PasswordManager::handlePrompt
(
const
std::string& cpHandle,
const
std::string& prompt,
bool
showRememberOption,
ConsoleProcess::Input* pInput)
{
//
is this a password prompt?
boost::smatch match;
if
(
regex_utils::match
(prompt, match, promptPattern_))
{
//
see if it matches any of our existing cached passwords
std::vector<CachedPassword>::const_iterator it =
std::find_if
(passwords_.
begin
(),
passwords_.
end
(),
boost::bind
(&hasPrompt, _1, prompt));
if
(it != passwords_.
end
())
{
//
cached password
*pInput =
ConsoleProcess::Input
(it->
password
+
"
\n
"
,
false
);
}
else
{
//
prompt for password
std::string password;
bool
remember;
if
(
promptHandler_
(prompt, showRememberOption, &password, &remember))
{
//
cache the password (but also set the remember flag so it
//
will be removed from the cache when the console process
//
exits if the user chose not to remember).
CachedPassword cachedPassword;
cachedPassword.
cpHandle
= cpHandle;
cachedPassword.
prompt
= prompt;
cachedPassword.
password
= password;
cachedPassword.
remember
= remember;
passwords_.
push_back
(cachedPassword);
//
interactively entered password
*pInput =
ConsoleProcess::Input
(password +
"
\n
"
,
false
);
}
else
{
//
user cancelled
*pInput =
ConsoleProcess::Input
();
}
}
return
true
;
}
//
not a password prompt so ignore
else
{
return
false
;
}
}
void
PasswordManager::onExit
(
const
std::string& cpHandle,
int
exitCode)
{
//
if a process exits with an error then remove any cached
//
passwords which originated from that process
if
(exitCode !=
EXIT_SUCCESS
)
{
passwords_.
erase
(
std::remove_if
(passwords_.
begin
(),
passwords_.
end
(),
boost::bind
(&hasHandle, _1, cpHandle)),
passwords_.
end
());
}
//
otherwise remove any cached password for this process which doesn't
//
have its remember flag set
else
{
passwords_.
erase
(
std::remove_if
(passwords_.
begin
(),
passwords_.
end
(),
boost::bind
(&forgetOnExit, _1, cpHandle)),
passwords_.
end
());
}
}
bool
PasswordManager::hasPrompt
(
const
CachedPassword& cachedPassword,
const
std::string& prompt)
{
return
cachedPassword.
prompt
== prompt;
}
bool
PasswordManager::hasHandle
(
const
CachedPassword& cachedPassword,
const
std::string& cpHandle)
{
return
cachedPassword.
cpHandle
== cpHandle;
}
bool
PasswordManager::forgetOnExit
(
const
CachedPassword& cachedPassword,
const
std::string& cpHandle)
{
return
hasHandle
(cachedPassword, cpHandle) && !cachedPassword.
remember
;
}
}
//
namespace console_process
}
//
namespace session
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL