]> Joshua Wise's Git repositories - dumload.git/blame_incremental - src/com/jcraft/jsch/UserAuthNone.java
Fix port usage and always try to add the generated key
[dumload.git] / src / com / jcraft / jsch / UserAuthNone.java
... / ...
CommitLineData
1/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
2/*
3Copyright (c) 2002-2010 ymnk, JCraft,Inc. All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10
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.
14
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.
17
18THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
19INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
21INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
22INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30package com.jcraft.jsch;
31
32class UserAuthNone extends UserAuth{
33 private static final int SSH_MSG_SERVICE_ACCEPT= 6;
34 private String methods=null;
35
36 public boolean start(Session session) throws Exception{
37 super.start(session);
38
39
40 // send
41 // byte SSH_MSG_SERVICE_REQUEST(5)
42 // string service name "ssh-userauth"
43 packet.reset();
44 buf.putByte((byte)Session.SSH_MSG_SERVICE_REQUEST);
45 buf.putString(Util.str2byte("ssh-userauth"));
46 session.write(packet);
47
48 if(JSch.getLogger().isEnabled(Logger.INFO)){
49 JSch.getLogger().log(Logger.INFO,
50 "SSH_MSG_SERVICE_REQUEST sent");
51 }
52
53 // receive
54 // byte SSH_MSG_SERVICE_ACCEPT(6)
55 // string service name
56 buf=session.read(buf);
57 int command=buf.getCommand();
58
59 boolean result=(command==SSH_MSG_SERVICE_ACCEPT);
60
61 if(JSch.getLogger().isEnabled(Logger.INFO)){
62 JSch.getLogger().log(Logger.INFO,
63 "SSH_MSG_SERVICE_ACCEPT received");
64 }
65 if(!result)
66 return false;
67
68 byte[] _username=null;
69 _username=Util.str2byte(username);
70
71 // send
72 // byte SSH_MSG_USERAUTH_REQUEST(50)
73 // string user name
74 // string service name ("ssh-connection")
75 // string "none"
76 packet.reset();
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);
82
83 loop:
84 while(true){
85 buf=session.read(buf);
86 command=buf.getCommand()&0xff;
87
88 if(command==SSH_MSG_USERAUTH_SUCCESS){
89 return true;
90 }
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);
96 if(userinfo!=null){
97 try{
98 userinfo.showMessage(message);
99 }
100 catch(RuntimeException ee){
101 }
102 }
103 continue loop;
104 }
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));
114// }
115
116 break;
117 }
118 else{
119// System.err.println("USERAUTH fail ("+command+")");
120 throw new JSchException("USERAUTH fail ("+command+")");
121 }
122 }
123 //throw new JSchException("USERAUTH fail");
124 return false;
125 }
126 String getMethods(){
127 return methods;
128 }
129}
This page took 0.027833 seconds and 4 git commands to generate.