auth.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifndef DROPBEAR_AUTH_H_
  25. #define DROPBEAR_AUTH_H_
  26. #include "includes.h"
  27. #include "signkey.h"
  28. #include "chansession.h"
  29. void svr_authinitialise(void);
  30. /* Server functions */
  31. void recv_msg_userauth_request(void);
  32. void send_msg_userauth_failure(int partial, int incrfail);
  33. void send_msg_userauth_success(void);
  34. void send_msg_userauth_banner(const buffer *msg);
  35. void svr_auth_password(int valid_user);
  36. void svr_auth_pubkey(int valid_user);
  37. void svr_auth_pam(int valid_user);
  38. #if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
  39. int svr_pubkey_allows_agentfwd(void);
  40. int svr_pubkey_allows_tcpfwd(void);
  41. int svr_pubkey_allows_x11fwd(void);
  42. int svr_pubkey_allows_pty(void);
  43. void svr_pubkey_set_forced_command(struct ChanSess *chansess);
  44. void svr_pubkey_options_cleanup(void);
  45. int svr_add_pubkey_options(buffer *options_buf, int line_num, const char* filename);
  46. #else
  47. /* no option : success */
  48. #define svr_pubkey_allows_agentfwd() 1
  49. #define svr_pubkey_allows_tcpfwd() 1
  50. #define svr_pubkey_allows_x11fwd() 1
  51. #define svr_pubkey_allows_pty() 1
  52. static inline void svr_pubkey_set_forced_command(struct ChanSess *chansess) { }
  53. static inline void svr_pubkey_options_cleanup(void) { }
  54. #define svr_add_pubkey_options(x,y,z) DROPBEAR_SUCCESS
  55. #endif
  56. /* Client functions */
  57. void recv_msg_userauth_failure(void);
  58. void recv_msg_userauth_success(void);
  59. void recv_msg_userauth_specific_60(void);
  60. void recv_msg_userauth_pk_ok(void);
  61. void recv_msg_userauth_info_request(void);
  62. void cli_get_user(void);
  63. void cli_auth_getmethods(void);
  64. int cli_auth_try(void);
  65. void recv_msg_userauth_banner(void);
  66. void cli_pubkeyfail(void);
  67. void cli_auth_password(void);
  68. int cli_auth_pubkey(void);
  69. void cli_auth_interactive(void);
  70. char* getpass_or_cancel(const char* prompt);
  71. void cli_auth_pubkey_cleanup(void);
  72. #define MAX_USERNAME_LEN 100 /* arbitrary for the moment */
  73. #define AUTH_TYPE_NONE 1
  74. #define AUTH_TYPE_PUBKEY (1 << 1)
  75. #define AUTH_TYPE_PASSWORD (1 << 2)
  76. #define AUTH_TYPE_INTERACT (1 << 3)
  77. #define AUTH_METHOD_NONE "none"
  78. #define AUTH_METHOD_NONE_LEN 4
  79. #define AUTH_METHOD_PUBKEY "publickey"
  80. #define AUTH_METHOD_PUBKEY_LEN 9
  81. #define AUTH_METHOD_PASSWORD "password"
  82. #define AUTH_METHOD_PASSWORD_LEN 8
  83. #define AUTH_METHOD_INTERACT "keyboard-interactive"
  84. #define AUTH_METHOD_INTERACT_LEN 20
  85. /* This structure is shared between server and client - it contains
  86. * relatively little extraneous bits when used for the client rather than the
  87. * server */
  88. struct AuthState {
  89. char *username; /* This is the username the client presents to check. It
  90. is updated each run through, used for auth checking */
  91. unsigned char authtypes; /* Flags indicating which auth types are still
  92. valid */
  93. unsigned int failcount; /* Number of (failed) authentication attempts.*/
  94. unsigned int authdone; /* 0 if we haven't authed, 1 if we have. Applies for
  95. client and server (though has differing
  96. meanings). */
  97. unsigned int perm_warn; /* Server only, set if bad permissions on
  98. ~/.ssh/authorized_keys have already been
  99. logged. */
  100. unsigned int checkusername_failed; /* Server only, set if checkusername
  101. has already failed */
  102. struct timespec auth_starttime; /* Server only, time of receiving current
  103. SSH_MSG_USERAUTH_REQUEST */
  104. /* These are only used for the server */
  105. uid_t pw_uid;
  106. gid_t pw_gid;
  107. char *pw_dir;
  108. char *pw_shell;
  109. char *pw_name;
  110. char *pw_passwd;
  111. #if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
  112. struct PubKeyOptions* pubkey_options;
  113. char *pubkey_info;
  114. #endif
  115. };
  116. #if DROPBEAR_SVR_PUBKEY_OPTIONS_BUILT
  117. struct PubKeyOptions;
  118. struct PubKeyOptions {
  119. /* Flags */
  120. int no_port_forwarding_flag;
  121. int no_agent_forwarding_flag;
  122. int no_x11_forwarding_flag;
  123. int no_pty_flag;
  124. /* "command=" option. */
  125. char * forced_command;
  126. };
  127. #endif
  128. #endif /* DROPBEAR_AUTH_H_ */