KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > packets > PacketUserauthRequestNone


1 package ch.ethz.ssh2.packets;
2
3 import java.io.IOException JavaDoc;
4
5 /**
6  * PacketUserauthRequestPassword.
7  *
8  * @author Christian Plattner, plattner@inf.ethz.ch
9  * @version $Id: PacketUserauthRequestNone.java,v 1.2 2005/08/24 17:54:08 cplattne Exp $
10  */

11 public class PacketUserauthRequestNone
12 {
13     byte[] payload;
14
15     String JavaDoc userName;
16     String JavaDoc serviceName;
17
18     public PacketUserauthRequestNone(String JavaDoc serviceName, String JavaDoc user)
19     {
20         this.serviceName = serviceName;
21         this.userName = user;
22     }
23
24     public PacketUserauthRequestNone(byte payload[], int off, int len) throws IOException JavaDoc
25     {
26         this.payload = new byte[len];
27         System.arraycopy(payload, off, this.payload, 0, len);
28
29         TypesReader tr = new TypesReader(payload, off, len);
30
31         int packet_type = tr.readByte();
32
33         if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
34             throw new IOException JavaDoc("This is not a SSH_MSG_USERAUTH_REQUEST! (" + packet_type + ")");
35
36         userName = tr.readString();
37         serviceName = tr.readString();
38
39         String JavaDoc method = tr.readString();
40
41         if (method.equals("none") == false)
42             throw new IOException JavaDoc("This is not a SSH_MSG_USERAUTH_REQUEST with type none!");
43
44         if (tr.remain() != 0)
45             throw new IOException JavaDoc("Padding in SSH_MSG_USERAUTH_REQUEST packet!");
46     }
47
48     public byte[] getPayload()
49     {
50         if (payload == null)
51         {
52             TypesWriter tw = new TypesWriter();
53             tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST);
54             tw.writeString(userName);
55             tw.writeString(serviceName);
56             tw.writeString("none");
57             payload = tw.getBytes();
58         }
59         return payload;
60     }
61 }
62
Popular Tags