aboutsummaryrefslogtreecommitdiff
path: root/include/libbb.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libbb.h')
-rw-r--r--include/libbb.h387
1 files changed, 335 insertions, 52 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 4d6193795..8dc4e4992 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
185extern char **environ; 195extern 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 */
187int klogctl(int type, char *b, int len); 198int 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;
570const char *bb_basename(const char *name) FAST_FUNC; 622const 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) */
572char *last_char_is(const char *s, int c) FAST_FUNC; 624char *last_char_is(const char *s, int c) FAST_FUNC;
625char *last_char_is_dir_sep(const char *s) FAST_FUNC;
573const char* endofname(const char *name) FAST_FUNC; 626const char* endofname(const char *name) FAST_FUNC;
574char *is_prefixed_with(const char *string, const char *key) FAST_FUNC; 627char *is_prefixed_with(const char *string, const char *key) FAST_FUNC;
575char *is_suffixed_with(const char *string, const char *key) FAST_FUNC; 628char *is_suffixed_with(const char *string, const char *key) FAST_FUNC;
576 629
630#if !ENABLE_PLATFORM_MINGW32
577int ndelay_on(int fd) FAST_FUNC; 631int ndelay_on(int fd) FAST_FUNC;
578int ndelay_off(int fd) FAST_FUNC; 632int ndelay_off(int fd) FAST_FUNC;
579void close_on_exec_on(int fd) FAST_FUNC; 633void close_on_exec_on(int fd) FAST_FUNC;
634#else
635static inline int ndelay_on(int fd UNUSED_PARAM) { return 0; }
636static inline int ndelay_off(int fd UNUSED_PARAM) { return 0; }
637static inline void close_on_exec_on(int fd UNUSED_PARAM) { return; }
638#endif
580void xdup2(int, int) FAST_FUNC; 639void xdup2(int, int) FAST_FUNC;
581void xmove_fd(int, int) FAST_FUNC; 640void 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
627void bb_signals(int sigs, void (*f)(int)) FAST_FUNC; 703void 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;
643int sigprocmask_allsigs(int how) FAST_FUNC; 719int sigprocmask_allsigs(int how) FAST_FUNC;
644/* Return old set in the same set: */ 720/* Return old set in the same set: */
645int sigprocmask2(int how, sigset_t *set) FAST_FUNC; 721int 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 */
647extern smallint bb_got_signal; 727extern smallint bb_got_signal;
648void record_signo(int signo); /* not FAST_FUNC! */ 728void record_signo(int signo); /* not FAST_FUNC! */
@@ -726,7 +806,7 @@ void xsettimeofday(const struct timeval *tv) FAST_FUNC;
726int xsocket(int domain, int type, int protocol) FAST_FUNC; 806int xsocket(int domain, int type, int protocol) FAST_FUNC;
727void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC; 807void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) FAST_FUNC;
728void xlisten(int s, int backlog) FAST_FUNC; 808void xlisten(int s, int backlog) FAST_FUNC;
729void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) FAST_FUNC; 809void xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) FAST_FUNC;
730ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, 810ssize_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
923typedef struct tls_state {
924 int ofd;
925 int ifd;
926
927 // handles
928 CredHandle cred_handle;
929 CtxtHandle ctx_handle;
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
842 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
843struct tls_aes { 952struct 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
900static inline tls_state_t *new_tls_state(void) 1010static 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
905void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; 1016void 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)
907void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; 1018void 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 */
934int bb_putchar_stderr(char ch) FAST_FUNC; 1045int bb_putchar_stderr(char ch) FAST_FUNC;
935int fputs_stdout(const char *s) FAST_FUNC; 1046int fputs_stdout(const char *s) FAST_FUNC;
936char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) FAST_FUNC RETURNS_MALLOC; 1047char *xasprintf(const char *format, ...) __attribute__ ((format(printf, 1, 2))) RETURNS_MALLOC;
937char *auto_string(char *str) FAST_FUNC; 1048char *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! */
1014int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC; 1125int setup_unzip_on_fd(int fd, int die_if_not_compressed) FAST_FUNC;
1015/* Autodetects .gz etc */ 1126/* Autodetects .gz etc */
1016extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC; 1127extern int open_zipped(const char *fname, int die_if_not_compressed) FAST_FUNC;
1017extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; 1128extern 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,16 @@ char *bin2hex(char *dst, const char *src, int count) FAST_FUNC;
1113/* Reverse */ 1224/* Reverse */
1114char* hex2bin(char *dst, const char *src, int count) FAST_FUNC; 1225char* hex2bin(char *dst, const char *src, int count) FAST_FUNC;
1115 1226
1227void FAST_FUNC xorbuf_3(void *dst, const void *src1, const void *src2, unsigned count);
1228void FAST_FUNC xorbuf(void* buf, const void* mask, unsigned count);
1229void FAST_FUNC xorbuf16_aligned_long(void* buf, const void* mask);
1230void FAST_FUNC xorbuf64_3_aligned64(void *dst, const void *src1, const void *src2);
1231#if BB_UNALIGNED_MEMACCESS_OK
1232# define xorbuf16(buf,mask) xorbuf16_aligned_long(buf,mask)
1233#else
1234void FAST_FUNC xorbuf16(void* buf, const void* mask);
1235#endif
1236
1116/* Generate a UUID */ 1237/* Generate a UUID */
1117void generate_uuid(uint8_t *buf) FAST_FUNC; 1238void generate_uuid(uint8_t *buf) FAST_FUNC;
1118 1239
@@ -1208,12 +1329,20 @@ gid_t *bb_getgroups(int *ngroups, gid_t *group_array) FAST_FUNC;
1208struct cached_groupinfo { 1329struct cached_groupinfo {
1209 uid_t euid; 1330 uid_t euid;
1210 gid_t egid; 1331 gid_t egid;
1332#if !ENABLE_PLATFORM_MINGW32
1333 // If these are ever restored on Windows it will be necessary to alter
1334 // globals_misc_size()/globals_misc_copy() in ash.
1211 int ngroups; 1335 int ngroups;
1212 gid_t *supplementary_array; 1336 gid_t *supplementary_array;
1337#endif
1213}; 1338};
1214uid_t FAST_FUNC get_cached_euid(uid_t *euid); 1339uid_t FAST_FUNC get_cached_euid(uid_t *euid);
1215gid_t FAST_FUNC get_cached_egid(gid_t *egid); 1340gid_t FAST_FUNC get_cached_egid(gid_t *egid);
1341#if !ENABLE_PLATFORM_MINGW32
1216int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid); 1342int FAST_FUNC is_in_supplementary_groups(struct cached_groupinfo *groupinfo, gid_t gid);
1343#else
1344# define is_in_supplementary_groups(g, i) (FALSE)
1345#endif
1217 1346
1218#if ENABLE_FEATURE_UTMP 1347#if ENABLE_FEATURE_UTMP
1219void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname); 1348void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname);
@@ -1249,6 +1378,7 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
1249 1378
1250/* xvfork() can't be a _function_, return after vfork in child mangles stack 1379/* xvfork() can't be a _function_, return after vfork in child mangles stack
1251 * in the parent. It must be a macro. */ 1380 * in the parent. It must be a macro. */
1381#if !ENABLE_PLATFORM_MINGW32
1252#define xvfork() \ 1382#define xvfork() \
1253({ \ 1383({ \
1254 pid_t bb__xvfork_pid = vfork(); \ 1384 pid_t bb__xvfork_pid = vfork(); \
@@ -1256,6 +1386,9 @@ void BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC;
1256 bb_simple_perror_msg_and_die("vfork"); \ 1386 bb_simple_perror_msg_and_die("vfork"); \
1257 bb__xvfork_pid; \ 1387 bb__xvfork_pid; \
1258}) 1388})
1389#else
1390#define xvfork() vfork()
1391#endif
1259#if BB_MMU 1392#if BB_MMU
1260pid_t xfork(void) FAST_FUNC; 1393pid_t xfork(void) FAST_FUNC;
1261#endif 1394#endif
@@ -1290,6 +1423,15 @@ void run_noexec_applet_and_exit(int a, const char *name, char **argv) NORETURN F
1290#ifndef BUILD_INDIVIDUAL 1423#ifndef BUILD_INDIVIDUAL
1291int find_applet_by_name(const char *name) FAST_FUNC; 1424int find_applet_by_name(const char *name) FAST_FUNC;
1292void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC; 1425void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
1426# if ENABLE_PLATFORM_MINGW32
1427# if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE
1428int prefer_applet(const char *name, const char *path) FAST_FUNC;
1429int find_applet_by_name_for_sh(const char *name, const char *path) FAST_FUNC;
1430# endif
1431# else
1432# define prefer_applet(n, p) (1)
1433# define find_applet_by_name_for_sh(n, p) find_applet_by_name(n)
1434# endif
1293#endif 1435#endif
1294void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC; 1436void show_usage_if_dash_dash_help(int applet_no, char **argv) FAST_FUNC;
1295#if defined(__linux__) 1437#if defined(__linux__)
@@ -1370,12 +1512,12 @@ char* single_argv(char **argv) FAST_FUNC;
1370char **skip_dash_dash(char **argv) FAST_FUNC; 1512char **skip_dash_dash(char **argv) FAST_FUNC;
1371extern const char *const bb_argv_dash[]; /* { "-", NULL } */ 1513extern const char *const bb_argv_dash[]; /* { "-", NULL } */
1372extern uint32_t option_mask32; 1514extern uint32_t option_mask32;
1373uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC; 1515uint32_t getopt32(char **argv, const char *applet_opts, ...);
1374# define No_argument "\0" 1516# define No_argument "\0"
1375# define Required_argument "\001" 1517# define Required_argument "\001"
1376# define Optional_argument "\002" 1518# define Optional_argument "\002"
1377#if ENABLE_LONG_OPTS 1519#if ENABLE_LONG_OPTS
1378uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...) FAST_FUNC; 1520uint32_t getopt32long(char **argv, const char *optstring, const char *longopts, ...);
1379#else 1521#else
1380#define getopt32long(argv,optstring,longopts,...) \ 1522#define getopt32long(argv,optstring,longopts,...) \
1381 getopt32(argv,optstring,##__VA_ARGS__) 1523 getopt32(argv,optstring,##__VA_ARGS__)
@@ -1450,17 +1592,17 @@ extern uint8_t xfunc_error_retval;
1450extern void (*die_func)(void); 1592extern void (*die_func)(void);
1451void xfunc_die(void) NORETURN FAST_FUNC; 1593void xfunc_die(void) NORETURN FAST_FUNC;
1452void bb_show_usage(void) NORETURN FAST_FUNC; 1594void bb_show_usage(void) NORETURN FAST_FUNC;
1453void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; 1595void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
1454void bb_simple_error_msg(const char *s) FAST_FUNC; 1596void bb_simple_error_msg(const char *s) FAST_FUNC;
1455void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; 1597void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
1456void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC; 1598void bb_simple_error_msg_and_die(const char *s) NORETURN FAST_FUNC;
1457void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; 1599void bb_perror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
1458void bb_simple_perror_msg(const char *s) FAST_FUNC; 1600void bb_simple_perror_msg(const char *s) FAST_FUNC;
1459void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; 1601void bb_perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
1460void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC; 1602void bb_simple_perror_msg_and_die(const char *s) NORETURN FAST_FUNC;
1461void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; 1603void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
1462void bb_simple_herror_msg(const char *s) FAST_FUNC; 1604void bb_simple_herror_msg(const char *s) FAST_FUNC;
1463void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC; 1605void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
1464void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC; 1606void bb_simple_herror_msg_and_die(const char *s) NORETURN FAST_FUNC;
1465void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC; 1607void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
1466void bb_perror_nomsg(void) FAST_FUNC; 1608void bb_perror_nomsg(void) FAST_FUNC;
@@ -1476,7 +1618,7 @@ void bb_logenv_override(void) FAST_FUNC;
1476typedef smalluint exitcode_t; 1618typedef smalluint exitcode_t;
1477 1619
1478#if ENABLE_FEATURE_SYSLOG_INFO 1620#if ENABLE_FEATURE_SYSLOG_INFO
1479void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC; 1621void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
1480void bb_simple_info_msg(const char *s) FAST_FUNC; 1622void bb_simple_info_msg(const char *s) FAST_FUNC;
1481void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC; 1623void bb_vinfo_msg(const char *s, va_list p) FAST_FUNC;
1482#else 1624#else
@@ -1806,18 +1948,25 @@ extern char *pw_encrypt(const char *clear, const char *salt, int cleanup) FAST_F
1806extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC; 1948extern int obscure(const char *old, const char *newval, const struct passwd *pwdp) FAST_FUNC;
1807/* 1949/*
1808 * rnd is additional random input. New one is returned. 1950 * rnd is additional random input. New one is returned.
1809 * Useful if you call crypt_make_salt many times in a row: 1951 * Useful if you call crypt_make_rand64encoded many times in a row:
1810 * rnd = crypt_make_salt(buf1, 4, 0); 1952 * rnd = crypt_make_rand64encoded(buf1, 4, 0);
1811 * rnd = crypt_make_salt(buf2, 4, rnd); 1953 * rnd = crypt_make_rand64encoded(buf2, 4, rnd);
1812 * rnd = crypt_make_salt(buf3, 4, rnd); 1954 * rnd = crypt_make_rand64encoded(buf3, 4, rnd);
1813 * (otherwise we risk having same salt generated) 1955 * (otherwise we risk having same salt generated)
1814 */ 1956 */
1815extern int crypt_make_salt(char *p, int cnt /*, int rnd*/) FAST_FUNC; 1957extern int crypt_make_rand64encoded(char *p, int cnt /*, int rnd*/) FAST_FUNC;
1816/* "$N$" + sha_salt_16_bytes + NUL */ 1958/* Size of char salt[] to hold randomly-generated salt string
1817#define MAX_PW_SALT_LEN (3 + 16 + 1) 1959 * sha256/512:
1960 * "$5$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>"
1961 * "$6$" ["rounds=999999999$"] "<sha_salt_16_chars><NUL>"
1962 * #define MAX_PW_SALT_LEN (3 + sizeof("rounds=999999999$")-1 + 16 + 1)
1963 * yescrypt:
1964 * "$y$" <up to 8 params of up to 6 chars each> "$" <up to 86 chars salt><NUL>
1965 * (86 chars are ascii64-encoded 64 binary bytes)
1966 */
1967#define MAX_PW_SALT_LEN (3 + 8*6 + 1 + 86 + 1)
1818extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC; 1968extern char* crypt_make_pw_salt(char p[MAX_PW_SALT_LEN], const char *algo) FAST_FUNC;
1819 1969
1820
1821/* Returns number of lines changed, or -1 on error */ 1970/* Returns number of lines changed, or -1 on error */
1822#if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP) 1971#if !(ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP)
1823#define update_passwd(filename, username, data, member) \ 1972#define update_passwd(filename, username, data, member) \
@@ -1853,8 +2002,8 @@ int get_termios_and_make_raw(int fd, struct termios *newterm, struct termios *ol
1853int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC; 2002int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC;
1854 2003
1855/* NB: "unsigned request" is crucial! "int request" will break some arches! */ 2004/* NB: "unsigned request" is crucial! "int request" will break some arches! */
1856int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; 2005int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
1857int ioctl_or_perror_and_die(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC; 2006int 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 2007#if ENABLE_IOCTL_HEX2STR_ERROR
1859int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; 2008int bb_ioctl_or_warn(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC;
1860int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC; 2009int bb_xioctl(int fd, unsigned request, void *argp, const char *ioctl_name) FAST_FUNC;
@@ -1867,9 +2016,15 @@ int bb_xioctl(int fd, unsigned request, void *argp) FAST_FUNC;
1867#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp) 2016#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp)
1868#endif 2017#endif
1869 2018
2019#if !ENABLE_PLATFORM_MINGW32 || ENABLE_FEATURE_EXTRA_FILE_DATA
1870char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC; 2020char *is_in_ino_dev_hashtable(const struct stat *statbuf) FAST_FUNC;
1871void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC; 2021void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) FAST_FUNC;
1872void reset_ino_dev_hashtable(void) FAST_FUNC; 2022void reset_ino_dev_hashtable(void) FAST_FUNC;
2023#else
2024#define add_to_ino_dev_hashtable(s, n) (void)0
2025#define is_in_ino_dev_hashtable(s) NULL
2026#define reset_ino_dev_hashtable()
2027#endif
1873#ifdef __GLIBC__ 2028#ifdef __GLIBC__
1874/* At least glibc has horrendously large inline for this, so wrap it */ 2029/* At least glibc has horrendously large inline for this, so wrap it */
1875unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC; 2030unsigned long long bb_makedev(unsigned major, unsigned minor) FAST_FUNC;
@@ -1947,10 +2102,17 @@ enum {
1947 * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout 2102 * >=0: poll() for TIMEOUT milliseconds, return -1/EAGAIN on timeout
1948 */ 2103 */
1949int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC; 2104int64_t read_key(int fd, char *buffer, int timeout) FAST_FUNC;
2105#if ENABLE_PLATFORM_MINGW32
2106int64_t windows_read_key(int fd, char *buffer, int timeout) FAST_FUNC;
2107#endif
1950/* This version loops on EINTR: */ 2108/* This version loops on EINTR: */
1951int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; 2109int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC;
1952void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; 2110void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC;
1953 2111
2112int check_got_signal_and_poll(struct pollfd pfd[1], int timeout) FAST_FUNC;
2113#if ENABLE_PLATFORM_MINGW32
2114# define check_got_signal_and_poll(p, t) poll(p, 1, t)
2115#endif
1954 2116
1955#if ENABLE_FEATURE_EDITING 2117#if ENABLE_FEATURE_EDITING
1956/* It's NOT just ENABLEd or disabled. It's a number: */ 2118/* It's NOT just ENABLEd or disabled. It's a number: */
@@ -1960,8 +2122,14 @@ unsigned size_from_HISTFILESIZE(const char *hp) FAST_FUNC;
1960# else 2122# else
1961# define MAX_HISTORY 0 2123# define MAX_HISTORY 0
1962# endif 2124# endif
2125# if defined CONFIG_FEATURE_EDITING_HISTORY_DEFAULT && CONFIG_FEATURE_EDITING_HISTORY_DEFAULT > 0
2126# define DEFAULT_HISTORY (CONFIG_FEATURE_EDITING_HISTORY_DEFAULT + 0)
2127# else
2128# define DEFAULT_HISTORY 0
2129# endif
1963typedef const char *get_exe_name_t(int i) FAST_FUNC; 2130typedef const char *get_exe_name_t(int i) FAST_FUNC;
1964typedef const char *sh_get_var_t(const char *name) FAST_FUNC; 2131typedef const char *sh_get_var_t(const char *name) FAST_FUNC;
2132typedef int sh_accept_glob_t(const char *name) FAST_FUNC;
1965typedef struct line_input_t { 2133typedef struct line_input_t {
1966 int flags; 2134 int flags;
1967 int timeout; 2135 int timeout;
@@ -1975,6 +2143,9 @@ typedef struct line_input_t {
1975# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH 2143# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH
1976 /* function to fetch additional application-specific names to match */ 2144 /* function to fetch additional application-specific names to match */
1977 get_exe_name_t *get_exe_name; 2145 get_exe_name_t *get_exe_name;
2146# if ENABLE_ASH_GLOB_OPTIONS
2147 sh_accept_glob_t *sh_accept_glob;
2148# endif
1978# endif 2149# endif
1979# endif 2150# endif
1980# if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \ 2151# if (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) \
@@ -1988,7 +2159,7 @@ typedef struct line_input_t {
1988# if MAX_HISTORY 2159# if MAX_HISTORY
1989 int cnt_history; 2160 int cnt_history;
1990 int cur_history; 2161 int cur_history;
1991 int max_history; /* must never be <= 0 */ 2162 int max_history; /* must never be < 0 */
1992# if ENABLE_FEATURE_EDITING_SAVEHISTORY 2163# if ENABLE_FEATURE_EDITING_SAVEHISTORY
1993 /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT: 2164 /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT:
1994 * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are 2165 * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are
@@ -2009,6 +2180,9 @@ enum {
2009 VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI, 2180 VI_MODE = 8 * ENABLE_FEATURE_EDITING_VI,
2010 WITH_PATH_LOOKUP = 0x10, 2181 WITH_PATH_LOOKUP = 0x10,
2011 LI_INTERRUPTIBLE = 0x20, 2182 LI_INTERRUPTIBLE = 0x20,
2183#if ENABLE_PLATFORM_MINGW32
2184 IGNORE_CTRL_C = 0x40,
2185#endif
2012 FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE, 2186 FOR_SHELL = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION | LI_INTERRUPTIBLE,
2013}; 2187};
2014line_input_t *new_line_input_t(int flags) FAST_FUNC; 2188line_input_t *new_line_input_t(int flags) FAST_FUNC;
@@ -2038,6 +2212,10 @@ int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC;
2038 2212
2039unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz); 2213unsigned long* FAST_FUNC get_malloc_cpu_affinity(int pid, unsigned *sz);
2040 2214
2215#if ENABLE_PLATFORM_MINGW32
2216# undef COMM_LEN
2217# define COMM_LEN 32
2218#endif
2041#ifndef COMM_LEN 2219#ifndef COMM_LEN
2042# ifdef TASK_COMM_LEN 2220# ifdef TASK_COMM_LEN
2043enum { COMM_LEN = TASK_COMM_LEN }; 2221enum { COMM_LEN = TASK_COMM_LEN };
@@ -2075,7 +2253,13 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
2075 void (*cb)(struct smaprec *, void *), void *data); 2253 void (*cb)(struct smaprec *, void *), void *data);
2076 2254
2077typedef struct procps_status_t { 2255typedef struct procps_status_t {
2256#if !ENABLE_PLATFORM_MINGW32
2078 DIR *dir; 2257 DIR *dir;
2258#else
2259 HANDLE snapshot;
2260 DWORD *pids;
2261 int npids;
2262#endif
2079 IF_FEATURE_SHOW_THREADS(DIR *task_dir;) 2263 IF_FEATURE_SHOW_THREADS(DIR *task_dir;)
2080 uint8_t shift_pages_to_bytes; 2264 uint8_t shift_pages_to_bytes;
2081 uint8_t shift_pages_to_kb; 2265 uint8_t shift_pages_to_kb;
@@ -2182,6 +2366,51 @@ char *decode_base64(char *dst, const char **pp_src) FAST_FUNC;
2182char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; 2366char *decode_base32(char *dst, const char **pp_src) FAST_FUNC;
2183void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; 2367void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC;
2184 2368
2369int FAST_FUNC i2a64(int i);
2370int FAST_FUNC a2i64(char c);
2371char* FAST_FUNC num2str64_lsb_first(char *s, unsigned v, int n);
2372
2373enum {
2374 /* how many bytes XYZ_end() fills */
2375 MD5_OUTSIZE = 16,
2376 SHA1_OUTSIZE = 20,
2377 SHA256_OUTSIZE = 32,
2378 SHA512_OUTSIZE = 64,
2379 SHA3_OUTSIZE = 28,
2380 /* size of input block */
2381 SHA2_INSIZE = 64,
2382};
2383
2384#if defined CONFIG_FEATURE_USE_CNG_API
2385struct bcrypt_hash_ctx_t {
2386 void *handle;
2387 void *hash_obj;
2388 unsigned int output_size;
2389};
2390typedef struct bcrypt_hash_ctx_t md5_ctx_t;
2391typedef struct bcrypt_hash_ctx_t sha1_ctx_t;
2392typedef struct bcrypt_hash_ctx_t sha256_ctx_t;
2393typedef struct bcrypt_hash_ctx_t sha512_ctx_t;
2394typedef struct sha3_ctx_t {
2395 uint64_t state[25];
2396 unsigned bytes_queued;
2397 unsigned input_block_bytes;
2398} sha3_ctx_t;
2399void md5_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2400void sha1_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2401void sha256_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2402void sha512_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC;
2403void generic_hash(struct bcrypt_hash_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2404unsigned generic_end(struct bcrypt_hash_ctx_t *ctx, void *resbuf) FAST_FUNC;
2405# define md5_hash generic_hash
2406# define sha1_hash generic_hash
2407# define sha256_hash generic_hash
2408# define sha512_hash generic_hash
2409# define md5_end generic_end
2410# define sha1_end generic_end
2411# define sha256_end generic_end
2412# define sha512_end generic_end
2413#else
2185typedef struct md5_ctx_t { 2414typedef struct md5_ctx_t {
2186 uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ 2415 uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */
2187 void (*process_block)(struct md5_ctx_t*) FAST_FUNC; 2416 void (*process_block)(struct md5_ctx_t*) FAST_FUNC;
@@ -2212,20 +2441,66 @@ void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
2212void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; 2441void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
2213void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 2442void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2214unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; 2443unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
2444#endif
2215void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; 2445void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
2216void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; 2446void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
2217unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; 2447unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
2448void 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 */ 2449/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */
2450#if defined CONFIG_FEATURE_USE_CNG_API
2451typedef struct bcrypt_hash_ctx_t md5sha_ctx_t;
2452#define md5sha_hash generic_hash
2453#define sha_end generic_end
2454#else
2219typedef struct md5_ctx_t md5sha_ctx_t; 2455typedef struct md5_ctx_t md5sha_ctx_t;
2220#define md5sha_hash md5_hash 2456#define md5sha_hash md5_hash
2221#define sha_end sha1_end 2457#define sha_end sha1_end
2222enum { 2458#endif
2223 MD5_OUTSIZE = 16, 2459
2224 SHA1_OUTSIZE = 20, 2460/* RFC 2104 HMAC (hash-based message authentication code) */
2225 SHA256_OUTSIZE = 32, 2461#if !ENABLE_FEATURE_USE_CNG_API
2226 SHA512_OUTSIZE = 64, 2462typedef struct hmac_ctx {
2227 SHA3_OUTSIZE = 28, 2463 md5sha_ctx_t hashed_key_xor_ipad;
2228}; 2464 md5sha_ctx_t hashed_key_xor_opad;
2465} hmac_ctx_t;
2466#else
2467typedef struct bcrypt_hash_ctx_t hmac_ctx_t;
2468#endif
2469#define HMAC_ONLY_SHA256 (!ENABLE_FEATURE_TLS_SHA1)
2470typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC;
2471#if !ENABLE_FEATURE_USE_CNG_API
2472#if HMAC_ONLY_SHA256
2473#define hmac_begin(ctx,key,key_size,begin) \
2474 hmac_begin(ctx,key,key_size)
2475#endif
2476void FAST_FUNC hmac_begin(hmac_ctx_t *ctx, const uint8_t *key, unsigned key_size, md5sha_begin_func *begin);
2477static ALWAYS_INLINE void hmac_hash(hmac_ctx_t *ctx, const void *in, size_t len)
2478{
2479 md5sha_hash(&ctx->hashed_key_xor_ipad, in, len);
2480}
2481#else
2482# if HMAC_ONLY_SHA256
2483# define hmac_begin(pre,key,key_size,begin) \
2484 _hmac_begin(pre, key, key_size, sha256_begin_hmac)
2485# else
2486# define hmac_begin _hmac_begin
2487# endif
2488void _hmac_begin(hmac_ctx_t *pre, uint8_t *key, unsigned key_size,
2489 BCRYPT_ALG_HANDLE alg_handle);
2490void hmac_uninit(hmac_ctx_t *pre);
2491#endif
2492unsigned FAST_FUNC hmac_end(hmac_ctx_t *ctx, uint8_t *out);
2493#if HMAC_ONLY_SHA256
2494#define hmac_block(key,key_size,begin,in,sz,out) \
2495 hmac_block(key,key_size,in,sz,out)
2496#endif
2497unsigned FAST_FUNC hmac_block(const uint8_t *key, unsigned key_size,
2498 md5sha_begin_func *begin,
2499 const void *in, unsigned sz,
2500 uint8_t *out);
2501/* HMAC helpers for TLS: */
2502void FAST_FUNC hmac_hash_v(hmac_ctx_t *ctx, va_list va);
2503unsigned hmac_peek_hash(hmac_ctx_t *ctx, uint8_t *out, ...);
2229 2504
2230extern uint32_t *global_crc32_table; 2505extern uint32_t *global_crc32_table;
2231uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; 2506uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
@@ -2309,11 +2584,18 @@ extern const char bb_path_wtmp_file[] ALIGN1;
2309#define bb_path_motd_file "/etc/motd" 2584#define bb_path_motd_file "/etc/motd"
2310 2585
2311#define bb_dev_null "/dev/null" 2586#define bb_dev_null "/dev/null"
2587#if ENABLE_PLATFORM_MINGW32
2588#define bb_busybox_exec_path get_busybox_exec_path()
2589extern char bb_comm[];
2590extern char bb_command_line[];
2591#else
2312extern const char bb_busybox_exec_path[] ALIGN1; 2592extern const char bb_busybox_exec_path[] ALIGN1;
2593#endif
2313/* allow default system PATH to be extended via CFLAGS */ 2594/* allow default system PATH to be extended via CFLAGS */
2314#ifndef BB_ADDITIONAL_PATH 2595#ifndef BB_ADDITIONAL_PATH
2315#define BB_ADDITIONAL_PATH "" 2596#define BB_ADDITIONAL_PATH ""
2316#endif 2597#endif
2598#if !ENABLE_PLATFORM_MINGW32
2317#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH 2599#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH
2318extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ 2600extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */
2319#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) 2601#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
@@ -2321,6 +2603,23 @@ extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */
2321 * but I want to save a few bytes here: 2603 * but I want to save a few bytes here:
2322 */ 2604 */
2323#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin")) 2605#define bb_default_path (bb_PATH_root_path + sizeof("PATH=/sbin:/usr/sbin"))
2606#define PATH_SEP ':'
2607#define PATH_SEP_STR ":"
2608#else
2609#define BB_PATH_ROOT_PATH "PATH=C:/Windows/System32;C:/Windows" BB_ADDITIONAL_PATH
2610extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */
2611#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
2612#define bb_default_path (bb_PATH_root_path + sizeof("PATH"))
2613#define PATH_SEP ';'
2614#define PATH_SEP_STR ";"
2615extern const char bbvar[] ALIGN1;
2616#define bbafter(p) (p + sizeof(#p))
2617#define BB_OVERRIDE_APPLETS bbvar
2618#define BB_SKIP_ANSI_EMULATION bbafter(BB_OVERRIDE_APPLETS)
2619#define BB_TERMINAL_MODE bbafter(BB_SKIP_ANSI_EMULATION)
2620#define BB_SYSTEMROOT bbafter(BB_TERMINAL_MODE)
2621#define BB_CRITICAL_ERROR_DIALOGS bbafter(BB_SYSTEMROOT)
2622#endif
2324 2623
2325extern const int const_int_0; 2624extern const int const_int_0;
2326//extern const int const_int_1; 2625//extern const int const_int_1;
@@ -2337,26 +2636,10 @@ extern struct globals *BB_GLOBAL_CONST ptr_to_globals;
2337#define barrier() asm volatile ("":::"memory") 2636#define barrier() asm volatile ("":::"memory")
2338 2637
2339#if defined(__clang_major__) && __clang_major__ >= 9 2638#if defined(__clang_major__) && __clang_major__ >= 9
2340/* Clang/llvm drops assignment to "constant" storage. Silently. 2639/* {ASSIGN,XZALLOC}_CONST_PTR() are out-of-line functions
2341 * Needs serious convincing to not eliminate the store. 2640 * to prevent clang from reading pointer before it is assigned.
2342 */
2343static 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 */ 2641 */
2642void ASSIGN_CONST_PTR(const void *pptr, void *v) FAST_FUNC;
2360void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; 2643void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC;
2361#else 2644#else
2362# define ASSIGN_CONST_PTR(pptr, v) do { \ 2645# define ASSIGN_CONST_PTR(pptr, v) do { \