diff options
Diffstat (limited to '')
-rw-r--r-- | include/libbb.h | 453 |
1 files changed, 372 insertions, 81 deletions
diff --git a/include/libbb.h b/include/libbb.h index 4d6193795..60037ed3d 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. |
@@ -301,7 +353,7 @@ typedef unsigned long long uoff_t; | |||
301 | # define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX) | 353 | # define XATOOFF(a) xatoull_range((a), 0, LLONG_MAX) |
302 | # define BB_STRTOOFF bb_strtoull | 354 | # define BB_STRTOOFF bb_strtoull |
303 | # define STRTOOFF strtoull | 355 | # define STRTOOFF strtoull |
304 | # define OFF_FMT "ll" | 356 | # define OFF_FMT LL_FMT |
305 | # endif | 357 | # endif |
306 | #else | 358 | #else |
307 | /* CONFIG_LFS is off */ | 359 | /* CONFIG_LFS is off */ |
@@ -570,13 +622,20 @@ char *bb_get_last_path_component_nostrip(const char *path) FAST_FUNC; | |||
570 | const char *bb_basename(const char *name) FAST_FUNC; | 622 | const char *bb_basename(const char *name) FAST_FUNC; |
571 | /* NB: can violate const-ness (similarly to strchr) */ | 623 | /* NB: can violate const-ness (similarly to strchr) */ |
572 | char *last_char_is(const char *s, int c) FAST_FUNC; | 624 | char *last_char_is(const char *s, int c) FAST_FUNC; |
625 | char *last_char_is_dir_sep(const char *s) FAST_FUNC; | ||
573 | const char* endofname(const char *name) FAST_FUNC; | 626 | const char* endofname(const char *name) FAST_FUNC; |
574 | char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; | 627 | char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; |
575 | char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; | 628 | char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; |
576 | 629 | ||
630 | #if !ENABLE_PLATFORM_MINGW32 | ||
577 | int ndelay_on(int fd) FAST_FUNC; | 631 | int ndelay_on(int fd) FAST_FUNC; |
578 | int ndelay_off(int fd) FAST_FUNC; | 632 | int ndelay_off(int fd) FAST_FUNC; |
579 | void close_on_exec_on(int fd) FAST_FUNC; | 633 | void close_on_exec_on(int fd) FAST_FUNC; |
634 | #else | ||
635 | static inline int ndelay_on(int fd UNUSED_PARAM) { return 0; } | ||
636 | static inline int ndelay_off(int fd UNUSED_PARAM) { return 0; } | ||
637 | static inline void close_on_exec_on(int fd UNUSED_PARAM) { return; } | ||
638 | #endif | ||
580 | void xdup2(int, int) FAST_FUNC; | 639 | void xdup2(int, int) FAST_FUNC; |
581 | void xmove_fd(int, int) FAST_FUNC; | 640 | void xmove_fd(int, int) FAST_FUNC; |
582 | 641 | ||
@@ -610,20 +669,37 @@ enum { | |||
610 | * Dance around with long long to guard against that... | 669 | * Dance around with long long to guard against that... |
611 | */ | 670 | */ |
612 | BB_FATAL_SIGS = (int)(0 | 671 | BB_FATAL_SIGS = (int)(0 |
672 | #ifdef SIGHUP | ||
613 | + (1LL << SIGHUP) | 673 | + (1LL << SIGHUP) |
674 | #endif | ||
614 | + (1LL << SIGINT) | 675 | + (1LL << SIGINT) |
615 | + (1LL << SIGTERM) | 676 | + (1LL << SIGTERM) |
616 | + (1LL << SIGPIPE) // Write to pipe with no readers | 677 | + (1LL << SIGPIPE) // Write to pipe with no readers |
678 | #ifdef SIGQUIT | ||
617 | + (1LL << SIGQUIT) // Quit from keyboard | 679 | + (1LL << SIGQUIT) // Quit from keyboard |
680 | #endif | ||
618 | + (1LL << SIGABRT) // Abort signal from abort(3) | 681 | + (1LL << SIGABRT) // Abort signal from abort(3) |
682 | #ifdef SIGALRM | ||
619 | + (1LL << SIGALRM) // Timer signal from alarm(2) | 683 | + (1LL << SIGALRM) // Timer signal from alarm(2) |
684 | #endif | ||
685 | #ifdef SIGVTALRM | ||
620 | + (1LL << SIGVTALRM) // Virtual alarm clock | 686 | + (1LL << SIGVTALRM) // Virtual alarm clock |
687 | #endif | ||
688 | #ifdef SIGXCPU | ||
621 | + (1LL << SIGXCPU) // CPU time limit exceeded | 689 | + (1LL << SIGXCPU) // CPU time limit exceeded |
690 | #endif | ||
691 | #ifdef SIGXFSZ | ||
622 | + (1LL << SIGXFSZ) // File size limit exceeded | 692 | + (1LL << SIGXFSZ) // File size limit exceeded |
693 | #endif | ||
694 | #ifdef SIGUSR1 | ||
623 | + (1LL << SIGUSR1) // Yes kids, these are also fatal! | 695 | + (1LL << SIGUSR1) // Yes kids, these are also fatal! |
696 | #endif | ||
697 | #ifdef SIGUSR1 | ||
624 | + (1LL << SIGUSR2) | 698 | + (1LL << SIGUSR2) |
699 | #endif | ||
625 | + 0), | 700 | + 0), |
626 | }; | 701 | }; |
702 | #if !ENABLE_PLATFORM_MINGW32 | ||
627 | void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; | 703 | void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; |
628 | /* Unlike signal() and bb_signals, sets handler with sigaction() | 704 | /* Unlike signal() and bb_signals, sets handler with sigaction() |
629 | * and in a way that while signal handler is run, no other signals | 705 | * and in a way that while signal handler is run, no other signals |
@@ -643,6 +719,10 @@ int sigaction_set(int sig, const struct sigaction *act) FAST_FUNC; | |||
643 | int sigprocmask_allsigs(int how) FAST_FUNC; | 719 | int sigprocmask_allsigs(int how) FAST_FUNC; |
644 | /* Return old set in the same set: */ | 720 | /* Return old set in the same set: */ |
645 | int sigprocmask2(int how, sigset_t *set) FAST_FUNC; | 721 | int sigprocmask2(int how, sigset_t *set) FAST_FUNC; |
722 | #else | ||
723 | #define bb_signals(s, f) | ||
724 | #define kill_myself_with_sig(s) | ||
725 | #endif | ||
646 | /* Standard handler which just records signo */ | 726 | /* Standard handler which just records signo */ |
647 | extern smallint bb_got_signal; | 727 | extern smallint bb_got_signal; |
648 | void record_signo(int signo); /* not FAST_FUNC! */ | 728 | void record_signo(int signo); /* not FAST_FUNC! */ |
@@ -726,7 +806,7 @@ void xsettimeofday(const struct timeval *tv) FAST_FUNC; | |||
726 | int xsocket(int domain, int type, int protocol) FAST_FUNC; | 806 | int xsocket(int domain, int type, int protocol) FAST_FUNC; |
727 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; | 807 | void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; |
728 | void xlisten(int s, int backlog) FAST_FUNC; | 808 | void xlisten(int s, int backlog) FAST_FUNC; |
729 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; | 809 | void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC; |
730 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | 810 | ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, |
731 | socklen_t tolen) FAST_FUNC; | 811 | socklen_t tolen) FAST_FUNC; |
732 | 812 | ||
@@ -839,7 +919,36 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC; | |||
839 | // Also mount.c and inetd.c are using gethostbyname(), | 919 | // Also mount.c and inetd.c are using gethostbyname(), |
840 | // + inet_common.c has additional IPv4-only stuff | 920 | // + inet_common.c has additional IPv4-only stuff |
841 | 921 | ||
922 | #if defined CONFIG_FEATURE_TLS_SCHANNEL | ||
923 | typedef struct tls_state { | ||
924 | int ofd; | ||
925 | int ifd; | ||
926 | |||
927 | // handles | ||
928 | CredHandle cred_handle; | ||
929 | CtxtHandle ctx_handle; | ||
842 | 930 | ||
931 | // buffers | ||
932 | char in_buffer[16384 + 256]; // input buffer (to read from server) | ||
933 | unsigned long in_buffer_size; // amount of data currently in input buffer | ||
934 | |||
935 | char *out_buffer; // output buffer (for decrypted data), this is essentially the same as input buffer as data is decrypted in place | ||
936 | unsigned long out_buffer_size; // amount of data currently in output buffer | ||
937 | unsigned long out_buffer_used; // amount of extra data currently in output buffer | ||
938 | |||
939 | // data | ||
940 | char *hostname; | ||
941 | SecPkgContext_StreamSizes stream_sizes; | ||
942 | |||
943 | // booleans | ||
944 | |||
945 | // context initialized | ||
946 | int initialized; | ||
947 | |||
948 | // closed by remote peer | ||
949 | int closed; | ||
950 | } tls_state_t; | ||
951 | #else | ||
843 | struct tls_aes { | 952 | struct tls_aes { |
844 | uint32_t key[60]; | 953 | uint32_t key[60]; |
845 | unsigned rounds; | 954 | unsigned rounds; |
@@ -896,12 +1005,14 @@ typedef struct tls_state { | |||
896 | struct tls_aes aes_decrypt; | 1005 | struct tls_aes aes_decrypt; |
897 | uint8_t H[16]; //used by AES_GCM | 1006 | uint8_t H[16]; //used by AES_GCM |
898 | } tls_state_t; | 1007 | } tls_state_t; |
1008 | #endif | ||
899 | 1009 | ||
900 | static inline tls_state_t *new_tls_state(void) | 1010 | static inline tls_state_t *new_tls_state(void) |
901 | { | 1011 | { |
902 | tls_state_t *tls = xzalloc(sizeof(*tls)); | 1012 | tls_state_t *tls = xzalloc(sizeof(*tls)); |
903 | return tls; | 1013 | return tls; |
904 | } | 1014 | } |
1015 | |||
905 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; | 1016 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; |
906 | #define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) | 1017 | #define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) |
907 | void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; | 1018 | void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; |
@@ -933,7 +1044,7 @@ int bb_putchar(int ch) FAST_FUNC; | |||
933 | /* Note: does not use stdio, writes to fd 2 directly */ | 1044 | /* Note: does not use stdio, writes to fd 2 directly */ |
934 | int bb_putchar_stderr(char ch) FAST_FUNC; | 1045 | int bb_putchar_stderr(char ch) FAST_FUNC; |
935 | int fputs_stdout(const char *s) FAST_FUNC; | 1046 | int fputs_stdout(const char *s) FAST_FUNC; |
936 | char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC; | 1047 | char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) RETURNS_MALLOC; |
937 | char *auto_string(char *str) FAST_FUNC; | 1048 | char *auto_string(char *str) FAST_FUNC; |
938 | // gcc-4.1.1 still isn't good enough at optimizing it | 1049 | // gcc-4.1.1 still isn't good enough at optimizing it |
939 | // (+200 bytes compared to macro) | 1050 | // (+200 bytes compared to macro) |
@@ -1011,13 +1122,13 @@ unsigned bb_clk_tck(void) FAST_FUNC; | |||
1011 | 1122 | ||
1012 | #if SEAMLESS_COMPRESSION | 1123 | #if SEAMLESS_COMPRESSION |
1013 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ | 1124 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ |
1014 | int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC; | 1125 | int setup_unzip_on_fd(int fd, int die_if_not_compressed) FAST_FUNC; |
1015 | /* Autodetects .gz etc */ | 1126 | /* Autodetects .gz etc */ |
1016 | extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC; | 1127 | extern int open_zipped(const char *fname, int die_if_not_compressed) FAST_FUNC; |
1017 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 1128 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
1018 | #else | 1129 | #else |
1019 | # define setup_unzip_on_fd(...) (0) | 1130 | # define setup_unzip_on_fd(...) (0) |
1020 | # define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY); | 1131 | # define open_zipped(fname, die_if_not_compressed) open((fname), O_RDONLY); |
1021 | # define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p)) | 1132 | # define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p)) |
1022 | #endif | 1133 | #endif |
1023 | /* lzma has no signature, need a little helper. NB: exist only for ENABLE_FEATURE_SEAMLESS_LZMA=y */ | 1134 | /* lzma has no signature, need a little helper. NB: exist only for ENABLE_FEATURE_SEAMLESS_LZMA=y */ |
@@ -1113,6 +1224,32 @@ char *bin2hex(char *dst, const char *src, int count) FAST_FUNC; | |||
1113 | /* Reverse */ | 1224 | /* Reverse */ |
1114 | char* hex2bin(char *dst, const char *src, int count) FAST_FUNC; | 1225 | char* hex2bin(char *dst, const char *src, int count) FAST_FUNC; |
1115 | 1226 | ||
1227 | /* Returns strlen as a bonus */ | ||
1228 | //size_t replace_char(char *s, char what, char with) FAST_FUNC; | ||
1229 | static inline size_t replace_char(char *str, char from, char to) | ||
1230 | { | ||
1231 | char *p = str; | ||
1232 | while (*p) { | ||
1233 | if (*p == from) | ||
1234 | *p = to; | ||
1235 | p++; | ||
1236 | } | ||
1237 | return p - str; | ||
1238 | } | ||
1239 | |||
1240 | extern const char c_escape_conv_str00[]; | ||
1241 | #define c_escape_conv_str07 (c_escape_conv_str00+3) | ||
1242 | |||
1243 | void FAST_FUNC xorbuf_3(void *dst, const void *src1, const void *src2, unsigned count); | ||
1244 | void FAST_FUNC xorbuf(void* buf, const void* mask, unsigned count); | ||
1245 | void FAST_FUNC xorbuf16_aligned_long(void* buf, const void* mask); | ||
1246 | void FAST_FUNC xorbuf64_3_aligned64(void *dst, const void *src1, const void *src2); | ||
1247 | #if BB_UNALIGNED_MEMACCESS_OK | ||
1248 | # define xorbuf16(buf,mask) xorbuf16_aligned_long(buf,mask) | ||
1249 | #else | ||
1250 | void FAST_FUNC xorbuf16(void* buf, const void* mask); | ||
1251 | #endif | ||
1252 | |||
1116 | /* Generate a UUID */ | 1253 | /* Generate a UUID */ |
1117 | void generate_uuid(uint8_t *buf) FAST_FUNC; | 1254 | void generate_uuid(uint8_t *buf) FAST_FUNC; |
1118 | 1255 | ||
@@ -1208,12 +1345,20 @@ gid_t *bb_getgroups(int *ngroups, gid_t *group_array) FAST_FUNC; | |||
1208 | struct cached_groupinfo { | 1345 | struct cached_groupinfo { |
1209 | uid_t euid; | 1346 | uid_t euid; |
1210 | gid_t egid; | 1347 | gid_t egid; |
1348 | #if !ENABLE_PLATFORM_MINGW32 | ||
1349 | // If these are ever restored on Windows it will be necessary to alter | ||
1350 | // globals_misc_size()/globals_misc_copy() in ash. | ||
1211 | int ngroups; | 1351 | int ngroups; |
1212 | gid_t *supplementary_array; | 1352 | gid_t *supplementary_array; |
1353 | #endif | ||
1213 | }; | 1354 | }; |
1214 | uid_t FAST_FUNC get_cached_euid(uid_t *euid); | 1355 | uid_t FAST_FUNC get_cached_euid(uid_t *euid); |
1215 | gid_t FAST_FUNC get_cached_egid(gid_t *egid); | 1356 | gid_t FAST_FUNC get_cached_egid(gid_t *egid); |
1357 | #if !ENABLE_PLATFORM_MINGW32 | ||
1216 | int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid); | 1358 | int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid); |
1359 | #else | ||
1360 | # define is_in_supplementary_groups(g, i) (FALSE) | ||
1361 | #endif | ||
1217 | 1362 | ||
1218 | #if ENABLE_FEATURE_UTMP | 1363 | #if ENABLE_FEATURE_UTMP |
1219 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); | 1364 | void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); |
@@ -1249,6 +1394,7 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; | |||
1249 | 1394 | ||
1250 | /* xvfork() can't be a _function_, return after vfork in child mangles stack | 1395 | /* xvfork() can't be a _function_, return after vfork in child mangles stack |
1251 | * in the parent. It must be a macro. */ | 1396 | * in the parent. It must be a macro. */ |
1397 | #if !ENABLE_PLATFORM_MINGW32 | ||
1252 | #define xvfork() \ | 1398 | #define xvfork() \ |
1253 | ({ \ | 1399 | ({ \ |
1254 | pid_t bb__xvfork_pid = vfork(); \ | 1400 | pid_t bb__xvfork_pid = vfork(); \ |
@@ -1256,6 +1402,9 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; | |||
1256 | bb_simple_perror_msg_and_die("vfork"); \ | 1402 | bb_simple_perror_msg_and_die("vfork"); \ |
1257 | bb__xvfork_pid; \ | 1403 | bb__xvfork_pid; \ |
1258 | }) | 1404 | }) |
1405 | #else | ||
1406 | #define xvfork() vfork() | ||
1407 | #endif | ||
1259 | #if BB_MMU | 1408 | #if BB_MMU |
1260 | pid_t xfork(void) FAST_FUNC; | 1409 | pid_t xfork(void) FAST_FUNC; |
1261 | #endif | 1410 | #endif |
@@ -1290,6 +1439,15 @@ void run_noexec_applet_and_exit(int a, const char *name, char **argv) NORETURN F | |||
1290 | #ifndef BUILD_INDIVIDUAL | 1439 | #ifndef BUILD_INDIVIDUAL |
1291 | int find_applet_by_name(const char *name) FAST_FUNC; | 1440 | int find_applet_by_name(const char *name) FAST_FUNC; |
1292 | void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; | 1441 | void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; |
1442 | # if ENABLE_PLATFORM_MINGW32 | ||
1443 | # if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | ||
1444 | int prefer_applet(const char *name, const char *path) FAST_FUNC; | ||
1445 | int find_applet_by_name_for_sh(const char *name, const char *path) FAST_FUNC; | ||
1446 | # endif | ||
1447 | # else | ||
1448 | # define prefer_applet(n, p) (1) | ||
1449 | # define find_applet_by_name_for_sh(n, p) find_applet_by_name(n) | ||
1450 | # endif | ||
1293 | #endif | 1451 | #endif |
1294 | void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC; | 1452 | void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC; |
1295 | #if defined(__linux__) | 1453 | #if defined(__linux__) |
@@ -1370,12 +1528,12 @@ char* single_argv(char **argv) FAST_FUNC; | |||
1370 | char **skip_dash_dash(char **argv) FAST_FUNC; | 1528 | char **skip_dash_dash(char **argv) FAST_FUNC; |
1371 | extern const char *const bb_argv_dash[]; /* { "-", NULL } */ | 1529 | extern const char *const bb_argv_dash[]; /* { "-", NULL } */ |
1372 | extern uint32_t option_mask32; | 1530 | extern uint32_t option_mask32; |
1373 | uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; | 1531 | uint32_t getopt32(char **argv, const char *applet_opts, ...); |
1374 | # define No_argument "\0" | 1532 | # define No_argument "\0" |
1375 | # define Required_argument "\001" | 1533 | # define Required_argument "\001" |
1376 | # define Optional_argument "\002" | 1534 | # define Optional_argument "\002" |
1377 | #if ENABLE_LONG_OPTS | 1535 | #if ENABLE_LONG_OPTS |
1378 | uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...) FAST_FUNC; | 1536 | uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...); |
1379 | #else | 1537 | #else |
1380 | #define getopt32long(argv,optstring,longopts,...) \ | 1538 | #define getopt32long(argv,optstring,longopts,...) \ |
1381 | getopt32(argv,optstring,##__VA_ARGS__) | 1539 | getopt32(argv,optstring,##__VA_ARGS__) |
@@ -1450,17 +1608,17 @@ extern uint8_t xfunc_error_retval; | |||
1450 | extern void (*die_func)(void); | 1608 | extern void (*die_func)(void); |
1451 | void xfunc_die(void) NORETURN FAST_FUNC; | 1609 | void xfunc_die(void) NORETURN FAST_FUNC; |
1452 | void bb_show_usage(void) NORETURN FAST_FUNC; | 1610 | void bb_show_usage(void) NORETURN FAST_FUNC; |
1453 | void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1611 | void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
1454 | void bb_simple_error_msg(const char *s) FAST_FUNC; | 1612 | void bb_simple_error_msg(const char *s) FAST_FUNC; |
1455 | void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1613 | void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
1456 | void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1614 | void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC; |
1457 | void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1615 | void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
1458 | void bb_simple_perror_msg(const char *s) FAST_FUNC; | 1616 | void bb_simple_perror_msg(const char *s) FAST_FUNC; |
1459 | void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1617 | void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
1460 | void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1618 | void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; |
1461 | void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1619 | void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
1462 | void bb_simple_herror_msg(const char *s) FAST_FUNC; | 1620 | void bb_simple_herror_msg(const char *s) FAST_FUNC; |
1463 | void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; | 1621 | void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
1464 | void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC; | 1622 | void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC; |
1465 | void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; | 1623 | void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; |
1466 | void bb_perror_nomsg(void) FAST_FUNC; | 1624 | void bb_perror_nomsg(void) FAST_FUNC; |
@@ -1476,7 +1634,7 @@ void bb_logenv_override(void) FAST_FUNC; | |||
1476 | typedef smalluint exitcode_t; | 1634 | typedef smalluint exitcode_t; |
1477 | 1635 | ||
1478 | #if ENABLE_FEATURE_SYSLOG_INFO | 1636 | #if ENABLE_FEATURE_SYSLOG_INFO |
1479 | void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; | 1637 | void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
1480 | void bb_simple_info_msg(const char *s) FAST_FUNC; | 1638 | void bb_simple_info_msg(const char *s) FAST_FUNC; |
1481 | void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC; | 1639 | void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC; |
1482 | #else | 1640 | #else |
@@ -1806,18 +1964,25 @@ extern char *pw_encrypt(const char *clear, const char *salt, int cleanup) FAST_F | |||
1806 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC; | 1964 | extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC; |
1807 | /* | 1965 | /* |
1808 | * rnd is additional random input. New one is returned. | 1966 | * rnd is additional random input. New one is returned. |
1809 | * Useful if you call crypt_make_salt many times in a row: | 1967 | * Useful if you call crypt_make_rand64encoded many times in a row: |
1810 | * rnd = crypt_make_salt(buf1, 4, 0); | 1968 | * rnd = crypt_make_rand64encoded(buf1, 4, 0); |
1811 | * rnd = crypt_make_salt(buf2, 4, rnd); | 1969 | * rnd = crypt_make_rand64encoded(buf2, 4, rnd); |
1812 | * rnd = crypt_make_salt(buf3, 4, rnd); | 1970 | * rnd = crypt_make_rand64encoded(buf3, 4, rnd); |
1813 | * (otherwise we risk having same salt generated) | 1971 | * (otherwise we risk having same salt generated) |
1814 | */ | 1972 | */ |
1815 | extern int crypt_make_salt(char *p, int cnt /*, int rnd*/) FAST_FUNC; | 1973 | extern int crypt_make_rand64encoded(char *p, int cnt /*, int rnd*/) FAST_FUNC; |
1816 | /* "$N$" + sha_salt_16_bytes + NUL */ | 1974 | /* Size of char salt[] to hold randomly-generated salt string |
1817 | #define MAX_PW_SALT_LEN (3 + 16 + 1) | 1975 | * sha256/512: |
1976 | * "$5$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>" | ||
1977 | * "$6$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>" | ||
1978 | * #define MAX_PW_SALT_LEN (3 + sizeof("rounds=999999999$")-1 + 16 + 1) | ||
1979 | * yescrypt: | ||
1980 | * "$y$" <up to 8 params of up to 6 chars each> "$" <up to 86 chars salt><NUL> | ||
1981 | * (86 chars are ascii64-encoded 64 binary bytes) | ||
1982 | */ | ||
1983 | #define MAX_PW_SALT_LEN (3 + 8*6 + 1 + 86 + 1) | ||
1818 | extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC; | 1984 | extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC; |
1819 | 1985 | ||
1820 | |||
1821 | /* Returns number of lines changed, or -1 on error */ | 1986 | /* Returns number of lines changed, or -1 on error */ |
1822 | #if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP) | 1987 | #if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP) |
1823 | #define update_passwd(filename, username, data, member) \ | 1988 | #define update_passwd(filename, username, data, member) \ |
@@ -1853,8 +2018,8 @@ int get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *ol | |||
1853 | int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; | 2018 | int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; |
1854 | 2019 | ||
1855 | /* NB: "unsigned request" is crucial! "int request" will break some arches! */ | 2020 | /* NB: "unsigned request" is crucial! "int request" will break some arches! */ |
1856 | int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; | 2021 | int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); |
1857 | int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; | 2022 | int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))); |
1858 | #if ENABLE_IOCTL_HEX2STR_ERROR | 2023 | #if ENABLE_IOCTL_HEX2STR_ERROR |
1859 | int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; | 2024 | int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; |
1860 | int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; | 2025 | int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; |
@@ -1867,9 +2032,15 @@ int bb_xioctl(int fd, unsigned request, void *argp) FAST_FUNC; | |||
1867 | #define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) | 2032 | #define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) |
1868 | #endif | 2033 | #endif |
1869 | 2034 | ||
2035 | #if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA | ||
1870 | char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC; | 2036 | char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC; |
1871 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC; | 2037 | void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC; |
1872 | void reset_ino_dev_hashtable(void) FAST_FUNC; | 2038 | void reset_ino_dev_hashtable(void) FAST_FUNC; |
2039 | #else | ||
2040 | #define add_to_ino_dev_hashtable(s, n) (void)0 | ||
2041 | #define is_in_ino_dev_hashtable(s) NULL | ||
2042 | #define reset_ino_dev_hashtable() | ||
2043 | #endif | ||
1873 | #ifdef __GLIBC__ | 2044 | #ifdef __GLIBC__ |
1874 | /* At least glibc has horrendously large inline for this, so wrap it */ | 2045 | /* At least glibc has horrendously large inline for this, so wrap it */ |
1875 | unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; | 2046 | unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; |
@@ -1947,10 +2118,17 @@ enum { | |||
1947 | * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout | 2118 | * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout |
1948 | */ | 2119 | */ |
1949 | int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 2120 | int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
2121 | #if ENABLE_PLATFORM_MINGW32 | ||
2122 | int64_t windows_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | ||
2123 | #endif | ||
1950 | /* This version loops on EINTR: */ | 2124 | /* This version loops on EINTR: */ |
1951 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 2125 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
1952 | void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; | 2126 | void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; |
1953 | 2127 | ||
2128 | int check_got_signal_and_poll(struct pollfd pfd[1], int timeout) FAST_FUNC; | ||
2129 | #if ENABLE_PLATFORM_MINGW32 | ||
2130 | # define check_got_signal_and_poll(p, t) poll(p, 1, t) | ||
2131 | #endif | ||
1954 | 2132 | ||
1955 | #if ENABLE_FEATURE_EDITING | 2133 | #if ENABLE_FEATURE_EDITING |
1956 | /* It's NOT just ENABLEd or disabled. It's a number: */ | 2134 | /* It's NOT just ENABLEd or disabled. It's a number: */ |
@@ -1960,8 +2138,14 @@ unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC; | |||
1960 | # else | 2138 | # else |
1961 | # define MAX_HISTORY 0 | 2139 | # define MAX_HISTORY 0 |
1962 | # endif | 2140 | # endif |
2141 | # if defined CONFIG_FEATURE_EDITING_HISTORY_DEFAULT && CONFIG_FEATURE_EDITING_HISTORY_DEFAULT > 0 | ||
2142 | # define DEFAULT_HISTORY (CONFIG_FEATURE_EDITING_HISTORY_DEFAULT + 0) | ||
2143 | # else | ||
2144 | # define DEFAULT_HISTORY 0 | ||
2145 | # endif | ||
1963 | typedef const char *get_exe_name_t(int i) FAST_FUNC; | 2146 | typedef const char *get_exe_name_t(int i) FAST_FUNC; |
1964 | typedef const char *sh_get_var_t(const char *name) FAST_FUNC; | 2147 | typedef const char *sh_get_var_t(const char *name) FAST_FUNC; |
2148 | typedef int sh_accept_glob_t(const char *name) FAST_FUNC; | ||
1965 | typedef struct line_input_t { | 2149 | typedef struct line_input_t { |
1966 | int flags; | 2150 | int flags; |
1967 | int timeout; | 2151 | int timeout; |
@@ -1975,6 +2159,9 @@ typedef struct line_input_t { | |||
1975 | # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH | 2159 | # if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH |
1976 | /* function to fetch additional application-specific names to match */ | 2160 | /* function to fetch additional application-specific names to match */ |
1977 | get_exe_name_t *get_exe_name; | 2161 | get_exe_name_t *get_exe_name; |
2162 | # if ENABLE_ASH_GLOB_OPTIONS | ||
2163 | sh_accept_glob_t *sh_accept_glob; | ||
2164 | # endif | ||
1978 | # endif | 2165 | # endif |
1979 | # endif | 2166 | # endif |
1980 | # if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \ | 2167 | # if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \ |
@@ -1988,7 +2175,7 @@ typedef struct line_input_t { | |||
1988 | # if MAX_HISTORY | 2175 | # if MAX_HISTORY |
1989 | int cnt_history; | 2176 | int cnt_history; |
1990 | int cur_history; | 2177 | int cur_history; |
1991 | int max_history; /* must never be <= 0 */ | 2178 | int max_history; /* must never be < 0 */ |
1992 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY | 2179 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY |
1993 | /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT: | 2180 | /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT: |
1994 | * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are | 2181 | * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are |
@@ -2009,6 +2196,9 @@ enum { | |||
2009 | VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI, | 2196 | VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI, |
2010 | WITH_PATH_LOOKUP = 0x10, | 2197 | WITH_PATH_LOOKUP = 0x10, |
2011 | LI_INTERRUPTIBLE = 0x20, | 2198 | LI_INTERRUPTIBLE = 0x20, |
2199 | #if ENABLE_PLATFORM_MINGW32 | ||
2200 | IGNORE_CTRL_C = 0x40, | ||
2201 | #endif | ||
2012 | FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE, | 2202 | FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE, |
2013 | }; | 2203 | }; |
2014 | line_input_t *new_line_input_t(int flags) FAST_FUNC; | 2204 | line_input_t *new_line_input_t(int flags) FAST_FUNC; |
@@ -2038,6 +2228,10 @@ int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC; | |||
2038 | 2228 | ||
2039 | unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz); | 2229 | unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz); |
2040 | 2230 | ||
2231 | #if ENABLE_PLATFORM_MINGW32 | ||
2232 | # undef COMM_LEN | ||
2233 | # define COMM_LEN 32 | ||
2234 | #endif | ||
2041 | #ifndef COMM_LEN | 2235 | #ifndef COMM_LEN |
2042 | # ifdef TASK_COMM_LEN | 2236 | # ifdef TASK_COMM_LEN |
2043 | enum { COMM_LEN = TASK_COMM_LEN }; | 2237 | enum { COMM_LEN = TASK_COMM_LEN }; |
@@ -2047,35 +2241,14 @@ enum { COMM_LEN = 16 }; | |||
2047 | # endif | 2241 | # endif |
2048 | #endif | 2242 | #endif |
2049 | 2243 | ||
2050 | struct smaprec { | ||
2051 | unsigned long mapped_rw; | ||
2052 | unsigned long mapped_ro; | ||
2053 | unsigned long shared_clean; | ||
2054 | unsigned long shared_dirty; | ||
2055 | unsigned long private_clean; | ||
2056 | unsigned long private_dirty; | ||
2057 | unsigned long stack; | ||
2058 | unsigned long smap_pss, smap_swap; | ||
2059 | unsigned long smap_size; | ||
2060 | // For mixed 32/64 userspace, 32-bit pmap still needs | ||
2061 | // 64-bit field here to correctly show 64-bit processes: | ||
2062 | unsigned long long smap_start; | ||
2063 | // (strictly speaking, other fields need to be wider too, | ||
2064 | // but they are in kbytes, not bytes, and they hold sizes, | ||
2065 | // not start addresses, sizes tend to be less than 4 terabytes) | ||
2066 | char smap_mode[5]; | ||
2067 | char *smap_name; | ||
2068 | }; | ||
2069 | |||
2070 | #if !ENABLE_PMAP | ||
2071 | #define procps_read_smaps(pid, total, cb, data) \ | ||
2072 | procps_read_smaps(pid, total) | ||
2073 | #endif | ||
2074 | int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total, | ||
2075 | void (*cb)(struct smaprec *, void *), void *data); | ||
2076 | |||
2077 | typedef struct procps_status_t { | 2244 | typedef struct procps_status_t { |
2245 | #if !ENABLE_PLATFORM_MINGW32 | ||
2078 | DIR *dir; | 2246 | DIR *dir; |
2247 | #else | ||
2248 | HANDLE snapshot; | ||
2249 | DWORD *pids; | ||
2250 | int npids; | ||
2251 | #endif | ||
2079 | IF_FEATURE_SHOW_THREADS(DIR *task_dir;) | 2252 | IF_FEATURE_SHOW_THREADS(DIR *task_dir;) |
2080 | uint8_t shift_pages_to_bytes; | 2253 | uint8_t shift_pages_to_bytes; |
2081 | uint8_t shift_pages_to_kb; | 2254 | uint8_t shift_pages_to_kb; |
@@ -2103,7 +2276,13 @@ typedef struct procps_status_t { | |||
2103 | #endif | 2276 | #endif |
2104 | unsigned tty_major,tty_minor; | 2277 | unsigned tty_major,tty_minor; |
2105 | #if ENABLE_FEATURE_TOPMEM | 2278 | #if ENABLE_FEATURE_TOPMEM |
2106 | struct smaprec smaps; | 2279 | unsigned long mapped_rw; |
2280 | unsigned long mapped_ro; | ||
2281 | unsigned long shared_clean; | ||
2282 | unsigned long shared_dirty; | ||
2283 | unsigned long private_clean; | ||
2284 | unsigned long private_dirty; | ||
2285 | unsigned long stack; | ||
2107 | #endif | 2286 | #endif |
2108 | char state[4]; | 2287 | char state[4]; |
2109 | /* basename of executable in exec(2), read from /proc/N/stat | 2288 | /* basename of executable in exec(2), read from /proc/N/stat |
@@ -2152,11 +2331,15 @@ void free_procps_scan(procps_status_t* sp) FAST_FUNC; | |||
2152 | procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; | 2331 | procps_status_t* procps_scan(procps_status_t* sp, int flags) FAST_FUNC; |
2153 | /* Format cmdline (up to col chars) into char buf[size] */ | 2332 | /* Format cmdline (up to col chars) into char buf[size] */ |
2154 | /* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ | 2333 | /* Puts [comm] if cmdline is empty (-> process is a kernel thread) */ |
2155 | void read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; | 2334 | int read_cmdline(char *buf, int size, unsigned pid, const char *comm) FAST_FUNC; |
2156 | pid_t *find_pid_by_name(const char* procName) FAST_FUNC; | 2335 | pid_t *find_pid_by_name(const char* procName) FAST_FUNC; |
2157 | pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; | 2336 | pid_t *pidlist_reverse(pid_t *pidList) FAST_FUNC; |
2158 | int starts_with_cpu(const char *str) FAST_FUNC; | 2337 | int starts_with_cpu(const char *str) FAST_FUNC; |
2159 | unsigned get_cpu_count(void) FAST_FUNC; | 2338 | unsigned get_cpu_count(void) FAST_FUNC; |
2339 | /* Some internals reused by pmap: */ | ||
2340 | unsigned long FAST_FUNC fast_strtoul_10(char **endptr); | ||
2341 | unsigned long long FAST_FUNC fast_strtoull_16(char **endptr); | ||
2342 | char* FAST_FUNC skip_fields(char *str, int count); | ||
2160 | 2343 | ||
2161 | 2344 | ||
2162 | /* Use strict=1 if you process input from untrusted source: | 2345 | /* Use strict=1 if you process input from untrusted source: |
@@ -2182,6 +2365,56 @@ char *decode_base64(char *dst, const char **pp_src) FAST_FUNC; | |||
2182 | char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; | 2365 | char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; |
2183 | void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; | 2366 | void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; |
2184 | 2367 | ||
2368 | int FAST_FUNC i2a64(int i); | ||
2369 | int FAST_FUNC a2i64(char c); | ||
2370 | char* FAST_FUNC num2str64_lsb_first(char *s, unsigned v, int n); | ||
2371 | |||
2372 | enum { | ||
2373 | /* how many bytes XYZ_end() fills */ | ||
2374 | MD5_OUTSIZE = 16, | ||
2375 | SHA1_OUTSIZE = 20, | ||
2376 | SHA256_OUTSIZE = 32, | ||
2377 | SHA384_OUTSIZE = 48, | ||
2378 | SHA512_OUTSIZE = 64, | ||
2379 | //SHA3-224_OUTSIZE = 28, | ||
2380 | /* size of input block */ | ||
2381 | SHA2_INSIZE = 64, | ||
2382 | }; | ||
2383 | |||
2384 | #if defined CONFIG_FEATURE_USE_CNG_API | ||
2385 | struct bcrypt_hash_ctx_t { | ||
2386 | void *handle; | ||
2387 | void *hash_obj; | ||
2388 | unsigned int output_size; | ||
2389 | }; | ||
2390 | typedef struct bcrypt_hash_ctx_t md5_ctx_t; | ||
2391 | typedef struct bcrypt_hash_ctx_t sha1_ctx_t; | ||
2392 | typedef struct bcrypt_hash_ctx_t sha256_ctx_t; | ||
2393 | typedef struct bcrypt_hash_ctx_t sha384_ctx_t; | ||
2394 | typedef struct bcrypt_hash_ctx_t sha512_ctx_t; | ||
2395 | typedef struct sha3_ctx_t { | ||
2396 | uint64_t state[25]; | ||
2397 | unsigned bytes_queued; | ||
2398 | unsigned input_block_bytes; | ||
2399 | } sha3_ctx_t; | ||
2400 | void md5_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2401 | void sha1_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2402 | void sha256_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2403 | void sha384_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2404 | void sha512_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2405 | void generic_hash(struct bcrypt_hash_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | ||
2406 | unsigned generic_end(struct bcrypt_hash_ctx_t *ctx, void *resbuf) FAST_FUNC; | ||
2407 | # define md5_hash generic_hash | ||
2408 | # define sha1_hash generic_hash | ||
2409 | # define sha256_hash generic_hash | ||
2410 | # define sha384_hash generic_hash | ||
2411 | # define sha512_hash generic_hash | ||
2412 | # define md5_end generic_end | ||
2413 | # define sha1_end generic_end | ||
2414 | # define sha256_end generic_end | ||
2415 | # define sha384_end generic_end | ||
2416 | # define sha512_end generic_end | ||
2417 | #else | ||
2185 | typedef struct md5_ctx_t { | 2418 | typedef struct md5_ctx_t { |
2186 | uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ | 2419 | uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ |
2187 | void (*process_block)(struct md5_ctx_t*) FAST_FUNC; | 2420 | void (*process_block)(struct md5_ctx_t*) FAST_FUNC; |
@@ -2195,6 +2428,7 @@ typedef struct sha512_ctx_t { | |||
2195 | uint64_t hash[8]; | 2428 | uint64_t hash[8]; |
2196 | uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */ | 2429 | uint8_t wbuffer[128]; /* always correctly aligned for uint64_t */ |
2197 | } sha512_ctx_t; | 2430 | } sha512_ctx_t; |
2431 | typedef struct sha512_ctx_t sha384_ctx_t; | ||
2198 | typedef struct sha3_ctx_t { | 2432 | typedef struct sha3_ctx_t { |
2199 | uint64_t state[25]; | 2433 | uint64_t state[25]; |
2200 | unsigned bytes_queued; | 2434 | unsigned bytes_queued; |
@@ -2212,20 +2446,69 @@ void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; | |||
2212 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; | 2446 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; |
2213 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 2447 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
2214 | unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; | 2448 | unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; |
2449 | void sha384_begin(sha384_ctx_t *ctx) FAST_FUNC; | ||
2450 | #define sha384_hash sha512_hash | ||
2451 | unsigned sha384_end(sha384_ctx_t *ctx, void *resbuf) FAST_FUNC; | ||
2452 | #endif | ||
2215 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; | 2453 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; |
2216 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 2454 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
2217 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; | 2455 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; |
2456 | void FAST_FUNC sha256_block(const void *in, size_t len, uint8_t hash[32]); | ||
2218 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ | 2457 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ |
2458 | #if defined CONFIG_FEATURE_USE_CNG_API | ||
2459 | typedef struct bcrypt_hash_ctx_t md5sha_ctx_t; | ||
2460 | #define md5sha_hash generic_hash | ||
2461 | #define sha_end generic_end | ||
2462 | #else | ||
2219 | typedef struct md5_ctx_t md5sha_ctx_t; | 2463 | typedef struct md5_ctx_t md5sha_ctx_t; |
2220 | #define md5sha_hash md5_hash | 2464 | #define md5sha_hash md5_hash |
2221 | #define sha_end sha1_end | 2465 | #define sha_end sha1_end |
2222 | enum { | 2466 | #endif |
2223 | MD5_OUTSIZE = 16, | 2467 | |
2224 | SHA1_OUTSIZE = 20, | 2468 | /* RFC 2104 HMAC (hash-based message authentication code) */ |
2225 | SHA256_OUTSIZE = 32, | 2469 | #if !ENABLE_FEATURE_USE_CNG_API |
2226 | SHA512_OUTSIZE = 64, | 2470 | typedef struct hmac_ctx { |
2227 | SHA3_OUTSIZE = 28, | 2471 | md5sha_ctx_t hashed_key_xor_ipad; |
2228 | }; | 2472 | md5sha_ctx_t hashed_key_xor_opad; |
2473 | } hmac_ctx_t; | ||
2474 | #else | ||
2475 | typedef struct bcrypt_hash_ctx_t hmac_ctx_t; | ||
2476 | #endif | ||
2477 | #define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1) | ||
2478 | typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; | ||
2479 | #if !ENABLE_FEATURE_USE_CNG_API | ||
2480 | #if HMAC_ONLY_SHA256 | ||
2481 | #define hmac_begin(ctx,key,key_size,begin) \ | ||
2482 | hmac_begin(ctx,key,key_size) | ||
2483 | #endif | ||
2484 | void FAST_FUNC hmac_begin(hmac_ctx_t *ctx, const uint8_t *key, unsigned key_size, md5sha_begin_func *begin); | ||
2485 | static ALWAYS_INLINE void hmac_hash(hmac_ctx_t *ctx, const void *in, size_t len) | ||
2486 | { | ||
2487 | md5sha_hash(&ctx->hashed_key_xor_ipad, in, len); | ||
2488 | } | ||
2489 | #else | ||
2490 | # if HMAC_ONLY_SHA256 | ||
2491 | # define hmac_begin(pre,key,key_size,begin) \ | ||
2492 | _hmac_begin(pre, key, key_size, sha256_begin_hmac) | ||
2493 | # else | ||
2494 | # define hmac_begin _hmac_begin | ||
2495 | # endif | ||
2496 | void _hmac_begin(hmac_ctx_t *pre, uint8_t *key, unsigned key_size, | ||
2497 | BCRYPT_ALG_HANDLE alg_handle); | ||
2498 | void hmac_uninit(hmac_ctx_t *pre); | ||
2499 | #endif | ||
2500 | unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out); | ||
2501 | #if HMAC_ONLY_SHA256 | ||
2502 | #define hmac_block(key,key_size,begin,in,sz,out) \ | ||
2503 | hmac_block(key,key_size,in,sz,out) | ||
2504 | #endif | ||
2505 | unsigned FAST_FUNC hmac_block(const uint8_t *key, unsigned key_size, | ||
2506 | md5sha_begin_func *begin, | ||
2507 | const void *in, unsigned sz, | ||
2508 | uint8_t *out); | ||
2509 | /* HMAC helpers for TLS: */ | ||
2510 | void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va); | ||
2511 | unsigned hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...); | ||
2229 | 2512 | ||
2230 | extern uint32_t *global_crc32_table; | 2513 | extern uint32_t *global_crc32_table; |
2231 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; | 2514 | uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; |
@@ -2309,11 +2592,18 @@ extern const char bb_path_wtmp_file[] ALIGN1; | |||
2309 | #define bb_path_motd_file "/etc/motd" | 2592 | #define bb_path_motd_file "/etc/motd" |
2310 | 2593 | ||
2311 | #define bb_dev_null "/dev/null" | 2594 | #define bb_dev_null "/dev/null" |
2595 | #if ENABLE_PLATFORM_MINGW32 | ||
2596 | #define bb_busybox_exec_path get_busybox_exec_path() | ||
2597 | extern char bb_comm[]; | ||
2598 | extern char bb_command_line[]; | ||
2599 | #else | ||
2312 | extern const char bb_busybox_exec_path[] ALIGN1; | 2600 | extern const char bb_busybox_exec_path[] ALIGN1; |
2601 | #endif | ||
2313 | /* allow default system PATH to be extended via CFLAGS */ | 2602 | /* allow default system PATH to be extended via CFLAGS */ |
2314 | #ifndef BB_ADDITIONAL_PATH | 2603 | #ifndef BB_ADDITIONAL_PATH |
2315 | #define BB_ADDITIONAL_PATH "" | 2604 | #define BB_ADDITIONAL_PATH "" |
2316 | #endif | 2605 | #endif |
2606 | #if !ENABLE_PLATFORM_MINGW32 | ||
2317 | #define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH | 2607 | #define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH |
2318 | extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | 2608 | extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ |
2319 | #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) | 2609 | #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) |
@@ -2321,6 +2611,23 @@ extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | |||
2321 | * but I want to save a few bytes here: | 2611 | * but I want to save a few bytes here: |
2322 | */ | 2612 | */ |
2323 | #define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) | 2613 | #define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) |
2614 | #define PATH_SEP ':' | ||
2615 | #define PATH_SEP_STR ":" | ||
2616 | #else | ||
2617 | #define BB_PATH_ROOT_PATH "PATH=C:/Windows/System32;C:/Windows" BB_ADDITIONAL_PATH | ||
2618 | extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ | ||
2619 | #define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) | ||
2620 | #define bb_default_path (bb_PATH_root_path + sizeof("PATH")) | ||
2621 | #define PATH_SEP ';' | ||
2622 | #define PATH_SEP_STR ";" | ||
2623 | extern const char bbvar[] ALIGN1; | ||
2624 | #define bbafter(p) (p + sizeof(#p)) | ||
2625 | #define BB_OVERRIDE_APPLETS bbvar | ||
2626 | #define BB_SKIP_ANSI_EMULATION bbafter(BB_OVERRIDE_APPLETS) | ||
2627 | #define BB_TERMINAL_MODE bbafter(BB_SKIP_ANSI_EMULATION) | ||
2628 | #define BB_SYSTEMROOT bbafter(BB_TERMINAL_MODE) | ||
2629 | #define BB_CRITICAL_ERROR_DIALOGS bbafter(BB_SYSTEMROOT) | ||
2630 | #endif | ||
2324 | 2631 | ||
2325 | extern const int const_int_0; | 2632 | extern const int const_int_0; |
2326 | //extern const int const_int_1; | 2633 | //extern const int const_int_1; |
@@ -2337,26 +2644,10 @@ extern struct globals *BB_GLOBAL_CONST ptr_to_globals; | |||
2337 | #define barrier() asm volatile ("":::"memory") | 2644 | #define barrier() asm volatile ("":::"memory") |
2338 | 2645 | ||
2339 | #if defined(__clang_major__) && __clang_major__ >= 9 | 2646 | #if defined(__clang_major__) && __clang_major__ >= 9 |
2340 | /* Clang/llvm drops assignment to "constant" storage. Silently. | 2647 | /* {ASSIGN,XZALLOC}_CONST_PTR() are out-of-line functions |
2341 | * Needs serious convincing to not eliminate the store. | 2648 | * to prevent clang from reading pointer before it is assigned. |
2342 | */ | ||
2343 | static ALWAYS_INLINE void* not_const_pp(const void *p) | ||
2344 | { | ||
2345 | void *pp; | ||
2346 | asm volatile ( | ||
2347 | "# forget that p points to const" | ||
2348 | : /*outputs*/ "=r" (pp) | ||
2349 | : /*inputs*/ "0" (p) | ||
2350 | ); | ||
2351 | return pp; | ||
2352 | } | ||
2353 | # define ASSIGN_CONST_PTR(pptr, v) do { \ | ||
2354 | *(void**)not_const_pp(pptr) = (void*)(v); \ | ||
2355 | barrier(); \ | ||
2356 | } while (0) | ||
2357 | /* XZALLOC_CONST_PTR() is an out-of-line function to prevent | ||
2358 | * clang from reading pointer before it is assigned. | ||
2359 | */ | 2649 | */ |
2650 | void ASSIGN_CONST_PTR(const void *pptr, void *v) FAST_FUNC; | ||
2360 | void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; | 2651 | void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; |
2361 | #else | 2652 | #else |
2362 | # define ASSIGN_CONST_PTR(pptr, v) do { \ | 2653 | # define ASSIGN_CONST_PTR(pptr, v) do { \ |