OLD | NEW |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ssh | 5 package ssh |
6 | 6 |
7 // Session implements an interactive session described in | 7 // Session implements an interactive session described in |
8 // "RFC 4254, section 6". | 8 // "RFC 4254, section 6". |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 Request: "subsystem", | 218 Request: "subsystem", |
219 WantReply: true, | 219 WantReply: true, |
220 Subsystem: subsystem, | 220 Subsystem: subsystem, |
221 } | 221 } |
222 if err := s.writePacket(marshal(msgChannelRequest, req)); err != nil { | 222 if err := s.writePacket(marshal(msgChannelRequest, req)); err != nil { |
223 return err | 223 return err |
224 } | 224 } |
225 return s.waitForResponse() | 225 return s.waitForResponse() |
226 } | 226 } |
227 | 227 |
| 228 func (s *Session) issueAgentRequest() error { |
| 229 req := channelRequestMsg{ |
| 230 PeersId: s.remoteId, |
| 231 Request: "auth-agent-req@openssh.com", |
| 232 WantReply: false, |
| 233 } |
| 234 if err := s.writePacket(marshal(msgChannelRequest, req)); err != nil { |
| 235 return err |
| 236 } |
| 237 return nil |
| 238 } |
| 239 |
228 // RFC 4254 Section 6.9. | 240 // RFC 4254 Section 6.9. |
229 type signalMsg struct { | 241 type signalMsg struct { |
230 PeersId uint32 | 242 PeersId uint32 |
231 Request string | 243 Request string |
232 WantReply bool | 244 WantReply bool |
233 Signal string | 245 Signal string |
234 } | 246 } |
235 | 247 |
236 // Signal sends the given signal to the remote process. | 248 // Signal sends the given signal to the remote process. |
237 // sig is one of the SIG* constants. | 249 // sig is one of the SIG* constants. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 353 } |
342 req := channelRequestMsg{ | 354 req := channelRequestMsg{ |
343 PeersId: s.remoteId, | 355 PeersId: s.remoteId, |
344 Request: "shell", | 356 Request: "shell", |
345 WantReply: true, | 357 WantReply: true, |
346 } | 358 } |
347 if err := s.writePacket(marshal(msgChannelRequest, req)); err != nil { | 359 if err := s.writePacket(marshal(msgChannelRequest, req)); err != nil { |
348 return err | 360 return err |
349 } | 361 } |
350 if err := s.waitForResponse(); err != nil { | 362 if err := s.waitForResponse(); err != nil { |
351 » » return fmt.Errorf("ssh: cound not execute shell: %v", err) | 363 » » return fmt.Errorf("ssh: could not execute shell: %v", err) |
352 } | 364 } |
353 return s.start() | 365 return s.start() |
354 } | 366 } |
355 | 367 |
356 func (s *Session) waitForResponse() error { | 368 func (s *Session) waitForResponse() error { |
357 msg := <-s.msg | 369 msg := <-s.msg |
358 switch msg.(type) { | 370 switch msg.(type) { |
359 case *channelRequestSuccessMsg: | 371 case *channelRequestSuccessMsg: |
360 return nil | 372 return nil |
361 case *channelRequestFailureMsg: | 373 case *channelRequestFailureMsg: |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 PeersWindow: 1 << 14, | 582 PeersWindow: 1 << 14, |
571 MaxPacketSize: 1 << 15, // RFC 4253 6.1 | 583 MaxPacketSize: 1 << 15, // RFC 4253 6.1 |
572 })); err != nil { | 584 })); err != nil { |
573 c.chanList.remove(ch.localId) | 585 c.chanList.remove(ch.localId) |
574 return nil, err | 586 return nil, err |
575 } | 587 } |
576 if err := ch.waitForChannelOpenResponse(); err != nil { | 588 if err := ch.waitForChannelOpenResponse(); err != nil { |
577 c.chanList.remove(ch.localId) | 589 c.chanList.remove(ch.localId) |
578 return nil, fmt.Errorf("ssh: unable to open session: %v", err) | 590 return nil, fmt.Errorf("ssh: unable to open session: %v", err) |
579 } | 591 } |
580 » return &Session{ | 592 » s := &Session{ |
581 clientChan: ch, | 593 clientChan: ch, |
582 » }, nil | 594 » } |
| 595 » if c.config.ForwardingAgentDialer != nil { |
| 596 » » err := s.issueAgentRequest() |
| 597 » » if err != nil { |
| 598 » » » return nil, fmt.Errorf("ssh: unable to request agent for
warding: %v", err) |
| 599 » » } |
| 600 » } |
| 601 » return s, nil |
583 } | 602 } |
584 | 603 |
585 // An ExitError reports unsuccessful completion of a remote command. | 604 // An ExitError reports unsuccessful completion of a remote command. |
586 type ExitError struct { | 605 type ExitError struct { |
587 Waitmsg | 606 Waitmsg |
588 } | 607 } |
589 | 608 |
590 func (e *ExitError) Error() string { | 609 func (e *ExitError) Error() string { |
591 return e.Waitmsg.String() | 610 return e.Waitmsg.String() |
592 } | 611 } |
(...skipping 24 matching lines...) Expand all Loading... |
617 } | 636 } |
618 | 637 |
619 // Lang returns the language tag. See RFC 3066 | 638 // Lang returns the language tag. See RFC 3066 |
620 func (w Waitmsg) Lang() string { | 639 func (w Waitmsg) Lang() string { |
621 return w.lang | 640 return w.lang |
622 } | 641 } |
623 | 642 |
624 func (w Waitmsg) String() string { | 643 func (w Waitmsg) String() string { |
625 return fmt.Sprintf("Process exited with: %v. Reason was: %v (%v)", w.sta
tus, w.msg, w.signal) | 644 return fmt.Sprintf("Process exited with: %v. Reason was: %v (%v)", w.sta
tus, w.msg, w.signal) |
626 } | 645 } |
OLD | NEW |