diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 113 | ||||
-rw-r--r-- | include/mingw.h | 2 |
2 files changed, 87 insertions, 28 deletions
diff --git a/include/libbb.h b/include/libbb.h index bc1453e12..4cacdacba 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -281,6 +281,12 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | |||
281 | # endif | 281 | # endif |
282 | #endif | 282 | #endif |
283 | 283 | ||
284 | #if ENABLE_FEATURE_TLS_SCHANNEL | ||
285 | # define SECURITY_WIN32 | ||
286 | # include <windows.h> | ||
287 | # include <security.h> | ||
288 | #endif | ||
289 | |||
284 | /* Tested to work correctly with all int types (IIRC :]) */ | 290 | /* Tested to work correctly with all int types (IIRC :]) */ |
285 | #define MAXINT(T) (T)( \ | 291 | #define MAXINT(T) (T)( \ |
286 | ((T)-1) > 0 \ | 292 | ((T)-1) > 0 \ |
@@ -899,7 +905,36 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC; | |||
899 | // Also mount.c and inetd.c are using gethostbyname(), | 905 | // Also mount.c and inetd.c are using gethostbyname(), |
900 | // + inet_common.c has additional IPv4-only stuff | 906 | // + inet_common.c has additional IPv4-only stuff |
901 | 907 | ||
908 | #if defined CONFIG_FEATURE_TLS_SCHANNEL | ||
909 | typedef struct tls_state { | ||
910 | int ofd; | ||
911 | int ifd; | ||
912 | |||
913 | // handles | ||
914 | CredHandle cred_handle; | ||
915 | CtxtHandle ctx_handle; | ||
916 | |||
917 | // buffers | ||
918 | char in_buffer[16384 + 256]; // input buffer (to read from server) | ||
919 | unsigned long in_buffer_size; // amount of data currently in input buffer | ||
920 | |||
921 | char *out_buffer; // output buffer (for decrypted data), this is essentially the same as input buffer as data is decrypted in place | ||
922 | unsigned long out_buffer_size; // amount of data currently in output buffer | ||
923 | unsigned long out_buffer_used; // amount of extra data currently in output buffer | ||
924 | |||
925 | // data | ||
926 | char *hostname; | ||
927 | SecPkgContext_StreamSizes stream_sizes; | ||
902 | 928 | ||
929 | // booleans | ||
930 | |||
931 | // context initialized | ||
932 | int initialized; | ||
933 | |||
934 | // closed by remote peer | ||
935 | int closed; | ||
936 | } tls_state_t; | ||
937 | #else | ||
903 | struct tls_aes { | 938 | struct tls_aes { |
904 | uint32_t key[60]; | 939 | uint32_t key[60]; |
905 | unsigned rounds; | 940 | unsigned rounds; |
@@ -956,12 +991,14 @@ typedef struct tls_state { | |||
956 | struct tls_aes aes_decrypt; | 991 | struct tls_aes aes_decrypt; |
957 | uint8_t H[16]; //used by AES_GCM | 992 | uint8_t H[16]; //used by AES_GCM |
958 | } tls_state_t; | 993 | } tls_state_t; |
994 | #endif | ||
959 | 995 | ||
960 | static inline tls_state_t *new_tls_state(void) | 996 | static inline tls_state_t *new_tls_state(void) |
961 | { | 997 | { |
962 | tls_state_t *tls = xzalloc(sizeof(*tls)); | 998 | tls_state_t *tls = xzalloc(sizeof(*tls)); |
963 | return tls; | 999 | return tls; |
964 | } | 1000 | } |
1001 | |||
965 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; | 1002 | void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC; |
966 | #define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) | 1003 | #define TLSLOOP_EXIT_ON_LOCAL_EOF (1 << 0) |
967 | void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; | 1004 | void tls_run_copy_loop(tls_state_t *tls, unsigned flags) FAST_FUNC; |
@@ -1071,13 +1108,13 @@ unsigned bb_clk_tck(void) FAST_FUNC; | |||
1071 | 1108 | ||
1072 | #if SEAMLESS_COMPRESSION | 1109 | #if SEAMLESS_COMPRESSION |
1073 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ | 1110 | /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */ |
1074 | int setup_unzip_on_fd(int fd, int fail_if_not_compressed) FAST_FUNC; | 1111 | int setup_unzip_on_fd(int fd, int die_if_not_compressed) FAST_FUNC; |
1075 | /* Autodetects .gz etc */ | 1112 | /* Autodetects .gz etc */ |
1076 | extern int open_zipped(const char *fname, int fail_if_not_compressed) FAST_FUNC; | 1113 | extern int open_zipped(const char *fname, int die_if_not_compressed) FAST_FUNC; |
1077 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; | 1114 | extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC; |
1078 | #else | 1115 | #else |
1079 | # define setup_unzip_on_fd(...) (0) | 1116 | # define setup_unzip_on_fd(...) (0) |
1080 | # define open_zipped(fname, fail_if_not_compressed) open((fname), O_RDONLY); | 1117 | # define open_zipped(fname, die_if_not_compressed) open((fname), O_RDONLY); |
1081 | # define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p)) | 1118 | # define xmalloc_open_zipped_read_close(fname, maxsz_p) xmalloc_open_read_close((fname), (maxsz_p)) |
1082 | #endif | 1119 | #endif |
1083 | /* lzma has no signature, need a little helper. NB: exist only for ENABLE_FEATURE_SEAMLESS_LZMA=y */ | 1120 | /* lzma has no signature, need a little helper. NB: exist only for ENABLE_FEATURE_SEAMLESS_LZMA=y */ |
@@ -2041,6 +2078,10 @@ int64_t windows_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | |||
2041 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; | 2078 | int64_t safe_read_key(int fd, char *buffer, int timeout) FAST_FUNC; |
2042 | void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; | 2079 | void read_key_ungets(char *buffer, const char *str, unsigned len) FAST_FUNC; |
2043 | 2080 | ||
2081 | int check_got_signal_and_poll(struct pollfd pfd[1], int timeout) FAST_FUNC; | ||
2082 | #if ENABLE_PLATFORM_MINGW32 | ||
2083 | # define check_got_signal_and_poll(p, t) poll(p, 1, t) | ||
2084 | #endif | ||
2044 | 2085 | ||
2045 | #if ENABLE_FEATURE_EDITING | 2086 | #if ENABLE_FEATURE_EDITING |
2046 | /* It's NOT just ENABLEd or disabled. It's a number: */ | 2087 | /* It's NOT just ENABLEd or disabled. It's a number: */ |
@@ -2087,7 +2128,7 @@ typedef struct line_input_t { | |||
2087 | # if MAX_HISTORY | 2128 | # if MAX_HISTORY |
2088 | int cnt_history; | 2129 | int cnt_history; |
2089 | int cur_history; | 2130 | int cur_history; |
2090 | int max_history; /* must never be <= 0 */ | 2131 | int max_history; /* must never be < 0 */ |
2091 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY | 2132 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY |
2092 | /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT: | 2133 | /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT: |
2093 | * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are | 2134 | * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are |
@@ -2294,6 +2335,36 @@ char *decode_base64(char *dst, const char **pp_src) FAST_FUNC; | |||
2294 | char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; | 2335 | char *decode_base32(char *dst, const char **pp_src) FAST_FUNC; |
2295 | void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; | 2336 | void read_base64(FILE *src_stream, FILE *dst_stream, int flags) FAST_FUNC; |
2296 | 2337 | ||
2338 | #if defined CONFIG_FEATURE_USE_CNG_API | ||
2339 | struct bcrypt_hash_ctx_t { | ||
2340 | void *handle; | ||
2341 | void *hash_obj; | ||
2342 | unsigned int output_size; | ||
2343 | }; | ||
2344 | typedef struct bcrypt_hash_ctx_t md5_ctx_t; | ||
2345 | typedef struct bcrypt_hash_ctx_t sha1_ctx_t; | ||
2346 | typedef struct bcrypt_hash_ctx_t sha256_ctx_t; | ||
2347 | typedef struct bcrypt_hash_ctx_t sha512_ctx_t; | ||
2348 | typedef struct sha3_ctx_t { | ||
2349 | uint64_t state[25]; | ||
2350 | unsigned bytes_queued; | ||
2351 | unsigned input_block_bytes; | ||
2352 | } sha3_ctx_t; | ||
2353 | void md5_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2354 | void sha1_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2355 | void sha256_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2356 | void sha512_begin(struct bcrypt_hash_ctx_t *ctx) FAST_FUNC; | ||
2357 | void generic_hash(struct bcrypt_hash_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | ||
2358 | unsigned generic_end(struct bcrypt_hash_ctx_t *ctx, void *resbuf) FAST_FUNC; | ||
2359 | # define md5_hash generic_hash | ||
2360 | # define sha1_hash generic_hash | ||
2361 | # define sha256_hash generic_hash | ||
2362 | # define sha512_hash generic_hash | ||
2363 | # define md5_end generic_end | ||
2364 | # define sha1_end generic_end | ||
2365 | # define sha256_end generic_end | ||
2366 | # define sha512_end generic_end | ||
2367 | #else | ||
2297 | typedef struct md5_ctx_t { | 2368 | typedef struct md5_ctx_t { |
2298 | uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ | 2369 | uint8_t wbuffer[64]; /* always correctly aligned for uint64_t */ |
2299 | void (*process_block)(struct md5_ctx_t*) FAST_FUNC; | 2370 | void (*process_block)(struct md5_ctx_t*) FAST_FUNC; |
@@ -2324,13 +2395,20 @@ void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC; | |||
2324 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; | 2395 | void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC; |
2325 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 2396 | void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
2326 | unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; | 2397 | unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC; |
2398 | #endif | ||
2327 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; | 2399 | void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC; |
2328 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; | 2400 | void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC; |
2329 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; | 2401 | unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; |
2330 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ | 2402 | /* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */ |
2403 | #if defined CONFIG_FEATURE_USE_CNG_API | ||
2404 | typedef struct bcrypt_hash_ctx_t md5sha_ctx_t; | ||
2405 | #define md5sha_hash generic_hash | ||
2406 | #define sha_end generic_end | ||
2407 | #else | ||
2331 | typedef struct md5_ctx_t md5sha_ctx_t; | 2408 | typedef struct md5_ctx_t md5sha_ctx_t; |
2332 | #define md5sha_hash md5_hash | 2409 | #define md5sha_hash md5_hash |
2333 | #define sha_end sha1_end | 2410 | #define sha_end sha1_end |
2411 | #endif | ||
2334 | enum { | 2412 | enum { |
2335 | MD5_OUTSIZE = 16, | 2413 | MD5_OUTSIZE = 16, |
2336 | SHA1_OUTSIZE = 20, | 2414 | SHA1_OUTSIZE = 20, |
@@ -2473,31 +2551,10 @@ extern struct globals *BB_GLOBAL_CONST ptr_to_globals; | |||
2473 | #define barrier() asm volatile ("":::"memory") | 2551 | #define barrier() asm volatile ("":::"memory") |
2474 | 2552 | ||
2475 | #if defined(__clang_major__) && __clang_major__ >= 9 | 2553 | #if defined(__clang_major__) && __clang_major__ >= 9 |
2476 | /* Clang/llvm drops assignment to "constant" storage. Silently. | 2554 | /* {ASSIGN,XZALLOC}_CONST_PTR() are out-of-line functions |
2477 | * Needs serious convincing to not eliminate the store. | 2555 | * to prevent clang from reading pointer before it is assigned. |
2478 | */ | ||
2479 | static ALWAYS_INLINE void* not_const_pp(const void *p) | ||
2480 | { | ||
2481 | void *pp; | ||
2482 | asm volatile ( | ||
2483 | "# forget that p points to const" | ||
2484 | : /*outputs*/ "=r" (pp) | ||
2485 | : /*inputs*/ "0" (p) | ||
2486 | ); | ||
2487 | return pp; | ||
2488 | } | ||
2489 | # if !ENABLE_PLATFORM_MINGW32 | ||
2490 | # define ASSIGN_CONST_PTR(pptr, v) do { \ | ||
2491 | *(void**)not_const_pp(pptr) = (void*)(v); \ | ||
2492 | barrier(); \ | ||
2493 | } while (0) | ||
2494 | #else | ||
2495 | /* On Windows it seems necessary for this to be a function too. */ | ||
2496 | void ASSIGN_CONST_PTR(const void *pptr, const void *ptr) FAST_FUNC; | ||
2497 | #endif | ||
2498 | /* XZALLOC_CONST_PTR() is an out-of-line function to prevent | ||
2499 | * clang from reading pointer before it is assigned. | ||
2500 | */ | 2556 | */ |
2557 | void ASSIGN_CONST_PTR(const void *pptr, void *v) FAST_FUNC; | ||
2501 | void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; | 2558 | void XZALLOC_CONST_PTR(const void *pptr, size_t size) FAST_FUNC; |
2502 | #else | 2559 | #else |
2503 | # define ASSIGN_CONST_PTR(pptr, v) do { \ | 2560 | # define ASSIGN_CONST_PTR(pptr, v) do { \ |
diff --git a/include/mingw.h b/include/mingw.h index 3ee1cc46f..276e40659 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -259,6 +259,7 @@ int ffs(int i); | |||
259 | */ | 259 | */ |
260 | 260 | ||
261 | #define TIOCGWINSZ 0x5413 | 261 | #define TIOCGWINSZ 0x5413 |
262 | #define TIOCSWINSZ 0x5414 | ||
262 | 263 | ||
263 | int ioctl(int fd, int code, ...); | 264 | int ioctl(int fd, int code, ...); |
264 | 265 | ||
@@ -670,3 +671,4 @@ enum { | |||
670 | int elevation_state(void); | 671 | int elevation_state(void); |
671 | void set_interp(int i) FAST_FUNC; | 672 | void set_interp(int i) FAST_FUNC; |
672 | int mingw_shell_execute(SHELLEXECUTEINFO *info); | 673 | int mingw_shell_execute(SHELLEXECUTEINFO *info); |
674 | void mingw_die_if_error(NTSTATUS status, const char *function_name); | ||