]> eyrie.org Git - kerberos/krb5-strength.git/blobdiff - cracklib/packlib.c
Declare fast forward from 3.1-2
[kerberos/krb5-strength.git] / cracklib / packlib.c
index 0dfe2fd2877e25caa7e97b90f2cbcb41b701599a..e5805c46146512d3dfd685957f753e0322f3ff91 100644 (file)
@@ -9,18 +9,27 @@
 /*
  * Modified as part of the krb5-strength project as follows:
  *
- * 2007-03-23  Russ Allbery <rra@stanford.edu>
+ * 2007-03-23  Russ Allbery <eagle@eyrie.org>
  *   - Apply Debian patch to improve the search logic.
  *   - Don't crash if the dictionary is corrupt.
  *   - Additional system includes for other functions.
- * 2009-10-14  Russ Allbery <rra@stanford.edu>
+ * 2009-10-14  Russ Allbery <eagle@eyrie.org>
  *   - Add ANSI C protototypes for all functions.
  *   - Tweaks for const cleanliness.
  *   - Add parentheses around assignment used for its truth value.
  *   - Make internal functions static.
  *   - Remove unused variables.
- * 2009-11-18  Russ Allbery <rra@stanford.edu>
+ * 2009-11-18  Russ Allbery <eagle@eyrie.org>
  *   - Fixed the data format output by packer to properly pad the end.
+ * 2013-09-24  Russ Allbery <eagle@eyrie.org>
+ *   - Add a missing ANSI C prototype.
+ *   - Remove last block optimization in GetPW and start fresh each time.
+ * 2013-12-13  Russ Allbery <eagle@eyrie.org>
+ *   - Close the wfp file handle on PWClose if it's open.
+ * 2016-11-06  Russ Allbery <eagle@eyrie.org>
+ *   - Remove unused vers_id to silence GCC warnings.
+ * 2020-05-16  Russ Allbery <eagle@eyrie.org>
+ *   - Fix types of printf formatting directives in DEBUG conditionals.
  */
 
 #include <stdio.h>
@@ -28,8 +37,6 @@
 
 #include "packer.h"
 
-static const char vers_id[] = "packlib.c : v2.3p2 Alec Muffett 18 May 1993";
-
 PWDICT *
 PWOpen(const char *prefix, const char *mode)
 {
@@ -94,6 +101,10 @@ PWOpen(const char *prefix, const char *mode)
            pdesc.header.pih_magic = 0;
            fclose(ifp);
            fclose(dfp);
+           if (wfp != NULL)
+           {
+               fclose(wfp);
+           }
            return ((PWDICT *) 0);
        }
 
@@ -104,6 +115,10 @@ PWOpen(const char *prefix, const char *mode)
            pdesc.header.pih_magic = 0;
            fclose(ifp);
            fclose(dfp);
+           if (wfp != NULL)
+           {
+               fclose(wfp);
+           }
            return ((PWDICT *) 0);
        }
 
@@ -114,6 +129,10 @@ PWOpen(const char *prefix, const char *mode)
            pdesc.header.pih_magic = 0;
            fclose(ifp);
            fclose(dfp);
+           if (wfp != NULL)
+           {
+               fclose(wfp);
+           }
            return ((PWDICT *) 0);
        }
 
@@ -130,8 +149,7 @@ PWOpen(const char *prefix, const char *mode)
 }
 
 int
-PWClose(pwp)
-    PWDICT *pwp;
+PWClose(PWDICT *pwp)
 {
     if (pwp->header.pih_magic != PIH_MAGIC)
     {
@@ -166,7 +184,7 @@ PWClose(pwp)
                    pwp->hwms[i] = pwp->hwms[i-1];
                }
 #ifdef DEBUG
-               printf("hwm[%02x] = %d\n", i, pwp->hwms[i]);
+               printf("hwm[%02x] = %u\n", i, pwp->hwms[i]);
 #endif
            }
            fwrite(pwp->hwms, 1, sizeof(pwp->hwms), pwp->wfp);
@@ -175,6 +193,10 @@ PWClose(pwp)
 
     fclose(pwp->ifp);
     fclose(pwp->dfp);
+    if (pwp->wfp != NULL)
+    {
+       fclose(pwp->wfp);
+    }
 
     pwp->header.pih_magic = 0;
 
@@ -255,16 +277,10 @@ GetPW(PWDICT *pwp, int32 number)
     register char *bptr;
     char buffer[NUMWORDS * MAXWORDLEN];
     static char data[NUMWORDS][MAXWORDLEN];
-    static int32 prevblock = 0xffffffff;
     int32 thisblock;
 
     thisblock = number / NUMWORDS;
 
-    if (prevblock == thisblock)
-    {
-       return (data[number % NUMWORDS]);
-    }
-
     if (fseek(pwp->ifp, sizeof(struct pi_header) + (thisblock * sizeof(int32)), 0))
     {
        perror("(index fseek failed)");
@@ -289,8 +305,6 @@ GetPW(PWDICT *pwp, int32 number)
        return ((char *) 0);
     }
 
-    prevblock = thisblock;
-
     bptr = buffer;
 
     for (ostr = data[0]; (*(ostr++) = *(bptr++)) != '\0'; /* nothing */ );
@@ -332,7 +346,7 @@ FindPW(PWDICT *pwp, const char *string)
     }
 
 #ifdef DEBUG
-    printf("---- %lu, %lu ----\n", lwm, hwm);
+    printf("---- %u, %u ----\n", lwm, hwm);
 #endif
 
     for (;;)
@@ -340,7 +354,7 @@ FindPW(PWDICT *pwp, const char *string)
        int cmp;
 
 #ifdef DEBUG
-       printf("%lu, %lu\n", lwm, hwm);
+       printf("%u, %u\n", lwm, hwm);
 #endif
 
        middle = lwm + ((hwm - lwm + 1) / 2);