Package: pwgen
Version: 2.07-1
Severity: wishlist
Tags: patch

Hi,
see the attached patch. It adds an option "-r chars" 
for removing an arbitrary char group.

Flo

commit acc97baf11505b5b741b3dde23b5855bf4eb8c88
Author: Florian Lohoff <f...@zz.de>
Date:   Thu Sep 1 21:12:28 2016 +0200

    Add -r chars option for removing chars from password.
    
    The biggest annoyance on German Keyboards is the swap
    of y and z to the American Keyboard layout. Sometimes
    it cant be avoided to use American Keyboard e.g. on
    LOM/BMC/IPMI access. It would be nice to be able to
    avoid yYzZ in passwords because of this problem.
    As there will definitly be other Keyboard layouts
    which have the same problem add an option to avoid
    an arbitrary group of chars.

diff --git a/pw_phonemes.c b/pw_phonemes.c
index f9de869..8705ffc 100644
--- a/pw_phonemes.c
+++ b/pw_phonemes.c
@@ -56,7 +56,7 @@ struct pw_element elements[] = {
 
 #define NUM_ELEMENTS (sizeof(elements) / sizeof (struct pw_element))
 
-void pw_phonemes(char *buf, int size, int pw_flags)
+void pw_phonemes(char *buf, int size, int pw_flags, char *remove)
 {
        int             c, i, len, flags, feature_flags;
        int             prev, should_be, first;
diff --git a/pw_rand.c b/pw_rand.c
index 240f173..2d28915 100644
--- a/pw_rand.c
+++ b/pw_rand.c
@@ -20,7 +20,7 @@ const char *pw_symbols = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
 const char *pw_ambiguous = "B8G6I1l0OQDS5Z2";
 const char *pw_vowels = "01aeiouyAEIOUY";
 
-void pw_rand(char *buf, int size, int pw_flags)
+void pw_rand(char *buf, int size, int pw_flags, char *remove)
 {
        char            ch, *chars, *wchars;
        int             i, len, feature_flags;
@@ -65,6 +65,8 @@ try_again:
                        continue;
                if ((pw_flags & PW_NO_VOWELS) && strchr(pw_vowels, ch))
                        continue;
+               if (remove != NULL && strchr(remove, ch))
+                       continue;
                buf[i++] = ch;
                if (strchr(pw_digits, ch))
                        feature_flags &= ~PW_DIGITS;
diff --git a/pwgen.1 b/pwgen.1
index 4aa8e60..0e61d29 100644
--- a/pwgen.1
+++ b/pwgen.1
@@ -101,6 +101,9 @@ Also, note that the name of the file may be easily 
available from the
 .B \-h, --help
 Print a help message.
 .TP
+.B \-r "chars"
+Dont use characters in password.
+.TP
 .B \-s, --secure
 Generate completely random, hard-to-memorize passwords.  These should
 only be used for machine passwords, since otherwise it's almost
diff --git a/pwgen.c b/pwgen.c
index d92579f..0da35e5 100644
--- a/pwgen.c
+++ b/pwgen.c
@@ -46,7 +46,7 @@ struct option pwgen_options[] = {
 };
 #endif
 
-const char *pw_options = "01AaBCcnN:shH:vy";
+const char *pw_options = "01AaBCcnN:sr:hH:vy";
 
 static void usage(void)
 {
@@ -66,6 +66,8 @@ static void usage(void)
        fputs("  -y or --symbols\n", stderr);
        fputs("\tInclude at least one special symbol in the password\n", 
              stderr);
+       fputs("  -r chars\n", stderr);
+       fputs("\tRemove characters from password\n", stderr);
        fputs("  -s or --secure\n", stderr);
        fputs("\tGenerate completely random passwords\n", stderr);
        fputs("  -B or --ambiguous\n", stderr);
@@ -92,7 +94,8 @@ int main(int argc, char **argv)
        int     c, i;
        int     num_cols = -1;
        char    *buf, *tmp;
-       void    (*pwgen)(char *inbuf, int size, int pw_flags);
+       char    *remove=NULL;
+       void    (*pwgen)(char *inbuf, int size, int pw_flags, char *remove);
 
        pwgen = pw_phonemes;
        pw_number = pw_random_number;
@@ -156,6 +159,10 @@ int main(int argc, char **argv)
                        pwgen = pw_rand;
                        pwgen_flags |= PW_NO_VOWELS | PW_DIGITS | PW_UPPERS;
                        break;
+               case 'r':
+                       remove = strdup(optarg);
+                       pwgen = pw_rand;
+                       break;
                case 'h':
                case '?':
                        usage();
@@ -201,7 +208,7 @@ int main(int argc, char **argv)
                exit(1);
        }
        for (i=0; i < num_pw; i++) {
-               pwgen(buf, pw_length, pwgen_flags);
+               pwgen(buf, pw_length, pwgen_flags, remove);
                if (!do_columns || ((i % num_cols) == (num_cols-1)))
                        printf("%s\n", buf);
                else
diff --git a/pwgen.h b/pwgen.h
index be7d76b..f408fe3 100644
--- a/pwgen.h
+++ b/pwgen.h
@@ -38,10 +38,10 @@ extern const char *pw_ambiguous;
 /* Function prototypes */
 
 /* pw_phonemes.c */
-extern void pw_phonemes(char *buf, int size, int pw_flags);
+extern void pw_phonemes(char *buf, int size, int pw_flags, char *remove);
 
 /* pw_rand.c */
-extern void pw_rand(char *buf, int size, int pw_flags);
+extern void pw_rand(char *buf, int size, int pw_flags, char *remove);
 
 /* randnum.c */
 extern int pw_random_number(int max_num);

-- System Information:
Debian Release: 8.5
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.6.0-0.bpo.1-rt-amd64 (SMP w/4 CPU cores; PREEMPT)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages pwgen depends on:
ii  libc6  2.19-18+deb8u4

pwgen recommends no packages.

pwgen suggests no packages.

-- no debconf information

Reply via email to