aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libbb.h124
-rw-r--r--include/platform.h15
-rw-r--r--include/usage.src.h8
3 files changed, 111 insertions, 36 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 0b9cfb585..1f5b211c1 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -366,6 +366,27 @@ extern char *skip_dev_pfx(const char *tty_name) FAST_FUNC;
366 366
367extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC; 367extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC;
368 368
369/* dmalloc will redefine these to it's own implementation. It is safe
370 * to have the prototypes here unconditionally. */
371void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
372void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
373void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
374void *xrealloc(void *old, size_t size) FAST_FUNC;
375/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
376 * at least v[idx] and v[idx+1], for all idx values.
377 * SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
378 * when all elements are used up. New elements are zeroed out.
379 * xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
380 * skipping an index is a bad bug - it may miss a realloc!
381 */
382#define xrealloc_vector(vector, shift, idx) \
383 xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
384void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
385char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
386char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
387void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
388
389
369//TODO: supply a pointer to char[11] buffer (avoid statics)? 390//TODO: supply a pointer to char[11] buffer (avoid statics)?
370extern const char *bb_mode_string(mode_t mode) FAST_FUNC; 391extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
371extern int is_directory(const char *name, int followLinks) FAST_FUNC; 392extern int is_directory(const char *name, int followLinks) FAST_FUNC;
@@ -709,6 +730,56 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC;
709// + inet_common.c has additional IPv4-only stuff 730// + inet_common.c has additional IPv4-only stuff
710 731
711 732
733#define TLS_MAX_MAC_SIZE 32
734#define TLS_MAX_KEY_SIZE 32
735struct tls_handshake_data; /* opaque */
736typedef struct tls_state {
737 int ofd;
738 int ifd;
739
740 unsigned min_encrypted_len_on_read;
741 uint16_t cipher_id;
742 uint8_t encrypt_on_write;
743 unsigned MAC_size;
744 unsigned key_size;
745
746 uint8_t *outbuf;
747 int outbuf_size;
748
749 int inbuf_size;
750 int ofs_to_buffered;
751 int buffered_size;
752 uint8_t *inbuf;
753
754 struct tls_handshake_data *hsd;
755
756 // RFC 5246
757 // sequence number
758 // Each connection state contains a sequence number, which is
759 // maintained separately for read and write states. The sequence
760 // number MUST be set to zero whenever a connection state is made the
761 // active state. Sequence numbers are of type uint64 and may not
762 // exceed 2^64-1.
763 /*uint64_t read_seq64_be;*/
764 uint64_t write_seq64_be;
765
766 uint8_t *client_write_key;
767 uint8_t *server_write_key;
768 uint8_t client_write_MAC_key[TLS_MAX_MAC_SIZE];
769 uint8_t server_write_MAC_k__[TLS_MAX_MAC_SIZE];
770 uint8_t client_write_k__[TLS_MAX_KEY_SIZE];
771 uint8_t server_write_k__[TLS_MAX_KEY_SIZE];
772} tls_state_t;
773
774static inline tls_state_t *new_tls_state(void)
775{
776 tls_state_t *tls = xzalloc(sizeof(*tls));
777 return tls;
778}
779void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC;
780void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC;
781
782
712void socket_want_pktinfo(int fd) FAST_FUNC; 783void socket_want_pktinfo(int fd) FAST_FUNC;
713ssize_t send_to_from(int fd, void *buf, size_t len, int flags, 784ssize_t send_to_from(int fd, void *buf, size_t len, int flags,
714 const struct sockaddr *to, 785 const struct sockaddr *to,
@@ -721,9 +792,6 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
721 792
722uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC; 793uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
723 794
724char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
725char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
726void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
727void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; 795void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
728char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; 796char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
729char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; 797char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
@@ -769,24 +837,6 @@ enum {
769}; 837};
770void visible(unsigned ch, char *buf, int flags) FAST_FUNC; 838void visible(unsigned ch, char *buf, int flags) FAST_FUNC;
771 839
772/* dmalloc will redefine these to it's own implementation. It is safe
773 * to have the prototypes here unconditionally. */
774void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
775void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
776void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
777void *xrealloc(void *old, size_t size) FAST_FUNC;
778/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
779 * at least v[idx] and v[idx+1], for all idx values.
780 * SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
781 * when all elements are used up. New elements are zeroed out.
782 * xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
783 * skipping an index is a bad bug - it may miss a realloc!
784 */
785#define xrealloc_vector(vector, shift, idx) \
786 xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
787void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
788
789
790extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; 840extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
791extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC; 841extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
792// NB: will return short read on error, not -1, 842// NB: will return short read on error, not -1,
@@ -1062,10 +1112,19 @@ pid_t wait_any_nohang(int *wstat) FAST_FUNC;
1062 */ 1112 */
1063int wait4pid(pid_t pid) FAST_FUNC; 1113int wait4pid(pid_t pid) FAST_FUNC;
1064int wait_for_exitstatus(pid_t pid) FAST_FUNC; 1114int wait_for_exitstatus(pid_t pid) FAST_FUNC;
1115/************************************************************************/
1116/* spawn_and_wait/run_nofork_applet/run_applet_no_and_exit need to work */
1117/* carefully together to reinit some global state while not disturbing */
1118/* other. Be careful if you change them. Consult docs/nofork_noexec.txt */
1119/************************************************************************/
1065/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */ 1120/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
1066int spawn_and_wait(char **argv) FAST_FUNC; 1121int spawn_and_wait(char **argv) FAST_FUNC;
1067/* Does NOT check that applet is NOFORK, just blindly runs it */ 1122/* Does NOT check that applet is NOFORK, just blindly runs it */
1068int run_nofork_applet(int applet_no, char **argv) FAST_FUNC; 1123int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
1124#ifndef BUILD_INDIVIDUAL
1125extern int find_applet_by_name(const char *name) FAST_FUNC;
1126extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
1127#endif
1069 1128
1070/* Helpers for daemonization. 1129/* Helpers for daemonization.
1071 * 1130 *
@@ -1272,13 +1331,8 @@ const struct hwtype *get_hwtype(const char *name) FAST_FUNC;
1272const struct hwtype *get_hwntype(int type) FAST_FUNC; 1331const struct hwtype *get_hwntype(int type) FAST_FUNC;
1273 1332
1274 1333
1275#ifndef BUILD_INDIVIDUAL 1334extern int fstype_matches(const char *fstype, const char *comma_list) FAST_FUNC;
1276extern int find_applet_by_name(const char *name) FAST_FUNC;
1277extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
1278#endif
1279
1280#ifdef HAVE_MNTENT_H 1335#ifdef HAVE_MNTENT_H
1281extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC;
1282extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC; 1336extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC;
1283#endif 1337#endif
1284extern void erase_mtab(const char * name) FAST_FUNC; 1338extern void erase_mtab(const char * name) FAST_FUNC;
@@ -1457,6 +1511,10 @@ int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FU
1457int get_terminal_width(int fd) FAST_FUNC; 1511int get_terminal_width(int fd) FAST_FUNC;
1458 1512
1459int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC; 1513int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
1514#define TERMIOS_CLEAR_ISIG (1 << 0)
1515#define TERMIOS_RAW_CRNL (1 << 1)
1516#define TERMIOS_RAW_INPUT (1 << 2)
1517int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC;
1460 1518
1461/* NB: "unsigned request" is crucial! "int request" will break some arches! */ 1519/* NB: "unsigned request" is crucial! "int request" will break some arches! */
1462int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; 1520int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
@@ -1775,19 +1833,23 @@ typedef struct sha3_ctx_t {
1775} sha3_ctx_t; 1833} sha3_ctx_t;
1776void md5_begin(md5_ctx_t *ctx) FAST_FUNC; 1834void md5_begin(md5_ctx_t *ctx) FAST_FUNC;
1777void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 1835void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
1778void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; 1836unsigned md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
1779void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; 1837void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
1780#define sha1_hash md5_hash 1838#define sha1_hash md5_hash
1781void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC; 1839unsigned sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
1782void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; 1840void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
1783#define sha256_hash md5_hash 1841#define sha256_hash md5_hash
1784#define sha256_end sha1_end 1842#define sha256_end sha1_end
1785void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; 1843void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
1786void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 1844void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
1787void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; 1845unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
1788void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; 1846void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
1789void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 1847void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
1790void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; 1848unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
1849/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */
1850typedef struct md5_ctx_t md5sha_ctx_t;
1851#define md5sha_hash md5_hash
1852#define sha_end sha1_end
1791 1853
1792extern uint32_t *global_crc32_table; 1854extern uint32_t *global_crc32_table;
1793uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; 1855uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
diff --git a/include/platform.h b/include/platform.h
index 94368539e..13f818202 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -117,13 +117,18 @@
117 * and/or smaller by using modified ABI. It is usually only needed 117 * and/or smaller by using modified ABI. It is usually only needed
118 * on non-static, busybox internal functions. Recent versions of gcc 118 * on non-static, busybox internal functions. Recent versions of gcc
119 * optimize statics automatically. FAST_FUNC on static is required 119 * optimize statics automatically. FAST_FUNC on static is required
120 * only if you need to match a function pointer's type */ 120 * only if you need to match a function pointer's type.
121#if __GNUC_PREREQ(3,0) && defined(i386) /* || defined(__x86_64__)? */ 121 * FAST_FUNC may not work well with -flto so allow user to disable this.
122 * (-DFAST_FUNC= )
123 */
124#ifndef FAST_FUNC
125# if __GNUC_PREREQ(3,0) && defined(i386)
122/* stdcall makes callee to pop arguments from stack, not caller */ 126/* stdcall makes callee to pop arguments from stack, not caller */
123# define FAST_FUNC __attribute__((regparm(3),stdcall)) 127# define FAST_FUNC __attribute__((regparm(3),stdcall))
124/* #elif ... - add your favorite arch today! */ 128/* #elif ... - add your favorite arch today! */
125#else 129# else
126# define FAST_FUNC 130# define FAST_FUNC
131# endif
127#endif 132#endif
128 133
129/* Make all declarations hidden (-fvisibility flag only affects definitions) */ 134/* Make all declarations hidden (-fvisibility flag only affects definitions) */
diff --git a/include/usage.src.h b/include/usage.src.h
index 78beccf4d..00369dfb3 100644
--- a/include/usage.src.h
+++ b/include/usage.src.h
@@ -14,6 +14,14 @@
14 14
15#define NOUSAGE_STR "\b" 15#define NOUSAGE_STR "\b"
16 16
17#if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
18# define CRYPT_METHODS_HELP_STR "des,md5,sha256/512" \
19 " (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
20#else
21# define CRYPT_METHODS_HELP_STR "des,md5" \
22 " (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
23#endif
24
17INSERT 25INSERT
18 26
19#define busybox_notes_usage \ 27#define busybox_notes_usage \