Re: Intent to Rewrite: pwgen
Hello!
As an answer for Your letter, I would like to write:
[cut]
> I've already rewritten the core parts of the password generator from
> scratch, and it's already producing better passwords (resolving Debian
> bugs #66006 and #70058) than the original. What's currently missing is
> the command-line options parser (front-end interface) and man page, and
> other fussy items like that.
Writing man page before options parser isn't the best idea though ;)
> 1) Is it important that I maintain compatibility with the existing
> command-line interface? I'd much rather use one which is a bit more
> user-friendly. However, if there are a largish number of scripts
> that are depending on the existing command-line interface, I'd like
> to know that.
I think, that compatibility is always important, so it would be nice to
maintain old command line interface (even as an option selected from
makefile).
BTW: Isn't there makepasswd doing the thing like pwgen?
> 2) Once this code is finished, will Debian be willing to use this
> codebase to replace the existing pwgen package?
Well, I tried to compile it, but found it difficult. I added some
changes (file included at the end of this mail). I don't know is that my
Debian or my self, but if it don't compile it won't be included in
Debian ;)
> 4) Are there any other requirements/features you'd like to see in a
> program like pwgen?
Now changes:
---------------------------------------------------------------------
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2001-05-31 17:07 CEST by <root@debian>.
# Source directory was `/root/mkpw/new'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 234 -rw-r--r-- Makefile
# 2893 -rw-r--r-- randnum.c
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f
200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f
123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901
-a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh06882; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= Makefile ==============
if test -f 'Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'Makefile' '(file already exists)'
else
$echo 'x -' extracting 'Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CC = gcc
RM = rm -f
CFLAGS = -g -O2
DEFS = -DHAVE_RAND38
#DEFS = -DHAVE_RAND38 -DUSE_POSIX_TIME
TAR = tar
X
CCOPTS = $(CFLAGS) $(DEFS)
X
OBJS= pwgen.o randnum.o
X
pwgen: $(OBJS)
X $(CC) -o pwgen $(OBJS)
X
clean:
X $(RM) $(OBJS) pwgen *~
X
SHAR_EOF
(set 20 01 05 31 17 05 44 'Makefile'; eval "$shar_touch") &&
chmod 0644 'Makefile' ||
$echo 'restore of' 'Makefile' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'Makefile:' 'MD5 check failed'
c94c51b68cd3d19471f2f2f9713f3db7 Makefile
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
test 234 -eq "$shar_count" ||
$echo 'Makefile:' 'original size' '234,' 'current size' "$shar_count!"
fi
fi
# ============= randnum.c ==============
if test -f 'randnum.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'randnum.c' '(file already exists)'
else
$echo 'x -' extracting 'randnum.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'randnum.c' &&
/*
X * randnum.c -- generate (good) randum numbers.
X *
X * Copyright (C) 2001 by Theodore Ts'o
X *
X * This file may be distributed under the terms of the GNU Public
X * License.
X */
X
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#ifdef USE_POSIX_TIME
#include <time.h>
#endif
X
#include "pwgen.h"
X
#ifdef HAVE_DRAND48
extern double drand48();
#endif
X
/* Borrowed/adapted from e2fsprogs's UUID generation code */
static int get_random_fd(void)
{
#ifdef USE_POSIX_TIME
X struct timespec tv;
#else
X struct timeval tv;
#endif
X static int fd = -2;
X int i;
X
X if (fd == -2) {
X gettimeofday(&tv, 0);
X fd = open("/dev/urandom", O_RDONLY);
X if (fd == -1)
X fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
#ifdef HAVE_DRAND48
X srand48((tv.tv_sec<<9) ^ (getpgrp()<<15) ^
#ifdef USE_POSIX_TIME
X (getpid()) ^ (tv.tv_nsec>>11));
#else
X (getpid()) ^ (tv.tv_usec>>11));
#endif
#else
#ifdef USE_POSIX_TIME
X srandom((getpid() << 16) ^ (getpgrp() << 8) ^ getuid()
X ^ tv.tv_sec ^ tv.tv_nsec);
#else
X srandom((getpid() << 16) ^ (getpgrp() << 8) ^ getuid()
X ^ tv.tv_sec ^ tv.tv_usec);
#endif
#endif
X }
X /* Crank the random number generator a few times */
X gettimeofday(&tv, 0);
#ifdef USE_POSIX_TIME
X for (i = (tv.tv_sec ^ tv.tv_nsec) & 0x1F; i > 0; i--)
#else
X for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
#endif
#ifdef HAVE_DRAND48
X drand48();
#else
X rand();
#endif
X return fd;
}
X
/*
X * Generate a random number n, where 0 <= n < max_num, using
X * /dev/urandom if possible.
X */
int pw_random_number(int max_num)
{
X int i, fd = get_random_fd();
X int lose_counter = 0, nbytes=4;
X unsigned int rand;
X char *cp = (char *) &rand;
X
X if (fd >= 0) {
X while (nbytes > 0) {
X i = read(fd, cp, nbytes);
X if ((i < 0) &&
X ((errno == EINTR) || (errno == EAGAIN)))
X continue;
X if (i <= 0) {
X if (lose_counter++ == 8)
X break;
X continue;
X }
X nbytes -= i;
X cp += i;
X lose_counter = 0;
X }
X }
X if (nbytes == 0)
X return (rand % max_num);
X
X /* OK, we weren't able to use /dev/random, fall back to rand/rand48
*/
X
#ifdef RAND48
X return ((int) ((drand48() * max_num)));
#else
X return ((int) (random() / ((float) RAND_MAX) * max_num));
#endif
}
SHAR_EOF
(set 20 01 05 31 17 05 17 'randnum.c'; eval "$shar_touch") &&
chmod 0644 'randnum.c' ||
$echo 'restore of' 'randnum.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'randnum.c:' 'MD5 check failed'
eaefa388162fdc36754c1336ccf68b03 randnum.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'randnum.c'`"
test 2893 -eq "$shar_count" ||
$echo 'randnum.c:' 'original size' '2893,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh06882
exit 0
---------------------------------------------------------------------
Best Regards
IronHand
--
,------[ IronHand of CruX ]------- GCS d- s:- a19 C+++ UL++++ P+++ -.
| MAIL:ironhand@go2.pl L+++@ E- W+++ N+ o? K w+++ !O M |
| WWW: +none yet+ ICQ:43598300 V- PS+ PE- Y PGP- t+ 5+ X-- R++ |
`--------------------------------- tv- b+ !DI D+ G++ e h!>h++ r y? -'
Reply to: