Home | History | Annotate | Download | only in dropbear
      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:
     14  *
     15  * The above copyright notice and this permission notice shall be included in
     16  * all copies or substantial portions of the Software.
     17  *
     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. */
     25 
     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"
     33 
     34 void send_msg_service_request(char* servicename) {
     35 
     36 	TRACE(("enter send_msg_service_request: servicename='%s'", servicename))
     37 
     38 	CHECKCLEARTOWRITE();
     39 
     40 	buf_putbyte(ses.writepayload, SSH_MSG_SERVICE_REQUEST);
     41 	buf_putstring(ses.writepayload, servicename, strlen(servicename));
     42 
     43 	encrypt_packet();
     44 	TRACE(("leave send_msg_service_request"))
     45 }
     46 
     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() {
     50 
     51 	unsigned char* servicename;
     52 	unsigned int len;
     53 
     54 	TRACE(("enter recv_msg_service_accept"))
     55 
     56 	servicename = buf_getstring(ses.payload, &len);
     57 
     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) {
     62 
     63 		cli_ses.state = SERVICE_AUTH_ACCEPT_RCVD;
     64 		m_free(servicename);
     65 		TRACE(("leave recv_msg_service_accept: done ssh-userauth"))
     66 		return;
     67 	}
     68 
     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) {
     73 
     74 		if (ses.authstate.authdone != 1) {
     75 			dropbear_exit("request for connection before auth");
     76 		}
     77 
     78 		cli_ses.state = SERVICE_CONN_ACCEPT_RCVD;
     79 		m_free(servicename);
     80 		TRACE(("leave recv_msg_service_accept: done ssh-connection"))
     81 		return;
     82 	}
     83 
     84 	dropbear_exit("unrecognised service accept");
     85 }
     86