1 /* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
3 Copyright (c) 2002-2010 ymnk, JCraft,Inc. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the distribution.
15 3. The names of the authors may not be used to endorse or promote products
16 derived from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21 INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 package com.jcraft.jsch;
32 class UserAuthNone extends UserAuth{
33 private static final int SSH_MSG_SERVICE_ACCEPT= 6;
34 private String methods=null;
36 public boolean start(Session session) throws Exception{
41 // byte SSH_MSG_SERVICE_REQUEST(5)
42 // string service name "ssh-userauth"
44 buf.putByte((byte)Session.SSH_MSG_SERVICE_REQUEST);
45 buf.putString(Util.str2byte("ssh-userauth"));
46 session.write(packet);
48 if(JSch.getLogger().isEnabled(Logger.INFO)){
49 JSch.getLogger().log(Logger.INFO,
50 "SSH_MSG_SERVICE_REQUEST sent");
54 // byte SSH_MSG_SERVICE_ACCEPT(6)
55 // string service name
56 buf=session.read(buf);
57 int command=buf.getCommand();
59 boolean result=(command==SSH_MSG_SERVICE_ACCEPT);
61 if(JSch.getLogger().isEnabled(Logger.INFO)){
62 JSch.getLogger().log(Logger.INFO,
63 "SSH_MSG_SERVICE_ACCEPT received");
68 byte[] _username=null;
69 _username=Util.str2byte(username);
72 // byte SSH_MSG_USERAUTH_REQUEST(50)
74 // string service name ("ssh-connection")
77 buf.putByte((byte)SSH_MSG_USERAUTH_REQUEST);
78 buf.putString(_username);
79 buf.putString(Util.str2byte("ssh-connection"));
80 buf.putString(Util.str2byte("none"));
81 session.write(packet);
85 buf=session.read(buf);
86 command=buf.getCommand()&0xff;
88 if(command==SSH_MSG_USERAUTH_SUCCESS){
91 if(command==SSH_MSG_USERAUTH_BANNER){
92 buf.getInt(); buf.getByte(); buf.getByte();
93 byte[] _message=buf.getString();
94 byte[] lang=buf.getString();
95 String message=Util.byte2str(_message);
98 userinfo.showMessage(message);
100 catch(RuntimeException ee){
105 if(command==SSH_MSG_USERAUTH_FAILURE){
106 buf.getInt(); buf.getByte(); buf.getByte();
107 byte[] foo=buf.getString();
108 int partial_success=buf.getByte();
109 methods=Util.byte2str(foo);
110 //System.err.println("UserAuthNONE: "+methods+
111 // " partial_success:"+(partial_success!=0));
112 // if(partial_success!=0){
113 // throw new JSchPartialAuthException(new String(foo));
119 // System.err.println("USERAUTH fail ("+command+")");
120 throw new JSchException("USERAUTH fail ("+command+")");
123 //throw new JSchException("USERAUTH fail");