Tomato 1.28
[tomato.git] / release / src / router / dropbear / auth.h
blob83a2f8ebe164addd28896972df2fccf3a6c4c983
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 _AUTH_H_
26 #define _AUTH_H_
28 #include "includes.h"
29 #include "chansession.h"
31 void svr_authinitialise();
32 void cli_authinitialise();
34 /* Server functions */
35 void recv_msg_userauth_request();
36 void send_msg_userauth_failure(int partial, int incrfail);
37 void send_msg_userauth_success();
38 void svr_auth_password();
39 void svr_auth_pubkey();
40 void svr_auth_pam();
42 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
43 int svr_pubkey_allows_agentfwd();
44 int svr_pubkey_allows_tcpfwd();
45 int svr_pubkey_allows_x11fwd();
46 int svr_pubkey_allows_pty();
47 void svr_pubkey_set_forced_command(struct ChanSess *chansess);
48 void svr_pubkey_options_cleanup();
49 int svr_add_pubkey_options(buffer *options_buf, int line_num, const char* filename);
50 #else
51 /* no option : success */
52 #define svr_pubkey_allows_agentfwd() 1
53 #define svr_pubkey_allows_tcpfwd() 1
54 #define svr_pubkey_allows_x11fwd() 1
55 #define svr_pubkey_allows_pty() 1
56 static inline void svr_pubkey_set_forced_command(struct ChanSess *chansess) { }
57 static inline void svr_pubkey_options_cleanup() { }
58 #define svr_add_pubkey_options(x,y,z) DROPBEAR_SUCCESS
59 #endif
61 /* Client functions */
62 void recv_msg_userauth_failure();
63 void recv_msg_userauth_success();
64 void recv_msg_userauth_specific_60();
65 void recv_msg_userauth_pk_ok();
66 void recv_msg_userauth_info_request();
67 void cli_get_user();
68 void cli_auth_getmethods();
69 void cli_auth_try();
70 void recv_msg_userauth_banner();
71 void cli_pubkeyfail();
72 void cli_auth_password();
73 int cli_auth_pubkey();
74 void cli_auth_interactive();
75 char* getpass_or_cancel(char* prompt);
78 #define MAX_USERNAME_LEN 25 /* arbitrary for the moment */
80 #define AUTH_TYPE_NONE 1
81 #define AUTH_TYPE_PUBKEY 1 << 1
82 #define AUTH_TYPE_PASSWORD 1 << 2
83 #define AUTH_TYPE_INTERACT 1 << 3
85 #define AUTH_METHOD_NONE "none"
86 #define AUTH_METHOD_NONE_LEN 4
87 #define AUTH_METHOD_PUBKEY "publickey"
88 #define AUTH_METHOD_PUBKEY_LEN 9
89 #define AUTH_METHOD_PASSWORD "password"
90 #define AUTH_METHOD_PASSWORD_LEN 8
91 #define AUTH_METHOD_INTERACT "keyboard-interactive"
92 #define AUTH_METHOD_INTERACT_LEN 20
96 /* This structure is shared between server and client - it contains
97 * relatively little extraneous bits when used for the client rather than the
98 * server */
99 struct AuthState {
101 char *username; /* This is the username the client presents to check. It
102 is updated each run through, used for auth checking */
103 unsigned char authtypes; /* Flags indicating which auth types are still
104 valid */
105 unsigned int failcount; /* Number of (failed) authentication attempts.*/
106 unsigned authdone : 1; /* 0 if we haven't authed, 1 if we have. Applies for
107 client and server (though has differing [obvious]
108 meanings). */
109 unsigned perm_warn : 1; /* Server only, set if bad permissions on
110 ~/.ssh/authorized_keys have already been
111 logged. */
113 /* These are only used for the server */
114 uid_t pw_uid;
115 gid_t pw_gid;
116 char *pw_dir;
117 char *pw_shell;
118 char *pw_name;
119 char *pw_passwd;
120 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
121 struct PubKeyOptions* pubkey_options;
122 #endif
126 struct SignKeyList;
127 /* A singly linked list of signing keys */
128 struct SignKeyList {
130 sign_key *key;
131 int type; /* The type of key */
132 struct SignKeyList *next;
133 /* filename? or the buffer? for encrypted keys, so we can later get
134 * the private key portion */
138 #ifdef ENABLE_SVR_PUBKEY_OPTIONS
139 struct PubKeyOptions;
140 struct PubKeyOptions {
141 /* Flags */
142 int no_port_forwarding_flag;
143 int no_agent_forwarding_flag;
144 int no_x11_forwarding_flag;
145 int no_pty_flag;
146 /* "command=" option. */
147 unsigned char * forced_command;
150 #endif
152 #endif /* _AUTH_H_ */