01: package ch.ethz.ssh2.packets;
02:
03: import java.io.IOException;
04:
05: /**
06: * PacketUserauthRequestPassword.
07: *
08: * @author Christian Plattner, plattner@inf.ethz.ch
09: * @version $Id: PacketUserauthRequestNone.java,v 1.2 2005/08/24 17:54:08 cplattne Exp $
10: */
11: public class PacketUserauthRequestNone {
12: byte[] payload;
13:
14: String userName;
15: String serviceName;
16:
17: public PacketUserauthRequestNone(String serviceName, String user) {
18: this .serviceName = serviceName;
19: this .userName = user;
20: }
21:
22: public PacketUserauthRequestNone(byte payload[], int off, int len)
23: throws IOException {
24: this .payload = new byte[len];
25: System.arraycopy(payload, off, this .payload, 0, len);
26:
27: TypesReader tr = new TypesReader(payload, off, len);
28:
29: int packet_type = tr.readByte();
30:
31: if (packet_type != Packets.SSH_MSG_USERAUTH_REQUEST)
32: throw new IOException(
33: "This is not a SSH_MSG_USERAUTH_REQUEST! ("
34: + packet_type + ")");
35:
36: userName = tr.readString();
37: serviceName = tr.readString();
38:
39: String method = tr.readString();
40:
41: if (method.equals("none") == false)
42: throw new IOException(
43: "This is not a SSH_MSG_USERAUTH_REQUEST with type none!");
44:
45: if (tr.remain() != 0)
46: throw new IOException(
47: "Padding in SSH_MSG_USERAUTH_REQUEST packet!");
48: }
49:
50: public byte[] getPayload() {
51: if (payload == null) {
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: }
|