diff options
author | Nathan Neulinger <nneul@neulinger.org> | 2005-02-15 01:43:32 +0000 |
---|---|---|
committer | Nathan Neulinger <nneul@neulinger.org> | 2005-02-15 01:43:32 +0000 |
commit | f247d0ca38730aface174bfa051c07dc81bb11d7 (patch) | |
tree | a74d642b947dcc9e410115ee4bf938e00252065e | |
parent | b2a974b7f00bc494ca3875a43402ca3bcd80e3b1 (diff) | |
download | cracklib-f247d0ca38730aface174bfa051c07dc81bb11d7.tar.gz |
integrate the redhat 64bit patchv2.8pre2cracklib-2.8pre2
git-svn-id: file:///tmp/cracklib-svn/trunk@39 4175fe1e-86d5-4fdc-8e6a-506fab9d8533
-rw-r--r-- | cracklib/ChangeLog | 3 | ||||
-rw-r--r-- | cracklib/configure.in | 2 | ||||
-rw-r--r-- | cracklib/lib/packlib.c | 129 |
3 files changed, 123 insertions, 11 deletions
diff --git a/cracklib/ChangeLog b/cracklib/ChangeLog index e53b004..1336b83 100644 --- a/cracklib/ChangeLog +++ b/cracklib/ChangeLog @@ -1,3 +1,6 @@ +2005-02-14: + * Integrated the redhat/fedora patch for broken 64bit dictionaries + 2005-02-09: * Updated source to use SUSv2 specified integer types instead diff --git a/cracklib/configure.in b/cracklib/configure.in index 52b0b7f..2a812bc 100644 --- a/cracklib/configure.in +++ b/cracklib/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT([lib/crack.h]) -AM_INIT_AUTOMAKE(cracklib, 2.8pre1) +AM_INIT_AUTOMAKE(cracklib, 2.8pre2) AM_CONFIG_HEADER(config.h) dnl Checks for programs. diff --git a/cracklib/lib/packlib.c b/cracklib/lib/packlib.c index 2f045a5..673d540 100644 --- a/cracklib/lib/packlib.c +++ b/cracklib/lib/packlib.c @@ -18,13 +18,53 @@ static char vers_id[] = "packlib.c : v2.3p2 Alec Muffett 18 May 1993"; #define DEBUG 0 +/* Structures for processing "broken" 64bit dictionary files */ + +struct pi_header64 +{ + uint64_t pih_magic; + uint64_t pih_numwords; + uint16_t pih_blocklen; + uint16_t pih_pad; +}; + +typedef struct +{ + FILE *ifp; + FILE *dfp; + FILE *wfp; + uint64_t flags; + uint64_t hwms[256]; + struct pi_header64 header; + int count; + char data[NUMWORDS][MAXWORDLEN]; +} PWDICT64; + + +static int +_PWIsBroken64(FILE *ifp) +{ + PWDICT64 pdesc64; + + rewind(ifp); + if (!fread((char *) &pdesc64.header, sizeof(pdesc64.header), 1, ifp)) + { + return 0; + } + + return (pdesc64.header.pih_magic == PIH_MAGIC); +} + + PWDICT * PWOpen(prefix, mode) char *prefix; char *mode; { uint32_t i; + int use64 = 0; static PWDICT pdesc; + static PWDICT64 pdesc64; char iname[STRINGSIZE]; char dname[STRINGSIZE]; char wname[STRINGSIZE]; @@ -40,6 +80,7 @@ PWOpen(prefix, mode) } memset(&pdesc, '\0', sizeof(pdesc)); + memset(&pdesc64, '\0', sizeof(pdesc64)); sprintf(iname, "%s.pwi", prefix); sprintf(dname, "%s.pwd", prefix); @@ -89,6 +130,36 @@ PWOpen(prefix, mode) return ((PWDICT *) 0); } + if ((pdesc.header.pih_magic == 0) || (pdesc.header.pih_numwords == 0)) + { + /* uh-oh. either a broken "64-bit" file or a garbage file. */ + rewind (ifp); + if (!fread((char *) &pdesc64.header, sizeof(pdesc64.header), 1, ifp)) + { + fprintf(stderr, "%s: error reading header\n", prefix); + + pdesc.header.pih_magic = 0; + fclose(ifp); + fclose(dfp); + return ((PWDICT *) 0); + } + if (pdesc64.header.pih_magic != PIH_MAGIC) + { + /* nope, not "64-bit" after all */ + fprintf(stderr, "%s: error reading header\n", prefix); + + pdesc.header.pih_magic = 0; + fclose(ifp); + fclose(dfp); + return ((PWDICT *) 0); + } + pdesc.header.pih_magic = pdesc64.header.pih_magic; + pdesc.header.pih_numwords = pdesc64.header.pih_numwords; + pdesc.header.pih_blocklen = pdesc64.header.pih_blocklen; + pdesc.header.pih_pad = pdesc64.header.pih_pad; + use64 = 1; + } + if (pdesc.header.pih_magic != PIH_MAGIC) { fprintf(stderr, "%s: magic mismatch\n", prefix); @@ -99,6 +170,16 @@ PWOpen(prefix, mode) return ((PWDICT *) 0); } + if (pdesc.header.pih_numwords < 1) + { + fprintf(stderr, "%s: invalid word count\n", prefix); + + pdesc.header.pih_magic = 0; + fclose(ifp); + fclose(dfp); + return ((PWDICT *) 0); + } + if (pdesc.header.pih_blocklen != NUMWORDS) { fprintf(stderr, "%s: size mismatch\n", prefix); @@ -113,7 +194,18 @@ PWOpen(prefix, mode) { int i; - if (fread(pdesc.hwms, 1, sizeof(pdesc.hwms), wfp) != sizeof(pdesc.hwms)) + if (use64) + { + if (fread(pdesc64.hwms, 1, sizeof(pdesc64.hwms), wfp) != sizeof(pdesc64.hwms)) + { + pdesc.flags &= ~PFOR_USEHWMS; + } + for (i = 0; i < sizeof(pdesc.hwms) / sizeof(pdesc.hwms[0]); i++) + { + pdesc.hwms[i] = pdesc64.hwms[i]; + } + } + else if (fread(pdesc.hwms, 1, sizeof(pdesc.hwms), wfp) != sizeof(pdesc.hwms)) { pdesc.flags &= ~PFOR_USEHWMS; } @@ -269,16 +361,33 @@ GetPW(pwp, number) return (data[number % NUMWORDS]); } - if (fseek(pwp->ifp, sizeof(struct pi_header) + (thisblock * sizeof(uint32_t)), 0)) - { - perror("(index fseek failed)"); - return ((char *) 0); - } - - if (!fread((char *) &datum, sizeof(datum), 1, pwp->ifp)) + if (_PWIsBroken64(pwp->ifp)) { - perror("(index fread failed)"); - return ((char *) 0); + uint64_t datum64; + if (fseek(pwp->ifp, sizeof(struct pi_header64) + (thisblock * sizeof(uint64_t)), 0)) + { + perror("(index fseek failed)"); + return ((char *) 0); + } + + if (!fread((char *) &datum64, sizeof(datum64), 1, pwp->ifp)) + { + perror("(index fread failed)"); + return ((char *) 0); + } + datum = datum64; + } else { + if (fseek(pwp->ifp, sizeof(struct pi_header) + (thisblock * sizeof(uint32_t)), 0)) + { + perror("(index fseek failed)"); + return ((char *) 0); + } + + if (!fread((char *) &datum, sizeof(datum), 1, pwp->ifp)) + { + perror("(index fread failed)"); + return ((char *) 0); + } } if (fseek(pwp->dfp, datum, 0)) |