auth.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* $OpenBSD: auth.h,v 1.100 2019/09/06 05:23:55 djm Exp $ */
  2. /*
  3. * Copyright (c) 2000 Markus Friedl. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. *
  25. */
  26. #ifndef AUTH_H
  27. #define AUTH_H
  28. #include <signal.h>
  29. #ifdef HAVE_LOGIN_CAP
  30. #include <login_cap.h>
  31. #endif
  32. #ifdef BSD_AUTH
  33. #include <bsd_auth.h>
  34. #endif
  35. #ifdef KRB5
  36. #include <krb5.h>
  37. #endif
  38. struct passwd;
  39. struct ssh;
  40. struct sshbuf;
  41. struct sshkey;
  42. struct sshauthopt;
  43. typedef struct Authctxt Authctxt;
  44. typedef struct Authmethod Authmethod;
  45. typedef struct KbdintDevice KbdintDevice;
  46. struct Authctxt {
  47. sig_atomic_t success;
  48. int authenticated; /* authenticated and alarms cancelled */
  49. int postponed; /* authentication needs another step */
  50. int valid; /* user exists and is allowed to login */
  51. int attempt;
  52. int failures;
  53. int server_caused_failure;
  54. int force_pwchange;
  55. char *user; /* username sent by the client */
  56. char *service;
  57. struct passwd *pw; /* set if 'valid' */
  58. char *style;
  59. #ifdef WITH_SELINUX
  60. char *role;
  61. #endif
  62. /* Method lists for multiple authentication */
  63. char **auth_methods; /* modified from server config */
  64. u_int num_auth_methods;
  65. /* Authentication method-specific data */
  66. void *methoddata;
  67. void *kbdintctxt;
  68. #ifdef BSD_AUTH
  69. auth_session_t *as;
  70. #endif
  71. #ifdef KRB5
  72. krb5_context krb5_ctx;
  73. krb5_ccache krb5_fwd_ccache;
  74. krb5_principal krb5_user;
  75. char *krb5_ticket_file;
  76. char *krb5_ccname;
  77. #endif
  78. struct sshbuf *loginmsg;
  79. /* Authentication keys already used; these will be refused henceforth */
  80. struct sshkey **prev_keys;
  81. u_int nprev_keys;
  82. /* Last used key and ancillary information from active auth method */
  83. struct sshkey *auth_method_key;
  84. char *auth_method_info;
  85. /* Information exposed to session */
  86. struct sshbuf *session_info; /* Auth info for environment */
  87. };
  88. /*
  89. * Every authentication method has to handle authentication requests for
  90. * non-existing users, or for users that are not allowed to login. In this
  91. * case 'valid' is set to 0, but 'user' points to the username requested by
  92. * the client.
  93. */
  94. struct Authmethod {
  95. char *name;
  96. int (*userauth)(struct ssh *);
  97. int *enabled;
  98. };
  99. /*
  100. * Keyboard interactive device:
  101. * init_ctx returns: non NULL upon success
  102. * query returns: 0 - success, otherwise failure
  103. * respond returns: 0 - success, 1 - need further interaction,
  104. * otherwise - failure
  105. */
  106. struct KbdintDevice
  107. {
  108. const char *name;
  109. void* (*init_ctx)(Authctxt*);
  110. int (*query)(void *ctx, char **name, char **infotxt,
  111. u_int *numprompts, char ***prompts, u_int **echo_on);
  112. int (*respond)(void *ctx, u_int numresp, char **responses);
  113. void (*free_ctx)(void *ctx);
  114. };
  115. int
  116. auth_rhosts2(struct passwd *, const char *, const char *, const char *);
  117. int auth_password(struct ssh *, const char *);
  118. int hostbased_key_allowed(struct ssh *, struct passwd *,
  119. const char *, char *, struct sshkey *);
  120. int user_key_allowed(struct ssh *, struct passwd *, struct sshkey *, int,
  121. struct sshauthopt **);
  122. int auth2_key_already_used(Authctxt *, const struct sshkey *);
  123. /*
  124. * Handling auth method-specific information for logging and prevention
  125. * of key reuse during multiple authentication.
  126. */
  127. void auth2_authctxt_reset_info(Authctxt *);
  128. void auth2_record_key(Authctxt *, int, const struct sshkey *);
  129. void auth2_record_info(Authctxt *authctxt, const char *, ...)
  130. __attribute__((__format__ (printf, 2, 3)))
  131. __attribute__((__nonnull__ (2)));
  132. void auth2_update_session_info(Authctxt *, const char *, const char *);
  133. #ifdef KRB5
  134. int auth_krb5(Authctxt *authctxt, krb5_data *auth, char **client, krb5_data *);
  135. int auth_krb5_tgt(Authctxt *authctxt, krb5_data *tgt);
  136. int auth_krb5_password(Authctxt *authctxt, const char *password);
  137. void krb5_cleanup_proc(Authctxt *authctxt);
  138. #endif /* KRB5 */
  139. #if defined(USE_SHADOW) && defined(HAS_SHADOW_EXPIRE)
  140. #include <shadow.h>
  141. int auth_shadow_acctexpired(struct spwd *);
  142. int auth_shadow_pwexpired(Authctxt *);
  143. #endif
  144. #include "auth-pam.h"
  145. #include "audit.h"
  146. void remove_kbdint_device(const char *);
  147. void do_authentication2(struct ssh *);
  148. void auth_log(struct ssh *, int, int, const char *, const char *);
  149. void auth_maxtries_exceeded(struct ssh *) __attribute__((noreturn));
  150. void userauth_finish(struct ssh *, int, const char *, const char *);
  151. int auth_root_allowed(struct ssh *, const char *);
  152. char *auth2_read_banner(void);
  153. int auth2_methods_valid(const char *, int);
  154. int auth2_update_methods_lists(Authctxt *, const char *, const char *);
  155. int auth2_setup_methods_lists(Authctxt *);
  156. int auth2_method_allowed(Authctxt *, const char *, const char *);
  157. void privsep_challenge_enable(void);
  158. int auth2_challenge(struct ssh *, char *);
  159. void auth2_challenge_stop(struct ssh *);
  160. int bsdauth_query(void *, char **, char **, u_int *, char ***, u_int **);
  161. int bsdauth_respond(void *, u_int, char **);
  162. int allowed_user(struct ssh *, struct passwd *);
  163. struct passwd * getpwnamallow(struct ssh *, const char *user);
  164. char *expand_authorized_keys(const char *, struct passwd *pw);
  165. char *authorized_principals_file(struct passwd *);
  166. int user_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
  167. const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
  168. FILE *auth_openkeyfile(const char *, struct passwd *, int);
  169. FILE *auth_openprincipals(const char *, struct passwd *, int);
  170. int auth_key_is_revoked(struct sshkey *);
  171. const char *auth_get_canonical_hostname(struct ssh *, int);
  172. HostStatus
  173. check_key_in_hostfiles(struct passwd *, struct sshkey *, const char *,
  174. const char *, const char *);
  175. /* hostkey handling */
  176. struct sshkey *get_hostkey_by_index(int);
  177. struct sshkey *get_hostkey_public_by_index(int, struct ssh *);
  178. struct sshkey *get_hostkey_public_by_type(int, int, struct ssh *);
  179. struct sshkey *get_hostkey_private_by_type(int, int, struct ssh *);
  180. int get_hostkey_index(struct sshkey *, int, struct ssh *);
  181. int sshd_hostkey_sign(struct ssh *, struct sshkey *, struct sshkey *,
  182. u_char **, size_t *, const u_char *, size_t, const char *);
  183. int hostbased_key_verify(struct ssh *, const struct sshkey *, const u_char *, size_t,
  184. const u_char *, size_t, const char *, u_int, struct sshkey_sig_details **);
  185. /* Key / cert options linkage to auth layer */
  186. const struct sshauthopt *auth_options(struct ssh *);
  187. int auth_activate_options(struct ssh *, struct sshauthopt *);
  188. void auth_restrict_session(struct ssh *);
  189. int auth_authorise_keyopts(struct ssh *, struct passwd *pw,
  190. struct sshauthopt *, int, const char *);
  191. void auth_log_authopts(const char *, const struct sshauthopt *, int);
  192. /* debug messages during authentication */
  193. void auth_debug_add(const char *fmt,...)
  194. __attribute__((format(printf, 1, 2)));
  195. void auth_debug_send(struct ssh *);
  196. void auth_debug_reset(void);
  197. struct passwd *fakepw(void);
  198. int sys_auth_passwd(struct ssh *, const char *);
  199. #if defined(KRB5) && !defined(HEIMDAL)
  200. krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
  201. #endif
  202. #endif /* AUTH_H */