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