]> eyrie.org Git - kerberos/krb5-strength.git/blob - cracklib/packer.c
Release 3.3
[kerberos/krb5-strength.git] / cracklib / packer.c
1 /*
2  * This program is copyright Alec Muffett 1993. The author disclaims all 
3  * responsibility or liability with respect to it's usage or its effect 
4  * upon hardware or computer systems, and maintains copyright as set out 
5  * in the "LICENCE" document which accompanies distributions of Crack v4.0 
6  * and upwards.
7  */
8
9 /*
10  * Modified as part of the krb5-strength project as follows:
11  *
12  * 2009-10-14  Russ Allbery <eagle@eyrie.org>
13  *   - Add ANSI C protototypes for all functions.
14  * 2010-03-14  Russ Allbery <eagle@eyrie.org>
15  *   - Use unsigned long instead of int32 to avoid printf warnings.
16  * 2016-11-06  Mark Sirota <msirota@isc.upenn.edu>
17  *   - Display a warning when processing out-of-order input.
18  */
19
20 #include "packer.h"
21
22 int
23 main(int argc, char *argv[])
24 {
25     unsigned long readed;
26     unsigned long wrote;
27     PWDICT *pwp;
28     char buffer[STRINGSIZE], prev[STRINGSIZE];
29
30     if (argc <= 1)
31     {
32         fprintf(stderr, "Usage:\t%s dbname\n", argv[0]);
33         return (-1);
34     }
35
36     if (!(pwp = PWOpen(argv[1], "w")))
37     {
38         perror(argv[1]);
39         return (-1);
40     }
41
42     wrote = 0;
43     prev[0] = '\0';
44
45     for (readed = 0; fgets(buffer, STRINGSIZE, stdin); /* nothing */)
46     {
47         readed++;
48
49         buffer[MAXWORDLEN - 1] = '\0';
50
51         Chop(buffer);
52
53         if (!buffer[0])
54         {
55             fprintf(stderr, "skipping line: %lu\n", readed);
56             continue;
57         }
58
59         /*
60          * If this happens, strcmp() in FindPW() in packlib.c will be unhappy.
61          */
62         if (strcmp(buffer, prev) < 0)
63         {
64             fprintf(stderr, "warning: input out of order: '%s' should not"
65                     " follow '%s' (line %lu), skipping\n", buffer, prev,
66                     readed);
67             continue;
68         }
69         strcpy(prev, buffer);
70
71         if (PutPW(pwp, buffer))
72         {
73             fprintf(stderr, "error: PutPW '%s' line %luy\n", buffer, readed);
74         }
75
76         wrote++;
77     }
78
79     PWClose(pwp);
80
81     printf("%lu %lu\n", readed, wrote);
82
83     return (0);
84 }