svr-service.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Dropbear - a SSH2 server
  3. *
  4. * Copyright (c) 2002,2003 Matt Johnston
  5. * All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE. */
  24. #include "includes.h"
  25. #include "dbutil.h"
  26. #include "service.h"
  27. #include "session.h"
  28. #include "packet.h"
  29. #include "ssh.h"
  30. #include "auth.h"
  31. static void send_msg_service_accept(const char *name, int len);
  32. /* processes a SSH_MSG_SERVICE_REQUEST, returning 0 if finished,
  33. * 1 if not */
  34. void recv_msg_service_request() {
  35. char * name;
  36. unsigned int len;
  37. TRACE(("enter recv_msg_service_request"))
  38. name = buf_getstring(ses.payload, &len);
  39. /* ssh-userauth */
  40. if (len == SSH_SERVICE_USERAUTH_LEN &&
  41. strncmp(SSH_SERVICE_USERAUTH, name, len) == 0) {
  42. send_msg_service_accept(name, len);
  43. m_free(name);
  44. TRACE(("leave recv_msg_service_request: done ssh-userauth"))
  45. return;
  46. }
  47. /* ssh-connection */
  48. if (len == SSH_SERVICE_CONNECTION_LEN &&
  49. (strncmp(SSH_SERVICE_CONNECTION, name, len) == 0)) {
  50. if (ses.authstate.authdone != 1) {
  51. dropbear_exit("Request for connection before auth");
  52. }
  53. send_msg_service_accept(name, len);
  54. m_free(name);
  55. TRACE(("leave recv_msg_service_request: done ssh-connection"))
  56. return;
  57. }
  58. m_free(name);
  59. /* TODO this should be a MSG_DISCONNECT */
  60. dropbear_exit("Unrecognised SSH_MSG_SERVICE_REQUEST");
  61. }
  62. static void send_msg_service_accept(const char *name, int len) {
  63. TRACE(("accepting service %s", name))
  64. CHECKCLEARTOWRITE();
  65. buf_putbyte(ses.writepayload, SSH_MSG_SERVICE_ACCEPT);
  66. buf_putstring(ses.writepayload, name, len);
  67. encrypt_packet();
  68. }