diff options
author | Eivind Næss <eivnaes@yahoo.com> | 2023-01-20 22:12:58 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-21 17:12:58 +1100 |
commit | ba7f7e053daae846a54a1d08d3d133a5f1266ace (patch) | |
tree | 3da27cf3ca6d6eb76e3f9a05db4c5676591d5002 /pppd/chap.h | |
parent | 76016e1b948b7d9675b4e0750d1f943d96d9523b (diff) | |
download | ppp-ba7f7e053daae846a54a1d08d3d133a5f1266ace.tar.gz |
Header file reorganization and cleaning up the public API for pppd version 2.5.0 (#379)
This commit does several things, being a squash-and-merge of a series
of changes; squashed in order not to break bisection.
* Clean up pppd.h, moving declarations that should only be accessed by
pppd code (not by users of pppd) to a new pppd-private.h. Also,
other parts of pppd.h were moved to multilink.h, chap.h, eap.h,
eui64.h, and a new options.h.
* Provide an API for access to data that is needed by plugins (in no
particular order):
- ifname
- ifunit
- remote_name
- remote_number
- peer_authname
- status (now called "code" internally)
- phase
- doing_multilink
- multilink_master
- idle_time_limit
- link_connect_time
- max_connect_time
- link_stats
- ipparam
- hostname
- got_sigterm
- got_sigusr2
- got_sighup
- session_number
- maxoctets
- maxoctets_dir
- debug
- persist
- devnam
- modem
- peer_authname
- sync_serial
* Update the version number to 2.5.0.
* Detect availability of stddef.h and stdarg.h.
* Rename some headers:
- pppcrypt.c/h to crypto_ms.c/h
- ppp-crypto.c/h to crypto.c/h
- ppp-crypto-priv.h to crypto-priv.h
- chap-new.c/h to chap.c/h
* Remove chap-md5.h, crypto-priv.h, eap-tls.h, etc. from the list of
header files to be installed.
* Provide typedefs for the hook functions.
* Provide a typedef for the "phase" variable.
* Provide a typedef for the link statistics array.
* Remove the option_t typedef.
* Rename the following functions by adding a "ppp_" prefix (with the
intention that these are a "public" API for use by plugins):
- option_error
- add_options
- int_option,
- options_from_file
- script_setenv
- bad_ip_adrs,
- netif_get/set_mtu (renamed to ppp_get/set_mtu)
- get_time
- timeout
- untimeout
- safe_fork
- sys_close
- set_session_number
- update_link_stats (renamed to ppp_get_link_stats)
- add_notifier (renamed to ppp_add_notify)
- remove_notifier (renamed to ppp_del_notify)
- generic_[dis]establish_ppp (to ppp_generic_[dis]establish)
* Rename ppp_devnam to ppp_devname.
* Rename ppp_available() to ppp_check_kernel_support().
* Use unsigned char instead of u_char, unsigned short instead of
u_short, uint32_t instead of u_int32_t.
* Add const to some declarations
* Update comments
* Change the interface for notifiers to use an enum to identify which
notifier is to be modified.
* Provide an API for getting the path to a file, with an enum to
identify different types of file.
* Link plugins with the -DPLUGIN flag
[paulus@ozlabs.org - wrote commit message]
Signed-off-by: Eivind Næss <eivnaes@yahoo.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Diffstat (limited to 'pppd/chap.h')
-rw-r--r-- | pppd/chap.h | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/pppd/chap.h b/pppd/chap.h new file mode 100644 index 0000000..e693fc9 --- /dev/null +++ b/pppd/chap.h @@ -0,0 +1,168 @@ +/* + * chap-new.c - New CHAP implementation. + * + * Copyright (c) 2003 Paul Mackerras. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 3. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * <paulus@samba.org>". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef PPP_CHAP_NEW_H +#define PPP_CHAP_NEW_H + +#include "pppdconf.h" + +/* + * CHAP packets begin with a standard header with code, id, len (2 bytes). + */ +#define CHAP_HDRLEN 4 + +/* + * Values for the code field. + */ +#define CHAP_CHALLENGE 1 +#define CHAP_RESPONSE 2 +#define CHAP_SUCCESS 3 +#define CHAP_FAILURE 4 + +/* + * CHAP digest codes. + */ +#define CHAP_MD5 5 +#define CHAP_MICROSOFT 0x80 +#define CHAP_MICROSOFT_V2 0x81 + +/* + * Semi-arbitrary limits on challenge and response fields. + */ +#define MAX_CHALLENGE_LEN 64 +#define MAX_RESPONSE_LEN 64 + +/* bitmask of supported algorithms */ +#define MDTYPE_MICROSOFT_V2 0x1 +#define MDTYPE_MICROSOFT 0x2 +#define MDTYPE_MD5 0x4 +#define MDTYPE_NONE 0 + +/* hashes supported by this instance of pppd */ +extern int chap_mdtype_all; + +/* Return the digest alg. ID for the most preferred digest type. */ +#define CHAP_DIGEST(mdtype) \ + ((mdtype) & MDTYPE_MD5)? CHAP_MD5: \ + ((mdtype) & MDTYPE_MICROSOFT_V2)? CHAP_MICROSOFT_V2: \ + ((mdtype) & MDTYPE_MICROSOFT)? CHAP_MICROSOFT: \ + 0 + +/* Return the bit flag (lsb set) for our most preferred digest type. */ +#define CHAP_MDTYPE(mdtype) ((mdtype) ^ ((mdtype) - 1)) & (mdtype) + +/* Return the bit flag for a given digest algorithm ID. */ +#define CHAP_MDTYPE_D(digest) \ + ((digest) == CHAP_MICROSOFT_V2)? MDTYPE_MICROSOFT_V2: \ + ((digest) == CHAP_MICROSOFT)? MDTYPE_MICROSOFT: \ + ((digest) == CHAP_MD5)? MDTYPE_MD5: \ + 0 + +/* Can we do the requested digest? */ +#define CHAP_CANDIGEST(mdtype, digest) \ + ((digest) == CHAP_MICROSOFT_V2)? (mdtype) & MDTYPE_MICROSOFT_V2: \ + ((digest) == CHAP_MICROSOFT)? (mdtype) & MDTYPE_MICROSOFT: \ + ((digest) == CHAP_MD5)? (mdtype) & MDTYPE_MD5: \ + 0 + + +/* + * The code for each digest type has to supply one of these. + */ +struct chap_digest_type { + int code; + + /* + * Note: challenge and response arguments below are formatted as + * a length byte followed by the actual challenge/response data. + */ + void (*generate_challenge)(unsigned char *challenge); + int (*verify_response)(int id, char *name, + unsigned char *secret, int secret_len, + unsigned char *challenge, unsigned char *response, + char *message, int message_space); + void (*make_response)(unsigned char *response, int id, char *our_name, + unsigned char *challenge, char *secret, int secret_len, + unsigned char *priv); + int (*check_success)(int id, unsigned char *pkt, int len); + void (*handle_failure)(unsigned char *pkt, int len); + + struct chap_digest_type *next; +}; + +/* + * This function will return a value of 1 to indicate that a plugin intend to supply + * a username or a password to pppd through the chap_passwd_hook callback. + * + * Return a value > 0 to avoid parsing the chap-secrets file. + */ +typedef int (chap_check_hook_fn)(void); +extern chap_check_hook_fn *chap_check_hook; + +/* + * A plugin can chose to supply its own user and password overriding whatever + * has been provided by the configuration. Hook is only valid when pppd is + * acting as a client. + * + * The maximum size of the user argument is always MAXNAMELEN + * The length of the password is always MAXWORDLEN, however; secrets can't be + * longer than MAXSECRETLEN + * + * Return a value < 0 to fail the connection. + */ +typedef int (chap_passwd_hook_fn)(char *user, char *password); +extern chap_passwd_hook_fn *chap_passwd_hook; + +/* + * A plugin can chose to replace the default chap_verify_response function with + * one of their own. + */ +typedef int (chap_verify_hook_fn)(char *name, char *ourname, int id, + struct chap_digest_type *digest, + unsigned char *challenge, unsigned char *response, + char *message, int message_space); +extern chap_verify_hook_fn *chap_verify_hook; + +/* Called by digest code to register a digest type */ +extern void chap_register_digest(struct chap_digest_type *); + +/* Lookup a digest handler by type */ +extern struct chap_digest_type *chap_find_digest(int digest_code); + +/* Called by authentication code to start authenticating the peer. */ +extern void chap_auth_peer(int unit, char *our_name, int digest_code); + +/* Called by auth. code to start authenticating us to the peer. */ +extern void chap_auth_with_peer(int unit, char *our_name, int digest_code); + +/* Represents the CHAP protocol to the main pppd code */ +extern struct protent chap_protent; + +#endif |