UserAuthNone.java

Go to the documentation of this file.
00001 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
00002 /*
00003 Copyright (c) 2002-2011 ymnk, JCraft,Inc. All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008   1. Redistributions of source code must retain the above copyright notice,
00009      this list of conditions and the following disclaimer.
00010 
00011   2. Redistributions in binary form must reproduce the above copyright 
00012      notice, this list of conditions and the following disclaimer in 
00013      the documentation and/or other materials provided with the distribution.
00014 
00015   3. The names of the authors may not be used to endorse or promote products
00016      derived from this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
00019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
00021 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
00022 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00024 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00025 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00026 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00027 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 */
00029 
00030 package com.jcraft.jsch;
00031 
00032 class UserAuthNone extends UserAuth{
00033   private static final int SSH_MSG_SERVICE_ACCEPT=                  6;
00034   private String methods=null;
00035 
00036   public boolean start(Session session) throws Exception{
00037     super.start(session);
00038 
00039 
00040     // send
00041     // byte      SSH_MSG_SERVICE_REQUEST(5)
00042     // string    service name "ssh-userauth"
00043     packet.reset();
00044     buf.putByte((byte)Session.SSH_MSG_SERVICE_REQUEST);
00045     buf.putString(Util.str2byte("ssh-userauth"));
00046     session.write(packet);
00047 
00048     if(JSch.getLogger().isEnabled(Logger.INFO)){
00049       JSch.getLogger().log(Logger.INFO, 
00050                            "SSH_MSG_SERVICE_REQUEST sent");
00051     }
00052 
00053     // receive
00054     // byte      SSH_MSG_SERVICE_ACCEPT(6)
00055     // string    service name
00056     buf=session.read(buf);
00057     int command=buf.getCommand();
00058 
00059     boolean result=(command==SSH_MSG_SERVICE_ACCEPT);
00060 
00061     if(JSch.getLogger().isEnabled(Logger.INFO)){
00062       JSch.getLogger().log(Logger.INFO, 
00063                            "SSH_MSG_SERVICE_ACCEPT received");
00064     }
00065     if(!result)
00066       return false;
00067 
00068     byte[] _username=null;
00069     _username=Util.str2byte(username);
00070 
00071     // send
00072     // byte      SSH_MSG_USERAUTH_REQUEST(50)
00073     // string    user name
00074     // string    service name ("ssh-connection")
00075     // string    "none"
00076     packet.reset();
00077     buf.putByte((byte)SSH_MSG_USERAUTH_REQUEST);
00078     buf.putString(_username);
00079     buf.putString(Util.str2byte("ssh-connection"));
00080     buf.putString(Util.str2byte("none"));
00081     session.write(packet);
00082 
00083     loop:
00084     while(true){
00085       buf=session.read(buf);
00086       command=buf.getCommand()&0xff;
00087 
00088       if(command==SSH_MSG_USERAUTH_SUCCESS){
00089     return true;
00090       }
00091       if(command==SSH_MSG_USERAUTH_BANNER){
00092     buf.getInt(); buf.getByte(); buf.getByte();
00093     byte[] _message=buf.getString();
00094     byte[] lang=buf.getString();
00095     String message=Util.byte2str(_message);
00096     if(userinfo!=null){
00097           try{
00098             userinfo.showMessage(message);
00099           }
00100           catch(RuntimeException ee){
00101           }
00102     }
00103     continue loop;
00104       }
00105       if(command==SSH_MSG_USERAUTH_FAILURE){
00106     buf.getInt(); buf.getByte(); buf.getByte(); 
00107     byte[] foo=buf.getString();
00108     int partial_success=buf.getByte();
00109     methods=Util.byte2str(foo);
00110 //System.err.println("UserAuthNONE: "+methods+
00111 //         " partial_success:"+(partial_success!=0));
00112 //  if(partial_success!=0){
00113 //    throw new JSchPartialAuthException(new String(foo));
00114 //  }
00115 
00116         break;
00117       }
00118       else{
00119 //      System.err.println("USERAUTH fail ("+command+")");
00120     throw new JSchException("USERAUTH fail ("+command+")");
00121       }
00122     }
00123    //throw new JSchException("USERAUTH fail");
00124     return false;
00125   }
00126   String getMethods(){
00127     return methods;
00128   }
00129 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1