diff options
author | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-09-20 03:03:26 +0000 |
commit | 1f457376b478257b88d4a857f5ec1b6155442dd7 (patch) | |
tree | 2a06a60551dea362cf8cb0cb0ba66c78608717c4 /support/dktools/dk-pwgen.c | |
parent | ac690ca29ad5bf8a5203a65fd6252f7b564f4727 (diff) |
CTAN sync 202009200303
Diffstat (limited to 'support/dktools/dk-pwgen.c')
-rw-r--r-- | support/dktools/dk-pwgen.c | 230 |
1 files changed, 116 insertions, 114 deletions
diff --git a/support/dktools/dk-pwgen.c b/support/dktools/dk-pwgen.c index b5ef2d4f14..83b025d2c9 100644 --- a/support/dktools/dk-pwgen.c +++ b/support/dktools/dk-pwgen.c @@ -1,36 +1,14 @@ /* - WARNING: This file was generated by dkct. - Changes you make here will be lost if dkct is run again! - You should modify the original source and run dkct on it. - Original source: dk-pwgen.ctr +Copyright (C) 2015-2020, Dirk Krause +SPDX-License-Identifier: BSD-3-Clause */ /* -Copyright (C) 2015-2017, Dirk Krause - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above opyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -* Neither the name of the author nor the names of contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + WARNING: This file was generated by the dkct program (see + http://dktools.sourceforge.net/ for details). + Changes you make here will be lost if dkct is run again! + You should modify the original source and run dkct on it. + Original source: dk-pwgen.ctr */ /** @file dk-pwgen.c The dk-pwgen module. @@ -121,12 +99,16 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "dk4maasz.h" #include "dk4mpl.h" #include "dk4svbufa.h" +#include "dk4unused.h" +#ifndef DK4WMAIN_H_INCLUDED +#include "dk4wmain.h" +#endif -#line 97 "dk-pwgen.ctr" +#line 101 "dk-pwgen.ctr" @@ -194,7 +176,7 @@ dkT("verbose"), NULL -#line 167 "dk-pwgen.ctr" +#line 171 "dk-pwgen.ctr" }; @@ -224,12 +206,12 @@ dkT("\t\t--manual\t\t*** SHOW FULL MANUAL. ***"), dkT("\t\t--version\t\tShow version information."), dkT("\t\t--license\t\tShow license information."), dkT(""), -dkT("http://dktools.sourceforge.net"), +dkT("http://sourceforge.net/p/dktools/wiki/dk-pwgen/"), dkT(""), NULL -#line 200 "dk-pwgen.ctr" +#line 204 "dk-pwgen.ctr" }; @@ -239,7 +221,8 @@ dkT("This software uses code from the following projects, either directly or as" dkT("a library:"), dkT(""), dkT("dktools\t\tDirk Krause's tools and libraries."), -dkT("\t\tSee http://dktools.sourceforge.net/ for more information."), +dkT("\t\tSee http://sourceforge.net/p/dktools/wiki/Home"), +dkT("\t\tfor more information."), #if DK4_HAVE_ZLIB_H dkT(""), dkT("zlib\t\tData compression library."), @@ -277,27 +260,27 @@ dkT(""), dkT("Redistribution and use in source and binary forms, with or without"), dkT("modification, are permitted provided that the following conditions are met:"), dkT(""), -dkT("* Redistributions of source code must retain the above copyright notice,"), -dkT(" this list of conditions and the following disclaimer."), -dkT("* Redistributions in binary form must reproduce the above copyright"), -dkT(" notice, this list of conditions and the following disclaimer in the"), -dkT(" documentation and/or other materials provided with the distribution."), -dkT("* Neither the name of the Dirk Krause nor the names of contributors may be"), -dkT(" used to endorse or promote products derived from this software without"), -dkT(" specific prior written permission."), -dkT(""), -dkT("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\""), -dkT("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE"), -dkT("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE"), -dkT("ARE DISCLAIMED."), +dkT("1. Redistributions of source code must retain the above copyright notice,"), +dkT(" this list of conditions and the following disclaimer."), +dkT("2. Redistributions in binary form must reproduce the above copyright"), +dkT(" notice, this list of conditions and the following disclaimer in the"), +dkT(" documentation and/or other materials provided with the distribution."), +dkT("3. Neither the name of the copyright holder nor the names of its"), +dkT(" contributors may be used to endorse or promote products derived from"), +dkT(" this software without specific prior written permission."), dkT(""), -dkT("IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,"), -dkT("INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,"), -dkT("BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,"), -dkT("DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY"), -dkT("OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"), -dkT("NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,"), -dkT("EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."), +dkT("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS"), +dkT("``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT"), +dkT("LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR"), +dkT("A PARTICULAR PURPOSE ARE DISCLAIMED."), +dkT("IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY"), +dkT("DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES"), +dkT("(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR"), +dkT("SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER"), +dkT("CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT"), +dkT("LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY"), +dkT("OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF"), +dkT("SUCH DAMAGE."), #if DK4_HAVE_ZLIB_H dkT(""), dkT(""), @@ -500,7 +483,7 @@ dkT(""), NULL -#line 469 "dk-pwgen.ctr" +#line 474 "dk-pwgen.ctr" }; @@ -605,7 +588,7 @@ dkT("The -b option is not supported on Windows!"), NULL -#line 586 "dk-pwgen.ctr" +#line 591 "dk-pwgen.ctr" }; @@ -643,7 +626,9 @@ static char stdout_buffer[BUFSIZ]; /** Use an explicitly specified buffer when reading seed file so we can securely reset the memory before exiting. */ +#if (!(DK4_ON_WINDOWS)) static char seed_file_buf[BUFSIZ]; +#endif @@ -817,8 +802,9 @@ sig_pass_pointer(DK4_VOLATILE dk4_sig_atomic_t *ptr) */ static void -sig_handler_pipe(int signo) +sig_handler_pipe(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_pipe) = 1; } #endif @@ -828,8 +814,9 @@ sig_handler_pipe(int signo) */ static void -sig_handler_int(int signo) +sig_handler_int(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_int) = 1; } @@ -838,8 +825,9 @@ sig_handler_int(int signo) */ static void -sig_handler_term(int signo) +sig_handler_term(int DK4_ARG_UNUSED(signo) ) { + DK4_UNUSED_ARG(signo) *sig_pass_pointer(&sig_had_term) = 1; } @@ -863,10 +851,18 @@ sig_read_atomic(DK4_VOLATILE dk4_sig_atomic_t *ap) */ static int -sig_can_continue(int check_pipe) +sig_can_continue( +#ifdef SIGPIPE +int check_pipe +#else +int DK4_ARG_UNUSED(check_pipe) +#endif +) { int back = 1; -#ifdef SIGPIPE +#ifndef SIGPIPE + DK4_UNUSED_ARG(check_pipe) +#else if (0 != check_pipe) { if (0 != sig_read_atomic(&sig_had_pipe)) { back = 0; } } @@ -907,7 +903,7 @@ dk_pwgen_opt_range(size_t *minptr, size_t *maxptr, dkChar option) dkChar buf[32*sizeof(dk4_um_t)]; dk4_er_t er; const dkChar *endptr; - dkChar *p1; + dkChar *p1 = NULL; size_t val; int res; int rdf = 0; @@ -915,7 +911,8 @@ dk_pwgen_opt_range(size_t *minptr, size_t *maxptr, dkChar option) int passno = 0; -#line 894 "dk-pwgen.ctr" +#line 912 "dk-pwgen.ctr" + dk4error_init(&er); if (0 != dk4app_opt_is_set_long(app, dk_pwgen_kwnl[8], NULL)) { verbose = 1; } @@ -925,27 +922,26 @@ dk_pwgen_opt_range(size_t *minptr, size_t *maxptr, dkChar option) ); if (0 != res) { -#line 902 "dk-pwgen.ctr" +#line 921 "dk-pwgen.ctr" p1 = dk4str_chr(buf, dkT('-')); if (NULL != p1) { -#line 904 "dk-pwgen.ctr" +#line 923 "dk-pwgen.ctr" *(p1++) = dkT('\0'); p1 = dk4str_start(p1, NULL); } else { -#line 907 "dk-pwgen.ctr" +#line 926 "dk-pwgen.ctr" } val = 0; endptr = NULL; - dk4error_init(&er); if (0 != dk4ma_input_dk_dec_size_t(&val, buf, &endptr, 1, &er)) { *minptr = val; *maxptr = val; back = 1; if (NULL != p1) { -#line 916 "dk-pwgen.ctr" +#line 934 "dk-pwgen.ctr" passno = 1; back = 0; val = 0; @@ -960,38 +956,38 @@ dk_pwgen_opt_range(size_t *minptr, size_t *maxptr, dkChar option) } } else { -#line 929 "dk-pwgen.ctr" +#line 947 "dk-pwgen.ctr" /* ERROR: Failed to read size */ rdf = 1; } } } else { -#line 934 "dk-pwgen.ctr" +#line 952 "dk-pwgen.ctr" /* ERROR: Failed to read size */ rdf = 1; } } else { -#line 938 "dk-pwgen.ctr" +#line 956 "dk-pwgen.ctr" /* ERROR: Failed to obtain option argument, probably bug */ } } else { -#line 941 "dk-pwgen.ctr" +#line 959 "dk-pwgen.ctr" back = 1; } if ((0 == back) && (0 != rdf)) { switch (er.ec) { case DK4_E_MATH_OVERFLOW : { -#line 946 "dk-pwgen.ctr" +#line 964 "dk-pwgen.ctr" /* ERROR: Numeric overflow while reading number */ dk4app_log_1(app, dk_pwgen_msg, dk_pwgen_sz_msg, DK4_LL_ERROR, 3); } break; case DK4_E_SYNTAX : { -#line 950 "dk-pwgen.ctr" +#line 968 "dk-pwgen.ctr" /* ERROR: Not a size specification */ dk4app_log_3( app, dk_pwgen_msg, dk_pwgen_sz_msg, DK4_LL_ERROR, 4, 5, @@ -1000,7 +996,7 @@ dk_pwgen_opt_range(size_t *minptr, size_t *maxptr, dkChar option) } break; default: { -#line 957 "dk-pwgen.ctr" +#line 975 "dk-pwgen.ctr" /* ERROR: Failed to read size */ dk4app_log_3( app, dk_pwgen_msg, dk_pwgen_sz_msg, DK4_LL_ERROR, 6, 7, @@ -1010,7 +1006,7 @@ dk_pwgen_opt_range(size_t *minptr, size_t *maxptr, dkChar option) } } -#line 965 "dk-pwgen.ctr" +#line 983 "dk-pwgen.ctr" return back; } @@ -1028,7 +1024,7 @@ dk_pwgen_check_options(void) int back = 0; -#line 981 "dk-pwgen.ctr" +#line 999 "dk-pwgen.ctr" if (0 != dk4app_opt_is_set_short(app, dkT('b'), NULL)) { output_type = DK_PWGEN_MODE_BINARY; @@ -1161,7 +1157,7 @@ dk_pwgen_check_options(void) finished: -#line 1112 "dk-pwgen.ctr" +#line 1130 "dk-pwgen.ctr" return back; } @@ -1175,10 +1171,14 @@ int dk_pwgen_seed_prng(void) { #if DK4_CHAR_SIZE == 1 +#if DK4_HAVE_RAND_EGD && DK4_HAVE_STRUCT_SOCKADDR_UN dkChar snb[DK4_MAX_PATH]; #endif +#endif char buffer[64]; +#if DK4_HAVE_RAND_EGD && DK4_HAVE_STRUCT_SOCKADDR_UN char *envptr; +#endif #if DK4_ON_WINDOWS HCRYPTPROV hcp; BOOL res; @@ -1189,10 +1189,12 @@ dk_pwgen_seed_prng(void) int cc; int rounds = 0; int back = 0; +#if (!(DK4_ON_WINDOWS)) int svbres = 0; +#endif -#line 1141 "dk-pwgen.ctr" +#line 1165 "dk-pwgen.ctr" /* Let OpenSSL library functions try to initialize. */ @@ -1243,7 +1245,7 @@ dk_pwgen_seed_prng(void) cc = 1; do { if (0 != dk_pwgen_can_continue()) { - res = CryptGenRandom(hcp, (DWORD)sizeof(buffer), buffer); + res = CryptGenRandom(hcp, (DWORD)sizeof(buffer), (BYTE *)buffer); if (res) { RAND_seed(buffer, sizeof(buffer)); if (1 == RAND_status()) { @@ -1322,7 +1324,7 @@ dk_pwgen_seed_prng(void) finished: -#line 1269 "dk-pwgen.ctr" +#line 1293 "dk-pwgen.ctr" return back; } @@ -1343,14 +1345,14 @@ dk_pwgen_value_in_range(size_t *dptr, size_t min, size_t max) int back = 0; -#line 1288 "dk-pwgen.ctr" +#line 1312 "dk-pwgen.ctr" if (max > min) { width = max - min; if (0 != (width + 1)) { width++ ; } if (0 < RAND_bytes((unsigned char *)(&rval), (int)sizeof(rval))) { -#line 1293 "dk-pwgen.ctr" +#line 1317 "dk-pwgen.ctr" *dptr = min + (rval % width); back = 1; } else { @@ -1363,7 +1365,7 @@ dk_pwgen_value_in_range(size_t *dptr, size_t min, size_t max) } -#line 1304 "dk-pwgen.ctr" +#line 1328 "dk-pwgen.ctr" return back; } @@ -1384,7 +1386,7 @@ dk_pwgen_output_hex(int upper) dkChar dc; /* Current character to write */ -#line 1323 "dk-pwgen.ctr" +#line 1347 "dk-pwgen.ctr" cc = 1; i = 0; bi = 0; @@ -1434,7 +1436,7 @@ dk_pwgen_output_hex(int upper) } -#line 1371 "dk-pwgen.ctr" +#line 1395 "dk-pwgen.ctr" } @@ -1613,7 +1615,7 @@ dk_pwgen_output_normal(void) ti = dk4mem_new_app(char,length,app); if (NULL != ti) { -#line 1548 "dk-pwgen.ctr" +#line 1572 "dk-pwgen.ctr" DK4_MEMRES(ti, length); cc = 1; if (0 == dk_pwgen_value_in_range(&upper, upper_min, upper_max)) { @@ -1630,7 +1632,7 @@ dk_pwgen_output_normal(void) avail = length; while (3 > passno) { -#line 1563 "dk-pwgen.ctr" +#line 1587 "dk-pwgen.ctr" switch (passno) { case 2 : { max = specials; @@ -1649,7 +1651,7 @@ dk_pwgen_output_normal(void) while (curel < max) { -#line 1580 "dk-pwgen.ctr" +#line 1604 "dk-pwgen.ctr" if (0 != dk_pwgen_can_continue()) { res = RAND_bytes( (unsigned char *)(&ind_to_set), (int)sizeof(size_t) @@ -1659,18 +1661,18 @@ dk_pwgen_output_normal(void) ind_to_set = ind_to_set % avail; -#line 1588 "dk-pwgen.ctr" +#line 1612 "dk-pwgen.ctr" res = 0; i = 0; while (i < length) { -#line 1592 "dk-pwgen.ctr" +#line 1616 "dk-pwgen.ctr" if ('\0' == ti[i]) { if (0 == ind_to_set) { -#line 1595 "dk-pwgen.ctr" +#line 1619 "dk-pwgen.ctr" res = 1; ti[i] = ic; i = length - 1; @@ -1680,14 +1682,14 @@ dk_pwgen_output_normal(void) } } else { -#line 1603 "dk-pwgen.ctr" +#line 1627 "dk-pwgen.ctr" } i++; } curel++; if (0 == res) { -#line 1608 "dk-pwgen.ctr" +#line 1632 "dk-pwgen.ctr" /* No free cell found */ curel = max; passno = 3; cc = 0; dk4app_log_1( @@ -1715,16 +1717,16 @@ dk_pwgen_output_normal(void) } if ((1 == cc) && (0 != dk_pwgen_can_continue())) { -#line 1634 "dk-pwgen.ctr" +#line 1658 "dk-pwgen.ctr" i = 0; speclen = dk4str_len(dk_pwgen_kwnl[6]); -#line 1637 "dk-pwgen.ctr" +#line 1661 "dk-pwgen.ctr" while (i < length) { -#line 1639 "dk-pwgen.ctr" +#line 1663 "dk-pwgen.ctr" if (0 != dk_pwgen_can_continue()) { res = RAND_bytes( (unsigned char *)(&val), (int)sizeof(dk4_um_t) @@ -1732,13 +1734,13 @@ dk_pwgen_output_normal(void) if (0 < res) { -#line 1645 "dk-pwgen.ctr" +#line 1669 "dk-pwgen.ctr" switch (ti[i]) { case 's': { val = val % (dk4_um_t)speclen; -#line 1649 "dk-pwgen.ctr" +#line 1673 "dk-pwgen.ctr" dc = (dk_pwgen_kwnl[6])[(size_t)val]; } break; case 'd': { @@ -1787,7 +1789,7 @@ dk_pwgen_output_normal(void) } } else { -#line 1696 "dk-pwgen.ctr" +#line 1720 "dk-pwgen.ctr" exval = EXIT_FAILURE; /* ERROR: Memory, already reported */ } @@ -1803,38 +1805,38 @@ dk_pwgen_produce_output(void) { -#line 1710 "dk-pwgen.ctr" +#line 1734 "dk-pwgen.ctr" if (0 != dk_pwgen_value_in_range(&length, length_min, length_max)) { exval = EXIT_SUCCESS; switch (output_type) { case DK_PWGEN_MODE_BINARY : { -#line 1714 "dk-pwgen.ctr" +#line 1738 "dk-pwgen.ctr" dk_pwgen_output_binary(); } break; case DK_PWGEN_MODE_HARD : { -#line 1717 "dk-pwgen.ctr" +#line 1741 "dk-pwgen.ctr" dk_pwgen_output_hard(); } break; case DK_PWGEN_MODE_HEX_LOWER : { -#line 1720 "dk-pwgen.ctr" +#line 1744 "dk-pwgen.ctr" dk_pwgen_output_hex(0); } break; case DK_PWGEN_MODE_HEX_UPPER : { -#line 1723 "dk-pwgen.ctr" +#line 1747 "dk-pwgen.ctr" dk_pwgen_output_hex(1); } break; case DK_PWGEN_MODE_PIN : { -#line 1726 "dk-pwgen.ctr" +#line 1750 "dk-pwgen.ctr" dk_pwgen_output_pin(); } break; default : { -#line 1729 "dk-pwgen.ctr" +#line 1753 "dk-pwgen.ctr" dk_pwgen_output_normal(); } break; } @@ -1848,7 +1850,7 @@ dk_pwgen_produce_output(void) } -#line 1741 "dk-pwgen.ctr" +#line 1765 "dk-pwgen.ctr" } @@ -1861,7 +1863,7 @@ dk_pwgen_normal_run(void) { -#line 1752 "dk-pwgen.ctr" +#line 1776 "dk-pwgen.ctr" if (0 < dk_pwgen_check_options()) { if (0 < dk_pwgen_seed_prng()) { dk_pwgen_produce_output(); @@ -1873,7 +1875,7 @@ dk_pwgen_normal_run(void) } -#line 1762 "dk-pwgen.ctr" +#line 1786 "dk-pwgen.ctr" } @@ -2088,10 +2090,10 @@ int main(int argc, char *argv[]) ); -#line 1975 "dk-pwgen.ctr" +#line 1999 "dk-pwgen.ctr" -#line 1976 "dk-pwgen.ctr" +#line 2000 "dk-pwgen.ctr" dk4fput_initialize_stdout(); dk4fput_initialize_stderr(); app = dk4app_open_cmd( @@ -2170,10 +2172,10 @@ int main(int argc, char *argv[]) dk4fput_cleanup_stdout(); -#line 2053 "dk-pwgen.ctr" +#line 2077 "dk-pwgen.ctr" -#line 2054 "dk-pwgen.ctr" +#line 2078 "dk-pwgen.ctr" exit(exval); return exval; } |