FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rstudio/src/cpp/session/modules/SessionAskPass.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
/
modules
/
SessionAskPass.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
173 lines (137 loc) · 3.97 KB
Breadcrumbs
rstudio
/
src
/
cpp
/
session
/
modules
/
SessionAskPass.cpp
Copy path
File metadata and controls
173 lines (137 loc) · 3.97 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* SessionAskPass.cpp
*
* Copyright (C) 2009-12 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
"
SessionAskPass.hpp
"
#
include
<
boost/bind.hpp
>
#
include
<
core/Exec.hpp
>
#
include
<
core/Log.hpp
>
#
include
<
shared_core/json/Json.hpp
>
#
include
<
r/RSexp.hpp
>
#
include
<
r/RRoutines.hpp
>
#
include
<
session/SessionOptions.hpp
>
#
include
<
session/SessionModuleContext.hpp
>
#
include
"
session-config.h
"
#
ifdef
RSTUDIO_SERVER
#
include
<
core/system/Crypto.hpp
>
#
endif
using
namespace
rstudio
::core
;
namespace
rstudio
{
namespace
session
{
namespace
modules
{
namespace
ask_pass
{
namespace
{
std::string s_askPassWindow;
module_context::WaitForMethodFunction s_waitForAskPass;
void
onClientInit
()
{
s_askPassWindow =
"
"
;
}
//
show error message from R
SEXP
rs_askForPassword
(
SEXP
promptSEXP)
{
try
{
std::string prompt =
r::sexp::asString
(promptSEXP);
PasswordInput input;
Error error =
askForPassword
(prompt,
"
"
, &input);
if
(error)
{
LOG_ERROR
(error);
return
R_NilValue;
}
else
if
(input.
cancelled
|| input.
password
.
empty
())
{
return
R_NilValue;
}
else
{
r::sexp::Protect rProtect;
return
r::sexp::create
(input.
password
, &rProtect);
}
}
CATCH_UNEXPECTED_EXCEPTION
return
R_NilValue;
}
}
//
anonymous namespace
std::string
activeWindow
()
{
return
s_askPassWindow;
}
void
setActiveWindow
(
const
std::string& window)
{
s_askPassWindow = window;
}
Error
askForPassword
(
const
std::string& prompt,
const
std::string& rememberPrompt,
PasswordInput* pInput)
{
json::Object payload;
payload[
"
prompt
"
] = prompt;
payload[
"
remember_prompt
"
] = rememberPrompt;
payload[
"
window
"
] = s_askPassWindow;
ClientEvent
askPassEvent
(client_events::
kAskPass
, payload);
//
wait for method
core::json::JsonRpcRequest request;
if
(!
s_waitForAskPass
(&request, askPassEvent))
{
return
systemError
(boost::system::errc::operation_canceled,
ERROR_LOCATION
);
}
//
read params
json::Value value;
bool
remember =
false
;
Error error =
json::readParams
(request.
params
, &value, &remember);
if
(error)
return
error;
//
null passphrase means dialog was cancelled
if
(!json::isType<std::string>(value))
{
pInput->
cancelled
=
true
;
return
Success
();
}
//
read inputs
pInput->
remember
= remember;
pInput->
password
= value.
getValue
<std::string>();
//
decrypt if necessary
#
ifdef
RSTUDIO_SERVER
if
(
options
().
programMode
() ==
kSessionProgramModeServer
)
{
//
In server mode, passphrases are encrypted
error =
core::system::crypto::rsaPrivateDecrypt
(
pInput->
password
,
&pInput->
password
);
if
(error)
return
error;
}
#
endif
return
Success
();
}
Error
initialize
()
{
module_context::events
().
onClientInit
.
connect
(onClientInit);
//
register waitForMethod handler
s_waitForAskPass =
module_context::registerWaitForMethod
(
"
askpass_completed
"
);
//
register .Call methods
RS_REGISTER_CALL_METHOD
(rs_askForPassword);
//
complete initialization
ExecBlock initBlock ;
initBlock.
addFunctions
()
(
boost::bind
(module_context::sourceModuleRFile,
"
SessionAskPass.R
"
));
return
initBlock.
execute
();
}
}
//
namespace content_urls
}
//
namespace modules
}
//
namespace session
}
//
namespace rstudio
Back
|
FazBrowse Home
|
New Git URL