usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / dropbear / cli-service.c
blobf7631039b5df50986c6bc9db8570b2dcf572e5cc
1 /*
2 * Dropbear SSH
3 *
4 * Copyright (c) 2002,2003 Matt Johnston
5 * Copyright (c) 2004 by Mihnea Stoenescu
6 * All rights reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE. */
26 #include "includes.h"
27 #include "service.h"
28 #include "dbutil.h"
29 #include "packet.h"
30 #include "buffer.h"
31 #include "session.h"
32 #include "ssh.h"
34 void send_msg_service_request(char* servicename) {
36 TRACE(("enter send_msg_service_request: servicename='%s'", servicename))
38 CHECKCLEARTOWRITE();
40 buf_putbyte(ses.writepayload, SSH_MSG_SERVICE_REQUEST);
41 buf_putstring(ses.writepayload, servicename, strlen(servicename));
43 encrypt_packet();
44 TRACE(("leave send_msg_service_request"))
47 /* This just sets up the state variables right for the main client session loop
48 * to deal with */
49 void recv_msg_service_accept() {
51 unsigned char* servicename;
52 unsigned int len;
54 TRACE(("enter recv_msg_service_accept"))
56 servicename = buf_getstring(ses.payload, &len);
58 /* ssh-userauth */
59 if (cli_ses.state == SERVICE_AUTH_REQ_SENT
60 && len == SSH_SERVICE_USERAUTH_LEN
61 && strncmp(SSH_SERVICE_USERAUTH, servicename, len) == 0) {
63 cli_ses.state = SERVICE_AUTH_ACCEPT_RCVD;
64 m_free(servicename);
65 TRACE(("leave recv_msg_service_accept: done ssh-userauth"))
66 return;
69 /* ssh-connection */
70 if (cli_ses.state == SERVICE_CONN_REQ_SENT
71 && len == SSH_SERVICE_CONNECTION_LEN
72 && strncmp(SSH_SERVICE_CONNECTION, servicename, len) == 0) {
74 if (ses.authstate.authdone != 1) {
75 dropbear_exit("Request for connection before auth");
78 cli_ses.state = SERVICE_CONN_ACCEPT_RCVD;
79 m_free(servicename);
80 TRACE(("leave recv_msg_service_accept: done ssh-connection"))
81 return;
84 dropbear_exit("Unrecognised service accept");