Initial commit for Tizen
[profile/extras/shadow-utils.git] / doc / cracklib26.diff
1 diff -ur orig/cracklib26_small/cracklib/fascist.c cracklib26_small/cracklib/fascist.c
2 --- orig/cracklib26_small/cracklib/fascist.c    Mon Dec 15 02:56:55 1997
3 +++ cracklib26_small/cracklib/fascist.c Sat Apr  4 22:14:45 1998
4 @@ -12,6 +12,7 @@
5  #include <ctype.h>
6  #include <sys/types.h>
7  #include <pwd.h>
8 +#include <string.h>
9  
10  #define ISSKIP(x) (isspace(x) || ispunct(x))
11  
12 @@ -460,28 +461,27 @@
13  }
14  
15  char *
16 -FascistGecos(password, uid)
17 +FascistGecosPw(password, pwd)
18      char *password;
19 -    int uid;
20 +    struct passwd *pwd;
21  {
22      int i;
23      int j;
24      int wc;
25      char *ptr;
26 -    struct passwd *pwp;
27      char gbuffer[STRINGSIZE];
28      char tbuffer[STRINGSIZE];
29      char *uwords[STRINGSIZE];
30      char longbuffer[STRINGSIZE * 2];
31  
32 -    if (!(pwp = getpwuid(uid)))
33 +    if (!pwd)
34      {
35         return ("you are not registered in the password file");
36      }
37  
38      /* lets get really paranoid and assume a dangerously long gecos entry */
39  
40 -    strncpy(tbuffer, pwp->pw_name, STRINGSIZE);
41 +    strncpy(tbuffer, pwd->pw_name, STRINGSIZE);
42      tbuffer[STRINGSIZE-1] = '\0';
43      if (GTry(tbuffer, password))
44      {
45 @@ -490,12 +490,13 @@
46  
47      /* it never used to be that you got passwd strings > 1024 chars, but now... */
48  
49 -    strncpy(tbuffer, pwp->pw_gecos, STRINGSIZE);
50 +    strncpy(tbuffer, pwd->pw_gecos, STRINGSIZE);
51      tbuffer[STRINGSIZE-1] = '\0';
52      strcpy(gbuffer, Lowercase(tbuffer));
53  
54      wc = 0;
55      ptr = gbuffer;
56 +    uwords[0] = (char *) 0;
57  
58      while (*ptr)
59      {
60 @@ -530,6 +531,8 @@
61             *(ptr++) = '\0';
62         }
63      }
64 +    if (!uwords[0])
65 +       return ((char *) 0);  /* empty gecos */
66  #ifdef DEBUG
67      for (i = 0; uwords[i]; i++)
68      {
69 @@ -586,9 +589,10 @@
70  }
71  
72  char *
73 -FascistLook(pwp, instring)
74 +FascistLookPw(pwp, instring, pwd)
75      PWDICT *pwp;
76      char *instring;
77 +    struct passwd *pwd;
78  {
79      int i;
80      char *ptr;
81 @@ -667,7 +671,7 @@
82         return ("it looks like a National Insurance number.");
83      }
84  
85 -    if (ptr = FascistGecos(password, getuid()))
86 +    if (ptr = FascistGecosPw(password, pwd ? pwd : getpwuid(getuid())))
87      {
88         return (ptr);
89      }
90 @@ -715,9 +719,10 @@
91  }
92  
93  char *
94 -FascistCheck(password, path)
95 +FascistCheckPw(password, path, pwd)
96      char *password;
97      char *path;
98 +    struct passwd *pwd;
99  {
100      static char lastpath[STRINGSIZE];
101      static PWDICT *pwp;
102 @@ -750,5 +755,29 @@
103         strncpy(lastpath, path, STRINGSIZE);
104      }
105  
106 -    return (FascistLook(pwp, pwtrunced));
107 +    return (FascistLookPw(pwp, pwtrunced, pwd));
108 +}
109 +
110 +char *
111 +FascistGecos(password, uid)
112 +    char *password;
113 +    int uid;
114 +{
115 +    return (FascistGecosPw(password, getpwuid(uid)));
116 +}
117 +
118 +char *
119 +FascistLook(pwp, instring)
120 +    PWDICT *pwp;
121 +    char *instring;
122 +{
123 +    return (FascistLookPw(pwp, instring, (char *) 0));
124 +}
125 +
126 +char *
127 +FascistCheck(password, path)
128 +    char *password;
129 +    char *path;
130 +{
131 +    return (FascistCheckPw(password, path, (char *) 0));
132  }
133 diff -ur orig/cracklib26_small/cracklib/packer.h cracklib26_small/cracklib/packer.h
134 --- orig/cracklib26_small/cracklib/packer.h     Mon Dec 15 00:09:30 1997
135 +++ cracklib26_small/cracklib/packer.h  Sat Jan 10 22:13:46 1998
136 @@ -34,6 +34,7 @@
137      FILE *dfp;
138      FILE *wfp;
139  
140 +    int canfree;
141      int32 flags;
142  #define PFOR_WRITE     0x0001
143  #define PFOR_FLUSH     0x0002
144 diff -ur orig/cracklib26_small/cracklib/packlib.c cracklib26_small/cracklib/packlib.c
145 --- orig/cracklib26_small/cracklib/packlib.c    Fri Jul  9 22:22:58 1993
146 +++ cracklib26_small/cracklib/packlib.c Sat Jan 10 22:28:49 1998
147 @@ -16,7 +16,7 @@
148      char *mode;
149  {
150      int32 i;
151 -    static PWDICT pdesc;
152 +    PWDICT *pdesc;
153      char iname[STRINGSIZE];
154      char dname[STRINGSIZE];
155      char wname[STRINGSIZE];
156 @@ -25,92 +25,94 @@
157      FILE *ifp;
158      FILE *wfp;
159  
160 -    if (pdesc.header.pih_magic == PIH_MAGIC)
161 -    {
162 -       fprintf(stderr, "%s: another dictionary already open\n", prefix);
163 +    if ((pdesc = (PWDICT *) malloc(sizeof(PWDICT))) == 0)
164         return ((PWDICT *) 0);
165 -    }
166  
167 -    memset(&pdesc, '\0', sizeof(pdesc));
168 +    memset(pdesc, '\0', sizeof(*pdesc));
169  
170      sprintf(iname, "%s.pwi", prefix);
171      sprintf(dname, "%s.pwd", prefix);
172      sprintf(wname, "%s.hwm", prefix);
173  
174 -    if (!(pdesc.dfp = fopen(dname, mode)))
175 +    if (!(pdesc->dfp = fopen(dname, mode)))
176      {
177         perror(dname);
178 +       free(pdesc);
179         return ((PWDICT *) 0);
180      }
181  
182 -    if (!(pdesc.ifp = fopen(iname, mode)))
183 +    if (!(pdesc->ifp = fopen(iname, mode)))
184      {
185 -       fclose(pdesc.dfp);
186 +       fclose(pdesc->dfp);
187         perror(iname);
188 +       free(pdesc);
189         return ((PWDICT *) 0);
190      }
191  
192 -    if (pdesc.wfp = fopen(wname, mode))
193 +    if (pdesc->wfp = fopen(wname, mode))
194      {
195 -       pdesc.flags |= PFOR_USEHWMS;
196 +       pdesc->flags |= PFOR_USEHWMS;
197      }
198  
199 -    ifp = pdesc.ifp;
200 -    dfp = pdesc.dfp;
201 -    wfp = pdesc.wfp;
202 +    ifp = pdesc->ifp;
203 +    dfp = pdesc->dfp;
204 +    wfp = pdesc->wfp;
205  
206      if (mode[0] == 'w')
207      {
208 -       pdesc.flags |= PFOR_WRITE;
209 -       pdesc.header.pih_magic = PIH_MAGIC;
210 -       pdesc.header.pih_blocklen = NUMWORDS;
211 -       pdesc.header.pih_numwords = 0;
212 +       pdesc->flags |= PFOR_WRITE;
213 +       pdesc->header.pih_magic = PIH_MAGIC;
214 +       pdesc->header.pih_blocklen = NUMWORDS;
215 +       pdesc->header.pih_numwords = 0;
216  
217 -       fwrite((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp);
218 +       fwrite((char *) &pdesc->header, sizeof(pdesc->header), 1, ifp);
219      } else
220      {
221 -       pdesc.flags &= ~PFOR_WRITE;
222 +       pdesc->flags &= ~PFOR_WRITE;
223  
224 -       if (!fread((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp))
225 +       if (!fread((char *) &pdesc->header, sizeof(pdesc->header), 1, ifp))
226         {
227             fprintf(stderr, "%s: error reading header\n", prefix);
228  
229 -           pdesc.header.pih_magic = 0;
230 +           pdesc->header.pih_magic = 0;
231             fclose(ifp);
232             fclose(dfp);
233 +           free(pdesc);
234             return ((PWDICT *) 0);
235         }
236  
237 -       if (pdesc.header.pih_magic != PIH_MAGIC)
238 +       if (pdesc->header.pih_magic != PIH_MAGIC)
239         {
240             fprintf(stderr, "%s: magic mismatch\n", prefix);
241  
242 -           pdesc.header.pih_magic = 0;
243 +           pdesc->header.pih_magic = 0;
244             fclose(ifp);
245             fclose(dfp);
246 +           free(pdesc);
247             return ((PWDICT *) 0);
248         }
249  
250 -       if (pdesc.header.pih_blocklen != NUMWORDS)
251 +       if (pdesc->header.pih_blocklen != NUMWORDS)
252         {
253             fprintf(stderr, "%s: size mismatch\n", prefix);
254  
255 -           pdesc.header.pih_magic = 0;
256 +           pdesc->header.pih_magic = 0;
257             fclose(ifp);
258             fclose(dfp);
259 +           free(pdesc);
260             return ((PWDICT *) 0);
261         }
262  
263 -       if (pdesc.flags & PFOR_USEHWMS)
264 +       if (pdesc->flags & PFOR_USEHWMS)
265         {
266 -           if (fread(pdesc.hwms, 1, sizeof(pdesc.hwms), wfp) != sizeof(pdesc.hwms))
267 +           if (fread(pdesc->hwms, 1, sizeof(pdesc->hwms), wfp) != sizeof(pdesc->hwms))
268             {
269 -               pdesc.flags &= ~PFOR_USEHWMS;
270 +               pdesc->flags &= ~PFOR_USEHWMS;
271             }
272         }
273      }
274 -
275 -    return (&pdesc);
276 +    pdesc->canfree = 1;
277 +    return (pdesc);
278  }
279  
280  int
281 @@ -159,8 +161,13 @@
282  
283      fclose(pwp->ifp);
284      fclose(pwp->dfp);
285 +    if (pwp->wfp)
286 +       fclose(pwp->wfp);
287  
288 -    pwp->header.pih_magic = 0;
289 +    if (pwp->canfree)
290 +       free(pwp);
291 +    else
292 +       pwp->header.pih_magic = 0;
293  
294      return (0);
295  }
296 @@ -307,6 +314,11 @@
297      register char *this;
298      int idx;
299  
300 +/*
301 + * comment in npasswd-2.0beta4 says this:
302 + * This does not work under all circumstances, so don't bother
303 + */
304 +#if 0
305      if (pwp->flags & PFOR_USEHWMS)
306      {
307         idx = string[0] & 0xff;
308 @@ -317,6 +329,10 @@
309         lwm = 0;
310         hwm = PW_WORDS(pwp) - 1;
311      }
312 +#else
313 +    lwm = 0;
314 +    hwm = PW_WORDS(pwp);
315 +#endif
316  
317  #ifdef DEBUG
318      printf("---- %lu, %lu ----\n", lwm, hwm);
319 diff -ur orig/cracklib26_small/util/mkdict cracklib26_small/util/mkdict
320 --- orig/cracklib26_small/util/mkdict   Fri Jul  9 22:23:03 1993
321 +++ cracklib26_small/util/mkdict        Sat Apr  4 22:31:45 1998
322 @@ -14,9 +14,16 @@
323  SORT="sort"
324  ###SORT="sort -T /tmp"
325  
326 -cat $* |
327 +### Use zcat to read compressed (as well as uncompressed) dictionaries.
328 +### Compressed dictionaries can save quite a lot of disk space.
329 +
330 +CAT="gzip -cdf"
331 +###CAT="zcat"
332 +###CAT="cat"
333 +
334 +$CAT $* |
335         tr '[A-Z]' '[a-z]' |
336 -       tr -cd '[\012a-z0-9]' |
337 +       tr -cd '\012[a-z][0-9]' |
338         $SORT |
339         uniq |
340         grep -v '^#' |