Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 287305 | Differences between
and this patch

Collapse All | Expand All

(-)miners/org/eclipse/rse/internal/dstore/universal/miners/command/CommandMinerThread.java (-87 / +123 lines)
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
			// initialization
498
			if (didLogin || _isTTY)
476
			{
499
			{
500
				String initCmd = ""; //$NON-NLS-1$
501
				if (_isTTY){
502
					initCmd = "export PS1='$PWD>';" ; //$NON-NLS-1$ 
503
				}
504
				 if (didLogin && !userHome.equals(_cwdStr)){
505
					 initCmd += "cd " + _cwdStr; //$NON-NLS-1$
506
				 }
507
				 				 
477
				// need to CD to the correct directory
508
				// need to CD to the correct directory
478
				final String cdCmd = "cd " + _cwdStr; //$NON-NLS-1$
509
				final String finitCmd = initCmd;
479
				Thread cdThread = new Thread(
510
				Thread cdThread = new Thread(
480
						new Runnable()
511
						new Runnable()
481
						{
512
						{
Lines 490-496 Link Here
490
								{
521
								{
491
									
522
									
492
								}
523
								}
493
								sendInput(cdCmd);
524
								sendInput(finitCmd);
494
							}
525
							}
495
						});
526
						});
496
				cdThread.start();
527
				cdThread.start();
Lines 506-512 Link Here
506
		catch (IOException e) 
537
		catch (IOException e) 
507
		{
538
		{
508
			_theProcess = null;
539
			_theProcess = null;
509
			e.printStackTrace();
540
			_dataStore.trace(e);
510
			createObject("command", e.getMessage()); //$NON-NLS-1$
541
			createObject("command", e.getMessage()); //$NON-NLS-1$
511
			status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
542
			status.setAttribute(DE.A_NAME, "done"); //$NON-NLS-1$
512
			return;
543
			return;
Lines 650-660 Link Here
650
681
651
				if (!_isWindows && (input.startsWith("cd ") || input.equals("cd"))) //$NON-NLS-1$ //$NON-NLS-2$
682
				if (!_isWindows && (input.startsWith("cd ") || input.equals("cd"))) //$NON-NLS-1$ //$NON-NLS-2$
652
				{
683
				{
653
					queryCWD();
684
					if (!_isTTY)
685
						queryCWD();
654
				}
686
				}
655
				else if (!_didInitialCWDQuery)
687
				else if (!_didInitialCWDQuery)
656
				{
688
				{
657
					queryCWD();
689
					if (!_isTTY)
690
						queryCWD();
658
				}
691
				}
659
				if (!_isWindows && !_isTTY)
692
				if (!_isWindows && !_isTTY)
660
				{
693
				{
Lines 732-739 Link Here
732
765
733
		if (_isTTY)
766
		if (_isTTY)
734
		{
767
		{
735
			varTable.put("PS1","$PWD/>"); //$NON-NLS-1$ //$NON-NLS-2$
768
			varTable.put("PS1","'$PWD/>'"); //$NON-NLS-1$ //$NON-NLS-2$
736
			varTable.put("COLUMNS","256"); //$NON-NLS-1$ //$NON-NLS-2$
769
			
770
			//if (_maxLineLength )
771
			
772
			varTable.put("COLUMNS","" + _maxLineLength); //$NON-NLS-1$ //$NON-NLS-2$
737
		}
773
		}
738
		
774
		
739
775
Lines 846-852 Link Here
846
		}
882
		}
847
		catch (Throwable e)
883
		catch (Throwable e)
848
		{
884
		{
849
			e.printStackTrace();
885
			_dataStore.trace(e);
850
		}
886
		}
851
		return theValue.toString();
887
		return theValue.toString();
852
	}
888
	}
Lines 992-998 Link Here
992
					}
1028
					}
993
				}
1029
				}
994
				catch (IllegalThreadStateException e)
1030
				catch (IllegalThreadStateException e)
995
				{ //e.printStackTrace();
1031
				{ 
996
					exitcode = -1;
1032
					exitcode = -1;
997
					_theProcess.destroy();
1033
					_theProcess.destroy();
998
				}
1034
				}
Lines 1027-1033 Link Here
1027
		}
1063
		}
1028
		catch (IOException e)
1064
		catch (IOException e)
1029
		{
1065
		{
1030
			e.printStackTrace();
1066
			_dataStore.trace(e);
1031
		}				
1067
		}				
1032
	}
1068
	}
1033
	
1069
	
Lines 1118-1124 Link Here
1118
	 			}
1154
	 			}
1119
				catch (Throwable e) 
1155
				catch (Throwable e) 
1120
				{
1156
				{
1121
					e.printStackTrace();
1157
					_dataStore.trace(e);
1122
				}
1158
				}
1123
				if (parsedMsg == null)
1159
				if (parsedMsg == null)
1124
				{
1160
				{
Lines 1175-1181 Link Here
1175
					}
1211
					}
1176
					catch (NumberFormatException e)
1212
					catch (NumberFormatException e)
1177
					{
1213
					{
1178
						e.printStackTrace();
1214
						_dataStore.trace(e);
1179
					}
1215
					}
1180
				}
1216
				}
1181
			}
1217
			}
(-)miners/org/eclipse/rse/internal/dstore/universal/miners/command/OutputHandler.java (-3 / +4 lines)
Lines 17-22 Link Here
17
 * David McKnight     (IBM)   [249715] [dstore][shells] Unix shell does not echo command
17
 * David McKnight     (IBM)   [249715] [dstore][shells] Unix shell does not echo command
18
 * David McKnight   (IBM)        - [282919] [dstore] server shutdown results in exception in shell io reading
18
 * David McKnight   (IBM)        - [282919] [dstore] server shutdown results in exception in shell io reading
19
 * David McKnight (IBM) - [286671] Dstore shell service interprets &lt; and &gt; sequences
19
 * David McKnight (IBM) - [286671] Dstore shell service interprets &lt; and &gt; sequences
20
 * David McKnight     (IBM)   [287305] [dstore] Need to set proper uid for commands when using SecuredThread and single server for multiple clients[
20
 *******************************************************************************/
21
 *******************************************************************************/
21
22
22
package org.eclipse.rse.internal.dstore.universal.miners.command;
23
package org.eclipse.rse.internal.dstore.universal.miners.command;
Lines 153-159 Link Here
153
				}
154
				}
154
			}
155
			}
155
		} catch (IOException e) {
156
		} catch (IOException e) {
156
			e.printStackTrace();
157
			_commandThread._dataStore.trace(e);
157
		}
158
		}
158
	}
159
	}
159
160
Lines 317-327 Link Here
317
						return output;
318
						return output;
318
					}
319
					}
319
				} catch (Exception e) {
320
				} catch (Exception e) {
320
					e.printStackTrace();
321
					_commandThread._dataStore.trace(e);
321
				}
322
				}
322
			}
323
			}
323
		} catch (Exception e) {
324
		} catch (Exception e) {
324
			e.printStackTrace();
325
			_commandThread._dataStore.trace(e);
325
		}
326
		}
326
		return output;
327
		return output;
327
	}
328
	}

Return to bug 287305