|
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 98-103
Link Here
|
| 98 |
_isDone = false; |
100 |
_isDone = false; |
| 99 |
_status = status; |
101 |
_status = status; |
| 100 |
_descriptors = descriptors; |
102 |
_descriptors = descriptors; |
|
|
103 |
boolean isBash = false; |
| 101 |
|
104 |
|
| 102 |
_subject = theElement; |
105 |
_subject = theElement; |
| 103 |
|
106 |
|
|
Lines 132-145
Link Here
|
| 132 |
} |
135 |
} |
| 133 |
|
136 |
|
| 134 |
try |
137 |
try |
| 135 |
{ |
138 |
{ |
| 136 |
String userHome = null; |
139 |
String suCommand = null; |
| 137 |
if (_dataStore.getClient() != null){ |
140 |
String userHome = null; |
| 138 |
userHome = _dataStore.getClient().getProperty("user.home");//$NON-NLS-1$ |
141 |
Client client = _dataStore.getClient(); |
| 139 |
} |
142 |
|
| 140 |
else { |
143 |
if (client != null){ |
| 141 |
userHome = System.getProperty("user.home");//$NON-NLS-1$ |
144 |
String clientActualUserId = client.getProperty("user.name");//$NON-NLS-1$ |
|
|
145 |
String clientUserId = client.getUserid(); |
| 146 |
|
| 147 |
userHome = client.getProperty("user.home");//$NON-NLS-1$ |
| 148 |
if (clientUserId != null && !clientActualUserId.equals(clientUserId)){ |
| 149 |
suCommand = "su " + clientUserId + " -c "; //$NON-NLS-1$ |
| 150 |
} |
| 142 |
} |
151 |
} |
|
|
152 |
else { |
| 153 |
userHome = System.getProperty("user.home");//$NON-NLS-1$ |
| 154 |
} |
| 143 |
|
155 |
|
| 144 |
_cwdStr = theElement.getSource(); |
156 |
_cwdStr = theElement.getSource(); |
| 145 |
if (_cwdStr == null || _cwdStr.length() == 0) |
157 |
if (_cwdStr == null || _cwdStr.length() == 0) |
|
Lines 176-187
Link Here
|
| 176 |
{ |
188 |
{ |
| 177 |
_isTTY = false; |
189 |
_isTTY = false; |
| 178 |
} |
190 |
} |
|
|
191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 179 |
_patterns.setIsTerminal(_isTTY); |
196 |
_patterns.setIsTerminal(_isTTY); |
| 180 |
|
197 |
|
| 181 |
String property = "SHELL="; //$NON-NLS-1$ |
198 |
String property = "SHELL="; //$NON-NLS-1$ |
| 182 |
|
199 |
|
| 183 |
String[] env = getEnvironment(_subject); |
200 |
String[] env = getEnvironment(_subject); |
| 184 |
boolean isBash = false; |
|
|
| 185 |
boolean isBashonZ = false; |
201 |
boolean isBashonZ = false; |
| 186 |
boolean isSHonZ = false; |
202 |
boolean isSHonZ = false; |
| 187 |
|
203 |
|
|
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(""+_maxLineLength); //$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 472-481
Link Here
|
| 472 |
_stdOutputHandler.setDataStore(_dataStore); |
494 |
_stdOutputHandler.setDataStore(_dataStore); |
| 473 |
_stdErrorHandler.start(); |
495 |
_stdErrorHandler.start(); |
| 474 |
|
496 |
|
| 475 |
if (didLogin && !userHome.equals(_cwdStr)) |
497 |
if (didLogin) |
| 476 |
{ |
498 |
{ |
|
|
499 |
String initCmd = isBash ? "export PS1='$PWD>';" : "export PS1=$PWD>"; //$NON-NLS-1$ |
| 500 |
if (!userHome.equals(_cwdStr)){ |
| 501 |
initCmd += "cd " + _cwdStr; //$NON-NLS-1$ |
| 502 |
} |
| 503 |
|
| 477 |
// need to CD to the correct directory |
504 |
// need to CD to the correct directory |
| 478 |
final String cdCmd = "cd " + _cwdStr; //$NON-NLS-1$ |
505 |
final String finitCmd = initCmd; |
| 479 |
Thread cdThread = new Thread( |
506 |
Thread cdThread = new Thread( |
| 480 |
new Runnable() |
507 |
new Runnable() |
| 481 |
{ |
508 |
{ |
|
Lines 490-496
Link Here
|
| 490 |
{ |
517 |
{ |
| 491 |
|
518 |
|
| 492 |
} |
519 |
} |
| 493 |
sendInput(cdCmd); |
520 |
sendInput(finitCmd); |
| 494 |
} |
521 |
} |
| 495 |
}); |
522 |
}); |
| 496 |
cdThread.start(); |
523 |
cdThread.start(); |
|
Lines 506-512
Link Here
|
| 506 |
catch (IOException e) |
533 |
catch (IOException e) |
| 507 |
{ |
534 |
{ |
| 508 |
_theProcess = null; |
535 |
_theProcess = null; |
| 509 |
e.printStackTrace(); |
536 |
_dataStore.trace(e); |
| 510 |
createObject("command", e.getMessage()); //$NON-NLS-1$ |
537 |
createObject("command", e.getMessage()); //$NON-NLS-1$ |
| 511 |
status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ |
538 |
status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$ |
| 512 |
return; |
539 |
return; |
|
Lines 650-660
Link Here
|
| 650 |
|
677 |
|
| 651 |
if (!_isWindows && (input.startsWith("cd ") || input.equals("cd"))) //$NON-NLS-1$ //$NON-NLS-2$ |
678 |
if (!_isWindows && (input.startsWith("cd ") || input.equals("cd"))) //$NON-NLS-1$ //$NON-NLS-2$ |
| 652 |
{ |
679 |
{ |
| 653 |
queryCWD(); |
680 |
if (!_isTTY) |
|
|
681 |
queryCWD(); |
| 654 |
} |
682 |
} |
| 655 |
else if (!_didInitialCWDQuery) |
683 |
else if (!_didInitialCWDQuery) |
| 656 |
{ |
684 |
{ |
| 657 |
queryCWD(); |
685 |
if (!_isTTY) |
|
|
686 |
queryCWD(); |
| 658 |
} |
687 |
} |
| 659 |
if (!_isWindows && !_isTTY) |
688 |
if (!_isWindows && !_isTTY) |
| 660 |
{ |
689 |
{ |
|
Lines 732-739
Link Here
|
| 732 |
|
761 |
|
| 733 |
if (_isTTY) |
762 |
if (_isTTY) |
| 734 |
{ |
763 |
{ |
| 735 |
varTable.put("PS1","$PWD/>"); //$NON-NLS-1$ //$NON-NLS-2$ |
764 |
varTable.put("PS1","'$PWD/>'"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 736 |
varTable.put("COLUMNS","256"); //$NON-NLS-1$ //$NON-NLS-2$ |
765 |
|
|
|
766 |
//if (_maxLineLength ) |
| 767 |
|
| 768 |
varTable.put("COLUMNS","" + _maxLineLength); //$NON-NLS-1$ //$NON-NLS-2$ |
| 737 |
} |
769 |
} |
| 738 |
|
770 |
|
| 739 |
|
771 |
|
|
Lines 846-852
Link Here
|
| 846 |
} |
878 |
} |
| 847 |
catch (Throwable e) |
879 |
catch (Throwable e) |
| 848 |
{ |
880 |
{ |
| 849 |
e.printStackTrace(); |
881 |
_dataStore.trace(e); |
| 850 |
} |
882 |
} |
| 851 |
return theValue.toString(); |
883 |
return theValue.toString(); |
| 852 |
} |
884 |
} |
|
Lines 992-998
Link Here
|
| 992 |
} |
1024 |
} |
| 993 |
} |
1025 |
} |
| 994 |
catch (IllegalThreadStateException e) |
1026 |
catch (IllegalThreadStateException e) |
| 995 |
{ //e.printStackTrace(); |
1027 |
{ |
| 996 |
exitcode = -1; |
1028 |
exitcode = -1; |
| 997 |
_theProcess.destroy(); |
1029 |
_theProcess.destroy(); |
| 998 |
} |
1030 |
} |
|
Lines 1027-1033
Link Here
|
| 1027 |
} |
1059 |
} |
| 1028 |
catch (IOException e) |
1060 |
catch (IOException e) |
| 1029 |
{ |
1061 |
{ |
| 1030 |
e.printStackTrace(); |
1062 |
_dataStore.trace(e); |
| 1031 |
} |
1063 |
} |
| 1032 |
} |
1064 |
} |
| 1033 |
|
1065 |
|
|
Lines 1118-1124
Link Here
|
| 1118 |
} |
1150 |
} |
| 1119 |
catch (Throwable e) |
1151 |
catch (Throwable e) |
| 1120 |
{ |
1152 |
{ |
| 1121 |
e.printStackTrace(); |
1153 |
_dataStore.trace(e); |
| 1122 |
} |
1154 |
} |
| 1123 |
if (parsedMsg == null) |
1155 |
if (parsedMsg == null) |
| 1124 |
{ |
1156 |
{ |
|
Lines 1175-1181
Link Here
|
| 1175 |
} |
1207 |
} |
| 1176 |
catch (NumberFormatException e) |
1208 |
catch (NumberFormatException e) |
| 1177 |
{ |
1209 |
{ |
| 1178 |
e.printStackTrace(); |
1210 |
_dataStore.trace(e); |
| 1179 |
} |
1211 |
} |
| 1180 |
} |
1212 |
} |
| 1181 |
} |
1213 |
} |