auth.h 4.6 KB

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