diff options
Diffstat (limited to 'include/libbb.h')
| -rw-r--r-- | include/libbb.h | 278 |
1 files changed, 263 insertions, 15 deletions
diff --git a/include/libbb.h b/include/libbb.h index 8d252d455..09ebad1f6 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -10,6 +10,12 @@ | |||
| 10 | #ifndef LIBBB_H | 10 | #ifndef LIBBB_H |
| 11 | #define LIBBB_H 1 | 11 | #define LIBBB_H 1 |
| 12 | 12 | ||
| 13 | #if ENABLE_PLATFORM_MINGW32 | ||
| 14 | /* We have our own nanosleep(), clock_gettime() and clock_settime(). */ | ||
| 15 | /* Skip the Windows include file that declares them. */ | ||
| 16 | # define WIN_PTHREADS_TIME_H | ||
| 17 | #endif | ||
| 18 | |||
| 13 | #include "platform.h" | 19 | #include "platform.h" |
| 14 | 20 | ||
| 15 | #include <ctype.h> | 21 | #include <ctype.h> |
| @@ -143,6 +149,9 @@ | |||
| 143 | # include <arpa/inet.h> | 149 | # include <arpa/inet.h> |
| 144 | #elif defined __APPLE__ | 150 | #elif defined __APPLE__ |
| 145 | # include <netinet/in.h> | 151 | # include <netinet/in.h> |
| 152 | #elif ENABLE_PLATFORM_MINGW32 | ||
| 153 | # include <winsock2.h> | ||
| 154 | # include <ws2tcpip.h> | ||
| 146 | #else | 155 | #else |
| 147 | # include <arpa/inet.h> | 156 | # include <arpa/inet.h> |
| 148 | //This breaks on bionic: | 157 | //This breaks on bionic: |
| @@ -182,7 +191,9 @@ | |||
| 182 | 191 | ||
| 183 | /* Some libc's forget to declare these, do it ourself */ | 192 | /* Some libc's forget to declare these, do it ourself */ |
| 184 | 193 | ||
| 194 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 185 | extern char **environ; | 195 | extern char **environ; |
| 196 | #endif | ||
| 186 | /* klogctl is in libc's klog.h, but we cheat and not #include that */ | 197 | /* klogctl is in libc's klog.h, but we cheat and not #include that */ |
| 187 | int klogctl(int type, char *b, int len); | 198 | int klogctl(int type, char *b, int len); |
| 188 | #ifndef PATH_MAX | 199 | #ifndef PATH_MAX |
| @@ -192,6 +203,13 @@ int klogctl(int type, char *b, int len); | |||
| 192 | # define BUFSIZ 4096 | 203 | # define BUFSIZ 4096 |
| 193 | #endif | 204 | #endif |
| 194 | 205 | ||
| 206 | #if ENABLE_PLATFORM_MINGW32 | ||
| 207 | # include "mingw.h" | ||
| 208 | # define MINGW_SPECIAL(a) mingw_ ## a | ||
| 209 | #else | ||
| 210 | # define MINGW_SPECIAL(a) a | ||
| 211 | #endif | ||
| 212 | |||
| 195 | #if __GNUC_PREREQ(5,0) | 213 | #if __GNUC_PREREQ(5,0) |
| 196 | /* Since musl is apparently unable to get it right and would use | 214 | /* Since musl is apparently unable to get it right and would use |
| 197 | * a function call to a single-instruction function of "bswap %eax", | 215 | * a function call to a single-instruction function of "bswap %eax", |
| @@ -263,6 +281,26 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | |||
| 263 | # endif | 281 | # endif |
| 264 | #endif | 282 | #endif |
| 265 | 283 | ||
| 284 | #if ENABLE_FEATURE_TLS_SCHANNEL || ENABLE_FEATURE_USE_CNG_API | ||
| 285 | # define SECURITY_WIN32 | ||
| 286 | # include <windows.h> | ||
| 287 | # include <security.h> | ||
| 288 | #endif | ||
| 289 | |||
| 290 | #if ENABLE_FEATURE_USE_CNG_API | ||
| 291 | # include <bcrypt.h> | ||
| 292 | |||
| 293 | // these work on Windows >= 10 | ||
| 294 | # define BCRYPT_HMAC_SHA1_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000a1) | ||
| 295 | # define BCRYPT_HMAC_SHA256_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x000000b1) | ||
| 296 | # define sha1_begin_hmac BCRYPT_HMAC_SHA1_ALG_HANDLE | ||
| 297 | # define sha256_begin_hmac BCRYPT_HMAC_SHA256_ALG_HANDLE | ||
| 298 | #else | ||
| 299 | # define sha1_begin_hmac sha1_begin | ||
| 300 | # define sha256_begin_hmac sha256_begin | ||
| 301 | # define hmac_uninit(...) ((void)0) | ||
| 302 | #endif | ||
| 303 | |||
| 266 | /* Tested to work correctly with all int types (IIRC :]) */ | 304 | /* Tested to work correctly with all int types (IIRC :]) */ |
| 267 | #define MAXINT(T) (T)( \ | 305 | #define MAXINT(T) (T)( \ |
| 268 | ((T)-1) > 0 \ | 306 | ((T)-1) > 0 \ |
| @@ -276,6 +314,20 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | |||
| 276 | : ((T)1 << (sizeof(T)*8-1)) \ | 314 | : ((T)1 << (sizeof(T)*8-1)) \ |
| 277 | ) | 315 | ) |
| 278 | 316 | ||
| 317 | // UCRT supports both "ll" and "I64", but gcc warns on "I64" with UCRT mingw | ||
| 318 | #if ENABLE_PLATFORM_MINGW32 && !defined(_UCRT) && \ | ||
| 319 | (!defined(__USE_MINGW_ANSI_STDIO) || !__USE_MINGW_ANSI_STDIO) | ||
| 320 | #define LL_FMT "I64" | ||
| 321 | #else | ||
| 322 | #define LL_FMT "ll" | ||
| 323 | #endif | ||
| 324 | |||
| 325 | #if ENABLE_PLATFORM_MINGW32 && defined(_WIN64) | ||
| 326 | #define PID_FMT LL_FMT | ||
| 327 | #else | ||
| 328 | #define PID_FMT | ||
| 329 | #endif | ||
| 330 | |||
| 279 | /* Large file support */ | 331 | /* Large file support */ |
| 280 | /* Note that CONFIG_LFS=y forces bbox to be built with all common ops | 332 | /* Note that CONFIG_LFS=y forces bbox to be built with all common ops |
| 281 | * (stat, lseek etc) mapped to "largefile" variants by libc. | 333 | * (stat, lseek etc) mapped to "largefile" variants by libc. |
| @@ -303,7 +355,7 @@ typedef unsigned long long uoff_t; | |||
| 303 | # define XATOOFF_SFX(a, s) xatoull_range_sfx((a), 0, LLONG_MAX, s) | 355 | # define XATOOFF_SFX(a, s) xatoull_range_sfx((a), 0, LLONG_MAX, s) |
| 304 | # define BB_STRTOOFF bb_strtoull | 356 | # define BB_STRTOOFF bb_strtoull |
| 305 | # define STRTOOFF strtoull | 357 | # define STRTOOFF strtoull |
| 306 | # define OFF_FMT "ll" | 358 | # define OFF_FMT LL_FMT |
| 307 | # endif | 359 | # endif |
| 308 | #else | 360 | #else |
| 309 | /* CONFIG_LFS is off */ | 361 | /* CONFIG_LFS is off */ |
| @@ -574,13 +626,20 @@ char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC; | |||
| 574 | const char *bb_basename(const char *name) FAST_FUNC; | 626 | const char *bb_basename(const char *name) FAST_FUNC; |
| 575 | /* NB: can violate const-ness (similarly to strchr) */ | 627 | /* NB: can violate const-ness (similarly to strchr) */ |
| 576 | char *last_char_is(const char *s, int c) FAST_FUNC; | 628 | char *last_char_is(const char *s, int c) FAST_FUNC; |
| 629 | char *last_char_is_dir_sep(const char *s) FAST_FUNC; | ||
| 577 | const char* endofname(const char *name) FAST_FUNC; | 630 | const char* endofname(const char *name) FAST_FUNC; |
| 578 | char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; | 631 | char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; |
| 579 | char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; | 632 | char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; |
| 580 | 633 | ||
| 634 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 581 | int ndelay_on(int fd) FAST_FUNC; | 635 | int ndelay_on(int fd) FAST_FUNC; |
| 582 | int ndelay_off(int fd) FAST_FUNC; | 636 | int ndelay_off(int fd) FAST_FUNC; |
| 583 | void close_on_exec_on(int fd) FAST_FUNC; | 637 | void close_on_exec_on(int fd) FAST_FUNC; |
| 638 | #else | ||
| 639 | static inline int ndelay_on(int fd UNUSED_PARAM) { return 0; } | ||
| 640 | static inline int ndelay_off(int fd UNUSED_PARAM) { return 0; } | ||
| 641 | static inline void close_on_exec_on(int fd UNUSED_PARAM) { return; } | ||
| 642 | #endif | ||
| 584 | void xdup2(int, int) FAST_FUNC; | 643 | void xdup2(int, int) FAST_FUNC; |
| 585 | void xmove_fd(int, int) FAST_FUNC; | 644 | void xmove_fd(int, int) FAST_FUNC; |
| 586 | 645 | ||
| @@ -614,20 +673,37 @@ enum { | |||
| 614 | * Dance around with long long to guard against that... | 673 | * Dance around with long long to guard against that... |
| 615 | */ | 674 | */ |
| 616 | BB_FATAL_SIGS = (int)(0 | 675 | BB_FATAL_SIGS = (int)(0 |
| 676 | #ifdef SIGHUP | ||
| 617 | + (1LL << SIGHUP) | 677 | + (1LL << SIGHUP) |
| 678 | #endif | ||
| 618 | + (1LL << SIGINT) | 679 | + (1LL << SIGINT) |
| 619 | + (1LL << SIGTERM) | 680 | + (1LL << SIGTERM) |
| 620 | + (1LL << SIGPIPE) // Write to pipe with no readers | 681 | + (1LL << SIGPIPE) // Write to pipe with no readers |
| 682 | #ifdef SIGQUIT | ||
| 621 | + (1LL << SIGQUIT) // Quit from keyboard | 683 | + (1LL << SIGQUIT) // Quit from keyboard |
| 684 | #endif | ||
| 622 | + (1LL << SIGABRT) // Abort signal from abort(3) | 685 | + (1LL << SIGABRT) // Abort signal from abort(3) |
| 686 | #ifdef SIGALRM | ||
| 623 | + (1LL << SIGALRM) // Timer signal from alarm(2) | 687 | + (1LL << SIGALRM) // Timer signal from alarm(2) |
| 688 | #endif | ||
| 689 | #ifdef SIGVTALRM | ||
| 624 | + (1LL << SIGVTALRM) // Virtual alarm clock | 690 | + (1LL << SIGVTALRM) // Virtual alarm clock |
| 691 | #endif | ||
| 692 | #ifdef SIGXCPU | ||
| 625 | + (1LL << SIGXCPU) // CPU time limit exceeded | 693 | + (1LL << SIGXCPU) // CPU time limit exceeded |
| 694 | #endif | ||
| 695 | #ifdef SIGXFSZ | ||
| 626 | + (1LL << SIGXFSZ) // File size limit exceeded | 696 | + (1LL << SIGXFSZ) // File size limit exceeded |
| 697 | #endif | ||
| 698 | #ifdef SIGUSR1 | ||
| 627 | + (1LL << SIGUSR1) // Yes kids, these are also fatal! | 699 | + (1LL << SIGUSR1) // Yes kids, these are also fatal! |
| 700 | #endif | ||
| 701 | #ifdef SIGUSR1 | ||
| 628 | + (1LL << SIGUSR2) | 702 | + (1LL << SIGUSR2) |
| 703 | #endif | ||
| 629 | + 0), | 704 | + 0), |
| 630 | }; | 705 | }; |
| 706 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 631 | void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; | 707 | void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; |
| 632 | /* Unlike signal() and bb_signals, sets handler with sigaction() | 708 | /* Unlike signal() and bb_signals, sets handler with sigaction() |
| 633 | * and in a way that while signal handler is run, no other signals | 709 | * and in a way that while signal handler is run, no other signals |
| @@ -649,6 +725,10 @@ int sigprocmask_allsigs(int how) FAST_FUNC; | |||
| 649 | int sigprocmask2(int how, sigset_t *set) FAST_FUNC; | 725 | int sigprocmask2(int how, sigset_t *set) FAST_FUNC; |
| 650 | /* SIG_BLOCK all signals, return old set: */ | 726 | /* SIG_BLOCK all signals, return old set: */ |
| 651 | int sigblockall(sigset_t *set) FAST_FUNC; | 727 | int sigblockall(sigset_t *set) FAST_FUNC; |
| 728 | #else | ||
| 729 | #define bb_signals(s, f) | ||
| 730 | #define kill_myself_with_sig(s) | ||
| 731 | #endif | ||
| 652 | /* Standard handler which just records signo */ | 732 | /* Standard handler which just records signo */ |
| 653 | extern smallint bb_got_signal; | 733 | extern smallint bb_got_signal; |
| 654 | void record_signo(int signo); /* not FAST_FUNC! */ | 734 | void record_signo(int signo); /* not FAST_FUNC! */ |
| @@ -732,7 +812,7 @@ void xsettimeofday(const struct timeval *tv) FAST_FUNC; | |||
| 732 | int xsocket(int domain, int type, int protocol) FAST_FUNC; | 812 | int xsocket(int domain, int type, int protocol) FAST_FUNC; |
| 733 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; | 813 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; |
| 734 | void xlisten(int s, int backlog) FAST_FUNC; | 814 | void xlisten(int s, int backlog) FAST_FUNC; |
| 735 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; | 815 | void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC; |
| 736 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | 816 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, |
| 737 | socklen_t tolen) FAST_FUNC; | 817 | socklen_t tolen) FAST_FUNC; |
| 738 | 818 | ||
| @@ -845,7 +925,36 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC; | |||
| 845 | // Also mount.c and inetd.c are using gethostbyname(), | 925 | // Also mount.c and inetd.c are using gethostbyname(), |
| 846 | // + inet_common.c has additional IPv4-only stuff | 926 | // + inet_common.c has additional IPv4-only stuff |
| 847 | 927 | ||
| 928 | #if defined CONFIG_FEATURE_TLS_SCHANNEL | ||
| 929 | enum schannel_connection_state { | ||
| 930 | BB_SCHANNEL_OPEN = 0, | ||
| 931 | BB_SCHANNEL_CLOSED = 1, | ||
| 932 | BB_SCHANNEL_CLOSED_AND_FREED = 2 | ||
| 933 | }; | ||
| 848 | 934 | ||
| 935 | typedef struct tls_state { | ||
| 936 | int ofd; | ||
| 937 | int ifd; | ||
| 938 | |||
| 939 | // handles | ||
| 940 | CredHandle cred_handle; | ||
| 941 | CtxtHandle ctx_handle; | ||
| 942 | |||
| 943 | // buffers | ||
| 944 | char in_buffer[16384 + 256]; // input buffer (to read from server), length is maximum TLS packet size | ||
| 945 | unsigned long in_buffer_offset; | ||
| 946 | |||
| 947 | char *out_buffer; // output buffer (for decrypted data, offset from in_buffer) | ||
| 948 | unsigned long out_buffer_length; | ||
| 949 | unsigned long out_buffer_extra; | ||
| 950 | |||
| 951 | // data | ||
| 952 | char *hostname; | ||
| 953 | SecPkgContext_StreamSizes stream_sizes; | ||
| 954 | bool initialized; | ||
| 955 | enum schannel_connection_state connection_state; | ||
| 956 | } tls_state_t; | ||
| 957 | #else | ||
| 849 | struct tls_aes { | 958 | struct tls_aes { |
| 850 | uint32_t key[60]; | 959 | uint32_t key[60]; |
| 851 | unsigned rounds; | 960 | unsigned rounds; |
| @@ -902,12 +1011,14 @@ typedef struct tls_state { | |||
| 902 | struct tls_aes aes_decrypt; | 1011 | struct tls_aes aes_decrypt; |
| 903 | uint8_t H[16]; //used by AES_GCM | 1012 | uint8_t H[16]; //used by AES_GCM |
| 904 | } tls_state_t; | 1013 | } tls_state_t; |
| 1014 | #endif | ||
| 905 | 1015 | ||
| 906 | static inline tls_state_t *new_tls_state(void) | 1016 | static inline tls_state_t *new_tls_state(void) |
| 907 | { | 1017 | { |
| 908 | tls_state_t *tls = xzalloc(sizeof(*tls)); | 1018 | tls_state_t *tls = xzalloc(sizeof(*tls)); |
| 909 | return tls; | 1019 | return tls; |
| 910 | } | 1020 | } |
| 1021 | |||
| 911 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; | 1022 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; |
| 912 | #define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) | 1023 | #define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) |
| 913 | void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; | 1024 | void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; |
| @@ -939,7 +1050,7 @@ int bb_putchar(int ch) FAST_FUNC; | |||
| 939 | /* Note: does not use stdio, writes to fd 2 directly */ | 1050 | /* Note: does not use stdio, writes to fd 2 directly */ |
| 940 | int bb_putchar_stderr(char ch) FAST_FUNC; | 1051 | int bb_putchar_stderr(char ch) FAST_FUNC; |
| 941 | int fputs_stdout(const char *s) FAST_FUNC; | 1052 | int fputs_stdout(const char *s) FAST_FUNC; |
| 942 | char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC; | 1053 | char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) RETURNS_MALLOC; |
| 943 | char *auto_string(char *str) FAST_FUNC; | 1054 | char *auto_string(char *str) FAST_FUNC; |
| 944 | // gcc-4.1.1 still isn't good enough at optimizing it | 1055 | // gcc-4.1.1 still isn't good enough at optimizing it |
| 945 | // (+200 bytes compared to macro) | 1056 | // (+200 bytes compared to macro) |
| @@ -1240,12 +1351,20 @@ gid_t *bb_getgroups(int *ngroups, gid_t *group_array) FAST_FUNC; | |||
| 1240 | struct cached_groupinfo { | 1351 | struct cached_groupinfo { |
| 1241 | uid_t euid; | 1352 | uid_t euid; |
| 1242 | gid_t egid; | 1353 | gid_t egid; |
| 1354 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1355 | // If these are ever restored on Windows it will be necessary to alter | ||
| 1356 | // globals_misc_size()/globals_misc_copy() in ash. | ||
| 1243 | int ngroups; | 1357 | int ngroups; |
| 1244 | gid_t *supplementary_array; | 1358 | gid_t *supplementary_array; |
| 1359 | #endif | ||
| 1245 | }; | 1360 | }; |
| 1246 | uid_t FAST_FUNC get_cached_euid(uid_t *euid); | 1361 | uid_t FAST_FUNC get_cached_euid(uid_t *euid); |
| 1247 | gid_t FAST_FUNC get_cached_egid(gid_t *egid); | 1362 | gid_t FAST_FUNC get_cached_egid(gid_t *egid); |
| 1363 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1248 | int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid); | 1364 | int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid); |
| 1365 | #else | ||
| 1366 | # define is_in_supplementary_groups(g, i) (FALSE) | ||
| 1367 | #endif | ||
| 1249 | 1368 | ||
| 1250 | #if ENABLE_FEATURE_UTMP | 1369 | #if ENABLE_FEATURE_UTMP |
| 1251 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); | 1370 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); |
| @@ -1281,6 +1400,7 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; | |||
| 1281 | 1400 | ||
| 1282 | /* xvfork() can't be a _function_, return after vfork in child mangles stack | 1401 | /* xvfork() can't be a _function_, return after vfork in child mangles stack |
| 1283 | * in the parent. It must be a macro. */ | 1402 | * in the parent. It must be a macro. */ |
| 1403 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1284 | #define xvfork() \ | 1404 | #define xvfork() \ |
| 1285 | ({ \ | 1405 | ({ \ |
| 1286 | pid_t bb__xvfork_pid = vfork(); \ | 1406 | pid_t bb__xvfork_pid = vfork(); \ |
| @@ -1288,6 +1408,9 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; | |||
| 1288 | bb_simple_perror_msg_and_die("vfork"); \ | 1408 | bb_simple_perror_msg_and_die("vfork"); \ |
| 1289 | bb__xvfork_pid; \ | 1409 | bb__xvfork_pid; \ |
| 1290 | }) | 1410 | }) |
| 1411 | #else | ||
| 1412 | #define xvfork() vfork() | ||
| 1413 | #endif | ||
| 1291 | #if BB_MMU | 1414 | #if BB_MMU |
| 1292 | pid_t xfork(void) FAST_FUNC; | 1415 | pid_t xfork(void) FAST_FUNC; |
| 1293 | #endif | 1416 | #endif |
| @@ -1322,6 +1445,15 @@ void run_noexec_applet_and_exit(int a, const char *name, char **argv) NORETURN F | |||
| 1322 | #ifndef BUILD_INDIVIDUAL | 1445 | #ifndef BUILD_INDIVIDUAL |
| 1323 | int find_applet_by_name(const char *name) FAST_FUNC; | 1446 | int find_applet_by_name(const char *name) FAST_FUNC; |
| 1324 | void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; | 1447 | void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; |
| 1448 | # if ENABLE_PLATFORM_MINGW32 | ||
| 1449 | # if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | ||
| 1450 | int prefer_applet(const char *name, const char *path) FAST_FUNC; | ||
| 1451 | int find_applet_by_name_for_sh(const char *name, const char *path) FAST_FUNC; | ||
| 1452 | # endif | ||
| 1453 | # else | ||
| 1454 | # define prefer_applet(n, p) (1) | ||
| 1455 | # define find_applet_by_name_for_sh(n, p) find_applet_by_name(n) | ||
| 1456 | # endif | ||
| 1325 | #endif | 1457 | #endif |
| 1326 | void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC; | 1458 | void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC; |
| 1327 | #if defined(__linux__) | 1459 | #if defined(__linux__) |
| @@ -1402,12 +1534,12 @@ char* single_argv(char **argv) FAST_FUNC; | |||
| 1402 | char **skip_dash_dash(char **argv) FAST_FUNC; | 1534 | char **skip_dash_dash(char **argv) FAST_FUNC; |
| 1403 | extern const char *const bb_argv_dash[]; /* { "-", NULL } */ | 1535 | extern const char *const bb_argv_dash[]; /* { "-", NULL } */ |
| 1404 | extern uint32_t option_mask32; | 1536 | extern uint32_t option_mask32; |
| 1405 | uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; | 1537 | uint32_t getopt32(char **argv, const char *applet_opts, ...); |
| 1406 | # define No_argument "\0" | 1538 | # define No_argument "\0" |
| 1407 | # define Required_argument "\001" | 1539 | # define Required_argument "\001" |
| 1408 | # define Optional_argument "\002" | 1540 | # define Optional_argument "\002" |
| 1409 | #if ENABLE_LONG_OPTS | 1541 | #if ENABLE_LONG_OPTS |
| 1410 | uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...) FAST_FUNC; | 1542 | uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...); |
| 1411 | #else | 1543 | #else |
| 1412 | #define getopt32long(argv,optstring,longopts,...) \ | 1544 | #define getopt32long(argv,optstring,longopts,...) \ |
| 1413 | getopt32(argv,optstring,##__VA_ARGS__) | 1545 | getopt32(argv,optstring,##__VA_ARGS__) |
| @@ -1482,17 +1614,17 @@ extern uint8_t xfunc_error_retval; | |||
| 1482 | extern void (*die_func)(void); | 1614 | extern void (*die_func)(void); |
| 1483 | void xfunc_die(void) NORETURN FAST_FUNC; | 1615 | void xfunc_die(void) NORETURN FAST_FUNC; |
| 1484 | void bb_show_usage(void) NORETURN FAST_FUNC; | 1616 | void bb_show_usage(void) NORETURN FAST_FUNC; |
| 1485 | void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1617 | void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 1486 | void bb_simple_error_msg(const char *s) FAST_FUNC; | 1618 | void bb_simple_error_msg(const char *s) FAST_FUNC; |
| 1487 | void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1619 | void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 1488 | void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1620 | void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC; |
| 1489 | void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1621 | void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 1490 | void bb_simple_perror_msg(const char *s) FAST_FUNC; | 1622 | void bb_simple_perror_msg(const char *s) FAST_FUNC; |
| 1491 | void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1623 | void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 1492 | void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1624 | void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; |
| 1493 | void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1625 | void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 1494 | void bb_simple_herror_msg(const char *s) FAST_FUNC; | 1626 | void bb_simple_herror_msg(const char *s) FAST_FUNC; |
| 1495 | void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1627 | void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 1496 | void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1628 | void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC; |
| 1497 | void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; | 1629 | void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; |
| 1498 | void bb_perror_nomsg(void) FAST_FUNC; | 1630 | void bb_perror_nomsg(void) FAST_FUNC; |
| @@ -1508,7 +1640,7 @@ void bb_logenv_override(void) FAST_FUNC; | |||
| 1508 | typedef smalluint exitcode_t; | 1640 | typedef smalluint exitcode_t; |
| 1509 | 1641 | ||
| 1510 | #if ENABLE_FEATURE_SYSLOG_INFO | 1642 | #if ENABLE_FEATURE_SYSLOG_INFO |
| 1511 | void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1643 | void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
| 1512 | void bb_simple_info_msg(const char *s) FAST_FUNC; | 1644 | void bb_simple_info_msg(const char *s) FAST_FUNC; |
| 1513 | void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC; | 1645 | void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC; |
| 1514 | #else | 1646 | #else |
| @@ -1892,8 +2024,8 @@ int get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *ol | |||
| 1892 | int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; | 2024 | int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; |
| 1893 | 2025 | ||
| 1894 | /* NB: "unsigned request" is crucial! "int request" will break some arches! */ | 2026 | /* NB: "unsigned request" is crucial! "int request" will break some arches! */ |
| 1895 | int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; | 2027 | int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); |
| 1896 | int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; | 2028 | int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); |
| 1897 | #if ENABLE_IOCTL_HEX2STR_ERROR | 2029 | #if ENABLE_IOCTL_HEX2STR_ERROR |
| 1898 | int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; | 2030 | int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; |
| 1899 | int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; | 2031 | int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; |
| @@ -1906,9 +2038,15 @@ int bb_xioctl(int fd, unsigned request, void *argp) FAST_FUNC; | |||
| 1906 | #define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) | 2038 | #define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) |
| 1907 | #endif | 2039 | #endif |
| 1908 | 2040 | ||
| 2041 | #if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA | ||
| 1909 | char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC; | 2042 | char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC; |
| 1910 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC; | 2043 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC; |
| 1911 | void reset_ino_dev_hashtable(void) FAST_FUNC; | 2044 | void reset_ino_dev_hashtable(void) FAST_FUNC; |
| 2045 | #else | ||
| 2046 | #define add_to_ino_dev_hashtable(s, n) (void)0 | ||
| 2047 | #define is_in_ino_dev_hashtable(s) NULL | ||
| 2048 | #define reset_ino_dev_hashtable() | ||
| 2049 | #endif | ||
| 1912 | #ifdef __GLIBC__ | 2050 | #ifdef __GLIBC__ |
| 1913 | /* At least glibc has horrendously large inline for this, so wrap it */ | 2051 | /* At least glibc has horrendously large inline for this, so wrap it */ |
| 1914 | unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; | 2052 | unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; |
| @@ -1986,11 +2124,17 @@ enum { | |||
| 1986 | * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout | 2124 | * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout |
| 1987 | */ | 2125 | */ |
| 1988 | int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 2126 | int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
| 2127 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2128 | int64_t windows_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | ||
| 2129 | #endif | ||
| 1989 | /* This version loops on EINTR: */ | 2130 | /* This version loops on EINTR: */ |
| 1990 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 2131 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
| 1991 | void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; | 2132 | void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; |
| 1992 | 2133 | ||
| 1993 | int check_got_signal_and_poll(struct pollfd pfd[1], int timeout) FAST_FUNC; | 2134 | int check_got_signal_and_poll(struct pollfd pfd[1], int timeout) FAST_FUNC; |
| 2135 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2136 | # define check_got_signal_and_poll(p, t) poll(p, 1, t) | ||
| 2137 | #endif | ||
| 1994 | 2138 | ||
| 1995 | #if ENABLE_FEATURE_EDITING | 2139 | #if ENABLE_FEATURE_EDITING |
| 1996 | /* It's NOT just ENABLEd or disabled. It's a number: */ | 2140 | /* It's NOT just ENABLEd or disabled. It's a number: */ |
| @@ -2000,8 +2144,14 @@ unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC; | |||
| 2000 | # else | 2144 | # else |
| 2001 | # define MAX_HISTORY 0 | 2145 | # define MAX_HISTORY 0 |
| 2002 | # endif | 2146 | # endif |
| 2147 | # if defined CONFIG_FEATURE_EDITING_HISTORY_DEFAULT && CONFIG_FEATURE_EDITING_HISTORY_DEFAULT > 0 | ||
| 2148 | # define DEFAULT_HISTORY (CONFIG_FEATURE_EDITING_HISTORY_DEFAULT + 0) | ||
| 2149 | # else | ||
| 2150 | # define DEFAULT_HISTORY 0 | ||
| 2151 | # endif | ||
| 2003 | typedef const char *get_exe_name_t(int i) FAST_FUNC; | 2152 | typedef const char *get_exe_name_t(int i) FAST_FUNC; |
| 2004 | typedef const char *sh_get_var_t(const char *name) FAST_FUNC; | 2153 | typedef const char *sh_get_var_t(const char *name) FAST_FUNC; |
| 2154 | typedef int sh_accept_glob_t(const char *name) FAST_FUNC; | ||
| 2005 | typedef struct line_input_t { | 2155 | typedef struct line_input_t { |
| 2006 | int flags; | 2156 | int flags; |
| 2007 | int timeout; | 2157 | int timeout; |
| @@ -2015,6 +2165,9 @@ typedef struct line_input_t { | |||
| 2015 | # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH | 2165 | # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH |
| 2016 | /* function to fetch additional application-specific names to match */ | 2166 | /* function to fetch additional application-specific names to match */ |
| 2017 | get_exe_name_t *get_exe_name; | 2167 | get_exe_name_t *get_exe_name; |
| 2168 | # if ENABLE_ASH_GLOB_OPTIONS | ||
| 2169 | sh_accept_glob_t *sh_accept_glob; | ||
| 2170 | # endif | ||
| 2018 | # endif | 2171 | # endif |
| 2019 | # endif | 2172 | # endif |
| 2020 | # if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \ | 2173 | # if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \ |
| @@ -2049,6 +2202,9 @@ enum { | |||
| 2049 | VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI, | 2202 | VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI, |
| 2050 | WITH_PATH_LOOKUP = 0x10, | 2203 | WITH_PATH_LOOKUP = 0x10, |
| 2051 | LI_INTERRUPTIBLE = 0x20, | 2204 | LI_INTERRUPTIBLE = 0x20, |
| 2205 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2206 | IGNORE_CTRL_C = 0x40, | ||
| 2207 | #endif | ||
| 2052 | FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE, | 2208 | FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE, |
| 2053 | }; | 2209 | }; |
| 2054 | line_input_t *new_line_input_t(int flags) FAST_FUNC; | 2210 | line_input_t *new_line_input_t(int flags) FAST_FUNC; |
| @@ -2078,6 +2234,10 @@ int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC; | |||
| 2078 | 2234 | ||
| 2079 | unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz); | 2235 | unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz); |
| 2080 | 2236 | ||
| 2237 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2238 | # undef COMM_LEN | ||
| 2239 | # define COMM_LEN 32 | ||
| 2240 | #endif | ||
| 2081 | #ifndef COMM_LEN | 2241 | #ifndef COMM_LEN |
| 2082 | # ifdef TASK_COMM_LEN | 2242 | # ifdef TASK_COMM_LEN |
| 2083 | enum { COMM_LEN = TASK_COMM_LEN }; | 2243 | enum { COMM_LEN = TASK_COMM_LEN }; |
| @@ -2088,7 +2248,13 @@ enum { COMM_LEN = 16 }; | |||
| 2088 | #endif | 2248 | #endif |
| 2089 | 2249 | ||
| 2090 | typedef struct procps_status_t { | 2250 | typedef struct procps_status_t { |
| 2251 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 2091 | DIR *dir; | 2252 | DIR *dir; |
| 2253 | #else | ||
| 2254 | HANDLE snapshot; | ||
| 2255 | DWORD *pids; | ||
| 2256 | int npids; | ||
| 2257 | #endif | ||
| 2092 | IF_FEATURE_SHOW_THREADS(DIR *task_dir;) | 2258 | IF_FEATURE_SHOW_THREADS(DIR *task_dir;) |
| 2093 | uint8_t shift_pages_to_bytes; | 2259 | uint8_t shift_pages_to_bytes; |
| 2094 | uint8_t shift_pages_to_kb; | 2260 | uint8_t shift_pages_to_kb; |
| @@ -2220,6 +2386,41 @@ enum { | |||
| 2220 | /* size of input block */ | 2386 | /* size of input block */ |
| 2221 | SHA2_INSIZE = 64, | 2387 | SHA2_INSIZE = 64, |
| 2222 | }; | 2388 | }; |
| 2389 | |||
| 2390 | #if defined CONFIG_FEATURE_USE_CNG_API | ||
| 2391 | struct bcrypt_hash_ctx_t { | ||
| 2392 | void *handle; | ||
| 2393 | void *hash_obj; | ||
| 2394 | unsigned int output_size; | ||
| 2395 | }; | ||
| 2396 | typedef struct bcrypt_hash_ctx_t md5_ctx_t; | ||
| 2397 | typedef struct bcrypt_hash_ctx_t sha1_ctx_t; | ||
| 2398 | typedef struct bcrypt_hash_ctx_t sha256_ctx_t; | ||
| 2399 | typedef struct bcrypt_hash_ctx_t sha384_ctx_t; | ||
| 2400 | typedef struct bcrypt_hash_ctx_t sha512_ctx_t; | ||
| 2401 | typedef struct sha3_ctx_t { | ||
| 2402 | uint64_t state[25]; | ||
| 2403 | unsigned bytes_queued; | ||
| 2404 | unsigned input_block_bytes; | ||
| 2405 | } sha3_ctx_t; | ||
| 2406 | void md5_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
| 2407 | void sha1_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
| 2408 | void sha256_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
| 2409 | void sha384_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
| 2410 | void sha512_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
| 2411 | void generic_hash(struct bcrypt_hash_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | ||
| 2412 | unsigned generic_end(struct bcrypt_hash_ctx_t *ctx, void *resbuf) FAST_FUNC; | ||
| 2413 | # define md5_hash generic_hash | ||
| 2414 | # define sha1_hash generic_hash | ||
| 2415 | # define sha256_hash generic_hash | ||
| 2416 | # define sha384_hash generic_hash | ||
| 2417 | # define sha512_hash generic_hash | ||
| 2418 | # define md5_end generic_end | ||
| 2419 | # define sha1_end generic_end | ||
| 2420 | # define sha256_end generic_end | ||
| 2421 | # define sha384_end generic_end | ||
| 2422 | # define sha512_end generic_end | ||
| 2423 | #else | ||
| 2223 | typedef struct md5_ctx_t { | 2424 | typedef struct md5_ctx_t { |
| 2224 | uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ | 2425 | uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ |
| 2225 | void (*process_block)(struct md5_ctx_t*) FAST_FUNC; | 2426 | void (*process_block)(struct md5_ctx_t*) FAST_FUNC; |
| @@ -2254,22 +2455,34 @@ unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; | |||
| 2254 | void sha384_begin(sha384_ctx_t *ctx) FAST_FUNC; | 2455 | void sha384_begin(sha384_ctx_t *ctx) FAST_FUNC; |
| 2255 | #define sha384_hash sha512_hash | 2456 | #define sha384_hash sha512_hash |
| 2256 | unsigned sha384_end(sha384_ctx_t *ctx, void *resbuf) FAST_FUNC; | 2457 | unsigned sha384_end(sha384_ctx_t *ctx, void *resbuf) FAST_FUNC; |
| 2458 | #endif | ||
| 2257 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; | 2459 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; |
| 2258 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 2460 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
| 2259 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; | 2461 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; |
| 2260 | void FAST_FUNC sha256_block(const void *in, size_t len, uint8_t hash[32]); | 2462 | void FAST_FUNC sha256_block(const void *in, size_t len, uint8_t hash[32]); |
| 2261 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ | 2463 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ |
| 2464 | #if defined CONFIG_FEATURE_USE_CNG_API | ||
| 2465 | typedef struct bcrypt_hash_ctx_t md5sha_ctx_t; | ||
| 2466 | #define md5sha_hash generic_hash | ||
| 2467 | #define sha_end generic_end | ||
| 2468 | #else | ||
| 2262 | typedef struct md5_ctx_t md5sha_ctx_t; | 2469 | typedef struct md5_ctx_t md5sha_ctx_t; |
| 2263 | #define md5sha_hash md5_hash | 2470 | #define md5sha_hash md5_hash |
| 2264 | #define sha_end sha1_end | 2471 | #define sha_end sha1_end |
| 2472 | #endif | ||
| 2265 | 2473 | ||
| 2266 | /* RFC 2104 HMAC (hash-based message authentication code) */ | 2474 | /* RFC 2104 HMAC (hash-based message authentication code) */ |
| 2475 | #if !ENABLE_FEATURE_USE_CNG_API | ||
| 2267 | typedef struct hmac_ctx { | 2476 | typedef struct hmac_ctx { |
| 2268 | md5sha_ctx_t hashed_key_xor_ipad; | 2477 | md5sha_ctx_t hashed_key_xor_ipad; |
| 2269 | md5sha_ctx_t hashed_key_xor_opad; | 2478 | md5sha_ctx_t hashed_key_xor_opad; |
| 2270 | } hmac_ctx_t; | 2479 | } hmac_ctx_t; |
| 2480 | #else | ||
| 2481 | typedef struct bcrypt_hash_ctx_t hmac_ctx_t; | ||
| 2482 | #endif | ||
| 2271 | #define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1) | 2483 | #define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1) |
| 2272 | typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; | 2484 | typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; |
| 2485 | #if !ENABLE_FEATURE_USE_CNG_API | ||
| 2273 | #if HMAC_ONLY_SHA256 | 2486 | #if HMAC_ONLY_SHA256 |
| 2274 | #define hmac_begin(ctx,key,key_size,begin) \ | 2487 | #define hmac_begin(ctx,key,key_size,begin) \ |
| 2275 | hmac_begin(ctx,key,key_size) | 2488 | hmac_begin(ctx,key,key_size) |
| @@ -2279,6 +2492,17 @@ static ALWAYS_INLINE void hmac_hash(hmac_ctx_t *ctx, const void *in, size_t len) | |||
| 2279 | { | 2492 | { |
| 2280 | md5sha_hash(&ctx->hashed_key_xor_ipad, in, len); | 2493 | md5sha_hash(&ctx->hashed_key_xor_ipad, in, len); |
| 2281 | } | 2494 | } |
| 2495 | #else | ||
| 2496 | # if HMAC_ONLY_SHA256 | ||
| 2497 | # define hmac_begin(pre,key,key_size,begin) \ | ||
| 2498 | _hmac_begin(pre, key, key_size, sha256_begin_hmac) | ||
| 2499 | # else | ||
| 2500 | # define hmac_begin _hmac_begin | ||
| 2501 | # endif | ||
| 2502 | void _hmac_begin(hmac_ctx_t *pre, uint8_t *key, unsigned key_size, | ||
| 2503 | BCRYPT_ALG_HANDLE alg_handle); | ||
| 2504 | void hmac_uninit(hmac_ctx_t *pre); | ||
| 2505 | #endif | ||
| 2282 | unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out); | 2506 | unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out); |
| 2283 | #if HMAC_ONLY_SHA256 | 2507 | #if HMAC_ONLY_SHA256 |
| 2284 | #define hmac_block(key,key_size,begin,in,sz,out) \ | 2508 | #define hmac_block(key,key_size,begin,in,sz,out) \ |
| @@ -2290,7 +2514,7 @@ unsigned FAST_FUNC hmac_block(const uint8_t *key, unsigned key_size, | |||
| 2290 | uint8_t *out); | 2514 | uint8_t *out); |
| 2291 | /* HMAC helpers for TLS: */ | 2515 | /* HMAC helpers for TLS: */ |
| 2292 | void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va); | 2516 | void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va); |
| 2293 | unsigned FAST_FUNC hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...); | 2517 | unsigned hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...); |
| 2294 | 2518 | ||
| 2295 | extern uint32_t *global_crc32_table; | 2519 | extern uint32_t *global_crc32_table; |
| 2296 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 2520 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |
| @@ -2374,11 +2598,18 @@ extern const char bb_path_wtmp_file[] ALIGN1; | |||
| 2374 | #define bb_path_motd_file "/etc/motd" | 2598 | #define bb_path_motd_file "/etc/motd" |
| 2375 | 2599 | ||
| 2376 | #define bb_dev_null "/dev/null" | 2600 | #define bb_dev_null "/dev/null" |
| 2601 | #if ENABLE_PLATFORM_MINGW32 | ||
| 2602 | #define bb_busybox_exec_path get_busybox_exec_path() | ||
| 2603 | extern char bb_comm[]; | ||
| 2604 | extern char bb_command_line[]; | ||
| 2605 | #else | ||
| 2377 | extern const char bb_busybox_exec_path[] ALIGN1; | 2606 | extern const char bb_busybox_exec_path[] ALIGN1; |
| 2607 | #endif | ||
| 2378 | /* allow default system PATH to be extended via CFLAGS */ | 2608 | /* allow default system PATH to be extended via CFLAGS */ |
| 2379 | #ifndef BB_ADDITIONAL_PATH | 2609 | #ifndef BB_ADDITIONAL_PATH |
| 2380 | #define BB_ADDITIONAL_PATH "" | 2610 | #define BB_ADDITIONAL_PATH "" |
| 2381 | #endif | 2611 | #endif |
| 2612 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 2382 | #define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH | 2613 | #define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH |
| 2383 | extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | 2614 | extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ |
| 2384 | #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) | 2615 | #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) |
| @@ -2386,6 +2617,23 @@ extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | |||
| 2386 | * but I want to save a few bytes here: | 2617 | * but I want to save a few bytes here: |
| 2387 | */ | 2618 | */ |
| 2388 | #define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) | 2619 | #define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) |
| 2620 | #define PATH_SEP ':' | ||
| 2621 | #define PATH_SEP_STR ":" | ||
| 2622 | #else | ||
| 2623 | #define BB_PATH_ROOT_PATH "PATH=C:/Windows/System32;C:/Windows" BB_ADDITIONAL_PATH | ||
| 2624 | extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | ||
| 2625 | #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) | ||
| 2626 | #define bb_default_path (bb_PATH_root_path + sizeof("PATH")) | ||
| 2627 | #define PATH_SEP ';' | ||
| 2628 | #define PATH_SEP_STR ";" | ||
| 2629 | extern const char bbvar[] ALIGN1; | ||
| 2630 | #define bbafter(p) (p + sizeof(#p)) | ||
| 2631 | #define BB_OVERRIDE_APPLETS bbvar | ||
| 2632 | #define BB_SKIP_ANSI_EMULATION bbafter(BB_OVERRIDE_APPLETS) | ||
| 2633 | #define BB_TERMINAL_MODE bbafter(BB_SKIP_ANSI_EMULATION) | ||
| 2634 | #define BB_SYSTEMROOT bbafter(BB_TERMINAL_MODE) | ||
| 2635 | #define BB_CRITICAL_ERROR_DIALOGS bbafter(BB_SYSTEMROOT) | ||
| 2636 | #endif | ||
| 2389 | 2637 | ||
| 2390 | extern const int const_int_0; | 2638 | extern const int const_int_0; |
| 2391 | //extern const int const_int_1; | 2639 | //extern const int const_int_1; |
