SELINUX設為Disable 影響java SSH工具包Jsch 0.1.49.jar的一個案例

來源:互聯網
上載者:User

標籤:

最近項目中遇到一個典型事件,當RHEL 的SELINUX設為DISABLE時

使用JAVA的Jsch 庫調用SSH命令時將隨機返回Null 字元串,我使用的版本是0.1.49,最新版本0.1.51未測試。

關於Jsch: http://www.jcraft.com/jsch/

為此,我特意寫了一個程式測試:

package com.ibm.leo;import com.ibm.gts.cms.common.guestssh.api.GuestSshServiceFactory;import com.ibm.gts.cms.common.guestssh.api.IGuestSshProperties;import com.ibm.gts.cms.common.guestssh.api.IGuestSshService;import com.ibm.gts.cms.common.guestssh.api.IScriptResponse;public class GuestSSH {    /**     * This code snippet will validate that the guestssh service remove execute will return null randomly  if the selinux was disabled.      * */public static void main(String[] args) {try{int sshRC=-1;if(args.length<3){System.out.println("Usage: java -jar testssh.jar <Host IP> <command> <count>");System.exit(1);}int count=Integer.parseInt(args[2]);if(count==0) count=1;int nullCount=0;System.out.println("start test...");// Run the command via SSHIGuestSshService sshService = GuestSshServiceFactory.GetService();IGuestSshProperties props = sshService.makeGuestSshProperties();props.setConnectTimeout(60000);  //  60 seconds to establish connection with the guestprops.setCommandTimeout(60 * 60 * 1000); // 1 hour to wait for command to complete (after connection)//props.setScriptInputStream(null); // stdin may be null, which is OK and means no stdin datafor(int i=1;i<=count;i++){IScriptResponse response = sshService.invoke("root", args[0], 22, null, args[1], null, props);sshRC = response.getReturnCode();String[] stdoutLines = response.getStandardOutputLines();if(stdoutLines[0].trim().equals("")) nullCount++;System.out.println("Exceute count:"+i+"  returnCode: "+sshRC +" return Lines:"+stdoutLines.length);for (String line : stdoutLines) {System.out.println("Command return: "+line);}}System.out.println("End test, the total execute count is "+count+", and  first line null return count is: " + nullCount);}catch(Exception e){System.out.println(e.getMessage());}}}

 測試結果如下:

D:\tmp>java -jar testssh.jar 192.168.1.244 hostname 5start test...Exceute count:1  returnCode: 0 return Lines:1Command return: GMTDevExceute count:2  returnCode: 0 return Lines:1Command return:Exceute count:3  returnCode: 0 return Lines:1Command return:Exceute count:4  returnCode: 0 return Lines:1Command return:Exceute count:5  returnCode: 0 return Lines:1Command return: GMTDevEnd test, the total execute count is 5, and  first line null return count is: 3

 從結果中可以看出,共取了5次主機名稱,只有兩得到,3次雖然命令成功執行,但返回空值,這種情況只有當SELINUX=disabled時出現,而Enforcing和permissive傳回值都正常。

或許是guestssh的一個BUG? 記錄一下備查。

SELINUX設為Disable 影響java SSH工具包Jsch 0.1.49.jar的一個案例

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.