|
Lines 23-28
Link Here
|
| 23 |
* David McKnight (IBM) [284179] [dstore] commands have a hard coded line length limit of 100 characters |
23 |
* David McKnight (IBM) [284179] [dstore] commands have a hard coded line length limit of 100 characters |
| 24 |
* David McKnight (IBM) - [286671] Dstore shell service interprets < and > sequences |
24 |
* David McKnight (IBM) - [286671] Dstore shell service interprets < and > sequences |
| 25 |
* David McKnight (IBM) [290743] [dstore][shells] allow bash shells and custom shell invocation |
25 |
* David McKnight (IBM) [290743] [dstore][shells] allow bash shells and custom shell invocation |
|
|
26 |
* David McKnight (IBM) [287305] [dstore] Need to set proper uid for commands when using SecuredThread and single server for multiple clients[ |
| 26 |
*******************************************************************************/ |
27 |
*******************************************************************************/ |
| 27 |
|
28 |
|
| 28 |
package org.eclipse.rse.internal.dstore.universal.miners.command; |
29 |
package org.eclipse.rse.internal.dstore.universal.miners.command; |
|
Lines 42-47
Link Here
|
| 42 |
import java.util.List; |
43 |
import java.util.List; |
| 43 |
|
44 |
|
| 44 |
import org.eclipse.dstore.core.miners.MinerThread; |
45 |
import org.eclipse.dstore.core.miners.MinerThread; |
|
|
46 |
import org.eclipse.dstore.core.model.Client; |
| 45 |
import org.eclipse.dstore.core.model.DE; |
47 |
import org.eclipse.dstore.core.model.DE; |
| 46 |
import org.eclipse.dstore.core.model.DataElement; |
48 |
import org.eclipse.dstore.core.model.DataElement; |
| 47 |
import org.eclipse.dstore.core.model.DataStoreAttributes; |
49 |
import org.eclipse.dstore.core.model.DataStoreAttributes; |
|
Lines 132-145
Link Here
|
| 132 |
} |
134 |
} |
| 133 |
|
135 |
|
| 134 |
try |
136 |
try |
| 135 |
{ |
137 |
{ |
| 136 |
String userHome = null; |
138 |
String suCommand = null; |
| 137 |
if (_dataStore.getClient() != null){ |
139 |
String userHome = null; |
| 138 |
userHome = _dataStore.getClient().getProperty("user.home");//$NON-NLS-1$ |
140 |
Client client = _dataStore.getClient(); |
| 139 |
} |
141 |
|
| 140 |
else { |
142 |
if (client != null){ |
| 141 |
userHome = System.getProperty("user.home");//$NON-NLS-1$ |
143 |
String clientActualUserId = client.getProperty("user.name");//$NON-NLS-1$ |
|
|
144 |
String clientUserId = client.getUserid(); |
| 145 |
|
| 146 |
userHome = client.getProperty("user.home");//$NON-NLS-1$ |
| 147 |
if (clientUserId != null && !clientActualUserId.equals(clientUserId)){ |
| 148 |
suCommand = "su " + clientUserId + " -c "; //$NON-NLS-1$ |
| 149 |
} |
| 142 |
} |
150 |
} |
|
|
151 |
else { |
| 152 |
userHome = System.getProperty("user.home");//$NON-NLS-1$ |
| 153 |
} |
| 143 |
|
154 |
|
| 144 |
_cwdStr = theElement.getSource(); |
155 |
_cwdStr = theElement.getSource(); |
| 145 |
if (_cwdStr == null || _cwdStr.length() == 0) |
156 |
if (_cwdStr == null || _cwdStr.length() == 0) |
|
Lines 176-181
Link Here
|
| 176 |
{ |
187 |
{ |
| 177 |
_isTTY = false; |
188 |
_isTTY = false; |
| 178 |
} |
189 |
} |
|
|
190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 179 |
_patterns.setIsTerminal(_isTTY); |
195 |
_patterns.setIsTerminal(_isTTY); |
| 180 |
|
196 |
|
| 181 |
String property = "SHELL="; //$NON-NLS-1$ |
197 |
String property = "SHELL="; //$NON-NLS-1$ |
|
Lines 229-245
Link Here
|
| 229 |
if (_invocation.equals(">")) //$NON-NLS-1$ |
245 |
if (_invocation.equals(">")) //$NON-NLS-1$ |
| 230 |
{ |
246 |
{ |
| 231 |
_invocation = "sh"; //$NON-NLS-1$ |
247 |
_invocation = "sh"; //$NON-NLS-1$ |
|
|
248 |
|
| 232 |
_isShell = true; |
249 |
_isShell = true; |
| 233 |
if (isZ) |
250 |
if (isZ) |
| 234 |
isSHonZ = true; |
251 |
isSHonZ = true; |
| 235 |
} |
252 |
} |
|
|
253 |
|
| 254 |
|
| 236 |
if (_isTTY) |
255 |
if (_isTTY) |
| 237 |
{ |
256 |
{ |
| 238 |
if (isSHonZ) |
257 |
if (isSHonZ) |
| 239 |
{ |
258 |
{ |
| 240 |
String args[] = new String[3]; |
259 |
String args[] = new String[3]; |
| 241 |
args[0] = PSEUDO_TERMINAL; |
260 |
args[0] = PSEUDO_TERMINAL; |
| 242 |
args[1] = _invocation; |
261 |
args[1] = "sh"; //$NON-NLS-1$ |
| 243 |
args[2] = "-L"; //$NON-NLS-1$ |
262 |
args[2] = "-L"; //$NON-NLS-1$ |
| 244 |
|
263 |
|
| 245 |
try { |
264 |
try { |
|
Lines 252-260
Link Here
|
| 252 |
} |
271 |
} |
| 253 |
else |
272 |
else |
| 254 |
{ |
273 |
{ |
| 255 |
String args[] = new String[2]; |
274 |
List argsList = new ArrayList(); |
| 256 |
args[0] = PSEUDO_TERMINAL; |
275 |
|
| 257 |
args[1] = _invocation; |
276 |
if (suCommand != null){ |
|
|
277 |
String[] suSplit = suCommand.split(" "); //$NON-NLS-1$ |
| 278 |
for (int i = 0; i < suSplit.length; i++){ // su before terminal |
| 279 |
argsList.add(suSplit[i]); |
| 280 |
} |
| 281 |
} |
| 282 |
argsList.add(PSEUDO_TERMINAL); |
| 283 |
argsList.add(invocation); |
| 284 |
|
| 285 |
|
| 286 |
String args[] = (String[])argsList.toArray(new String[argsList.size()]); |
| 258 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
287 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
| 259 |
} |
288 |
} |
| 260 |
} |
289 |
} |
|
Lines 268-318
Link Here
|
| 268 |
if (_invocation.equals(">")) //$NON-NLS-1$ |
297 |
if (_invocation.equals(">")) //$NON-NLS-1$ |
| 269 |
{ |
298 |
{ |
| 270 |
_invocation = theShell; |
299 |
_invocation = theShell; |
| 271 |
|
300 |
|
|
|
301 |
|
| 272 |
_isShell = true; |
302 |
_isShell = true; |
| 273 |
|
303 |
|
| 274 |
if (_isTTY) |
304 |
if (_isTTY) |
| 275 |
{ |
305 |
{ |
| 276 |
String args[] = null; |
306 |
List argsList = new ArrayList(); |
| 277 |
if (isBashonZ) |
307 |
|
| 278 |
{ |
308 |
if (!isBashonZ && !isSHonZ && suCommand != null){ |
| 279 |
args = new String[5]; |
309 |
// su before starting rseterm |
| 280 |
args[0] = PSEUDO_TERMINAL; |
310 |
String[] suArgs = suCommand.split(" "); //$NON-NLS-1$ |
| 281 |
args[1] = "-w"; //$NON-NLS-1$ |
311 |
for (int i = 0; i < suArgs.length; i++){ |
| 282 |
args[2] = "256"; //$NON-NLS-1$ |
312 |
argsList.add(suArgs[i]); |
| 283 |
args[3] = _invocation; |
313 |
} |
| 284 |
args[4] = "--login"; //$NON-NLS-1$ |
314 |
} |
|
|
315 |
argsList.add(PSEUDO_TERMINAL); |
| 316 |
|
| 317 |
if (!isBashonZ && !isSHonZ && suCommand != null){ |
| 318 |
// need sh -c before invocation |
| 319 |
argsList.add("sh"); //$NON-NLS-1$ |
| 320 |
argsList.add("-c"); //$NON-NLS-1$ |
| 321 |
} |
| 322 |
else { |
| 323 |
|
| 324 |
argsList.add("-w"); //$NON-NLS-1$ |
| 325 |
argsList.add("256"); //$NON-NLS-1$ |
| 326 |
} |
| 327 |
|
| 328 |
argsList.add(_invocation); |
| 329 |
|
| 330 |
if (isBashonZ){ |
| 331 |
argsList.add("--login"); //$NON-NLS-1$ |
| 285 |
didLogin = true; |
332 |
didLogin = true; |
| 286 |
} |
333 |
} |
| 287 |
else if (isBash) |
334 |
else if (isBash){ |
| 288 |
{ |
335 |
argsList.add("-l"); //$NON-NLS-1$ |
| 289 |
args = new String[5]; |
|
|
| 290 |
args[0] = PSEUDO_TERMINAL; |
| 291 |
args[1] = "-w"; //$NON-NLS-1$ |
| 292 |
args[2] = "256"; //$NON-NLS-1$ |
| 293 |
args[3] = _invocation; |
| 294 |
args[4] = "-l"; //$NON-NLS-1$ |
| 295 |
didLogin = true; |
336 |
didLogin = true; |
| 296 |
} |
337 |
} |
| 297 |
else if (isSHonZ) |
338 |
else if (isSHonZ){ |
| 298 |
{ |
339 |
argsList.add("-L"); //$NON-NLS-1$ |
| 299 |
args = new String[5]; |
|
|
| 300 |
args[0] = PSEUDO_TERMINAL; |
| 301 |
args[1] = "-w"; //$NON-NLS-1$ |
| 302 |
args[2] = "256"; //$NON-NLS-1$ |
| 303 |
args[3] = _invocation; |
| 304 |
args[4] = "-L"; //$NON-NLS-1$ |
| 305 |
didLogin = true; |
340 |
didLogin = true; |
| 306 |
} |
341 |
} |
| 307 |
else |
342 |
|
| 308 |
{ |
343 |
String args[] = (String[])argsList.toArray(new String[argsList.size()]); |
| 309 |
args = new String[4]; |
344 |
|
| 310 |
args[0] = PSEUDO_TERMINAL; |
|
|
| 311 |
args[1] = "-w"; //$NON-NLS-1$ |
| 312 |
args[2] = "256"; //$NON-NLS-1$ |
| 313 |
args[3] = _invocation; |
| 314 |
} |
| 315 |
|
| 316 |
try { |
345 |
try { |
| 317 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
346 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
| 318 |
} |
347 |
} |
|
Lines 323-328
Link Here
|
| 323 |
} |
352 |
} |
| 324 |
else |
353 |
else |
| 325 |
{ |
354 |
{ |
|
|
355 |
if (!isBashonZ && !isSHonZ && suCommand != null){ |
| 356 |
_invocation = suCommand + _invocation; |
| 357 |
} |
| 358 |
|
| 326 |
if (customShellInvocation != null && customShellInvocation.length() > 0){ |
359 |
if (customShellInvocation != null && customShellInvocation.length() > 0){ |
| 327 |
// all handled in the custom shell invocation |
360 |
// all handled in the custom shell invocation |
| 328 |
_theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); |
361 |
_theProcess = Runtime.getRuntime().exec(_invocation, env, theDirectory); |
|
Lines 352-383
Link Here
|
| 352 |
} |
385 |
} |
| 353 |
else |
386 |
else |
| 354 |
{ |
387 |
{ |
| 355 |
_isTTY = false; |
388 |
if (suCommand != null){ |
| 356 |
|
389 |
theShell = suCommand + theShell; |
|
|
390 |
} |
| 357 |
|
391 |
|
|
|
392 |
List argsList = new ArrayList(); |
| 358 |
|
393 |
|
| 359 |
//String[] inv = parseArgs(_invocation); |
394 |
String[] shellArray = theShell.split(" "); //$NON-NLS-1$ |
| 360 |
if (_isTTY) |
395 |
for (int i = 0; i < shellArray.length; i++){ |
| 361 |
{ |
396 |
argsList.add(shellArray[i]); |
| 362 |
String args[] = new String[4]; |
|
|
| 363 |
args[0] = PSEUDO_TERMINAL; |
| 364 |
args[1] = theShell; |
| 365 |
args[2] = "-c"; //$NON-NLS-1$ |
| 366 |
args[3] = _invocation; |
| 367 |
|
| 368 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
| 369 |
} |
| 370 |
else |
| 371 |
{ |
| 372 |
|
| 373 |
String args[] = new String[3]; |
| 374 |
args[0] = theShell; |
| 375 |
args[1] = "-c"; //$NON-NLS-1$ |
| 376 |
args[2] = _invocation; |
| 377 |
|
| 378 |
|
| 379 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
| 380 |
} |
397 |
} |
|
|
398 |
argsList.add("-c"); //$NON-NLS-1$ |
| 399 |
argsList.add(_invocation); |
| 400 |
|
| 401 |
String args[] = (String[])argsList.toArray(new String[argsList.size()]); |
| 402 |
_theProcess = Runtime.getRuntime().exec(args, env, theDirectory); |
| 381 |
} |
403 |
} |
| 382 |
} |
404 |
} |
| 383 |
} |
405 |
} |
|
Lines 506-512
Link Here
|
| 506 |
catch (IOException e) |
528 |
catch (IOException e) |
| 507 |
{ |
529 |
{ |
| 508 |
_theProcess = null; |
530 |
_theProcess = null; |
| 509 |
e.printStackTrace(); |
531 |
_dataStore.trace(e); |
| 510 |
createObject("command", e.getMessage()); //$NON-NLS-1$ |
532 |
createObject("command", e.getMessage()); //$NON-NLS-1$ |
| 511 |
status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ |
533 |
status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ |
| 512 |
return; |
534 |
return; |
|
Lines 846-852
Link Here
|
| 846 |
} |
868 |
} |
| 847 |
catch (Throwable e) |
869 |
catch (Throwable e) |
| 848 |
{ |
870 |
{ |
| 849 |
e.printStackTrace(); |
871 |
_dataStore.trace(e); |
| 850 |
} |
872 |
} |
| 851 |
return theValue.toString(); |
873 |
return theValue.toString(); |
| 852 |
} |
874 |
} |
|
Lines 992-998
Link Here
|
| 992 |
} |
1014 |
} |
| 993 |
} |
1015 |
} |
| 994 |
catch (IllegalThreadStateException e) |
1016 |
catch (IllegalThreadStateException e) |
| 995 |
{ //e.printStackTrace(); |
1017 |
{ |
| 996 |
exitcode = -1; |
1018 |
exitcode = -1; |
| 997 |
_theProcess.destroy(); |
1019 |
_theProcess.destroy(); |
| 998 |
} |
1020 |
} |
|
Lines 1027-1033
Link Here
|
| 1027 |
} |
1049 |
} |
| 1028 |
catch (IOException e) |
1050 |
catch (IOException e) |
| 1029 |
{ |
1051 |
{ |
| 1030 |
e.printStackTrace(); |
1052 |
_dataStore.trace(e); |
| 1031 |
} |
1053 |
} |
| 1032 |
} |
1054 |
} |
| 1033 |
|
1055 |
|
|
Lines 1118-1124
Link Here
|
| 1118 |
} |
1140 |
} |
| 1119 |
catch (Throwable e) |
1141 |
catch (Throwable e) |
| 1120 |
{ |
1142 |
{ |
| 1121 |
e.printStackTrace(); |
1143 |
_dataStore.trace(e); |
| 1122 |
} |
1144 |
} |
| 1123 |
if (parsedMsg == null) |
1145 |
if (parsedMsg == null) |
| 1124 |
{ |
1146 |
{ |
|
Lines 1175-1181
Link Here
|
| 1175 |
} |
1197 |
} |
| 1176 |
catch (NumberFormatException e) |
1198 |
catch (NumberFormatException e) |
| 1177 |
{ |
1199 |
{ |
| 1178 |
e.printStackTrace(); |
1200 |
_dataStore.trace(e); |
| 1179 |
} |
1201 |
} |
| 1180 |
} |
1202 |
} |
| 1181 |
} |
1203 |
} |