summaryrefslogtreecommitdiff
path: root/debian/patches-applied/007_modules_pam_unix
blob: f8f3d302768919cbbcd507218502833704aec79b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
Index: Linux-PAM/modules/pam_unix/pam_unix_passwd.c
===================================================================
--- Linux-PAM/modules/pam_unix/pam_unix_passwd.c.orig
+++ Linux-PAM/modules/pam_unix/pam_unix_passwd.c
@@ -127,6 +127,9 @@
 #define OPW_TMPFILE		"/etc/security/nopasswd"
 #define OLD_PASSWORDS_FILE	"/etc/security/opasswd"
 
+extern const char *obscure_msg(const char *, const char *, const struct passwd *,
+			       unsigned int);
+
 /*
  * i64c - convert an integer to a radix 64 character
  */
@@ -957,7 +960,8 @@
 static int _pam_unix_approve_pass(pam_handle_t * pamh
 				  ,unsigned int ctrl
 				  ,const char *pass_old
-				  ,const char *pass_new)
+				  ,const char *pass_new,
+                                  int pass_min_len)
 {
 	const void *user;
 	const char *remark = NULL;
@@ -991,11 +995,10 @@
 #ifdef USE_CRACKLIB
 		remark = FascistCheck (pass_new, CRACKLIB_DICTS);
 		D(("called cracklib [%s]", remark));
-#else
-		if (strlen(pass_new) < 6)
+#endif
+		if (strlen(pass_new) < pass_min_len)
 		  remark = _("You must choose a longer password");
 		D(("length check [%s]", remark));
-#endif
 		if (on(UNIX_REMEMBER_PASSWD, ctrl)) {
 			if ((retval = check_old_password(user, pass_new)) == PAM_AUTHTOK_ERR)
 			  remark = _("Password has been already used. Choose another.");
@@ -1005,6 +1008,11 @@
 				return retval;
 			}
 		}
+		if (!remark && pass_old != NULL) { /* only check if we don't already have a failure */
+			struct passwd *pwd;
+			pwd = pam_modutil_getpwnam(pamh, user);
+			remark = (char *)obscure_msg(pass_old,pass_new,pwd,ctrl); /* do obscure checks */
+		}
 	}
 	if (remark) {
 		_make_remark(pamh, ctrl, PAM_ERROR_MSG, remark);
@@ -1020,6 +1028,7 @@
 	unsigned int ctrl, lctrl;
 	int retval, i;
 	int remember = -1;
+	int pass_min_len = 6;
 
 	/* <DO NOT free() THESE> */
 	const char *user;
@@ -1028,7 +1037,7 @@
 
 	D(("called."));
 
-	ctrl = _set_ctrl(pamh, flags, &remember, argc, argv);
+	ctrl = _set_ctrl(pamh, flags, &remember, &pass_min_len, argc, argv);
 
 	/*
 	 * First get the name of a user
@@ -1235,7 +1244,8 @@
 			if (*(const char *)pass_new == '\0') {	/* "\0" password = NULL */
 				pass_new = NULL;
 			}
-			retval = _pam_unix_approve_pass(pamh, ctrl, pass_old, pass_new);
+			retval = _pam_unix_approve_pass(pamh, ctrl, pass_old,
+			                                pass_new, pass_min_len);
 		}
 
 		if (retval != PAM_SUCCESS) {
@@ -1281,7 +1291,8 @@
 			return retval;
 		}
 
-		retval = _pam_unix_approve_pass(pamh, ctrl, pass_old, pass_new);
+		retval = _pam_unix_approve_pass(pamh, ctrl, pass_old, pass_new,
+		                                pass_min_len);
 		if (retval != PAM_SUCCESS) {
 			pam_syslog(pamh, LOG_NOTICE,
 			         "new password not acceptable 2");
Index: Linux-PAM/modules/pam_unix/pam_unix_acct.c
===================================================================
--- Linux-PAM/modules/pam_unix/pam_unix_acct.c.orig
+++ Linux-PAM/modules/pam_unix/pam_unix_acct.c
@@ -202,7 +202,7 @@
 
 	D(("called."));
 
-	ctrl = _set_ctrl(pamh, flags, NULL, argc, argv);
+	ctrl = _set_ctrl(pamh, flags, NULL, NULL, argc, argv);
 
 	retval = pam_get_item(pamh, PAM_USER, &void_uname);
 	uname = void_uname;
@@ -266,7 +266,9 @@
 
 	curdays = time(NULL) / (60 * 60 * 24);
 	D(("today is %d, last change %d", curdays, spent->sp_lstchg));
-	if ((curdays > spent->sp_expire) && (spent->sp_expire != -1)) {
+	if ((curdays > spent->sp_expire) && (spent->sp_expire != -1)
+	    && (spent->sp_expire != 0))
+	{
 		pam_syslog(pamh, LOG_NOTICE,
 			 "account %s has expired (account expired)",
 			 uname);
@@ -293,7 +295,9 @@
 	if ((curdays - spent->sp_lstchg > spent->sp_max)
 	    && (curdays - spent->sp_lstchg > spent->sp_inact)
 	    && (curdays - spent->sp_lstchg > spent->sp_max + spent->sp_inact)
-	    && (spent->sp_max != -1) && (spent->sp_inact != -1)) {
+	    && (spent->sp_max != -1) && (spent->sp_max != 0)
+	    && (spent->sp_inact != -1) && (spent->sp_inact != 0))
+	{
 		pam_syslog(pamh, LOG_NOTICE,
 		    "account %s has expired (failed to change password)",
 		    uname);
@@ -302,7 +306,9 @@
 		D(("account expired 2"));
 		return PAM_ACCT_EXPIRED;
 	}
-	if ((curdays - spent->sp_lstchg > spent->sp_max) && (spent->sp_max != -1)) {
+	if ((curdays - spent->sp_lstchg > spent->sp_max)
+	    && (spent->sp_max != -1) && (spent->sp_max != 0))
+	{
 		pam_syslog(pamh, LOG_DEBUG,
 			 "expired password for user %s (password aged)",
 			 uname);
@@ -312,7 +318,9 @@
 		return PAM_NEW_AUTHTOK_REQD;
 	}
 	if ((curdays - spent->sp_lstchg > spent->sp_max - spent->sp_warn)
-	    && (spent->sp_max != -1) && (spent->sp_warn != -1)) {
+	    && (spent->sp_max != -1) && (spent->sp_warn != -1)
+	    && (spent->sp_max != 0) && (spent->sp_warn != 0))
+	{
 		daysleft = (spent->sp_lstchg + spent->sp_max) - curdays;
 		pam_syslog(pamh, LOG_DEBUG,
 			 "password for user %s will expire in %d days",
Index: Linux-PAM/modules/pam_unix/support.c
===================================================================
--- Linux-PAM/modules/pam_unix/support.c.orig
+++ Linux-PAM/modules/pam_unix/support.c
@@ -53,8 +53,8 @@
  * set the control flags for the UNIX module.
  */
 
-int _set_ctrl(pam_handle_t *pamh, int flags, int *remember, int argc,
-              const char **argv)
+int _set_ctrl(pam_handle_t *pamh, int flags, int *remember, int *pass_min_len,
+              int argc, const char **argv)
 {
 	unsigned int ctrl;
 
@@ -80,6 +80,7 @@
 		D(("SILENT"));
 		set(UNIX__QUIET, ctrl);
 	}
+
 	/* now parse the arguments to this module */
 
 	while (argc-- > 0) {
@@ -89,7 +90,8 @@
 
 		for (j = 0; j < UNIX_CTRLS_; ++j) {
 			if (unix_args[j].token
-			    && !strncmp(*argv, unix_args[j].token, strlen(unix_args[j].token))) {
+			    && !strncmp(*argv, unix_args[j].token, strlen(unix_args[j].token)))
+			{
 				break;
 			}
 		}
@@ -101,20 +103,25 @@
 			ctrl &= unix_args[j].mask;	/* for turning things off */
 			ctrl |= unix_args[j].flag;	/* for turning things on  */
 
-			if (remember != NULL) {
-				if (j == UNIX_REMEMBER_PASSWD) {
-					*remember = strtol(*argv + 9, NULL, 10);
-					if ((*remember == INT_MIN) || (*remember == INT_MAX))
-						*remember = -1;
-					if (*remember > 400)
-						*remember = 400;
-				}
+			/* special cases */
+			if (remember != NULL && j == UNIX_REMEMBER_PASSWD) {
+				*remember = strtol(*argv + 9, NULL, 10);
+				if ((*remember == INT_MIN) || (*remember == INT_MAX))
+					*remember = -1;
+				if (*remember > 400)
+					*remember = 400;
+			} else if (pass_min_len && j == UNIX_MIN_PASS_LEN) {
+				*pass_min_len = atoi(*argv + 4);
 			}
 		}
 
 		++argv;		/* step to next argument */
 	}
 
+	if (off(UNIX_BIGCRYPT,ctrl) && off(UNIX_MD5_PASS,ctrl)
+	    && pass_min_len && *pass_min_len > 8)
+		*pass_min_len = 8;
+
 	if (flags & PAM_DISALLOW_NULL_AUTHTOK) {
 		D(("DISALLOW_NULL_AUTHTOK"));
 		set(UNIX__NONULL, ctrl);
@@ -692,6 +699,8 @@
 	    } else if (!p || (*salt == '*')) {
 		retval = PAM_AUTH_ERR;
 	    } else {
+		/* Hack off sysv pw aging foo */
+		if (strrchr(salt, ',')) *(strrchr(salt, ',')) = '\0';
 		if (!strncmp(salt, "$1$", 3)) {
 		    pp = Goodcrypt_md5(p, salt);
 		    if (strcmp(pp, salt) != 0) {
Index: Linux-PAM/modules/pam_unix/support.h
===================================================================
--- Linux-PAM/modules/pam_unix/support.h.orig
+++ Linux-PAM/modules/pam_unix/support.h
@@ -84,8 +84,11 @@
 #define UNIX_NOREAP              21     /* don't reap child process */
 #define UNIX_BROKEN_SHADOW       22     /* ignore errors reading password aging
 					 * information during acct management */
+#define UNIX_MAX_PASS_LEN        23     /* internal, for compatibility only */
+#define UNIX_MIN_PASS_LEN        24     /* Min length for password */
+#define UNIX_OBSCURE_CHECKS      25     /* enable obscure checks on passwords */
 /* -------------- */
-#define UNIX_CTRLS_              23	/* number of ctrl arguments defined */
+#define UNIX_CTRLS_              26	/* number of ctrl arguments defined */
 
 
 static const UNIX_Ctrls unix_args[UNIX_CTRLS_] =
@@ -93,29 +96,32 @@
 /* symbol                  token name          ctrl mask             ctrl     *
  * ----------------------- ------------------- --------------------- -------- */
 
-/* UNIX__OLD_PASSWD */     {NULL,              _ALL_ON_,                  01},
-/* UNIX__VERIFY_PASSWD */  {NULL,              _ALL_ON_,                  02},
-/* UNIX__IAMROOT */        {NULL,              _ALL_ON_,                  04},
-/* UNIX_AUDIT */           {"audit",           _ALL_ON_,                 010},
-/* UNIX_USE_FIRST_PASS */  {"use_first_pass",  _ALL_ON_^(060),           020},
-/* UNIX_TRY_FIRST_PASS */  {"try_first_pass",  _ALL_ON_^(060),           040},
-/* UNIX_NOT_SET_PASS */    {"not_set_pass",    _ALL_ON_,                0100},
-/* UNIX__PRELIM */         {NULL,              _ALL_ON_^(0600),         0200},
-/* UNIX__UPDATE */         {NULL,              _ALL_ON_^(0600),         0400},
-/* UNIX__NONULL */         {NULL,              _ALL_ON_,               01000},
-/* UNIX__QUIET */          {NULL,              _ALL_ON_,               02000},
-/* UNIX_USE_AUTHTOK */     {"use_authtok",     _ALL_ON_,               04000},
-/* UNIX_SHADOW */          {"shadow",          _ALL_ON_,              010000},
-/* UNIX_MD5_PASS */        {"md5",             _ALL_ON_^(0400000),    020000},
-/* UNIX__NULLOK */         {"nullok",          _ALL_ON_^(01000),           0},
-/* UNIX_DEBUG */           {"debug",           _ALL_ON_,              040000},
-/* UNIX_NODELAY */         {"nodelay",         _ALL_ON_,             0100000},
-/* UNIX_NIS */             {"nis",             _ALL_ON_,             0200000},
-/* UNIX_BIGCRYPT */        {"bigcrypt",        _ALL_ON_^(020000),    0400000},
-/* UNIX_LIKE_AUTH */       {"likeauth",        _ALL_ON_,            01000000},
-/* UNIX_REMEMBER_PASSWD */ {"remember=",       _ALL_ON_,            02000000},
-/* UNIX_NOREAP */          {"noreap",          _ALL_ON_,            04000000},
-/* UNIX_BROKEN_SHADOW */   {"broken_shadow",   _ALL_ON_,           010000000},
+/* UNIX__OLD_PASSWD */     {NULL,              _ALL_ON_,                  0x1},
+/* UNIX__VERIFY_PASSWD */  {NULL,              _ALL_ON_,                  0x2},
+/* UNIX__IAMROOT */        {NULL,              _ALL_ON_,                  0x4},
+/* UNIX_AUDIT */           {"audit",           _ALL_ON_,                  0x8},
+/* UNIX_USE_FIRST_PASS */  {"use_first_pass",  _ALL_ON_^(0x30),          0x10},
+/* UNIX_TRY_FIRST_PASS */  {"try_first_pass",  _ALL_ON_^(0x30),          0x20},
+/* UNIX_NOT_SET_PASS */    {"not_set_pass",    _ALL_ON_,                 0x40},
+/* UNIX__PRELIM */         {NULL,              _ALL_ON_^(0x180),         0x80},
+/* UNIX__UPDATE */         {NULL,              _ALL_ON_^(0x180),        0x100},
+/* UNIX__NONULL */         {NULL,              _ALL_ON_,                0x200},
+/* UNIX__QUIET */          {NULL,              _ALL_ON_,                0x400},
+/* UNIX_USE_AUTHTOK */     {"use_authtok",     _ALL_ON_,                0x800},
+/* UNIX_SHADOW */          {"shadow",          _ALL_ON_,               0x1000},
+/* UNIX_MD5_PASS */        {"md5",             _ALL_ON_^(0x20000),     0x2000},
+/* UNIX__NULLOK */         {"nullok",          _ALL_ON_^(0x200),            0},
+/* UNIX_DEBUG */           {"debug",           _ALL_ON_,               0x4000},
+/* UNIX_NODELAY */         {"nodelay",         _ALL_ON_,               0x8000},
+/* UNIX_NIS */             {"nis",             _ALL_ON_,              0x10000},
+/* UNIX_BIGCRYPT */        {"bigcrypt",        _ALL_ON_^(0x2000),     0x20000},
+/* UNIX_LIKE_AUTH */       {"likeauth",        _ALL_ON_,              0x40000},
+/* UNIX_REMEMBER_PASSWD */ {"remember=",       _ALL_ON_,              0x80000},
+/* UNIX_NOREAP */          {"noreap",          _ALL_ON_,             0x100000},
+/* UNIX_BROKEN_SHADOW */   {"broken_shadow",   _ALL_ON_,             0x200000},
+/* UNIX_MAX_PASS_LEN */    {"max=",            _ALL_ON_,                    0},
+/* UNIX_MIN_PASS_LEN */    {"min=",            _ALL_ON_,             0x400000},
+/* UNIX_OBSCURE_CHECKS */  {"obscure",         _ALL_ON_,             0x800000},
 };
 
 #define UNIX_DEFAULTS  (unix_args[UNIX__NONULL].flag)
@@ -131,8 +137,8 @@
 
 extern int _make_remark(pam_handle_t * pamh, unsigned int ctrl
 		       ,int type, const char *text);
-extern int _set_ctrl(pam_handle_t * pamh, int flags, int *remember, int argc,
-		     const char **argv);
+extern int _set_ctrl(pam_handle_t * pamh, int flags, int *remember,
+                     int *pass_min_len, int argc, const char **argv);
 extern int _unix_getpwnam (pam_handle_t *pamh,
 			   const char *name, int files, int nis,
 			   struct passwd **ret);
Index: Linux-PAM/modules/pam_unix/unix_chkpwd.c
===================================================================
--- Linux-PAM/modules/pam_unix/unix_chkpwd.c.orig
+++ Linux-PAM/modules/pam_unix/unix_chkpwd.c
@@ -192,6 +192,13 @@
 		return PAM_AUTHTOK_ERR;
 	}
 
+	/* Hack off SysVR4 password aging */
+	{
+	    char *tmp;
+
+	    if ((tmp = strrchr(salt, ',')) != NULL) *tmp = '\0';
+	}
+
 	/* the moment of truth -- do we agree with the password? */
 	retval = PAM_AUTH_ERR;
 	if (!strncmp(salt, "$1$", 3)) {
Index: Linux-PAM/modules/pam_unix/pam_unix.8.xml
===================================================================
--- Linux-PAM/modules/pam_unix/pam_unix.8.xml.orig
+++ Linux-PAM/modules/pam_unix/pam_unix.8.xml
@@ -269,6 +269,90 @@
           </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term>
+          <option>min=<replaceable>n</replaceable></option>
+        </term>
+        <listitem>
+          <para>
+            Set a minimum password length of <replaceable>n</replaceable>
+            characters.  The default value is 1.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>
+          <option>obscure</option>
+        </term>
+        <listitem>
+          <para>
+            Enable some extra checks on password strength.  These checks
+            are based on the "obscure" checks in the original shadow
+            package.  The behavior is similar to the pam_cracklib
+            module, but for non-dictionary-based checks.  The following
+            checks are implemented:
+            <variablelist>
+              <varlistentry>
+                <term>
+                  <option>Palindrome</option>
+                </term>
+                <listitem>
+                  <para>
+                    Verifies that the new password is not a palindrome
+                    of (i.e., the reverse of) the previous one.
+                  </para>
+                </listitem>
+              </varlistentry>
+              <varlistentry>
+                <term>
+                  <option>Case Change Only</option>
+                </term>
+                <listitem>
+                  <para>
+                    Verifies that the new password isn't the same as the
+                    old one with a change of case.
+                  </para>
+                </listitem>
+              </varlistentry>
+              <varlistentry>
+                <term>
+                  <option>Similar</option>
+                </term>
+                <listitem>
+                  <para>
+                    Verifies that the new password isn't too much like
+                    the previous one.
+                  </para>
+                </listitem>
+              </varlistentry>
+              <varlistentry>
+                <term>
+                  <option>Simple</option>
+                </term>
+                <listitem>
+                  <para>
+                    Is the new password too simple?  This is based on
+                    the length of the password and the number of
+                    different types of characters (alpha, numeric, etc.)
+                    used.
+                  </para>
+                </listitem>
+              </varlistentry>
+              <varlistentry>
+                <term>
+                  <option>Rotated</option>
+                </term>
+                <listitem>
+                  <para>
+                    Is the new password a rotated version of the old
+                    password?  (E.g., "billy" and "illyb")
+                  </para>
+                </listitem>
+              </varlistentry>
+            </variablelist>
+          </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
     <para>
       Invalid arguments are logged with  <citerefentry>
Index: Linux-PAM/modules/pam_unix/obscure.c
===================================================================
--- /dev/null
+++ Linux-PAM/modules/pam_unix/obscure.c
@@ -0,0 +1,198 @@
+/*
+ * Copyright 1989 - 1994, Julianne Frances Haugh
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Julianne F. Haugh nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <ctype.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <security/pam_modules.h>
+#include <security/_pam_macros.h>
+
+
+#include "support.h"
+
+/* can't be a palindrome - like `R A D A R' or `M A D A M' */
+static int palindrome(const char *old, const char *new) {
+	int	i, j;
+
+	i = strlen (new);
+
+	for (j = 0;j < i;j++)
+		if (new[i - j - 1] != new[j])
+			return 0;
+
+	return 1;
+}
+
+/* more than half of the characters are different ones. */
+static int similar(const char *old, const char *new) {
+	int i, j;
+
+	/*
+	 * XXX - sometimes this fails when changing from a simple password
+	 * to a really long one (MD5).  For now, I just return success if
+	 * the new password is long enough.  Please feel free to suggest
+	 * something better...  --marekm
+	 */
+	if (strlen(new) >= 8)
+		return 0;
+
+	for (i = j = 0; new[i] && old[i]; i++)
+		if (strchr(new, old[i]))
+			j++;
+
+	if (i >= j * 2)
+		return 0;
+
+	return 1;
+}
+
+/* a nice mix of characters. */
+static int simple(const char *old, const char *new) {
+	int	digits = 0;
+	int	uppers = 0;
+	int	lowers = 0;
+	int	others = 0;
+	int	size;
+	int	i;
+
+	for (i = 0;new[i];i++) {
+		if (isdigit (new[i]))
+			digits++;
+		else if (isupper (new[i]))
+			uppers++;
+		else if (islower (new[i]))
+			lowers++;
+		else
+			others++;
+	}
+
+	/*
+	 * The scam is this - a password of only one character type
+	 * must be 8 letters long.  Two types, 7, and so on.
+	 */
+
+	size = 9;
+	if (digits) size--;
+	if (uppers) size--;
+	if (lowers) size--;
+	if (others) size--;
+
+	if (size <= i)
+		return 0;
+
+	return 1;
+}
+
+static char *str_lower(char *string) {
+	char *cp;
+
+	for (cp = string; *cp; cp++)
+		*cp = tolower(*cp);
+	return string;
+}
+
+static const char * password_check(const char *old, const char *new,
+				   const struct passwd *pwdp) {
+	const char *msg = NULL;
+	char *oldmono, *newmono, *wrapped;
+
+	if (strcmp(new, old) == 0)
+		return _("Bad: new password must be different than the old one");
+
+	newmono = str_lower(strdup(new));
+	oldmono = str_lower(strdup(old));
+	wrapped = (char *)malloc(strlen(oldmono) * 2 + 1);
+	strcpy (wrapped, oldmono);
+	strcat (wrapped, oldmono);
+
+	if (palindrome(oldmono, newmono)) {
+		msg = _("Bad: new password cannot be a palindrome");
+	} else if (strcmp(oldmono, newmono) == 0) {
+		msg = _("Bad: new and old password must differ by more than just case");
+	} else if (similar(oldmono, newmono)) {
+		msg = _("Bad: new and old password are too similar");
+	} else if (simple(old, new)) {
+		msg = _("Bad: new password is too simple");
+	} else if (strstr(wrapped, newmono)) {
+		msg = _("Bad: new password is just a wrapped version of the old one");
+	}
+
+	_pam_delete(newmono);
+	_pam_delete(oldmono);
+	_pam_delete(wrapped);
+
+	return msg;
+}
+
+const char *obscure_msg(const char *old, const char *new,
+			       const struct passwd *pwdp, unsigned int ctrl) {
+	int oldlen, newlen;
+	char *new1, *old1;
+	const char *msg;
+
+	if (old == NULL)
+		return NULL; /* no check if old is NULL */
+
+	oldlen = strlen(old);
+	newlen = strlen(new);
+
+	/* Remaining checks are optional. */
+	if (off(UNIX_OBSCURE_CHECKS,ctrl))
+		return NULL;
+
+	if ((msg = password_check(old, new, pwdp)) != NULL)
+		return msg;
+
+	/* The traditional crypt() truncates passwords to 8 chars.  It is
+	   possible to circumvent the above checks by choosing an easy
+	   8-char password and adding some random characters to it...
+	   Example: "password$%^&*123".  So check it again, this time
+	   truncated to the maximum length.  Idea from npasswd.  --marekm */
+
+	if (on(UNIX_MD5_PASS,ctrl) || on(UNIX_BIGCRYPT,ctrl))
+		return NULL;  /* unlimited password length */
+
+	if (oldlen <= 8 && newlen <= 8)
+		return NULL;
+
+	new1 = strndup(new,8);
+	old1 = strndup(old,8);
+
+	msg = password_check(old1, new1, pwdp);
+
+	_pam_delete(new1);
+	_pam_delete(old1);
+
+	return msg;
+}
Index: Linux-PAM/modules/pam_unix/pam_unix.8
===================================================================
--- Linux-PAM/modules/pam_unix/pam_unix.8.orig
+++ Linux-PAM/modules/pam_unix/pam_unix.8
@@ -1,133 +1,201 @@
 .\"     Title: pam_unix
 .\"    Author: 
-.\" Generator: DocBook XSL Stylesheets v1.70.1 <http://docbook.sf.net/>
-.\"      Date: 09/20/2006
-.\"    Manual: Linux\-PAM Manual
-.\"    Source: Linux\-PAM Manual
+.\" Generator: DocBook XSL Stylesheets v1.73.1 <http://docbook.sf.net/>
+.\"      Date: 08/31/2007
+.\"    Manual: Linux-PAM Manual
+.\"    Source: Linux-PAM Manual
 .\"
-.TH "PAM_UNIX" "8" "09/20/2006" "Linux\-PAM Manual" "Linux\-PAM Manual"
+.TH "PAM_UNIX" "8" "08/31/2007" "Linux-PAM Manual" "Linux\-PAM Manual"
 .\" disable hyphenation
 .nh
 .\" disable justification (adjust text to left margin only)
 .ad l
 .SH "NAME"
-pam_unix \- Module for traditional password authentication
+pam_unix - Module for traditional password authentication
 .SH "SYNOPSIS"
 .HP 12
-\fBpam_unix.so\fR [...]
+\fBpam_unix\.so\fR [\.\.\.]
 .SH "DESCRIPTION"
 .PP
-This is the standard Unix authentication module. It uses standard calls from the system's libraries to retrieve and set account information as well as authentication. Usually this is obtained from the /etc/passwd and the /etc/shadow file as well if shadow is enabled.
+This is the standard Unix authentication module\. It uses standard calls from the system\'s libraries to retrieve and set account information as well as authentication\. Usually this is obtained from the /etc/passwd and the /etc/shadow file as well if shadow is enabled\.
 .PP
-The account component performs the task of establishing the status of the user's account and password based on the following
+The account component performs the task of establishing the status of the user\'s account and password based on the following
 \fIshadow\fR
-elements: expire, last_change, max_change, min_change, warn_change. In the case of the latter, it may offer advice to the user on changing their password or, through the
+elements: expire, last_change, max_change, min_change, warn_change\. In the case of the latter, it may offer advice to the user on changing their password or, through the
 \fBPAM_AUTHTOKEN_REQD\fR
-return, delay giving service to the user until they have established a new password. The entries listed above are documented in the
+return, delay giving service to the user until they have established a new password\. The entries listed above are documented in the
 \fBshadow\fR(5)
-manual page. Should the user's record not contain one or more of these entries, the corresponding
+manual page\. Should the user\'s record not contain one or more of these entries, the corresponding
 \fIshadow\fR
-check is not performed.
+check is not performed\.
 .PP
-The authentication component performs the task of checking the users credentials (password). The default action of this module is to not permit the user access to a service if their official password is blank.
+The authentication component performs the task of checking the users credentials (password)\. The default action of this module is to not permit the user access to a service if their official password is blank\.
 .PP
 A helper binary,
-\fBunix_chkpwd\fR(8), is provided to check the user's password when it is stored in a read protected database. This binary is very simple and will only check the password of the user invoking it. It is called transparently on behalf of the user by the authenticating component of this module. In this way it is possible for applications like
+\fBunix_chkpwd\fR(8), is provided to check the user\'s password when it is stored in a read protected database\. This binary is very simple and will only check the password of the user invoking it\. It is called transparently on behalf of the user by the authenticating component of this module\. In this way it is possible for applications like
 \fBxlock\fR(1)
-to work without being setuid\-root. The module, by default, will temporarily turn off SIGCHLD handling for the duration of execution of the helper binary. This is generally the right thing to do, as many applications are not prepared to handle this signal from a child they didn't know was
-\fBfork()\fRd. The
+to work without being setuid\-root\. The module, by default, will temporarily turn off SIGCHLD handling for the duration of execution of the helper binary\. This is generally the right thing to do, as many applications are not prepared to handle this signal from a child they didn\'t know was
+\fBfork()\fRd\. The
 \fBnoreap\fR
-module argument can be used to suppress this temporary shielding and may be needed for use with certain applications.
+module argument can be used to suppress this temporary shielding and may be needed for use with certain applications\.
 .PP
-The password component of this module performs the task of updating the user's password.
+The password component of this module performs the task of updating the user\'s password\.
 .PP
-The session component of this module logs when a user logins or leave the system.
+The session component of this module logs when a user logins or leave the system\.
 .PP
-Remaining arguments, supported by others functions of this module, are silently ignored. Other arguments are logged as errors through
-\fBsyslog\fR(3).
+Remaining arguments, supported by others functions of this module, are silently ignored\. Other arguments are logged as errors through
+\fBsyslog\fR(3)\.
 .SH "OPTIONS"
-.TP 3n
+.PP
 \fBdebug\fR
+.RS 4
 Turns on debugging via
-\fBsyslog\fR(3).
-.TP 3n
+\fBsyslog\fR(3)\.
+.RE
+.PP
 \fBaudit\fR
-A little more extreme than debug.
-.TP 3n
+.RS 4
+A little more extreme than debug\.
+.RE
+.PP
 \fBnullok\fR
-The default action of this module is to not permit the user access to a service if their official password is blank. The
+.RS 4
+The default action of this module is to not permit the user access to a service if their official password is blank\. The
 \fBnullok\fR
-argument overrides this default.
-.TP 3n
+argument overrides this default\.
+.RE
+.PP
 \fBtry_first_pass\fR
-Before prompting the user for their password, the module first tries the previous stacked module's password in case that satisfies this module as well.
-.TP 3n
+.RS 4
+Before prompting the user for their password, the module first tries the previous stacked module\'s password in case that satisfies this module as well\.
+.RE
+.PP
 \fBuse_first_pass\fR
+.RS 4
 The argument
 \fBuse_first_pass\fR
-forces the module to use a previous stacked modules password and will never prompt the user \- if no password is available or the password is not appropriate, the user will be denied access.
-.TP 3n
+forces the module to use a previous stacked modules password and will never prompt the user \- if no password is available or the password is not appropriate, the user will be denied access\.
+.RE
+.PP
 \fBnodelay\fR
-This argument can be used to discourage the authentication component from requesting a delay should the authentication as a whole fail. The default action is for the module to request a delay\-on\-failure of the order of two second.
-.TP 3n
+.RS 4
+This argument can be used to discourage the authentication component from requesting a delay should the authentication as a whole fail\. The default action is for the module to request a delay\-on\-failure of the order of two second\.
+.RE
+.PP
 \fBuse_authtok\fR
+.RS 4
 When password changing enforce the module to set the new password to the one provided by a previously stacked
 \fBpassword\fR
 module (this is used in the example of the stacking of the
 \fBpam_cracklib\fR
-module documented above).
-.TP 3n
+module documented above)\.
+.RE
+.PP
 \fBnot_set_pass\fR
-This argument is used to inform the module that it is not to pay attention to/make available the old or new passwords from/to other (stacked) password modules.
-.TP 3n
+.RS 4
+This argument is used to inform the module that it is not to pay attention to/make available the old or new passwords from/to other (stacked) password modules\.
+.RE
+.PP
 \fBnis\fR
-NIS RPC is used for setting new passwords.
-.TP 3n
+.RS 4
+NIS RPC is used for setting new passwords\.
+.RE
+.PP
 \fBremember=\fR\fB\fIn\fR\fR
+.RS 4
 The last
 \fIn\fR
 passwords for each user are saved in
 \fI/etc/security/opasswd\fR
-in order to force password change history and keep the user from alternating between the same password too frequently.
-.TP 3n
+in order to force password change history and keep the user from alternating between the same password too frequently\.
+.RE
+.PP
 \fBshadow\fR
-Try to maintain a shadow based system.
-.TP 3n
+.RS 4
+Try to maintain a shadow based system\.
+.RE
+.PP
 \fBmd5\fR
-When a user changes their password next, encrypt it with the MD5 algorithm.
-.TP 3n
+.RS 4
+When a user changes their password next, encrypt it with the MD5 algorithm\.
+.RE
+.PP
 \fBbigcrypt\fR
-When a user changes their password next, encrypt it with the DEC C2 algorithm.
-.TP 3n
+.RS 4
+When a user changes their password next, encrypt it with the DEC C2 algorithm\.
+.RE
+.PP
 \fBbroken_shadow\fR
-Ignore errors reading shadow inforation for users in the account management module.
+.RS 4
+Ignore errors reading shadow inforation for users in the account management module\.
+.RE
+.PP
+\fBmin=\fR\fB\fIn\fR\fR
+.RS 4
+Set a minimum password length of
+\fIn\fR
+characters\. The default value is 1\.
+.RE
+.PP
+\fBobscure\fR
+.RS 4
+Enable some extra checks on password strength\. These checks are based on the "obscure" checks in the original shadow package\. The behavior is similar to the pam_cracklib module, but for non\-dictionary\-based checks\. The following checks are implemented:
+.PP
+\fBPalindrome\fR
+.RS 4
+Verifies that the new password is not a palindrome of (i\.e\., the reverse of) the previous one\.
+.RE
+.PP
+\fBCase Change Only\fR
+.RS 4
+Verifies that the new password isn\'t the same as the old one with a change of case\.
+.RE
+.PP
+\fBSimilar\fR
+.RS 4
+Verifies that the new password isn\'t too much like the previous one\.
+.RE
+.PP
+\fBSimple\fR
+.RS 4
+Is the new password too simple? This is based on the length of the password and the number of different types of characters (alpha, numeric, etc\.) used\.
+.RE
+.PP
+\fBRotated\fR
+.RS 4
+Is the new password a rotated version of the old password? (E\.g\., "billy" and "illyb")
+.RE
+.sp
+.RE
 .PP
 Invalid arguments are logged with
-\fBsyslog\fR(3).
+\fBsyslog\fR(3)\.
 .SH "MODULE SERVICES PROVIDED"
 .PP
-All service are supported.
+All service are supported\.
 .SH "RETURN VALUES"
-.TP 3n
+.PP
 PAM_IGNORE
-Ignore this module.
+.RS 4
+Ignore this module\.
+.RE
 .SH "EXAMPLES"
 .PP
 An example usage for
-\fI/etc/pam.d/login\fR
+\fI/etc/pam\.d/login\fR
 would be:
 .sp
-.RS 3n
+.RS 4
 .nf
 # Authenticate the user
-auth       required   pam_unix.so
+auth       required   pam_unix\.so
 # Ensure users account and password are still active
-account    required   pam_unix.so
+account    required   pam_unix\.so
 # Change the users password, but at first check the strength
 # with pam_cracklib(8)
-password   required   pam_cracklib.so retry=3 minlen=6 difok=3
-password   required   pam_unix.so use_authtok nullok md5
-session    required   pam_unix.so
+password   required   pam_cracklib\.so retry=3 minlen=6 difok=3
+password   required   pam_unix\.so use_authtok nullok md5
+session    required   pam_unix\.so
       
 .fi
 .RE
@@ -140,4 +208,4 @@
 \fBpam\fR(8)
 .SH "AUTHOR"
 .PP
-pam_unix was written by various people.
+pam_unix was written by various people\.
Index: Linux-PAM/modules/pam_unix/Makefile.am
===================================================================
--- Linux-PAM/modules/pam_unix/Makefile.am.orig
+++ Linux-PAM/modules/pam_unix/Makefile.am
@@ -42,7 +42,7 @@
 
 pam_unix_la_SOURCES = bigcrypt.c pam_unix_acct.c \
 	pam_unix_auth.c pam_unix_passwd.c pam_unix_sess.c support.c \
-	yppasswd_xdr.c md5_good.c md5_broken.c
+	yppasswd_xdr.c md5_good.c md5_broken.c obscure.c
 
 bigcrypt_SOURCES = bigcrypt.c bigcrypt_main.c
 bigcrypt_CFLAGS = $(AM_CFLAGS)
Index: Linux-PAM/modules/pam_unix/README
===================================================================
--- Linux-PAM/modules/pam_unix/README.orig
+++ Linux-PAM/modules/pam_unix/README
@@ -119,6 +119,42 @@
     Ignore errors reading shadow inforation for users in the account management
     module.
 
+min=n
+
+    Set a minimum password length of n characters. The default value is 6.
+
+obscure
+
+    Enable some extra checks on password strength. These checks are based on
+    the "obscure" checks in the original shadow package. The behavior is
+    similar to the pam_cracklib module, but for non-dictionary-based checks.
+    The following checks are implemented:
+
+    Palindrome
+
+        Verifies that the new password is not a palindrome of (i.e., the
+        reverse of) the previous one.
+
+    Case Change Only
+
+        Verifies that the new password isn't the same as the old one with a
+        change of case.
+
+    Similar
+
+        Verifies that the new password isn't too much like the previous one.
+
+    Simple
+
+        Is the new password too simple? This is based on the length of the
+        password and the number of different types of characters (alpha,
+        numeric, etc.) used.
+
+    Rotated
+
+        Is the new password a rotated version of the old password? (E.g.,
+        "billy" and "illyb")
+
 Invalid arguments are logged with syslog(3).
 
 EXAMPLES
Index: Linux-PAM/modules/pam_unix/pam_unix_auth.c
===================================================================
--- Linux-PAM/modules/pam_unix/pam_unix_auth.c.orig
+++ Linux-PAM/modules/pam_unix/pam_unix_auth.c
@@ -111,7 +111,7 @@
 
 	D(("called."));
 
-	ctrl = _set_ctrl(pamh, flags, NULL, argc, argv);
+	ctrl = _set_ctrl(pamh, flags, NULL, NULL, argc, argv);
 
 	/* Get a few bytes so we can pass our return value to
 	   pam_sm_setcred(). */
Index: Linux-PAM/modules/pam_unix/pam_unix_sess.c
===================================================================
--- Linux-PAM/modules/pam_unix/pam_unix_sess.c.orig
+++ Linux-PAM/modules/pam_unix/pam_unix_sess.c
@@ -73,7 +73,7 @@
 
 	D(("called."));
 
-	ctrl = _set_ctrl(pamh, flags, NULL, argc, argv);
+	ctrl = _set_ctrl(pamh, flags, NULL, NULL, argc, argv);
 
 	retval = pam_get_item(pamh, PAM_USER, (void *) &user_name);
 	if (user_name == NULL || *user_name == '\0' || retval != PAM_SUCCESS) {
@@ -107,7 +107,7 @@
 
 	D(("called."));
 
-	ctrl = _set_ctrl(pamh, flags, NULL, argc, argv);
+	ctrl = _set_ctrl(pamh, flags, NULL, NULL, argc, argv);
 
 	retval = pam_get_item(pamh, PAM_USER, (void *) &user_name);
 	if (user_name == NULL || *user_name == '\0' || retval != PAM_SUCCESS) {