diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 124 | ||||
-rw-r--r-- | include/platform.h | 15 | ||||
-rw-r--r-- | include/usage.src.h | 8 |
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 | ||
367 | extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC; | 367 | extern 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. */ | ||
371 | void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC; | ||
372 | void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC; | ||
373 | void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC; | ||
374 | void *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)) | ||
384 | void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC; | ||
385 | char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; | ||
386 | char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC; | ||
387 | void *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)? |
370 | extern const char *bb_mode_string(mode_t mode) FAST_FUNC; | 391 | extern const char *bb_mode_string(mode_t mode) FAST_FUNC; |
371 | extern int is_directory(const char *name, int followLinks) FAST_FUNC; | 392 | extern 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 | ||
735 | struct tls_handshake_data; /* opaque */ | ||
736 | typedef 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 | |||
774 | static inline tls_state_t *new_tls_state(void) | ||
775 | { | ||
776 | tls_state_t *tls = xzalloc(sizeof(*tls)); | ||
777 | return tls; | ||
778 | } | ||
779 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; | ||
780 | void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC; | ||
781 | |||
782 | |||
712 | void socket_want_pktinfo(int fd) FAST_FUNC; | 783 | void socket_want_pktinfo(int fd) FAST_FUNC; |
713 | ssize_t send_to_from(int fd, void *buf, size_t len, int flags, | 784 | ssize_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 | ||
722 | uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC; | 793 | uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC; |
723 | 794 | ||
724 | char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC; | ||
725 | char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC; | ||
726 | void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC; | ||
727 | void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; | 795 | void overlapping_strcpy(char *dst, const char *src) FAST_FUNC; |
728 | char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; | 796 | char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC; |
729 | char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; | 797 | char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC; |
@@ -769,24 +837,6 @@ enum { | |||
769 | }; | 837 | }; |
770 | void visible(unsigned ch, char *buf, int flags) FAST_FUNC; | 838 | void 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. */ | ||
774 | void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC; | ||
775 | void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC; | ||
776 | void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC; | ||
777 | void *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)) | ||
787 | void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC; | ||
788 | |||
789 | |||
790 | extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; | 840 | extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC; |
791 | extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC; | 841 | extern 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 | */ |
1063 | int wait4pid(pid_t pid) FAST_FUNC; | 1113 | int wait4pid(pid_t pid) FAST_FUNC; |
1064 | int wait_for_exitstatus(pid_t pid) FAST_FUNC; | 1114 | int 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: */ |
1066 | int spawn_and_wait(char **argv) FAST_FUNC; | 1121 | int 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 */ |
1068 | int run_nofork_applet(int applet_no, char **argv) FAST_FUNC; | 1123 | int run_nofork_applet(int applet_no, char **argv) FAST_FUNC; |
1124 | #ifndef BUILD_INDIVIDUAL | ||
1125 | extern int find_applet_by_name(const char *name) FAST_FUNC; | ||
1126 | extern 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; | |||
1272 | const struct hwtype *get_hwntype(int type) FAST_FUNC; | 1331 | const struct hwtype *get_hwntype(int type) FAST_FUNC; |
1273 | 1332 | ||
1274 | 1333 | ||
1275 | #ifndef BUILD_INDIVIDUAL | 1334 | extern int fstype_matches(const char *fstype, const char *comma_list) FAST_FUNC; |
1276 | extern int find_applet_by_name(const char *name) FAST_FUNC; | ||
1277 | extern 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 |
1281 | extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC; | ||
1282 | extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC; | 1336 | extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC; |
1283 | #endif | 1337 | #endif |
1284 | extern void erase_mtab(const char * name) FAST_FUNC; | 1338 | extern 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 | |||
1457 | int get_terminal_width(int fd) FAST_FUNC; | 1511 | int get_terminal_width(int fd) FAST_FUNC; |
1458 | 1512 | ||
1459 | int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC; | 1513 | int 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) | ||
1517 | int 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! */ |
1462 | int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; | 1520 | int 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; |
1776 | void md5_begin(md5_ctx_t *ctx) FAST_FUNC; | 1834 | void md5_begin(md5_ctx_t *ctx) FAST_FUNC; |
1777 | void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1835 | void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1778 | void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1836 | unsigned md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1779 | void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; | 1837 | void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC; |
1780 | #define sha1_hash md5_hash | 1838 | #define sha1_hash md5_hash |
1781 | void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1839 | unsigned sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1782 | void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; | 1840 | void 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 |
1785 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; | 1843 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; |
1786 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1844 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1787 | void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1845 | unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; |
1788 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; | 1846 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; |
1789 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 1847 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
1790 | void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; | 1848 | unsigned 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 */ | ||
1850 | typedef struct md5_ctx_t md5sha_ctx_t; | ||
1851 | #define md5sha_hash md5_hash | ||
1852 | #define sha_end sha1_end | ||
1791 | 1853 | ||
1792 | extern uint32_t *global_crc32_table; | 1854 | extern uint32_t *global_crc32_table; |
1793 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 1855 | uint32_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 | |||
17 | INSERT | 25 | INSERT |
18 | 26 | ||
19 | #define busybox_notes_usage \ | 27 | #define busybox_notes_usage \ |