Debian Codegraph @

contrib/mod_sftp/auth.h

raw symbols SCIP
1 /*
2 * ProFTPD - mod_sftp user authentication (auth)
3 * Copyright (c) 2008-2024 TJ Saunders
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, TJ Saunders and other respective copyright holders
20 * give permission to link this program with OpenSSL, and distribute the
21 * resulting executable, without including the source code for OpenSSL in the
22 * source distribution.
23 */
24
25 #ifndef MOD_SFTP_AUTH_H
26 #define MOD_SFTP_AUTH_H
27
28 #include "mod_sftp.h"
29 #include "packet.h"
30 #include "keys.h"
31
32 #define SFTP_AUTH_FL_METH_PUBLICKEY 0x001
33 #define SFTP_AUTH_FL_METH_KBDINT 0x002
34 #define SFTP_AUTH_FL_METH_PASSWORD 0x004
35 #define SFTP_AUTH_FL_METH_HOSTBASED 0x008
36
37 /* Structures which define a chain of authentication methods; when each method
38 * in a chain has been satisfied, authentication succeeds.
39 */
40 struct sftp_auth_method {
41 unsigned int method_id;
42 const char *method_name;
43
44 /* For e.g. kbdint driver names. */
45 const char *submethod_name;
46
47 /* For use during authentication. */
48 int succeeded, failed;
49 };
50
51 struct sftp_auth_chain {
52 pool *pool;
53 array_header *methods;
54 int completed;
55 };
56
57 struct sftp_auth_chain *sftp_auth_chain_alloc(pool *);
58
59 /* Add a new method to this authentication chain. */
60 int sftp_auth_chain_add_method(struct sftp_auth_chain *, unsigned int,
61 const char *, const char *);
62
63 /* Parse given method name, e.g. "password" or "keyboard-interactive:pam",
64 * into the ID for the method, and the submethod portion (if any).
65 */
66 int sftp_auth_chain_parse_method(pool *p, const char *, unsigned int *,
67 const char **, const char **);
68
69 /* Parse a chain of methods, e.g. "publickey+password", into its component
70 * method names. Returns the list of parsed method names, or NULL on error.
71 */
72 array_header *sftp_auth_chain_parse_method_chain(pool *p, const char *);
73
74 /* Verify that a given auth chain is correct, i.e. no unsupportable
75 * double/repeated methods, etc.
76 */
77 int sftp_auth_chain_isvalid(struct sftp_auth_chain *);
78
79 /* Returns true if the given algorithm name is a valid/supported algorithm
80 * for publickey authentication. If the algorithm is valid/supported, the
81 * corresponding key type will be returned in the optional key_type argument.
82 */
83 int sftp_auth_publickey_isvalid(const char *algo,
84 enum sftp_key_type_e *key_type);
85
86 char *sftp_auth_get_default_dir(void);
87 int sftp_auth_handle(struct ssh2_packet *);
88 int sftp_auth_init(void);
89
90 /* Handles 'hostbased' user authentication. */
91 int sftp_auth_hostbased(struct ssh2_packet *, cmd_rec *,
92 const char *, const char *, const char *, unsigned char **, uint32_t *,
93 int *);
94 int sftp_auth_hostbased_init(pool *);
95
96 /* Handles 'keyboard-interactive' user authentication. */
97 int sftp_auth_kbdint(struct ssh2_packet *, cmd_rec *,
98 const char *, const char *, const char *, unsigned char **, uint32_t *,
99 int *);
100 int sftp_auth_kbdint_init(pool *);
101
102 /* Handles 'password' user authentication. */
103 int sftp_auth_password(struct ssh2_packet *, cmd_rec *,
104 const char *, const char *, const char *, unsigned char **, uint32_t *,
105 int *);
106 int sftp_auth_password_init(pool *);
107
108 /* Handles 'publickey' user authentication. */
109 int sftp_auth_publickey(struct ssh2_packet *, cmd_rec *,
110 const char *, const char *, const char *, unsigned char **, uint32_t *,
111 int *);
112 int sftp_auth_publickey_init(pool *);
113
114 void sftp_auth_set_success_handler(int (*handler)(pool *, const char *));
115 #endif /* MOD_SFTP_AUTH_H */