summaryrefslogtreecommitdiff
path: root/usr/src/cmd/ypcmd/yp2lscripts/inityp2l.sh
blob: 1d3ad768a19c071d776dbffb095b93fa991c1f2f (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
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
#! /usr/bin/ksh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
#

#
# inityp2l -- Utility to generate YP (NIS) to LDAP
#             configuration file (/etc/default/ypserv)
#             and mapping file (/var/yp/NISLDAPmapping)
#



#
# Displays message corresponding to the argument tag passed.
#
display_msg()
{
    case "$1" in
    usage) cat <<EOF

 $PROG:  [ -m mapping_file ] [ -c config_file ]
   m <mapping_file> Name of the generated NISLDAP mapping file
                    Default is /var/yp/NISLDAPmapping
   c <config_file>  Name of the generated ypserv configuration file
                    Default is /etc/default/ypserv

EOF
    ;;
    no_config_file_name_specified) cat <<EOF

You have not specified the config file name. You still have the
option to skip creating this file, specify a config file name, or
continue creating it with the default file name (${CONFIG_FILE}).

EOF
    ;;
    no_mapping_file_name_specified) cat <<EOF

You have not specified the mapping file name. You still have the
option to skip creating this file, specify a mapping file name, or
continue creating it with the default file name (${MAP_FILE}).

EOF
    ;;
    new_config_file_name_help) cat <<EOF

You can either specify a new file name, or accept the default
config file name (${CONFIG_FILE}). 

It is recommended not to use the default file name since this
script just helps with rapid creation of a config file. You
should examine it's content before using it.

EOF
    ;;
    new_mapping_file_name_help) cat <<EOF

You can either specify a new file name, or accept the default
mapping file name (${MAP_FILE}). 

It is recommended not to use the default file name since this
script just helps with rapid creation of a mapping file. You
should examine it's content before using it. And if there are
custom maps, then their entries in the mapping file need to be
customized too.

Also, creation of default mapping file would cause NIS components
to work in NIS to LDAP (N2L), rather than traditional NIS, mode
when next restarted.

EOF
    ;;
    backup_config_file) cat <<EOF

The config file "${CONFIG_FILE}" already exists. It is strongly
recommended that you BACKUP this file before running $PROG.

However, even if you continue, you would be given the option to
back up this file before it gets overwritten.

EOF
    ;;
    backup_mapping_file) cat <<EOF

The mapping file "${MAP_FILE}" already exists. It is strongly
recommended that you BACKUP this file before running $PROG.

However, even if you continue, you would be given the option to
back up this file before it gets overwritten.

EOF
    ;;
    warn_n2l_mode) cat <<EOF

Warning : Creation of default mapping file (`basename $MAP_FILE`)
          at default location (`dirname $MAP_FILE`) would cause NIS
          components to work in NIS to LDAP (N2L) mode, rather than
          traditional NIS mode, when next restarted.

          "$PROG" assists with rapid creation of a simple N2L mapping
          file. The user should examine it's content before using it.
          For custom maps, this file needs to be customized which can
          be done using standard text editors.

EOF
    ;;
    config_auth_method_menu) cat <<EOF
    The following are the supported Authentication Methods -
      1  none
      2  simple
      3  sasl/cram-md5
      4  sasl/digest-md5
EOF
    ;;
    auth_method_menu) cat <<EOF
    The following are the supported Authentication Methods -
      1  simple
      2  sasl/cram-md5
      3  sasl/digest-md5
EOF
    ;;
    tls_method_menu) cat <<EOF
    The following are the supported TLS Methods -
      1  none
      2  ssl
EOF
    ;;
    retrieve_error_action_menu) cat <<EOF
    The following are the supported actions -
      1  use_cached
      2  fail
EOF
    ;;
    store_error_action_menu) cat <<EOF
    The following are the supported actions -
      1  retry
      2  fail
EOF
    ;;
    sorry) cat <<EOF

HELP - No help is available for this topic.

EOF
    ;;
    backup_config_file_cont_help) cat <<EOF

HELP - Since $PROG will overwrite the existing config file, it is
       strongly recommended that you backup this file prior to
       running this utility.

       However, even if you continue, you would be given the option
       to back up this file before it gets overwritten.

EOF
    ;;
    backup_config_file_help) cat <<EOF

HELP - If you choose to backup the existing config file, it would be
       saved with current date and time suffix in yymmdd.HH.MM.SS format.

EOF
    ;;
    backup_mapping_file_cont_help) cat <<EOF

HELP - Since $PROG will overwrite the existing mapping file, it is
       strongly recommended that you backup this file prior to running
       this utility.

       However, even if you continue, you would be given the option to
       back up this file before it gets overwritten.

EOF
    ;;
    backup_mapping_file_help) cat <<EOF

HELP - If you choose to backup the existing mapping file, it would be
       saved with current date and time suffix in yymmdd.HH.MM.SS format.

EOF
    ;;
    warn_n2l_mode_help) cat <<EOF

HELP - It is strongly recommended that the mapping file is created at
       non-default location (other than `dirname $MAP_FILE`). After this,
       it's content should be verified, custom maps should be handled,
       and if NIS components are desired to run in NIS to LDAP (N2L),
       then only it should be copied at the default location.

EOF
    ;;
    nisLDAPconfigDN_help) cat <<EOF

HELP - The DN which stores the configuration information in LDAP.
       There is no default value for this field. Leave empty or
       undefined to get this information from config file (ypserv).

EOF
    ;;
    nisLDAPconfigPreferredServerList_help) cat <<EOF

HELP - List of directory servers to provide the configuration
       information. There is no default. The preferred servers
       must be entered IN THE ORDER you wish to have them contacted.
       The preferred server list is a space separated list of IP
       addresses. Providing port numbers is optional, and when not
       supplied, port 389 is assumed. For an LDAP server running
       on this machine, at port 389, use "127.0.0.1:389".

EOF
    ;;
    auth_help) cat <<EOF

HELP - The authentication method to be used to obtain information
       from LDAP server. The supported methods are provided in menu.

EOF
    ;;
    tls_help) cat <<EOF

HELP - The transport layer security used for connection to the LDAP
       server. In order to successfully use transport layer security,
       the server must also support the chosen values. The supported
       methods are provided in menu. Default is "$DEF_TLS".

EOF
    ;;
    TLSCertificateDBPath_help) cat <<EOF

HELP - The absolute path name of the directory containing the certificate
       database. The default value is "$DEF_TLSCertificateDBPath"

EOF
    ;;
    nisLDAPconfigProxyUser_help) cat <<EOF

HELP - The bind DN of the proxy user used to obtain configuration
       information. There is no default value. If the value ends
       with a comma, the value of the nisLDAPconfigDN attribute
       is appended.

EOF
    ;;
    ProxyPassword_warn) cat <<EOF

Warning : In order to avoid having this password publicly visible
          on the machine, the password should appear only in the
          configuration file, and the file should have an appropriate
          owner, group, and file mode.

          So, once this file is ready, please modify appropriately
          to make sure this file is well protected.

EOF
    ;;
    preferredServerList_help) cat <<EOF

HELP - List of directory servers for mapping data to/from LDAP.
       There is no default. The preferred servers must be entered
       IN THE ORDER you wish to have them contacted. The preferred
       server list is a space separated list of IP addresses.
       Providing port numbers is optional, and when not supplied,
       port 389 is assumed. For an LDAP server running on this
       machine, at port 389, use "127.0.0.1:389".

EOF
    ;;
    nisLDAPproxyUser_help) cat <<EOF

HELP - The bind DN of the proxy user the ypserv to read or write
       from or to LDAP. Assumed to have the appropriate permission
       to read and modify LDAP data. There is no default value. If
       the value ends with a comma, the value of the context for
       the current domain (as defined by a nisLDAPdomainContext
       attribute (NISLDAPmapping(4))) is appended.

EOF
    ;;
    nisLDAPbindTimeout_help) cat <<EOF

HELP - The amount of time in seconds after which an LDAP bind operation
       will timeout. Default is $DEF_nisLDAPbindTimeout seconds.
       Decimal values are allowed.

EOF
    ;;
    nisLDAPsearchTimeout_help) cat <<EOF

HELP - The amount of time in seconds after which an LDAP search operation
       will timeout. Default is $DEF_nisLDAPsearchTimeout seconds.
       Decimal values are allowed.

EOF
    ;;
    nisLDAPmodifyTimeout_help) cat <<EOF

HELP - The amount of time in seconds after which an LDAP modify operation
       will timeout. Default is $DEF_nisLDAPmodifyTimeout seconds.
       Decimal values are allowed.

EOF
    ;;
    nisLDAPaddTimeout_help) cat <<EOF

HELP - The amount of time in seconds after which an LDAP add operation
       will timeout. Default is $DEF_nisLDAPaddTimeout seconds.
       Decimal values are allowed.

EOF
    ;;
    nisLDAPdeleteTimeout_help) cat <<EOF

HELP - The amount of time in seconds after which an LDAP delete operation
       will timeout. Default is $DEF_nisLDAPdeleteTimeout seconds.
       Decimal values are allowed.

EOF
    ;;
    nisLDAPsearchTimeLimit_help) cat <<EOF

HELP - Establish a value for the LDAP_OPT_TIMELIMIT option, which
       suggests a time limit for the search operation on the LDAP
       server. The server may impose its own constraints on possible
       values. See your LDAP server documentation. The default is the
       nisLDAPsearchTimeout ($DEF_nisLDAPsearchTimeout seconds) value.
       Only integer values are allowed.

       Since the nisLDAPsearchTimeout limits the amount of time the
       client ypserv will wait for completion of a search operation,
       setting the nisLDAPsearchTimeLimit larger than the
       nisLDAPsearchTimeout is not recommended.

EOF
    ;;
    nisLDAPsearchSizeLimit_help) cat <<EOF

HELP - Establish a value for the LDAP_OPT_SIZELIMIT option, which
       suggests a size limit, in bytes, for the search results on
       the LDAP server. The server may impose its own constraints
       on possible values. See your LDAP server documentation. The
       default is $DEF_nisLDAPsearchSizeLimit, which means unlimited.
       Only integer values are allowed.

EOF
    ;;
    nisLDAPfollowReferral_help) cat <<EOF

HELP - Determines if the ypserv should follow referrals or not.
       Recognized values are yes and no. Default is $DEF_nisLDAPfollowReferral.

EOF
    ;;
    nisLDAPretrieveErrorAction_help) cat <<EOF

HELP - If an error occurs while trying to retrieve an entry from
       LDAP, one of the following actions can be selected:

       use_cached : Retry the retrieval the number of time specified
                    by nisLDAPretrieveErrorAttempts, with the
                    nisLDAPretrieveErrorTimeout value controlling
                    the wait between each attempt.

                    If all attempts fail then log a warning and
                    return the value currently in the cache to the
                    client.  This is the default value.

       fail       : Proceed as for 'use_cached' but if all attempts
                    fail return a YPERR_YPERR error to the client.

EOF
    ;;
    nisLDAPretrieveErrorAttempts_help) cat <<EOF

HELP - The number of times a failed retrieval should be retried.
       The default is unlimited. Note while retries are made, the
       NIS daemon will be prevented from servicing further requests.
       Hence, values other than 1 should be used with caution.

EOF
    ;;
    nisLDAPretrieveErrorTimeout_help) cat <<EOF

HELP - The timeout (in seconds) between each new attempt to retrieve
       LDAP data. Default is $DEF_nisLDAPretrieveErrorTimeout seconds.

EOF
    ;;
    nisLDAPstoreErrorAction_help) cat <<EOF

HELP - If an error occurs while trying to store data to the LDAP
       repository, one of the following actions can be selected :

       retry : Retry operation nisLDAPstoreErrorAttempts times with
               nisLDAPstoreErrorTimeout seconds between each attempt.
               Note while retries are made the NIS daemon will be
               prevented from servicing further requests. Use with
               caution. This is the default value.

       fail  : Return YPERR_YPERR error to the client.

EOF
    ;;
    nisLDAPstoreErrorAttempts_help) cat <<EOF

HELP - The number of times a failed attempt to store data to the
       LDAP repository should be retried. The default is unlimited.

       The value for nisLDAPstoreErrorAttempts is ignored unless
       nisLDAPstoreErrorAction=retry.

EOF
    ;;
    nisLDAPstoreErrorTimeout_help) cat <<EOF

HELP - The timeout (in seconds) between each new attempt to store
       LDAP data. Default is $DEF_nisLDAPstoreErrorTimeout seconds.

       The value for nisLDAPstoreErrorTimeout is ignored unless
       nisLDAPstoreErrorAction=retry.

EOF
    ;;
    selectDomain4N2L_help) cat <<EOF

HELP - Whether this domain needs to be served by YP to LDAP transition
       solution. The default is no in which case the data in this
       domain would not be taken care for transitioning to LDAP.

EOF
    ;;
    generate_comment_info_for_cust_map_help) cat <<EOF

HELP - If selected, this script will try to add relevant comments
       in the mapping file which might help in customizing the
       mapping information for custom maps.

EOF
    ;;
    generate_mapping_info_for_cust_map_help) cat <<EOF

HELP - If selected, this script will try to generate mapping
       information for this map assuming it is a "simple" map.

       A map is assumed to be "simple" if each entry of this map
       has only one "key value" entry in YP, and if each map entry
       can be represented as a single DIT string in the LDAP server.

       If this map is not a simple map and you do want to store it
       in LDAP, you have two options :

       1 - Answer yes, and this script would generate the mapping
           information for this map assuming it is a simple map.
           And once the execution of the script is over, you can
           customize the mapping information by hand editing the
           mapping file.

       2 - Answer no, and this script would not generate mapping
           info for this map. And once the execution of the script
           is over, you can include the customized mapping
           information by hand editing the mapping file.

EOF
    ;;
    nisLDAPdomainContext_help) cat <<EOF

HELP - This parameter defines the context (default location) in
       the directory tree at which all the name service entries
       for this particular domain would be stored.

EOF
    ;;
    nisLDAPyppasswddDomains_help) cat <<EOF

HELP - Lists the domains for which password changes should be
       made.  If this is not present then the value returned by
       'domainname' will be used.

       NIS password change requests do not specify the domains in
       which any given password should be changed. (In traditional
       NIS this information is effectively hard coded in the NIS
       makefile.)

EOF
    ;;
    custom_map_comment_char_help) cat <<EOF

HELP - If selected, it will allow you to specify a character which
       would represent the start of the special 'comment' field in
       a given NIS map. If this attribute is not present then the
       default comment character '#' is used.

       If a map cannot contain comments then the blank comment
       character ('') should be specified (just hit the return key).

EOF
    ;;
    same_comment_char_help) cat <<EOF

HELP - If selected, for a given map, it will allow you to specify
       a common comment character for all the domains.

       Or else by selecting NO, for the same map, you would be
       given the option to specify different comment character
       for different domains.

EOF
    ;;
    secure_flag_on_help) cat <<EOF

HELP - Secure flag is set on maps which are generated with
       "makedbm -s". When converting data from LDAP to YP,
       it adds YP_SECURE entries.
       
EOF
    ;;
    secure_flag_all_domains_help) cat <<EOF

HELP - If selected, it will allow you to set the secure flag on
       for this map for all the domains.

       Or else by selecting NO, you would be given the option to
       set this flag, for the same map, on per domain basis.

EOF
    ;;
    interdomain_flag_on_help) cat <<EOF

HELP - Interdomain flag is set on a set of maps which are generated
       with "makedbm -b". It signals NIS servers to use the domain
       name resolver for host name and address lookups for hosts
       not found in the maps.

       If selected, it adds YP_INTERDOMAIN entries in these maps
       when converting data from LDAP to YP.
       
EOF
    ;;
    interdomain_flag_all_domains_help) cat <<EOF

HELP - If selected, it will allow you to set the interdomain flag
       on for all the domains.

       Or else by selecting NO, you would be given the option to
       set this flag on per domain basis.

EOF
    ;;
    initialTTLlo_help) cat <<EOF

HELP - The lower limit for the initial TTL (in seconds) for data
       read from disk when the ypserv starts. If initialTTLhi also
       is specified, the actual initialTTL will be randomly selected
       from the interval initialTTLlo to initialTTLhi (inclusive).

       Leaving the field empty yields the default value of $DEF_iTTLlo.

EOF
    ;;
    initialTTLhi_help) cat <<EOF

HELP - The upper limit for the initial TTL (in seconds).
       If left empty, defaults to "$DEF_iTTLhi".

EOF
    ;;
    runningTTL_help) cat <<EOF

HELP - The TTL (in seconds) for data retrieved from LDAP while the
       ypserv is running. If left empty, defaults to "$DEF_runTTL".

EOF
    ;;
    default_ttl_help) cat <<EOF

HELP - The default TTL value for each map is set to :
       ${DEF_iTTLlo}:${DEF_iTTLhi}:${DEF_runTTL}

       Select yes if you want to change the current TTL value.

EOF
    ;;
    non_default_same_ttl_help) cat <<EOF

HELP - Select yes if you want to set a new TTL value, but want
       to keep it same for all the maps.
      
EOF
    ;;
    non_default_different_ttl_help) cat <<EOF

HELP - Select yes if you want to set TTL value for each map, but
       want to keep it same for all the domains.
      
EOF
    ;;
    default_different_ttl_help) cat <<EOF

HELP - Select yes if you want to accept the default TTL
       value for this map.
      
EOF
    ;;
    same_ttl_across_domains_help) cat <<EOF

HELP - Select yes if you want to set TTL value for the map,
       but want to keep it same for all the domains.

EOF
    ;;

    esac
}

#
# Echo the message passed only if DEBUG is set.
# Reduces the line width significantly.
#
d_echo()
{
[ DEBUG -eq 1 ] && echo $@
}


#
# get_ans(): gets an answer from the user.
#		$1  instruction/comment/description/question
#		$2  default value
#
get_ans()
{
    if [ -z "$2" ]
    then
	echo "$1 \c"
    else
	echo "$1 [$2] \c"
    fi

    read ANS
    if [ -z "$ANS" ]
    then
	ANS=$2
    fi
}


#
# get_ans_req(): gets an answer (required) from the user, NULL value not allowed.
#		$@  instruction/comment/description/question
#
get_ans_req()
{
    ANS=""                  # Set ANS to NULL.
    while [ "$ANS" = "" ]
    do 
	get_ans "$@"
	[ "$ANS" = "" ] && echo "NULL value not allowed!"
    done
}


#
# get_integer(): Querys and verifies that number entered is integer.
#                Function will repeat prompt user for integer value.
#                $1  Message text.
#                $2  default value.
#                $3  Help argument.
#
get_integer()
{
    ANS=""                  # Set ANS to NULL.
    NUM=""

    get_ans "$1" "$2"

    # Verify that value is integer.
    while not_integer $ANS
    do
	case "$ANS" in
	    [Hh] | help | Help | \?) display_msg ${3:-sorry} ;;
	    * ) echo "Invalid value: \"${ANS}\". \c"
	     ;;
	esac

	# Get a new value.
	get_ans "Enter an integer value:" "$2"
    done
    NUM=$ANS
}


#
# get_number(): Querys and verifies that number entered is numeric.
#               Function will repeat prompt user for numeric value.
#               $1  Message text.
#	        $2  default value.
#               $3  Help argument.
#
get_number()
{
    ANS=""                  # Set ANS to NULL.
    NUM=""

    get_ans "$1" "$2"

    # Verify that value is numeric.
    while not_numeric $ANS
    do
	case "$ANS" in
	    [Hh] | help | Help | \?) display_msg ${3:-sorry} ;;
	    * ) echo "Invalid value: \"${ANS}\". \c"
	     ;;
	esac

	# Get a new value.
	get_ans "Enter a numeric value:" "$2"
    done
    NUM=$ANS
}


#
# get_pos_int(): Only allows positive integer.
#
#                   $1 - Prompt message.
#                   $2 - Default value (require).
#                   $3 - Optional help argument.
get_pos_int()
{
    while :
    do
	get_integer "$1" "$2" "$3"

	if [ $ANS -lt 0 ]; then
	    echo "Invalid number: please enter a positive integer."
	else
	    break      # Positive integer
	fi
    done
}


#
# get_pos_num(): Only allows positive number.
#
#                   $1 - Prompt message.
#                   $2 - Default value (require).
#                   $3 - Optional help argument.
get_pos_num()
{
    while :
    do
	get_number "$1" "$2" "$3"

	if [ $ANS -lt 0 ]; then
	    echo "Invalid number: please enter a positive number."
	else
	    break      # Positive number
	fi
    done
}


#
#
# get_passwd(): Reads a password from the user and verify with second.
#		$@  instruction/comment/description/question
#
get_passwd()
{
    [ $DEBUG -eq 1 ] && echo "In get_passwd()"

    # Temporary PASSWD variables
    _PASS1=""
    _PASS2=""

    # Handle signals, so that echo can be turned back on if Ctrl-C.
    trap "/usr/bin/stty echo; exit" 1 2 3 6 15

    /usr/bin/stty -echo     # Turn echo OFF

    # Endless loop that continues until passwd and re-entered passwd
    # match.
    while :
    do
	ANS=""                  # Set ANS to NULL.

	# Don't allow NULL for first try.
	while [ "$ANS" = "" ]
	do
	    get_ans "$@"
	    [ "$ANS" = "" ] && echo "" && echo "NULL passwd not allowed!"
	done
	_PASS1=$ANS         # Store first try.

	# Get second try.
	echo ""
	get_ans "Re-enter passwd:"
	_PASS2=$ANS

	# Test if passwords are identical.
	if [ "$_PASS1" = "$_PASS2" ]; then
	    break
	fi
	
	# Move cursor down to next line and print ERROR message.
	echo ""
	echo "ERROR: passwords don't match; try again."
    done

    /usr/bin/stty echo      # Turn echo ON

    # Removed signal handler
    trap 1 2 3 6 15

    echo ""
}


#
# get_passwd_nochk(): Reads a password from the user w/o check.
#		$@  instruction/comment/description/question
#
get_passwd_nochk()
{
    [ $DEBUG -eq 1 ] && echo "In get_passwd_nochk()"

    # Handle signals, so that echo can be turned back on if Ctrl-C.
    trap "/usr/bin/stty echo; exit" 1 2 3 6 15

    /usr/bin/stty -echo     # Turn echo OFF

    get_ans "$@"

    /usr/bin/stty echo      # Turn echo ON

    # Removed signal handler
    trap 1 2 3 6 15

    echo ""
}


#
# get_confirm(): Get confirmation from the user. (Y/Yes or N/No)
#                $1 - Message
#                $2 - default value.
#
get_confirm()
{
    _ANSWER=

    while :
    do
	# Display Internal ERROR if $2 not set.
	if [ -z "$2" ]; then
	    echo "INTERNAL ERROR: get_confirm requires 2 args, 3rd is optional."
	    exit 2
	fi

	# Display prompt.
	echo "$1 [$2] \c"

	# Get the ANSWER.
	read _ANSWER
	if [ "$_ANSWER" = "" ] && [ -n "$2" ] ; then
	    _ANSWER=$2
	fi
	case "$_ANSWER" in
	    [Yy] | yes | Yes | YES) return 1 ;;
	    [Nn] | no  | No  | NO)  return 0 ;;
	    [Hh] | help | Help | \?) display_msg ${3:-sorry};;
	    * ) echo "Please enter y or n."  ;;
	esac
    done
}


#
# get_confirm_nodef(): Get confirmation from the user. (Y/Yes or N/No)
#                      No default value supported. Returns 1 for yes.
#
get_confirm_nodef()
{
    _ANSWER=

    while :
    do
	echo "$@ \c"
	read _ANSWER
	case "$_ANSWER" in
	    [Yy] | yes | Yes | YES) return 1 ;;
	    [Nn] | no  | No  | NO)  return 0 ;;
	    * ) echo "Please enter y or n."  ;;
	esac
    done
}


#
# is_integer(): Tells if a string is numeric integer.
#    0 = Integer
#    1 = NOT Integer
#
is_integer()
{
    # Check for parameter.
    if [ $# -ne 1 ]; then
	return 1
    fi

    # Determine if integer.
    expr "$1" + 1 > /dev/null 2>&1

    if [ $? -ge 2 ]; then
	return 1
    fi

    # Made it here, it's Numeric.
    return 0
}


#
# not_integer(): Reverses the return values of is_integer.  Useful
#                for if and while statements that want to test for
#                non-integer data.
#    0 = NOT Integer
#    1 = Integer
#
not_integer()
{
    is_integer $1
    if [ $? -eq 0 ]; then
       return 1
    else
       return 0
    fi
}


#
# is_numeric(): Tells if a string is numeric.
#    0 = Numeric
#    1 = NOT Numeric
#
is_numeric()
{
    # Check for parameter.
    if [ $# -ne 1 ]; then
	return 1
    fi

    # Determine if numeric.
    let _NUM="$1 + 1" > /dev/null 2>&1

    if [ $? -eq 0 ]; then
	return 0
    fi
        
}


#
# not_numeric(): Reverses the return values of is_numeric.  Useful
#                for if and while statements that want to test for
#                non-numeric data.
#    0 = NOT Numeric
#    1 = Numeric
#
not_numeric()
{
    is_numeric $1
    if [ $? -eq 0 ]; then
       return 1
    else
       return 0
    fi
}


#
# domain_2_dc(): Convert a domain name into dc string.
#    $1  .. Domain name.
#
domain_2_dc()
{
    _DOM=$1           # Domain parameter.
    _DOM_2_DC=""      # Return value from function.
    _FIRST=1          # Flag for first time.
    
    export _DOM_2_DC  # Make visible for others.

    # Convert "."'s to spaces for "for" loop.
    domtmp="`echo ${_DOM} | tr '.' ' '`"
    for i in $domtmp; do
	if [ $_FIRST -eq 1 ]; then 
	    _DOM_2_DC="dc=${i}"
	    _FIRST=0
	else
	    _DOM_2_DC="${_DOM_2_DC},dc=${i}"
	fi
    done
}


#
# is_root_user(): Check to see if logged in as super user.
#
is_root_user()
{
    case `id` in
	uid=0\(root\)*) return 0 ;;
	* )             return 1 ;;
    esac
}


#
# parse_arg(): Parses the command line arguments and sets the 
#              appropriate variables.
#
parse_arg()
{
    while getopts ":dm:c:" ARG
    do
	case $ARG in
	    d)      DEBUG=1;;

	    m)      MAP_FILE=$OPTARG
	            MAPPING_FILE_SPECIFIED=1;;

	    c)      CONFIG_FILE=$OPTARG
                    CONFIG_FILE_SPECIFIED=1;;

	    \?)	    echo "**ERROR: Invalid option '$OPTARG'"
		    display_msg usage
		    exit 1;;
	esac
    done

    shift `expr $OPTIND - 1`
    if [ $# -gt 0 ]; then
        echo "**ERROR: wrong usage "
        display_msg usage
        exit 1
    fi
}


#
# present() : Checks if the first argument exists in the
#            argument list. Returns 0 if found, else 1.
#
present ()
{
_ELEMENT=$1

shift
ARG_LIST=$@

for item in $ARG_LIST
do
  [ "$_ELEMENT" = "$item" ] && return 0
done

# If reached here, then the clement does not exist
return 1
}


#
# remove() : Returns a new string after removing the first
#            argument in the argument list.
#
remove ()
{
_ELEMENT=$1

shift
ARG_LIST=$@

NEW_LIST=""

for item in $ARG_LIST
do
  [ "$_ELEMENT" != "$item" ] && NEW_LIST="$NEW_LIST $item"
done

echo $NEW_LIST
return 0
}


#
# merge_lists() : Returns a list after merging elements
#                 (uniquely) supplied in the argument list.
#
merge_lists()
{
MERGED_LIST=""

for _VAR in "$@"
do
  if ! present $_VAR $MERGED_LIST; then
    MERGED_LIST="$MERGED_LIST $_VAR"
  fi
done

echo $MERGED_LIST
return 0
}


#
# init(): initializes variables and options
#
init()
{
# General variables.
DEBUG=0             		# Set Debug OFF

MAPPING_FILE_SPECIFIED=0	# No file name passed
CONFIG_FILE_SPECIFIED=0		# No file name passed

# Prevent others from snooping
umask 077	

# Set default config and mapping files.
DEFAULT_MAP_FILE="/var/yp/NISLDAPmapping"
DEFAULT_CONFIG_FILE="/etc/default/ypserv"

MAP_FILE="$DEFAULT_MAP_FILE"
CONFIG_FILE="$DEFAULT_CONFIG_FILE"

# Set and create TMPDIR. Use a safe place to discourage hackers.
TMPDIR="/var/yp/inityp2l"

# Temporary file names to be used to prevent system starting in
# N2L mode in case something goes wrong during file creation.
TMPCONF="ypserv-tmp"
TMPMAP="NISLDAPmapping-tmp"

# Remove if the temp directory has been leftover
[ -d "$TMPDIR" ] && rm -rf $TMPDIR
mkdir $TMPDIR
if [ $? -ne 0 ]; then
  echo ERROR : Failed to create temp directory $TMPDIR
  exit 1
fi

# Initialize the default NIS maps.
DEFAULT_NIS_MAPS="passwd.byname
                  passwd.byuid
                  group.byname
                  group.bygid
                  hosts.byaddr
                  hosts.byname
                  ipnodes.byaddr
                  ipnodes.byname
                  ethers.byaddr
                  ethers.byname
                  networks.byaddr
                  networks.byname
                  rpc.bynumber
                  services.byname
                  services.byservicename
                  printers.conf.byname
                  project.byname
                  project.byprojid
                  protocols.byname
                  protocols.bynumber
                  netgroup
                  netgroup.byuser
                  netgroup.byhost
                  bootparams
                  mail.aliases
                  mail.byaddr
                  publickey.byname
                  netid.byname
                  netmasks.byaddr
                  passwd.adjunct.byname
                  group.adjunct.byname
                  timezone.byname
                  auth_attr
                  exec_attr
                  prof_attr
                  user_attr
                  audit_user
                  auto.master
                  auto.home
                  ypservers"

set -A DEF_NIS_MAP_ARRAY $DEFAULT_NIS_MAPS

# The default TTL maps in database ID format.
DEF_TTL_MAPLIST="audit_user
                 auto.home
                 auto.master
                 auth_attr
                 bootparams
                 ethers
                 exec_attr
                 group
                 group.adjunct.byname
                 keys.host
                 keys.pass
                 keys.nobody
                 hosts
                 multihosts
                 ipnodes
                 multiipnodes
                 netgroup
                 networks
                 passwd
                 passwd.adjunct.byname
                 printers.conf.byname
                 prof_attr
                 project
                 protocols
                 services
                 mail.aliases
                 mail.mapping
                 netid.host
                 netid.pass
                 netmasks.byaddr
                 rpc.bynumber
                 ageing.byname
                 timezone.byname
                 user_attr
                 ypservers"


# Initialize default values for config parameters.

configDN_flag=0
DEF_nisLDAPconfigDN=""
DEF_TLS=none
DEF_TLSCertificateDBPath=/var/yp/
DEF_nisLDAPbindTimeout=15
DEF_nisLDAPsearchTimeout=180
DEF_nisLDAPmodifyTimeout=15
DEF_nisLDAPaddTimeout=15
DEF_nisLDAPdeleteTimeout=15
DEF_nisLDAPsearchTimeLimit=${DEF_nisLDAPsearchTimeout}
DEF_nisLDAPsearchSizeLimit=0
DEF_nisLDAPfollowReferral=no
DEF_nisLDAPretrieveErrorAction=use_cached

# The default is unlimited, but since it prevents the NIS daemon,
# from servicing further requests, set 1 as the suggested value.
SUG_nisLDAPretrieveErrorAttempts=1
DEF_nisLDAPretrieveErrorTimeout=15
DEF_nisLDAPstoreErrorAction=retry

# The default is unlimited, but set 1 as the suggested value.
SUG_nisLDAPstoreErrorAttempts=1
DEF_nisLDAPstoreErrorTimeout=15

# Default TTL values (in seconds) for NIS MAPS for mapping file.
DEF_iTTLlo=1800
DEF_iTTLhi=5400
DEF_runTTL=3600

}


#
# config_auth_menu_handler(): Enter the authentication method
#                             for config server.
#
config_auth_menu_handler()
{
    # Display Auth menu
    display_msg config_auth_method_menu	

    # Get a Valid choice.
    while :
    do
	# Display appropriate prompt and get answer.
        get_ans_req "    Choose one Authentication Method (h=help):"

	# Determine choice.
	_MENU_CHOICE=$ANS
	case "$_MENU_CHOICE" in
	    1) _AUTHMETHOD="none"
		break ;;
	    2) _AUTHMETHOD="simple"
		break ;;
	    3) _AUTHMETHOD="sasl/cram-md5"
		break ;;
	    4) _AUTHMETHOD="sasl/digest-md5"
		break ;;
	    h) display_msg auth_help ;;
	    *) echo "Please enter 1-4, or h=help." ;;
	esac
    done
}


#
# auth_menu_handler(): Enter the Authentication method for LDAP server.
#
auth_menu_handler()
{
    # Display Auth menu
    display_msg auth_method_menu	

    # Get a Valid choice.
    while :
    do
	# Display appropriate prompt and get answer.
        get_ans_req "    Choose one Authentication Method (h=help):"

	# Determine choice.
	_MENU_CHOICE=$ANS
	case "$_MENU_CHOICE" in
	    1) _AUTHMETHOD="simple"
		break ;;
	    2) _AUTHMETHOD="sasl/cram-md5"
		break ;;
	    3) _AUTHMETHOD="sasl/digest-md5"
		break ;;
	    h) display_msg auth_help ;;
	    *) echo "Please enter 1-3, or h=help." ;;
	esac
    done
}


#
# tls_menu_handler(): Enter the transport layer security
#
tls_menu_handler()
{
    # Display TLS menu
    display_msg tls_method_menu	

    # Get a Valid choice.
    while :
    do
	# Display appropriate prompt and get answer.
	# Default value is "none".

        get_ans "    Choose one Transport Layer Security Method (h=help):" "1"

	# Determine choice.
	_MENU_CHOICE=$ANS
	case "$_MENU_CHOICE" in
	    1) _TLSMETHOD="none"
		break ;;
	    2) _TLSMETHOD="ssl"
		break ;;
	    h) display_msg tls_help ;;
	    *) echo "Please enter 1, 2, or h=help." ;;
	esac
    done
}


#
# retrieve_error_action_menu_handler(): Enter the retrieve error action
#
retrieve_error_action_menu_handler()
{
    # Display retrieve error action menu
    display_msg retrieve_error_action_menu	

    # Get a Valid choice.
    while :
    do
	# Display appropriate prompt and get answer. use_cached is default
        get_ans "    Choose one retrieval error action (h=help):" "1"

	# Determine choice.
	_MENU_CHOICE=$ANS
	case "$_MENU_CHOICE" in
	    1) _RET_ERR_ACT="use_cached"
		break ;;
	    2) _RET_ERR_ACT="fail"
		break ;;
	    h) display_msg nisLDAPretrieveErrorAction_help ;;
	    *) echo "Please enter 1, 2, or h=help." ;;
	esac
    done
}


#
# store_error_action_menu_handler(): Enter the store error action
#
store_error_action_menu_handler()
{
    # Display store error action menu
    display_msg store_error_action_menu	

    # Get a Valid choice.
    while :
    do
	# Display appropriate prompt and get answer. retry is default
        get_ans "    Choose one store error action (h=help):" "1"

	# Determine choice.
	_MENU_CHOICE=$ANS
	case "$_MENU_CHOICE" in
	    1) _STOR_ERR_ACT="retry"
		break ;;
	    2) _STOR_ERR_ACT="fail"
		break ;;
	    h) display_msg nisLDAPstoreErrorAction_help ;;
	    *) echo "Please enter 1, 2, or h=help." ;;
	esac
    done
}


#
# cleanup(): Remove the TMPDIR and all files in it.
#
cleanup()
{
[ $DEBUG -eq 1 ] && echo "In cleanup()"

# Leave the temp directory if debug is set
[ $DEBUG -eq 0 ] && rm -rf $TMPDIR
}


# Save existing config file if elected
check_back_config_file()
{
if [ -f $CONFIG_FILE ]; then
  display_msg backup_config_file

  get_confirm "Do you wish to continue (y/n/h)?" \
              "n" "backup_config_file_cont_help"

  if [ $? -eq 0 ]; then    # if No, cleanup and exit.
    cleanup ; exit 1
  fi

  get_confirm "Do you wish to backup the config file "${CONFIG_FILE}" (y/n/h)?" \
              "y" "backup_config_file_help"

  if [ $? -eq 1 ]; then    # Save the old config file with timestamp

    # SCCS converts '% H %' (without spaces) in current date during putback.
    # So use some other combination.
    SUFFIX=`date '+%d%h%Y.%H:%M:%S'`

    cp -p $CONFIG_FILE ${CONFIG_FILE}-${SUFFIX}
    echo "  Saved existing $CONFIG_FILE as ${CONFIG_FILE}-${SUFFIX}"
  fi
fi
}


# Save existing mapping file if elected
check_back_mapping_file()
{
if [ -f $MAP_FILE ]; then
  display_msg backup_mapping_file

  get_confirm "Do you wish to continue (y/n/h)?" \
              "n" "backup_mapping_file_cont_help"

  if [ $? -eq 0 ]; then    # if No, cleanup and exit.
    cleanup ; exit 1
  fi

  get_confirm "Do you wish to backup the map file "${MAP_FILE}" (y/n/h)?" \
                   "y" "backup_mapping_file_help"

  if [ $? -eq 1 ]; then    # if Yes, save the old map file with timestamp

    # SCCS converts '% H %' (without spaces) in current date during putback.
    # So use some other combination.
    SUFFIX=`date '+%d%h%Y.%H:%M:%S'`

    cp -p $MAP_FILE ${MAP_FILE}-${SUFFIX}
    echo "  Saved existing $MAP_FILE as ${MAP_FILE}-${SUFFIX}"
  fi

else
  if [ "$MAP_FILE" = "$DEFAULT_MAP_FILE" ]; then
    display_msg warn_n2l_mode

    get_confirm "Do you wish to continue (y/n/h)?" \
                "n" "warn_n2l_mode_help"

    if [ $? -eq 0 ]; then
      cleanup ; exit 1
    fi
  fi
fi
}


put_config_file_copyright_info()
{

# Start with an empty file, so don't append, but overwrite here.
# Just change the name, but keep the same date and version number
# as in the ident string of this script.

grep "ident	\"@(#)$PROG" $ABS_PROG | \
      sed "s/${PROG}/${NEW_NAME}/g" > $CONFIG_FILE

echo "\
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
#\
" >> $MAP_FILE
}


get_nisLDAPconfigDN()
{
while :
do

get_ans "DN for configuration information (h=help):"

# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg nisLDAPconfigDN_help ;;
                       * ) break ;;
esac
done

nisLDAPconfigDN="${ANS}"

# Store in config file only if a non-default value is specified.
if [ "$ANS" != "${DEF_nisLDAPconfigDN}" ]; then
  echo "nisLDAPconfigDN=${ANS}" >> $CONFIG_FILE
fi

# Ask remaining config server related questions only if this
# DN is set. So, if a value is specified, set a flag.

[ "$ANS" != "" ] && configDN_flag=1
}


get_nisLDAPconfigPreferredServerList()
{
while :
do

get_ans_req "Preferred server list for configuration information (h=help):"

# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg nisLDAPconfigPreferredServerList_help ;;
                       * ) break ;;
esac
done

nisLDAPconfigPreferredServerList=${ANS}
echo "nisLDAPconfigPreferredServerList=${ANS}" >> $CONFIG_FILE
}


get_nisLDAPconfigAuthenticationMethod()
{
_AUTHMETHOD=""

echo "Select the Authentication Method for configuration server :"
config_auth_menu_handler

nisLDAPconfigAuthenticationMethod=${_AUTHMETHOD}
echo "nisLDAPconfigAuthenticationMethod=${_AUTHMETHOD}" >> $CONFIG_FILE
}


get_nisLDAPconfigTLS()
{
_TLSMETHOD=""

echo "Select the Transport Layer Security (TLS) for configuration server :"
tls_menu_handler

nisLDAPconfigTLS=${_TLSMETHOD}

# Store in config file only if a non-default value is specified.
if [ "${_TLSMETHOD}" != "${DEF_TLS}" ]; then
    echo "nisLDAPconfigTLS=${_TLSMETHOD}" >> $CONFIG_FILE
fi
}


get_nisLDAPconfigTLSCertificateDBPath()
{
while :
do

get_ans "Path with TLS Certificate DB for configuration server (h=help):"\
            "${DEF_TLSCertificateDBPath}"

# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg TLSCertificateDBPath_help ;;
                       * ) break ;;
esac
done

nisLDAPconfigTLSCertificateDBPath=${ANS}

# Store in config file only if a non-default value is specified.
if [ "$ANS" != "${DEF_TLSCertificateDBPath}" ]; then
  echo "nisLDAPconfigTLSCertificateDBPath=${ANS}" >> $CONFIG_FILE
fi
}


get_nisLDAPconfigProxyUser()
{
while :
do

get_ans_req "Proxy user bind DN to obtain configuration information (h=help):"
# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg nisLDAPconfigProxyUser_help ;;
                       * ) break ;;
esac
done

nisLDAPconfigProxyUser=${ANS}
echo "nisLDAPconfigProxyUser=${ANS}" >> $CONFIG_FILE
}


get_nisLDAPconfigProxyPassword()
{
get_passwd "Proxy user password to obtain configuration information :"
nisLDAPconfigProxyPassword=${ANS}

echo "nisLDAPconfigProxyPassword=${ANS}" >> $CONFIG_FILE

display_msg ProxyPassword_warn
}


get_preferredServerList()
{
while :
do

get_ans_req "Preferred server list for mapping data to/from LDAP (h=help):"

# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg preferredServerList_help ;;
                       * ) break ;;
esac
done

preferredServerList=${ANS}
echo "preferredServerList=${ANS}" >> $CONFIG_FILE
}


get_authenticationMethod()
{
_AUTHMETHOD=""

echo "Select the Authentication Method for mapping data to/from LDAP :"
auth_menu_handler

authenticationMethod=${_AUTHMETHOD}
echo "authenticationMethod=${_AUTHMETHOD}" >> $CONFIG_FILE
}


get_nisLDAPTLS()
{
_TLSMETHOD=""

echo "Select the Transport Layer Security (TLS) for mapping data to/from LDAP :"
tls_menu_handler

nisLDAPTLS=${_TLSMETHOD}

# Store in config file only if a non-default value is specified.
if [ "${_TLSMETHOD}" != "${DEF_TLS}" ]; then
    echo "nisLDAPTLS=${_TLSMETHOD}" >> $CONFIG_FILE
fi
}


get_nisLDAPTLSCertificateDBPath()
{
while :
do

get_ans "Path with TLS Certificate DB for LDAP data server (h=help):"\
        "${DEF_nisLDAPTLSCertificateDBPath}"

# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg TLSCertificateDBPath_help ;;
                       * ) break ;;
esac
done

nisLDAPTLSCertificateDBPath=${ANS}

# Store in config file only if a non-default value is specified.
if [ "$ANS" != "${DEF_TLSCertificateDBPath}" ]; then
  echo "nisLDAPTLSCertificateDBPath=${ANS}" >> $CONFIG_FILE
fi
}


get_nisLDAPproxyUser()
{
while :
do

get_ans_req "Proxy user bind DN to read/write data from/to LDAP (h=help):"

# If help continue, otherwise break.
case "$ANS" in
  [Hh] | help | Help | \?) display_msg nisLDAPproxyUser_help ;;
                       * ) break ;;
esac
done

nisLDAPproxyUser=${ANS}
echo "nisLDAPproxyUser=${ANS}" >> $CONFIG_FILE
}


get_nisLDAPproxyPassword()
{
get_passwd "Proxy user password to read/write data from/to LDAP :"
nisLDAPproxyPassword=${ANS}

echo "nisLDAPproxyPassword=${ANS}" >> $CONFIG_FILE

display_msg ProxyPassword_warn
}


get_nisLDAPbindTimeout()
{
get_pos_int "Timeout value (in seconds) for LDAP bind operation (h=help):" \
              "${DEF_nisLDAPbindTimeout}" "nisLDAPbindTimeout_help"

nisLDAPbindTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPbindTimeout} ]; then
  echo "nisLDAPbindTimeout=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPsearchTimeout()
{
get_pos_int "Timeout value (in seconds) for LDAP search operation (h=help):" \
            "${DEF_nisLDAPsearchTimeout}" "nisLDAPsearchTimeout_help"

nisLDAPsearchTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPsearchTimeout} ]; then
  echo "nisLDAPsearchTimeout=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPmodifyTimeout()
{
get_pos_int "Timeout value (in seconds) for LDAP modify operation (h=help):" \
            "${DEF_nisLDAPmodifyTimeout}" "nisLDAPmodifyTimeout_help"

nisLDAPmodifyTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPmodifyTimeout} ]; then
  echo "nisLDAPmodifyTimeout=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPaddTimeout()
{
get_pos_int "Timeout value (in seconds) for LDAP add operation (h=help):" \
            "${DEF_nisLDAPaddTimeout}" "nisLDAPaddTimeout_help"

nisLDAPaddTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPaddTimeout} ]; then
  echo "nisLDAPaddTimeout=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPdeleteTimeout()
{
get_pos_int "Timeout value (in seconds) for LDAP delete operation (h=help):" \
            "${DEF_nisLDAPdeleteTimeout}" "nisLDAPdeleteTimeout_help"

nisLDAPdeleteTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPdeleteTimeout} ]; then
  echo "nisLDAPdeleteTimeout=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPsearchTimeLimit()
{
get_pos_int "Time limit (in seconds) for search operation on LDAP server (h=help):" \
            "${DEF_nisLDAPsearchTimeLimit}" "nisLDAPsearchTimeLimit_help"

nisLDAPsearchTimeLimit=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPsearchTimeLimit} ]; then
  echo "nisLDAPsearchTimeLimit=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPsearchSizeLimit()
{
get_pos_int "Size limit (in bytes) for search operation on LDAP server (h=help):" \
            "${DEF_nisLDAPsearchSizeLimit}" "nisLDAPsearchSizeLimit_help"

nisLDAPsearchSizeLimit=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPsearchSizeLimit} ]; then
  echo "nisLDAPsearchSizeLimit=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPfollowReferral()
{
get_confirm "Should the ypserv follow LDAP referrals (y/n/h):" \
            "n" "nisLDAPfollowReferral_help"

if [ $? -eq 1 ]; then
  _ANS="yes"
else
  _ANS="no"
fi

# Store in config file only if a non-default value is specified.
if [ "${_ANS}" != "${DEF_nisLDAPfollowReferral}" ]; then
  echo "nisLDAPfollowReferral=${_ANS}" >> $CONFIG_FILE
fi
}


get_nisLDAPretrieveErrorAction()
{
_RET_ERR_ACT=""

echo "Select the action to be taken in case of LDAP retrieval error :"
retrieve_error_action_menu_handler

nisLDAPretrieveErrorAction=${_RET_ERR_ACT}

# Store in config file only if a non-default value is specified.
if [ "${_RET_ERR_ACT}" != "${DEF_nisLDAPretrieveErrorAction}" ]; then
    echo "nisLDAPretrieveErrorAction=${_RET_ERR_ACT}" >> $CONFIG_FILE
fi
}


get_nisLDAPretrieveErrorAttempts()
{

get_pos_int "Number of attempts in case of LDAP retrieval error (h=help):" \
            "$SUG_nisLDAPretrieveErrorAttempts" \
            "nisLDAPretrieveErrorAttempts_help"

nisLDAPretrieveErrorAttempts=${NUM}

echo "nisLDAPretrieveErrorAttempts=${NUM}" >> $CONFIG_FILE
}


get_nisLDAPretrieveErrorTimeout()
{
# if nisLDAPretrieveErrorAttempts=0, then no point in asking
# for timeout vales as it is ignored anyway.

[ $nisLDAPretrieveErrorAttempts -eq 0 ] && return 0

get_pos_int "Timeout (in seconds) between each new attempt to retrieve LDAP data (h=help):"\
            "${DEF_nisLDAPretrieveErrorTimeout}" \
            "nisLDAPretrieveErrorTimeout_help"

nisLDAPretrieveErrorTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPretrieveErrorTimeout} ]; then
  echo "nisLDAPretrieveErrorTimeout=${NUM}" >> $CONFIG_FILE
fi
}


get_nisLDAPstoreErrorAction()
{
_STOR_ERR_ACT=""

echo "Select the action to be taken in case of LDAP store error :"
store_error_action_menu_handler

nisLDAPstoreErrorAction=${_STOR_ERR_ACT}

# Store in config file only if a non-default value is specified.
if [ "${_STOR_ERR_ACT}" != "${DEF_nisLDAPstoreErrorAction}" ]; then
    echo "nisLDAPstoreErrorAction=${_STOR_ERR_ACT}" >> $CONFIG_FILE
fi
}


get_nisLDAPstoreErrorAttempts()
{

# if nisLDAPstoreErrorAction="fail", then no point in asking
# for no. of attempts or timeout vales as they are ignored.

[ "$nisLDAPstoreErrorAction" = "fail" ] && return 0

get_pos_int "Number of attempts in case of LDAP store error (h=help):" \
            "$SUG_nisLDAPstoreErrorAttempts" \
            "nisLDAPstoreErrorAttempts_help"

nisLDAPstoreErrorAttempts=${NUM}

echo "nisLDAPstoreErrorAttempts=${NUM}" >> $CONFIG_FILE
}


get_nisLDAPstoreErrorTimeout()
{

# if nisLDAPstoreErrorAction="fail", then no point in asking
# for no. of attempts or timeout vales as they are ignored.

[ "$nisLDAPstoreErrorAction" = "fail" ] && return 0

# Similarly, if nisLDAPstoreErrorAttempts=0, ignore this question.

[ $nisLDAPstoreErrorAttempts -eq 0 ] && return 0

get_pos_int "Timeout (in seconds) between each new attempt to write LDAP data (h=help):"\
            "${DEF_nisLDAPstoreErrorTimeout}" \
            "nisLDAPstoreErrorTimeout_help"

nisLDAPstoreErrorTimeout=${NUM}

# Store in config file only if a non-default value is specified.
if [ $NUM -ne ${DEF_nisLDAPstoreErrorTimeout} ]; then
  echo "nisLDAPstoreErrorTimeout=${NUM}" >> $CONFIG_FILE
fi
}



create_config_file()
{

# To prevent from leaving a partial config file in case some error or
# signal takes place, store the output being generated in a temporary
# file first, and move it at the final destination only at the end if
# everything goes fine.

_CONFIG_FILE=$CONFIG_FILE
CONFIG_FILE=${TMPDIR}/${TMPCONF}.$$

echo "Generating config file temporarily as \"${CONFIG_FILE}\""

# Truncate the file before we append anything.
# Place copyright information
put_config_file_copyright_info

# Filter out all the YP domains in /var/yp
# The list of domains is stored in list "VARYP_DMN_LIST"

echo "\
#
# Configuration file for ypserv(1M); see ypserv(4) for more information,
# and NISLDAPmapping(4) for configuration of NIS to LDAP mapping.

# Unless otherwise noted, commented lines show default values.
" >> $CONFIG_FILE

echo "\
# Where to look for configuration information in LDAP. Leave empty or
# undefined to use this file, in which case the values of the other 
# 'nisLdapConfig*' attributes are ignored. 
#
#nisLDAPconfigDN=\
" >> $CONFIG_FILE

get_nisLDAPconfigDN

echo "

# Server(s) for configuration information. There is no default;
# use the value on the line below for an LDAP server running on
# this machine, at port 389.
#nisLDAPconfigPreferredServerList=127.0.0.1:389\
" >> $CONFIG_FILE

[ $configDN_flag -eq 1 ] && get_nisLDAPconfigPreferredServerList

echo "

# Authentication method(s) to obtain configuration information.
#\
" >> $CONFIG_FILE

[ $configDN_flag -eq 1 ] && get_nisLDAPconfigAuthenticationMethod

echo "

# Transport layer security for configuration information
#
#nisLDAPconfigTLS=${DEF_TLS}\
" >> $CONFIG_FILE

[ $configDN_flag -eq 1 ] && get_nisLDAPconfigTLS

echo "

# Certificate DB for transport layer security
#
#nisLDAPconfigTLSCertificateDBPath=${DEF_TLSCertificateDBPath}\
" >> $CONFIG_FILE

# ask for Certificate DB only if SSL is set
if [ "${nisLDAPconfigTLS}" = "ssl" ]; then
  [ $configDN_flag -eq 1 ] && get_nisLDAPconfigTLSCertificateDBPath
fi

echo "

# Proxy user(s) to obtain configuration information. The line below
# is an example of the format.
#
#nisLDAPconfigProxyUser=cn=nisAdmin,ou=People,\
" >> $CONFIG_FILE

# Ask proxy user bind DN only if needed.
if [ "${nisLDAPconfigAuthenticationMethod}" != "none" ]; then
  [ $configDN_flag -eq 1 ] && get_nisLDAPconfigProxyUser
fi

echo "

# Password for proxy user. Must be supplied if the authentication method
# requires a password. If a password appears in this file, it should be
# protected appropriately against access by unauthorized users.
#
#nisLDAPconfigProxyPassword=\
" >> $CONFIG_FILE

if [ "${nisLDAPconfigAuthenticationMethod}" != "none" ]; then
  [ $configDN_flag -eq 1 ] && get_nisLDAPconfigProxyPassword
fi

echo "

# Server list for mapping data to/from LDAP. There is no default;
# use the value on the line below for an LDAP server running on
# this machine, at port 389.
#preferredServerList=127.0.0.1:389\
" >> $CONFIG_FILE

get_preferredServerList

echo "

# Authentication method for mapping data to/from LDAP
#\
" >> $CONFIG_FILE

get_authenticationMethod

echo "

# Transport layer security for mapping data to/from LDAP.
#
#nisLDAPTLS=${DEF_TLS}\
" >> $CONFIG_FILE

get_nisLDAPTLS

echo "

# Certificate DB for transport layer security
#
#nisLDAPTLSCertificateDBPath=${DEF_TLSCertificateDBPath}\
" >> $CONFIG_FILE

# ask for Certificate DB only if SSL is set
if [ "${nisLDAPTLS}" = "ssl" ]; then
  get_nisLDAPTLSCertificateDBPath
fi

echo "

# Proxy user for ypserv. Assumed to have appropriate permission to read
# and/or create or modify LDAP data. The line below is an example of the
# format.
#
#nisLDAPproxyUser=cn=nisAdmin,ou=People,\
" >> $CONFIG_FILE

# Ask proxy user bind DN only if needed.
if [ "${authenticationMethod}" != "none" ]; then
  get_nisLDAPproxyUser
fi

echo "

# Password for proxy user. Must be supplied if the authentication method
# requires a password. If a password appears in this file, it should be
# protected appropriately against unauthorized access.
#
#nisLDAPproxyPassword=\
" >> $CONFIG_FILE

if [ "${authenticationMethod}" != "none" ]; then
  get_nisLDAPproxyPassword
fi

echo "

# Timeouts and time/size limits for LDAP operations.
#
#nisLDAPbindTimeout=${DEF_nisLDAPbindTimeout}\
" >> $CONFIG_FILE

get_nisLDAPbindTimeout

echo "
#nisLDAPsearchTimeout=${DEF_nisLDAPsearchTimeout}\
" >> $CONFIG_FILE

get_nisLDAPsearchTimeout

echo "
#nisLDAPmodifyTimeout=${DEF_nisLDAPmodifyTimeout}\
" >> $CONFIG_FILE

get_nisLDAPmodifyTimeout

echo "
#nisLDAPaddTimeout=${DEF_nisLDAPaddTimeout}\
" >> $CONFIG_FILE

get_nisLDAPaddTimeout

echo "
#nisLDAPdeleteTimeout=${DEF_nisLDAPdeleteTimeout}\
" >> $CONFIG_FILE

get_nisLDAPdeleteTimeout

echo "
#nisLDAPsearchTimeLimit=${DEF_nisLDAPsearchTimeLimit}\
" >> $CONFIG_FILE

get_nisLDAPsearchTimeLimit

echo "
#nisLDAPsearchSizeLimit=${DEF_nisLDAPsearchSizeLimit}\
" >> $CONFIG_FILE

get_nisLDAPsearchSizeLimit

echo "

# Should the ypserv follow LDAP referrals ?
#
#nisLDAPfollowReferral=${DEF_nisLDAPfollowReferral}\
" >> $CONFIG_FILE

get_nisLDAPfollowReferral

echo "

# Action, number of attempts, and timeout following an LDAP retrieval error
#
#nisLDAPretrieveErrorAction=${DEF_nisLDAPretrieveErrorAction}\
" >> $CONFIG_FILE

get_nisLDAPretrieveErrorAction

echo "
#nisLDAPretrieveErrorAttempts=\
" >> $CONFIG_FILE

get_nisLDAPretrieveErrorAttempts

echo "
#nisLDAPretrieveErrorTimeout=${DEF_nisLDAPretrieveErrorTimeout}\
" >> $CONFIG_FILE

get_nisLDAPretrieveErrorTimeout

echo "

# Action, number of attempts, and timeout following an LDAP store error
#
#nisLDAPstoreErrorAction=${DEF_nisLDAPstoreErrorAction}\
" >> $CONFIG_FILE

get_nisLDAPstoreErrorAction

echo "
#nisLDAPstoreErrorAttempts=\
" >> $CONFIG_FILE

get_nisLDAPstoreErrorAttempts

echo "
#nisLDAPstoreErrorTimeout=${DEF_nisLDAPstoreErrorTimeout}\
" >> $CONFIG_FILE

get_nisLDAPstoreErrorTimeout


# We are done, so move back the config file from temp. location
# to actual location.
# In case the config file name has a directory component which does
# not exist, then create it now, otherwise 'mv' will return error.

DIR_TO_CREATE=`dirname ${_CONFIG_FILE}`
mkdir -p ${DIR_TO_CREATE}

echo "Moving output from temporary file ($CONFIG_FILE) to actual file ($_CONFIG_FILE)"
mv $CONFIG_FILE $_CONFIG_FILE

# Revert back the config file name in case needed.
CONFIG_FILE=$_CONFIG_FILE
echo "Finished creation of config file ( $_CONFIG_FILE )"

}


put_mapping_file_copyright_info()
{

# Start with an emptty file, so don't append, but overwrite here.
# Just change the name and add the word pragma, but keep the same
# date and version number as in the ident string of this script.

grep "ident	\"@(#)$PROG" $ABS_PROG | \
      sed "s/ ident/pragma ident/g" | \
      sed "s/${PROG}/${NEW_NAME}/g" > $MAP_FILE

echo "\
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
#
#-------------------------------------------------------------------
#\
" >> $MAP_FILE
}


#
# Filter out all the YP domains in /var/yp
# The list of domains is stored in list "VARYP_DMN_LIST"
#
create_all_var_yp_domain_list()
{
VARYP_DMN_LIST=""

for entry in /var/yp/*
do
  DMN=`basename $entry`
  if [ -d "/var/yp/$DMN" ] && [ -f "/var/yp/binding/$DMN/ypservers" ]
  then
    VARYP_DMN_LIST="$VARYP_DMN_LIST $DMN"
  fi
done

# d_echo VARYP_DMN_LIST = "$VARYP_DMN_LIST"
[ $DEBUG -eq 1 ] && echo VARYP_DMN_LIST = "$VARYP_DMN_LIST"
}


#
# Ask user which domains would be served by N2L
# The list of N2L domains is stored in global array 
# "N2L_DMN_LIST" and number of domains in N2L_DMN_CNT
#
create_n2l_domain_list()
{
# First make a list of all the domains in /var/yp
create_all_var_yp_domain_list

# Now identify those to be served by N2L
let count=0

for DMN in $VARYP_DMN_LIST
do
  get_confirm "Do you want to store maps from ${DMN} domain to LDAP (y/n/h):" \
              "n" "selectDomain4N2L_help"

  if [ $? -eq 1 ]; then
    N2L_DMN_LIST[count]=$DMN
    let count="count + 1"
  fi

done
N2L_DMN_CNT=$count

[ $DEBUG -eq 1 ] && echo N2L_DMN_LIST=${N2L_DMN_LIST[*]}
[ $DEBUG -eq 1 ] && echo N2L_DMN_CNT=$N2L_DMN_CNT
}


#
# Make various lists for different types of maps for each N2L domain
# and ask user if mapping information and comments need to be generated
# for custom maps.
#
# This function looks big, but since KSH does not support 2-D arrays, or
# two level of dereferencing, it forced to have so many lists and arrays.
# Lists are better for adding or removing elements, and arrays are better
# for accessing with index and in knowing the no. of elements.
#
create_map_lists()
{
# Initialize them with no maps.
ALL_DMN_ALL_MAPLIST=""
ALL_DMN_DEF_MAPLIST=""
ALL_DMN_CUST_MAPLIST=""
ALL_DMN_AUTO_CUST_MAPLIST=""

# Default to don't generate custom mapping info or comment info.
CUST_MAP_NEEDED=0
CUST_CMT_NEEDED=0

let count=0

while (( $count < $N2L_DMN_CNT ))
do
  DMN=${N2L_DMN_LIST[count]}
  MAPDIR=/var/yp/${DMN}

  # Initialize per domain lists to NULL.
  ALL_MAPLIST=""
  DEF_MAPLIST=""
  CUST_MAPLIST=""
  AUTO_CUST_MAPLIST=""

  for dbmfile in $MAPDIR/*.dir
  do
    MAP=`basename $dbmfile .dir`

    # Ignore N2L maps (those with "LDAP_" prefix and ageing.byname)
    if [[ $MAP != LDAP_* ]] && [[ $MAP != "" ]] && \
       [ -f $MAPDIR/${MAP}.pag ] && [[ $MAP != ageing.byname ]]
    then
      ALL_MAPLIST="$ALL_MAPLIST $MAP"

      if present $MAP $DEFAULT_NIS_MAPS
      then
        DEF_MAPLIST="$DEF_MAPLIST $MAP"

      elif [[ $MAP = auto.* ]]
      then
        AUTO_CUST_MAPLIST="$AUTO_CUST_MAPLIST $MAP"

      else
        # If we reached here, means it is custom map.
        get_confirm "Do you want the mapping information to be generated for \"$MAP\" map of $DMN domain (y/n/h)?" \
                    "n" "generate_mapping_info_for_cust_map_help"

        if [ $? -eq 1 ]
        then
          CUST_MAPLIST="$CUST_MAPLIST $MAP"
        else
          # If a customer map is not desired, then delete it from
          # all maplist too.
          ALL_MAPLIST=$(remove $MAP $ALL_MAPLIST)
        fi

      fi

    fi

  done

  # Make ALL_DMN lists as they are very helpful in checking if a map exists.
  ALL_DMN_ALL_MAPLIST=$(merge_lists $ALL_DMN_ALL_MAPLIST $ALL_MAPLIST)
  ALL_DMN_DEF_MAPLIST=$(merge_lists $ALL_DMN_DEF_MAPLIST $DEF_MAPLIST)
  ALL_DMN_CUST_MAPLIST=$(merge_lists $ALL_DMN_CUST_MAPLIST $CUST_MAPLIST)
  ALL_DMN_AUTO_CUST_MAPLIST=$(merge_lists $ALL_DMN_AUTO_CUST_MAPLIST \
                                          $AUTO_CUST_MAPLIST)

  # Store per domain lists in arrays.
  ALL_MAPS[$count]="$ALL_MAPLIST"
  DEF_MAPS[$count]="$DEF_MAPLIST"
  CUST_MAPS[$count]="$CUST_MAPLIST"
  AUTO_CUST_MAPS[$count]="$AUTO_CUST_MAPLIST"

  [ $DEBUG -eq 1 ] && echo ALL_MAPS[$DMN] = ${ALL_MAPS[$count]}
  [ $DEBUG -eq 1 ] && echo DEF_MAPS[$DMN] = ${DEF_MAPS[$count]}
  [ $DEBUG -eq 1 ] && echo CUST_MAPS[$DMN] = ${CUST_MAPS[$count]}
  [ $DEBUG -eq 1 ] && echo AUTO_CUST_MAPS[$DMN] = ${AUTO_CUST_MAPS[$count]}

  let count="count + 1"
done

[ $DEBUG -eq 1 ] && echo ALL_DMN_ALL_MAPLIST = $ALL_DMN_ALL_MAPLIST
[ $DEBUG -eq 1 ] && echo ALL_DMN_DEF_MAPLIST = $ALL_DMN_DEF_MAPLIST
[ $DEBUG -eq 1 ] && echo ALL_DMN_CUST_MAPLIST = $ALL_DMN_CUST_MAPLIST
[ $DEBUG -eq 1 ] && echo ALL_DMN_AUTO_CUST_MAPLIST = $ALL_DMN_AUTO_CUST_MAPLIST

# Store all domain lists in array too.
set -A ALL_DMN_ALL_MAPS $ALL_DMN_ALL_MAPLIST
set -A ALL_DMN_DEF_MAPS $ALL_DMN_DEF_MAPLIST
set -A ALL_DMN_CUST_MAPS $ALL_DMN_CUST_MAPLIST
set -A ALL_DMN_AUTO_CUST_MAPS $ALL_DMN_AUTO_CUST_MAPLIST

# A positive customer map count implies custom mapping information
# is required. Set this flag.
[ ${#ALL_DMN_CUST_MAPS[*]} -gt 0 ] && CUST_MAP_NEEDED=1

# Give bit of info, and ask if comments need to be placed in mapping file
echo "
  This script can place relevant information regarding custom
  maps at appropriate places in the mapping file which can be
  helpful in customizing this file.
"

get_confirm "Do you want such information to be generated (y/n/h)?" \
            "n" "generate_comment_info_for_cust_map_help"

[ $? -eq 1 ] && CUST_CMT_NEEDED=1

[ $DEBUG -eq 1 ] && echo CUST_MAP_NEEDED = $CUST_MAP_NEEDED
[ $DEBUG -eq 1 ] && echo CUST_CMT_NEEDED = $CUST_CMT_NEEDED

}


#
# Ask user the context for each (N2l) domain
#
get_nisLDAPdomainContext()
{
echo "
# List domains and contexts
" >> $MAP_FILE

for DMN in ${N2L_DMN_LIST[*]}
do
  while :
  do
    # Convert to domain in dc format for default choice
    domain_2_dc $DMN

    get_ans "Enter the naming context for $DMN domain (h=help):"\
            "$_DOM_2_DC"

    # If help continue, otherwise break.
    case "$ANS" in
      [Hh] | help | Help | \?) display_msg nisLDAPdomainContext_help ;;
                           * ) break ;;
    esac
  done
  
  # If a value is specified, set it, and save in mapping file too.
  if [ "$ANS" != "" ]; then
    echo "nisLDAPdomainContext $DMN : ${ANS}" >> $MAP_FILE
  fi

  [ $DEBUG -eq 1 ] && echo "nisLDAPdomainContext $DMN : ${ANS}"
done
}


#
# Ask user the domains for which passwords should be changed
#
get_nisLDAPyppasswddDomains()
{

echo "
# List domains for which passwords should be changed. If this is not
# present then the value returned by 'domainname' will be used.
" >> $MAP_FILE

for DMN in ${N2L_DMN_LIST[*]}
do
  get_confirm "Enable password changes for ${DMN} domain (y/n/h)? " \
              "n" "nisLDAPyppasswddDomains_help"

  if [ $? -eq 1 ]; then
      echo "nisLDAPyppasswddDomains $DMN" >> $MAP_FILE
  fi
done

echo "
#
#-------------------------------------------------------------------
#\
" >> $MAP_FILE
}


#
# Create NIS databaseId mappings (aliases)
#
create_nisLDAPdatabaseIdMapping()
{
echo '
# Associate map names with databaseIds (aliases)

# Standard maps
nisLDAPdatabaseIdMapping	ethers: ethers.byaddr ethers.byname
nisLDAPdatabaseIdMapping	group: group.bygid group.byname
nisLDAPdatabaseIdMapping	hosts:[addr="[0-9]*.[0-9]*.[0-9]*.[0-9]*"] \
				hosts.byaddr hosts.byname
# Special mapping to handle the YP_MULTI cases
nisLDAPdatabaseIdMapping        multihosts: \
				[addr="[0-9]*.[0-9]*.[0-9]*.[0-9]*,*"] \
				hosts.byname
nisLDAPdatabaseIdMapping	networks: networks.byaddr networks.byname
nisLDAPdatabaseIdMapping	project: project.byname project.byprojid
nisLDAPdatabaseIdMapping	protocols: protocols.byname protocols.bynumber
nisLDAPdatabaseIdMapping	services: services.byname services.byservicename

# netid.byname is built up from the hosts and passwd files using different
# mappings. It thus has two associated nisLDAPdatabaseIdMappings.
nisLDAPdatabaseIdMapping	netid.host:[number="0"] netid.byname
nisLDAPdatabaseIdMapping	netid.pass:[number="[1-9]*"] netid.byname

# The next two are special databaseIds. They associate maps with databaseIds 
# but additionally identify which maps contain password and password adjunct
# information for yppasswdd. 
nisLDAPdatabaseIdMapping	passwd: passwd.byname passwd.byuid

# mail.byaddr needs to select entries of the form x@y or x!y
nisLDAPdatabaseIdMapping	mail.mapping:[rf_key="*@*", rf_key="*!*"] \
				mail.byaddr

# publickey.byname
# Each entry in publickey map consists of a network user name which
# may refer to a host or a user. It also contains a default entry for nobody.
# Hence, we need three nisLDAPdatabaseIdmappings to support the three
# different types of keys.
nisLDAPdatabaseIdMapping        keys.host:[rf_key="unix.[a-zA-Z]*@*"] \
				publickey.byname
nisLDAPdatabaseIdMapping        keys.pass:[rf_key="unix.[0-9]*@*"] \
				publickey.byname
nisLDAPdatabaseIdMapping        keys.nobody:[rf_key="nobody"] publickey.byname

# Single standard maps. No point aliasing.
# mail.aliases 
# netmasks.byaddr
# rpc.bynumber
# ypservers

# Other maps
# ipnodes looks identical to hosts but maps to a different context.
nisLDAPdatabaseIdMapping	ipnodes:[addr="*:*"] \
				ipnodes.byaddr ipnodes.byname
# Special mapping to handle the YP_MULTI cases
nisLDAPdatabaseIdMapping        multiipnodes: \
				[addr="*:*,*"] \
				ipnodes.byname

# Other single maps. No point aliasing
# audit_user
# auth_attr
# exec_attr
# prof_attr
# user_attr
# auto.home
# auto.master
# bootparams
# timezone.byname
# printers.conf.byname
# passwd.adjunct.byname
# group.adjunct.byname
' >> $MAP_FILE

[ CUST_CMT_NEEDED -eq 1 ] && \
echo "
# If any custom map needs to be aliased, then it should be listed
# here in the following format :
# nisLDAPdatabaseIdMapping databaseId ":" ["["indexlist"]"] mapname[" "...]
" >> $MAP_FILE

[ CUST_MAP_NEEDED -eq 1 ] && \
echo "\
# Not aliasing non-default/custom maps as they are assumed to be
# simple, single maps.\
" >> $MAP_FILE

for MAP in ${ALL_DMN_AUTO_CUST_MAPS[*]} ${ALL_DMN_CUST_MAPS[*]}
do
  echo "# $MAP" >> $MAP_FILE
done

echo "\
#
#------------------------------------------------------------------------------
#
" >> $MAP_FILE
}


#
# Finds the domains in which the given map exists in the supplied list.
# Sets result in PRESENT_COUNT and PRESENT_IN_DOMAINS. These fields are
# set globally, so they can be accessed from any where.
# Input : $1 - map, $2 - list name (just name, not the value)
#
find_domains()
{
_MAP=$1
_ARRAY=$2

let PRESENT_COUNT=0
PRESENT_IN_DOMAINS=""

let count=0

while (( $count < $N2L_DMN_CNT ))
do

  # Quick and dirty way to get around unavailability of 2D array
  case "$_ARRAY" in
          ALL_MAPS ) _LIST=${ALL_MAPS[$count]} ;;
          DEF_MAPS ) _LIST=${DEF_MAPS[$count]}  ;;
         CUST_MAPS ) _LIST=${CUST_MAPS[$count]}  ;;
    AUTO_CUST_MAPS ) _LIST=${AUTO_CUST_MAPS[$count]}  ;;
                 * ) echo "Invalid value: \"${_ARRAY}\". \c"
                  ;;
  esac

  if present $_MAP $_LIST
  then
    let PRESENT_COUNT="$PRESENT_COUNT + 1"
    PRESENT_IN_DOMAINS="$PRESENT_IN_DOMAINS ${N2L_DMN_LIST[count]}"
  fi
  let count="count + 1"
done

[ $DEBUG -eq 1 ] && echo "PRESENT_COUNT = $PRESENT_COUNT"
[ $DEBUG -eq 1 ] && echo "PRESENT_IN_DOMAINS = $PRESENT_IN_DOMAINS"

return 0
}


#
# For a given map, find out which list it belongs to (PRESENT_IN_LIST),
# and in how many domains this map shows up (PRESENT_COUNT), and in
# which ones (PRESENT_IN_DOMAINS). These fields are set globally, so
# they can be accessed from any where.
#
find_map_presence_details()
{
_MAP=$1

let PRESENT_COUNT=0
PRESENT_IN_LIST=""
PRESENT_IN_DOMAINS=""

# If the map does not exist, return right away, else
# find which list it belongs to.
# If a map exists in def or auto or cust lists, then
# it also exists in "all" list.

if ! present $_MAP $ALL_DMN_ALL_MAPLIST
then
  return 1

elif present $_MAP $ALL_DMN_DEF_MAPLIST
then
  PRESENT_IN_LIST="DEF_MAPS"

elif present $_MAP $ALL_DMN_CUST_MAPLIST
then
  PRESENT_IN_LIST="CUST_MAPS"

else
  # If map exists, and not in previous two lists,
  # then it has to be here only.
  PRESENT_IN_LIST="AUTO_CUST_MAPS"
fi

# Now we know which list the map belongs to. So, we need to
# find which are the domains in which this map exists.

find_domains $_MAP $PRESENT_IN_LIST

# Since the above function sets the values of PRESENT_COUNT and 
# PRESENT_IN_DOMAINS fields, we don't need to do anything else.

[ $DEBUG -eq 1 ] && echo "PRESENT_IN_LIST = $PRESENT_IN_LIST"

return 0
}


#
# Check if the comment char is a single character, return 0 on success.
# Input is passed via global variable "COMMENT_CHAR"
#
valid_comment_char()
{
COMMENT_CHAR_LENGTH=`echo "${COMMENT_CHAR}" | wc -c`

# echo adds new line character, so adjust length appropriately
if [ $COMMENT_CHAR_LENGTH -gt 2 ]; then
  echo " Comment character has to be a blank or single character; try again."
  return 1
else
  return 0
fi
}


#
# Read the comment character for a MAP. Append in mapping file if valid.
# Input - $1 : MAP name
#
get_comment_char()
{
_MAP=$1

while :
do
  get_ans "Specify the comment character for $_MAP :"
  COMMENT_CHAR=$ANS

  if valid_comment_char; then
    break
  fi
done

echo "nisLDAPcommentChar $_MAP : '${COMMENT_CHAR}'" >> $MAP_FILE
}


#
# Read a seperate comment character for a MAP for each domain and
# update this information in mapping file.
# Input - $1 : MAP name, $@ : list of domains
#
get_comment_char_per_domain()
{
_MAP=$1
shift
_DOMAIN_LIST="$@"

for _DMN in $_DOMAIN_LIST
do

  while :
  do

    get_ans "Specify the comment character for $_MAP,${_DMN} :"
    COMMENT_CHAR=$ANS

    if valid_comment_char; then
      break
    fi

  done
  echo "nisLDAPcommentChar $_MAP,${_DMN} : '${COMMENT_CHAR}'" >> $MAP_FILE

done
}


#
# This function generates custom comment entries. The output is
# appended in the mapping file.
#
get_custom_nisLDAPcommentChar()
{

# All the auto mounter maps are assumed to have '#' as the default comment
# char. But still list the non-default auto map entries here anyway. This
# will make it very easy in case these entries need to be changed.

for MAP in ${ALL_DMN_AUTO_CUST_MAPS[*]}
do
  echo "nisLDAPcommentChar $MAP : '#'" >> $MAP_FILE
done

if [ CUST_MAP_NEEDED -eq 1 ]; then
  get_confirm "Do you wish to specify the comment character for any custom map (y/n/h)?" \
              "n" "custom_map_comment_char_help"

  if [ $? -eq 1 ]; then
    for MAP in ${ALL_DMN_CUST_MAPS[*]}
    do

      get_confirm "Do you wish to specify comment character for \"$MAP\" (y/n/h)?" \
                  "n" "custom_map_comment_char_help"

      if [ $? -eq 1 ]; then
        find_domains $MAP CUST_MAPS
        if [ $PRESENT_COUNT -gt 1 ]; then
          echo "Map \"$MAP\" is present in these domains : $PRESENT_IN_DOMAINS"

          get_confirm "For \"$MAP\", should the same comment character be set for all the domains (y/n/h)?" \
                      "y" "same_comment_char_help"

          if [ $? -eq 1 ]; then
            get_comment_char $MAP
          else
            get_comment_char_per_domain  $MAP "$PRESENT_IN_DOMAINS"
          fi

        else
          get_comment_char $MAP
        fi

      fi
    done
  fi
fi

}


# List comment character (if any) for maps
create_nisLDAPcommentChar()
{

echo "\
# Specify the character representing the start of comments.
" >> $MAP_FILE

[ CUST_CMT_NEEDED -eq 1 ] && echo "\
# The comment character represents the start of the special 'comment'
# field in a given NIS map. If this attribute is not present then the
# default comment character '#' is used. If a map cannot contain comments
# then the NULL ('') comment character should be specified. The format to
# specify the comment character is :
# nisLDAPcommentChar MAP[,DOMAIN] : 'single_comment_char'
" >> $MAP_FILE

echo "\
nisLDAPcommentChar group : ''
nisLDAPcommentChar passwd : ''
nisLDAPcommentChar ageing.byname : ''
nisLDAPcommentChar audit_user : ''
nisLDAPcommentChar auth_attr : ''
nisLDAPcommentChar exec_attr : ''
nisLDAPcommentChar user_attr : ''
nisLDAPcommentChar bootparams : ''
" >> $MAP_FILE

# Need to handle passwd.adjunct.byname map for multiple domain.
_MAP=passwd.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo "#nisLDAPcommentChar passwd.adjunct.byname: ''" >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then
    # Don't put domain info as the map is present in all of them.
    echo "nisLDAPcommentChar passwd.adjunct.byname: ''" >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPcommentChar passwd.adjunct.byname,${_DMN}: ''" >> $MAP_FILE
    done
  fi
fi
# passwd.adjunct.byname done


# Need to handle group.adjunct.byname map for multiple domain.
_MAP=group.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo "#nisLDAPcommentChar group.adjunct.byname: ''" >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then
    # Don't put domain info as the map is present in all of them.
    echo "nisLDAPcommentChar group.adjunct.byname: ''" >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPcommentChar group.adjunct.byname,${_DMN}: ''" >> $MAP_FILE
    done
  fi
fi
# group.adjunct.byname done

echo "" >> $MAP_FILE

# Ask user for comment char for custom maps
get_custom_nisLDAPcommentChar

echo "
#
#------------------------------------------------------------------------------
#
" >> $MAP_FILE
}


#
# Generate secure flag entries
#
create_secure_flag_entries()
{
echo "\
# Specify YP_SECURE flags
" >> $MAP_FILE

[ CUST_CMT_NEEDED -eq 1 ] && echo "\
# If a map is secure, then it needs to be mentioned here
# in the following format :
# nisLDAPmapFlags mapname : s
">> $MAP_FILE

# Need to handle passwd.adjunct.byname map for multiple domain.
_MAP=passwd.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo "#nisLDAPmapFlags passwd.adjunct.byname : s" >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then
    # Don't put domain info as the map is present in all of them.
    echo "nisLDAPmapFlags passwd.adjunct.byname : s" >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPmapFlags passwd.adjunct.byname,${_DMN} : s" >> $MAP_FILE
    done
  fi
fi

# Need to handle group.adjunct.byname map for multiple domain.
_MAP=group.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo "#nisLDAPmapFlags group.adjunct.byname : s" >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then
    # Don't put domain info as the map is present in all of them.
    echo "nisLDAPmapFlags group.adjunct.byname : s" >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPmapFlags group.adjunct.byname,${_DMN} : s" >> $MAP_FILE
    done
  fi
fi

echo "" >> $MAP_FILE

STR="any"    # Just to make the question look better.
while :
do
  get_confirm "Do you wish to set the secure flag for $STR map (y/n/h)?" \
              "n" "secure_flag_on_help"

  if [ $? -eq 0 ]; then
    return 0

  else
    get_ans "Enter the MAP name :"
    MAP=$ANS
    
    if [[ $MAP = "" ]]; then
      echo " Error : BLANK map name not allowed; try again"
      continue
    fi

    # Check if the supplied map name exists, and if yes, then
    # set the PRESENT attributes for further processing

    find_map_presence_details $MAP

    case $PRESENT_COUNT in

      0 ) echo " Error : $MAP not found in any domain; try again"
          ;;

      1 ) # The map exists in only one domain.
          echo "nisLDAPmapFlags $MAP : s" >> $MAP_FILE
          STR="another"    # Just to make the question look better.
          ;;

      * ) # The map exists in multiple domain. Ask if this flag needs
          # to be set for all domains, or some specific ones.

          echo "Map \"$MAP\" is present in these domains : $PRESENT_IN_DOMAINS"
          get_confirm "For this map, do you wish to set this flag for all the domains (y/n/h)?" \
                      "y" "secure_flag_all_domains_help"
  
          if [ $? -eq 1 ]; then
            echo "nisLDAPmapFlags $MAP : s" >> $MAP_FILE
          else

            for _DMN in $PRESENT_IN_DOMAINS
            do

              get_confirm_nodef "Set secure flag for $MAP,${_DMN} (y/n)?"

              if [ $? -eq 1 ]; then
                echo "nisLDAPmapFlags $MAP,${_DMN} : s" >> $MAP_FILE
              fi

            done
          fi
          STR="another"    # Just to make the question look better.
          ;;

    esac

  fi
done
}


#
# Generate interdomain flag entries
#
create_interdomain_flag_entries()
{

INTERDOMAIN_MAP_LIST="ipnodes
                       multiipnodes
                       hosts
                       multihosts
                       services.byservicename"

#
# Simple function to avoid duplication of code
#
print_interdomain_entries()
{
for _MAP in $INTERDOMAIN_MAP_LIST
do
  echo "nisLDAPmapFlags ${_MAP} : b" >> $MAP_FILE
done
}

echo "
# Specify YP_INTERDOMAIN flags
" >> $MAP_FILE

[ CUST_CMT_NEEDED -eq 1 ] && echo "\
# It is used to indicate NIS servers to use the domain name resolver for
# host name and address lookups for hosts not found in the maps.
# If set, it adds YP_INTERDOMAIN entries in these maps when converting 
# data from LDAP to YP. It needs to be set in the following format :
# nisLDAPmapFlags mapname : b
" >> $MAP_FILE
 
# List one set of entries in commented form anyway as it might help
# user understand what it means.

echo "\
# If \$B is set in /var/yp/Makefile, then this flag should be
# set for following maps :\
" >> $MAP_FILE

for _MAP in $INTERDOMAIN_MAP_LIST
do
  echo "# nisLDAPmapFlags ${_MAP} : b" >> $MAP_FILE
done

# Put a blank line for indentation purpose
echo  >> $MAP_FILE

get_confirm "Do you wish to set the \"interdomain\" flag for any domain (y/n/h)?" \
            "n" "interdomain_flag_on_help"

if [ $? -eq 1 ]; then

  if [ $N2L_DMN_CNT -gt 1 ]; then

    get_confirm "Should \"interdomain\" flag be set for all domain (y/n/h)?" \
                "y" "interdomain_flag_all_domains_help"

    if [ $? -eq 1 ]; then
      print_interdomain_entries
    else

      for _DMN in ${N2L_DMN_LIST[*]}
      do
        get_confirm_nodef "Set interdomain flag for ${_DMN} (y/n)?"

        if [ $? -eq 1 ]; then
          for _MAP in $INTERDOMAIN_MAP_LIST
          do
            echo "nisLDAPmapFlags ${_MAP},${_DMN} : b" >> $MAP_FILE
          done
        fi

      done
    fi

  else
    print_interdomain_entries
  fi
fi

echo "
#
#------------------------------------------------------------------------------
#
" >> $MAP_FILE

return 0
}


#
# List SECURE and INTERDOMAIN flags
#
create_nisLDAPmapFlags()
{
create_secure_flag_entries
create_interdomain_flag_entries
}


#
# Print one Map TTL entry in mapping file using supplied TTL.
#
print_one_map_ttl_entry()
{
_Map=$1
_iTtlLo=$2
_iTtlHi=$3
_runTtl=$4

echo "\
nisLDAPentryTtl        ${_Map}:${_iTtlLo}:${_iTtlHi}:${_runTtl}\
" >> $MAP_FILE

return 0
}


#
# Print all the maps TTL entries of same TTL
# values using the supplied TTL triplet.
#
print_all_same_ttl_entries()
{
_iTTLlo=$1
_iTTLhi=$2
_runTTL=$3

for _MAP in ${DEF_TTL_MAPLIST} ${ALL_DMN_CUST_MAPS[*]} \
            ${ALL_DMN_AUTO_CUST_MAPS[*]}
do

  if [ "$_MAP" != "passwd.adjunct.byname" ] && \
	[ "$_MAP" != "group.adjunct.byname" ]
  then
    print_one_map_ttl_entry $_MAP $_iTTLlo $_iTTLhi $_runTTL

  else

    # adjunct maps might not exist in all the domains.
    find_domains $_MAP DEF_MAPS

    if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
    then

      # Don't put domain info as the map is present in all of them.
      print_one_map_ttl_entry $_MAP $_iTTLlo $_iTTLhi $_runTTL

    else

      for _DMN_ in $PRESENT_IN_DOMAINS
      do
        _STR="${_MAP},${_DMN_}"
        print_one_map_ttl_entry $_STR $_iTTLlo $_iTTLhi $_runTTL
      done

    fi
  fi
done

return 0
}

#
# Read the initialTTLlo. Set the value in global variable.
#
get_ittl_lo()
{
get_pos_int "Lower limit for initial TTL (in seconds) (h=help):" \
            "$DEF_iTTLlo" "initialTTLlo_help"

iTTLlo=${NUM}
}


#
# Read the initialTTLhi. Set the value in global variable.
#
get_ittl_hi()
{
get_pos_int "Higher limit for initial TTL (in seconds) (h=help):" \
            "$DEF_iTTLhi" "initialTTLhi_help"

iTTLhi=${NUM}
}


#
# Read the initialTTLhi. Set the value in global variable.
#
get_run_ttl()
{
get_pos_int "Runtime TTL (in seconds) (h=help):" \
            "$DEF_runTTL" "runningTTL_help"

runTTL=${NUM}
}


#
# Read one TTL triplet. Set the result in global variables.
#
read_one_ttl_triplet()
{
# Just call the individual functions for each TTL.

  get_ittl_lo
  get_ittl_hi
  get_run_ttl

[ $DEBUG -eq 1 ] && \
  echo "TTL = ${iTTLlo}:${iTTLhi}:${runTTL}"

return 0
}

#
# Takes MAP name (with or without domain name) as argument, asks
# user for TTL values, and appends the entry in the mapping file.
#
process_one_map_ttl_value()
{

_Map_="$1"

get_confirm "Retain the default TTL values [$DEF_iTTLlo:$DEF_iTTLhi:$DEF_runTTL] for \"$_Map_\" (y/n/h) ?" \
            "y" "default_different_ttl_help"

if [ $? -eq 1 ]; then
  print_one_map_ttl_entry $_Map_ $DEF_iTTLlo $DEF_iTTLhi $DEF_runTTL
else

  echo "Reading TTL values for $_Map_ :"
  read_one_ttl_triplet
  print_one_map_ttl_entry $_Map_ $iTTLlo $iTTLhi $runTTL

fi
return 0
}


#
# Read only one TTL triplet for each existing MAP without asking
# different values for each domain and update the mapping file.
#
read_all_maps_ttl_values_no_multiple_domain_issue()
{

# Need to read only one TTL triplet for each existing MAP.

for _MAP in ${DEF_TTL_MAPLIST} ${ALL_DMN_CUST_MAPS[*]} \
            ${ALL_DMN_AUTO_CUST_MAPS[*]}
do

  if [ "$_MAP" != "passwd.adjunct.byname" ] && \
	[ "$_MAP" != "group.adjunct.byname" ] 
  then
    process_one_map_ttl_value $_MAP

  else

    # adjunct maps might not exist in all the domains.
    find_domains $_MAP DEF_MAPS

    if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
    then

      # Don't put domain info as the map is present in all of them.
      process_one_map_ttl_value $_MAP

    else

      for _DMN_ in $PRESENT_IN_DOMAINS
      do
        _STR="${_MAP},${_DMN_}"
        process_one_map_ttl_value $_STR
      done

    fi
  fi
done

return 0
}


#
# Read TTL triplet for each default MAP (in database ID form) while
# taking care of multiple domains issue and update the mapping file.
#
read_default_maps_ttl_values_with_multi_domain_issue()
{

for _MAP_ in ${DEF_TTL_MAPLIST}
do
  if [ "$_MAP_" != "passwd.adjunct.byname" ] && \
	[ "$_MAP_" != "group.adjunct.byname" ]
  then

    for _DMN_ in ${N2L_DMN_LIST[*]}
    do
      _STR_="${_MAP_},${_DMN_}"
      # Now process each combination one at a time.
      process_one_map_ttl_value "$_STR_"
    done

  else
    # List only those domains in which adjunct.byname exists.
    find_domains $_MAP_ DEF_MAPS
    for _DMN_ in $PRESENT_IN_DOMAINS
    do
      _STR_="${_MAP_},${_DMN_}"
      process_one_map_ttl_value "$_STR_"
    done
  fi
done

return 0
}


#
# Read TTL triplet for each existing custom MAP while taking
# care of multiple domains issue and update the mapping file.
#
read_custom_maps_ttl_values_with_multi_domain_issue()
{

for _MAP_ in ${ALL_DMN_CUST_MAPS[*]} ${ALL_DMN_AUTO_CUST_MAPS[*]}
do

  find_map_presence_details $_MAP_

  if [ $PRESENT_COUNT -eq 1 ]; then

    # This map exists in only one domain.
    # So, no need to ask for multiple domains.

    process_one_map_ttl_value $_MAP_

  else

    # Handle multiple domains.

    echo "Map \"${_MAP_}\" is present in these domains : $PRESENT_IN_DOMAINS"

    get_confirm "For this map, do you wish to use the same TTL values for all the domains (y/n/h) ?" \
                "y" "same_ttl_across_domains_help"

    if [ $? -eq 1 ]; then

      # Need to read only one TTL triplet for this MAP.
      process_one_map_ttl_value $_MAP_

    else

      # Need to ask for each domain

      for _DMN_ in $PRESENT_IN_DOMAINS
      do
        _STR="${_MAP_},${_DMN_}"

        # Now process each combination one at a time.
        process_one_map_ttl_value "$_STR"

      done
    fi
  fi
done

return 0
}


#
# List the TTL values for various MAPs
#
create_nisLDAPentryTtl()
{

echo "\
# Associate TTLs with NIS entries derived from LDAP
" >> $MAP_FILE

[ CUST_CMT_NEEDED -eq 1 ] && echo "\
# Each map has three TTL values which are specified in seconds.
# 1. initialTTLlo (default $DEF_iTTLlo sec) The lower limit for the initial
#    TTL (in seconds) for data read from disk when the ypserv starts.
#
# 2. initialTTLhi (default $DEF_iTTLhi sec) The upper limit for initial TTL.
#
# 3. runningTTL   (default $DEF_runTTL sec) The TTL (in seconds) for data 
#    retrieved from LDAP while the ypserv is running.
#
# If any value is not specified, then default value is used.
# The format of TTL entry is :
# nisLDAPentryTtl   MAP[,DOMAIN]:initialTTLlo:initialTTLhi:runningTTL
" >> $MAP_FILE

# If no maps are present, just return.
[ ${#ALL_DMN_ALL_MAPS[*]} -eq 0 ] && return 0

echo "The default TTL for each map is set to ${DEF_iTTLlo}:${DEF_iTTLhi}:${DEF_runTTL}"
get_confirm "Do you wish to change the TTL values for any map (y/n/h) ?" \
            "n" "default_ttl_help"

if [ $? -eq 0 ]; then
  # Default values accepted for all the maps.
  # So, just print all the maps with default TTL values.

  print_all_same_ttl_entries $DEF_iTTLlo $DEF_iTTLhi $DEF_runTTL

else
  echo "You would be allowed to enter the new TTL values."
  get_confirm "Do you wish to use the same TTL values for all the maps (y/n/h) ?" \
              "y" "non_default_same_ttl_help"

  if [ $? -eq 1 ]; then
    # Need to read only one TTL triplet.
    # Print all the maps with new TTL triplet.

    # read one ttl triplet
    echo "Enter the new TTL values :"

    read_one_ttl_triplet

    print_all_same_ttl_entries $iTTLlo $iTTLhi $runTTL
    
  else
    if [ $N2L_DMN_CNT -eq 1 ]; then

      # TTL values are different now. But we haev only one domain.
      # So, no need to worry about multiple domains. Need to read
      # only one TTL triplet for each existing MAP.

      read_all_maps_ttl_values_no_multiple_domain_issue

    else

      # TTL values are different now. And we have multiple domains
      # too. Check if MAPS are going to have same TTL across domains.
      # This is just to avoid asking too many TTL triplet inputs 

      echo "You would be allowed to enter different TTL values for each map."

      get_confirm "For a given map, do you wish to use the same TTL values for all the domains (y/n/h) ?" \
                  "y" "non_default_different_ttl_help"

      if [ $? -eq 1 ]; then

        # Need to read only one TTL triplet for each existing MAP.
        read_all_maps_ttl_values_no_multiple_domain_issue

      else

        # We have hit the worst case scenario. TTLs could be 
        # different per map and per domain.

        read_default_maps_ttl_values_with_multi_domain_issue
        read_custom_maps_ttl_values_with_multi_domain_issue
      fi
    fi
  fi
fi

echo "
#
#------------------------------------------------------------------------------
#
" >> $MAP_FILE

return 0
}


#
# The custom maps for which we do not have enough
# information to be able to generate specific entries,
# we just log the message that the user needs to take
# care of those entries manually.
#
ask_user_to_update_the_custom_map_entries_too()
{

if [ ${#ALL_DMN_CUST_MAPS[*]} -gt 0 ]; then

  echo "
# Similar entries need to be created
# for following custom maps too :\
" >> $MAP_FILE

  for _MAP in ${ALL_DMN_CUST_MAPS[*]}
  do
    echo "# $_MAP" >> $MAP_FILE
  done
fi
}


put_default_nisLDAPnameFields()
{
echo '
# Associate names with fields in the maps. Must be same for all domains.
nisLDAPnameFields audit_user: \
			("%s:%s:%s", name, alwaysAuditFlags, neverAuditFlags)

nisLDAPnameFields auto.home: \
			("%s",value)

nisLDAPnameFields auto.master: \
			("%s",value)

nisLDAPnameFields auth_attr: \
			("%s:%s:%s:%s:%s:%s", \
			name, res1, res2, short_desc, long_desc, attrs )

nisLDAPnameFields bootparams: \
			("%s", params)

nisLDAPnameFields ethers: \
			("%s %s", addr, name)

nisLDAPnameFields exec_attr: \
			("%s:%s:%s:%s:%s:%s:%s", \
			name, policy, type, res1, res2, id, attrs)

nisLDAPnameFields group: \
			("%s:%s:%s:%s", name, passwd, gid, users)
' >> $MAP_FILE

# Need to handle group.adjunct.byname map for multiple domain. 

_MAP=group.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo '#nisLDAPnameFields group.adjunct.byname: \
#			("%s:%s", name, passwd)
' >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then

    # Don't put domain info as the map is present in all of them.
    echo 'nisLDAPnameFields group.adjunct.byname: \
			("%s:%s", name, passwd)
' >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPnameFields group.adjunct.byname,${_DMN}: \\
			(\"%s:%s\", name, passwd)
" >> $MAP_FILE
    done
  fi
fi

echo 'nisLDAPnameFields keys.host: \
			("%s:%s", publicKey ,secretKey)

nisLDAPnameFields keys.pass: \
			("%s:%s", publicKey ,secretKey)

nisLDAPnameFields keys.nobody: \
			("%s:%s", publicKey ,secretKey)

nisLDAPnameFields hosts: \
			("%a %s %s", addr, canonicalName, aliases)

nisLDAPnameFields multihosts: \
			("%a %s %s", addr, canonicalName, aliases)

nisLDAPnameFields ipnodes: \
			("%a %s %s", addr, canonicalName, aliases)

nisLDAPnameFields multiipnodes: \
			("%a %s %s", addr, canonicalName, aliases)

nisLDAPnameFields mail.aliases: \
			("%s", addresses)

nisLDAPnameFields mail.mapping: \
			("%s", address)

# memberTriples	is split into sub-fields by a latter nisLDAPsplitField
# attribute.
nisLDAPnameFields netgroup: \
			("%s", memberTriples)

nisLDAPnameFields netid.host: \
			("%s:%s", number, data)

nisLDAPnameFields netid.pass: \
			("%s:%s", number, data)

nisLDAPnameFields netmasks.byaddr: \
			("%a", mask)

nisLDAPnameFields networks: \
			("%s %s %s", name, number, aliases)

nisLDAPnameFields project: \
			("%s:%s:%s:%s:%s:%s", \
			name, projID, comment, users, groups, attrs)

nisLDAPnameFields protocols:	\
			("%s %s %s", name, number, aliases)

nisLDAPnameFields rpc.bynumber:	\
			("%s %s %s", name, number, aliases)

nisLDAPnameFields passwd: \
			("%s:%s:%s:%s:%s:%s:%s", \
			name, passwd, uid, gid, gecos, home, shell)

# It is not obvious what the fields in passwd.adjunct are for. They are not
# the same as the shadow map. The following is based on information in:-
#
#	lib/libbc/inc/include/pwdadj.h.
#
# This file implies that these are documented in getpwaent(3) but this man page
# does not seem to exist.
#			
# It is believed that 'min','max' and 'def' labels were reserved fields in 
# SunOS 4.x and are now unused.  'always' and 'never' audit information is 
# now contained in audit_user(4) so is now unused.
#
' >> $MAP_FILE

# Need to handle passwd.adjunct.byname map for multiple domain. 

_MAP=passwd.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo '#nisLDAPnameFields passwd.adjunct.byname: \
#			("%s:%s:%s:%s:%s:%s:%s", \
#			name, passwd, min, max, def, always, \
#			never)
' >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS

  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then

    # Don't put domain info as the map is present in all of them.
    echo 'nisLDAPnameFields passwd.adjunct.byname: \
			("%s:%s:%s:%s:%s:%s:%s", \
			name, passwd, min, max, def, always, \
			never)
' >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPnameFields passwd.adjunct.byname,${_DMN}: \\
			(\"%s:%s:%s:%s:%s:%s:%s\", \\
                        name, passwd, min, max, def, always, \\
                        never)
" >> $MAP_FILE
    done
  fi
fi

echo '
nisLDAPnameFields printers.conf.byname: \
			("%s:%s", names, values)

nisLDAPnameFields prof_attr: \
			("%s:%s:%s:%s:%s", \
			name, res1, res2, desc, attrs)

nisLDAPnameFields services: \
			("%s %s/%s %s", name, port, protocol, aliases)

# This map is never created but yppasswd uses the mapping to extract password
# ageing information from the DIT. The password itself is not required by this
# mechanism so is not included in the ageing mapping.
nisLDAPnameFields ageing.byname: \
			("%s:%s:%s:%s:%s:%s:%s:%s", \
			name, lastchg, min, max, warn, inactive, \
			expire, flag)

nisLDAPnameFields timezone.byname: \
			("%s %s", zoneName, hostName)

nisLDAPnameFields user_attr: \
			("%s:%s:%s:%s:%s", user, qualifier, res1, res2, attrs)
' >> $MAP_FILE
}

#
# List namefields for non-default auto maps and custom maps.
#
put_auto_and_custom_map_nisLDAPnameFields()
{
for _MAP in ${ALL_DMN_AUTO_CUST_MAPS[*]} ${ALL_DMN_CUST_MAPS[*]}
do

  echo "\
nisLDAPnameFields ${_MAP}: \\
                      (\"%s\",value)
" >> $MAP_FILE

done
}


create_nisLDAPnameFields()
{
# Put format information of "nisLDAPnameFields"
[ CUST_CMT_NEEDED -eq 1 ] && echo '
# "nisLDAPnameFields" specifies the content of entries in a NIS map
# and how they should be broken into named fields. It is required as,
# unlike NIS+, NIS maps do not store information in named fields.
#
# Following is the syntax for nisLDAPnameFields :
#
# "nisLDAPnameFields" mapName ":" "(" matchspec "," fieldNames ")"
# fieldName       = nameOrArrayName[","...]
# nameOrArrayName = Name of field or 'array' of repeated fields.
# matchspec       = \" formatString \"
' >> $MAP_FILE

# List the default nameField values
put_default_nisLDAPnameFields

# List the underlying assumption
echo "\
# With the assumption that all the custom maps are simple, single
# map (single key-value pair type), below is the nisLDAPnameFields
# information for all the custom and non-default auto.* maps. If
# this assumption is not valid, then refer to the NISLDAPmapping
# man page for information on how to customize this section.
" >> $MAP_FILE

# List namefields for non-default auto maps and custom maps.
put_auto_and_custom_map_nisLDAPnameFields


echo "
#
#------------------------------------------------------------------------------
#
" >> $MAP_FILE

return 0
}


#
# List repeated field seperators
#
create_nisLDAPrepeatedFieldSeparators()
{

[ CUST_CMT_NEEDED -eq 1 ] && echo "
# nisLDAPrepeatedFieldSeparators : It is a character which separates
# the repeatable instnaces of splitable fields. It's format is :
#
# nisLDAPrepeatedFieldSeparators fieldName \"sepChar[...]\"
#               sepChar = A separator character.
#               Default value is space or tab.
" >> $MAP_FILE

echo "\
#nisLDAPrepeatedFieldSeparators memberTriples: \" \t\"
" >> $MAP_FILE

}


#
# List split fields
#
create_nisLDAPsplitField()
{
# List the default split fields

[ CUST_CMT_NEEDED -eq 1 ] && echo '
# nisLDAPsplitFields : It defines how a field, or list of fields,
# named by nisLDAPnameFields is split into sub fields. The original
# field is compared with each line of this attribute until one matches.
# When a match is found named sub-fields are generated. In latter
# operations sub-field names can be used in the same way as other
# field names. The format of nisLDAPsplitFields is :
#
# "nisLDAPsplitFields" fieldName ":" splitSpec[","...]
# splitSpec       = "(" matchspec "," subFieldNames ")"
# fieldName       = Name of a field from nisLDAPnameFields
# subFieldNames   = subFieldname[","...]
# matchspec       = \" formatString \"  
' >> $MAP_FILE

echo '
nisLDAPsplitField memberTriples: \
			("(%s,%s,%s)", host, user, domain), \
			("%s", group)
' >> $MAP_FILE

}

#
# List split fields and repeated field separators.
#
create_split_field_and_repeatedfield_seperators()
{

echo "\
# Specify how to break fields up into sub fields.
" >> $MAP_FILE

create_nisLDAPrepeatedFieldSeparators

create_nisLDAPsplitField

echo "
#
#------------------------------------------------------------------------------
#
" >> $MAP_FILE
}

list_default_nisLDAPobjectDN()
{
echo '
# Associate maps with RDNs and object classes. Base DN comes from the 
# nisLDAPdomainContext.
#
# As supplied this file gives only the most derived objectClass for each map.
# For some servers it may be necessary to add "objectClass=" statements for 
# all the superclasses. This should be done here.

nisLDAPobjectDN	auto.home: \
			automountmapname=auto_home,?one? \
			objectClass=automount:

nisLDAPobjectDN	auto.master: \
			automountmapname=auto_master,?one? \
			objectClass=automount:

nisLDAPobjectDN	auth_attr: \
			ou=SolarisAuthAttr,?one? \
			objectClass=SolarisAuthAttr:

nisLDAPobjectDN	bootparams: \
			ou=ethers,?one? \
			objectClass=bootableDevice, \
			bootParameter=*:\
			ou=ethers,?one? \
			objectClass=device, \
			objectClass=bootableDevice 


nisLDAPobjectDN exec_attr:\
			ou=SolarisProfAttr,?one?objectClass=SolarisExecAttr,\
				SolarisKernelSecurityPolicy=*:\
			ou=SolarisProfAttr,?one?objectClass=SolarisExecAttr,\
				objectClass=SolarisProfAttr,\
				objectClass=top

nisLDAPobjectDN	ethers: \
			ou=ethers,?one? \
			objectClass=ieee802Device, \
			macAddress=*:\
			ou=ethers,?one? \
			objectClass=device, \
			objectClass=ieee802Device

nisLDAPobjectDN	group: \
			ou=group,?one? \
			objectClass=posixGroup:
' >> $MAP_FILE


# Need to handle group.adjunct.byname map for multiple domain.

_MAP=group.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo '#nisLDAPobjectDN group.adjunct.byname: \
#			ou=group,?one? \
#			objectClass=posixGroup:
' >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then
    # Don't put domain info as the map is present in all of them.
    echo 'nisLDAPobjectDN group.adjunct.byname: \
			ou=group,?one? \
			objectClass=posixGroup:
' >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPobjectDN group.adjunct.byname,${_DMN}: \\
			ou=group,?one? \\
			objectClass=posixGroup:
" >> $MAP_FILE
    done
  fi
fi


echo 'nisLDAPobjectDN	hosts: \
			ou=hosts,?one? \
			objectClass=ipHost:\
			ou=hosts,?one? \
			objectClass=device, \
			objectClass=ipHost

nisLDAPobjectDN multihosts: \
			ou=hosts,?one? \
			objectClass=ipHost, \
			ipHostNumber=*.*

nisLDAPobjectDN	ipnodes: \
			ou=hosts,?one? \
			objectClass=ipHost:\
			ou=hosts,?one? \
			objectClass=device, \
			objectClass=ipHost

nisLDAPobjectDN multiipnodes: \
			ou=hosts,?one? \
			objectClass=ipHost, \
			ipHostNumber=*\:*

nisLDAPobjectDN	mail.aliases: \
			ou=aliases,?one? \
			objectClass=mailGroup:

nisLDAPobjectDN	mail.mapping: \
			ou=aliases,?one? \
			objectClass=mailGroup

nisLDAPobjectDN	netgroup: \
			ou=netgroup,?one? \
			objectClass=nisNetgroup:

nisLDAPobjectDN	networks: \
			ou=networks,?one? \
			objectClass=ipNetwork, \
			cn=*:

# Must come after networks (or equivalent) that creates ipNetworks
nisLDAPobjectDN netmasks.byaddr: \
			ou=networks,?one? \
			objectClass=ipNetwork, \
			ipNetMaskNumber=*:

nisLDAPobjectDN	passwd: \
			ou=people,?one? \
			objectClass=posixAccount:\
			ou=people,?one? \
			objectClass=account, \
			objectClass=shadowAccount, \
			objectClass=posixAccount
' >> $MAP_FILE


# Need to handle passwd.adjunct.byname map for multiple domain.

_MAP=passwd.adjunct.byname
if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then
  # Just put the syntax in comment form
  echo '#nisLDAPobjectDN passwd.adjunct.byname: \
#			ou=people,?one? \
#			objectClass=posixAccount:\
#			ou=people,?one? \
#			objectClass=account, \
#			objectClass=shadowAccount, \
#			objectClass=posixAccount
' >> $MAP_FILE
else
  # Find the domains in which this map exists.
  find_domains $_MAP DEF_MAPS
  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then
    # Don't put domain info as the map is present in all of them.
    echo 'nisLDAPobjectDN passwd.adjunct.byname: \
			ou=people,?one? \
			objectClass=posixAccount:\
			ou=people,?one? \
			objectClass=account, \
			objectClass=shadowAccount, \
			objectClass=posixAccount
' >> $MAP_FILE
  else
    # Not every domain has this map. So, list for the ones which do.
    for _DMN in $PRESENT_IN_DOMAINS
    do
      echo "nisLDAPobjectDN passwd.adjunct.byname,${_DMN}: \\
			ou=people,?one? \\
			objectClass=posixAccount:\\
			ou=people,?one? \\
			objectClass=account, \\
			objectClass=shadowAccount, \\
			objectClass=posixAccount
" >> $MAP_FILE
    done
  fi
fi


echo '# Must follow passwd
nisLDAPobjectDN netid.pass: \
			ou=people,?one? \
			objectClass=posixAccount

# Must follow hosts
nisLDAPobjectDN netid.host: \
			ou=hosts,?one? \
			objectClass=ipHost

nisLDAPobjectDN	printers.conf.byname: \
			ou=printers,?one? \
				objectClass=printerService:\
			ou=printers,?one? \
				objectClass=sunPrinter, \
				objectClass=printerService, \
				objectClass=printerLPR, \
				objectClass=printerAbstract

nisLDAPobjectDN prof_attr:\
			ou=SolarisProfAttr,?one?objectClass=SolarisProfAttr,\
				SolarisAttrLongDesc=*:\
			ou=SolarisProfAttr,?one?objectClass=SolarisProfAttr,\
				objectClass=SolarisExecAttr,\
				objectClass=top
nisLDAPobjectDN project: \
			ou=project,?one? \
			objectClass=SolarisProject:

nisLDAPobjectDN	protocols: \
			ou=protocols,?one? \
			objectClass=ipProtocol:

nisLDAPobjectDN rpc.bynumber: \
			ou=rpc,?one? \
			objectClass=oncRpc:

nisLDAPobjectDN	services.byname: \
			ou=services,?one? \
			objectClass=ipService:

# Because services.byservicename contains keys of form both 'name'
# and 'name/protocol' we generate the DIT just from services.byname.
# Hence, write-disabled for services.byservicename
nisLDAPobjectDN	services.byservicename: \
			ou=services,?one? \
			objectClass=ipService

# This map is never created but yppasswd uses the mapping to extract password
# aging information from the DIT.			
nisLDAPobjectDN	ageing.byname: \
			ou=people,?one? \
			objectClass=shadowAccount:

# Using nisplusTimeZoneData objectClass for compatibility with nis+2ldap
nisLDAPobjectDN	timezone.byname: \
			ou=Timezone,?one? \
			objectClass=nisplusTimeZoneData:

nisLDAPobjectDN	user_attr: \
			ou=people,?one? \
			objectClass=SolarisUserAttr:

# Must come after passwd (or equivalent) that creates posixAccounts
nisLDAPobjectDN	audit_user: \
			ou=people,?one? \
			objectClass=SolarisAuditUser:

# Must come after hosts + passwd.
nisLDAPobjectDN keys.host: \
			ou=hosts,?one? \
			objectClass=NisKeyObject:

nisLDAPobjectDN keys.pass: \
			ou=people,?one? \
			objectClass=NisKeyObject:

nisLDAPobjectDN keys.nobody: \
			ou=people,?one? \
			objectClass=NisKeyObject:\
			ou=people,?one? \
			objectClass=account, \
			objectClass=NisKeyObject
			
nisLDAPobjectDN ypservers: \
			ou=ypservers,?one? \
			objectClass=device:
' >> $MAP_FILE
}

# List all the non-default auto.* and custom maps.
list_auto_custom_nisLDAPobjectDN()
{

# auto.* entries are easy. 
if [ ${#ALL_DMN_AUTO_CUST_MAPS[*]} -gt 0 ]; then
  echo "# Non-default custom auto maps (auto.*)\n" >> $MAP_FILE

  for _MAP in ${ALL_DMN_AUTO_CUST_MAPS[*]}
  do

    # We need to find one container for each auto.* map.
    # Assume that each auto.* maps's container is auto_*.

    _MAP_UNDERSCORE=`echo $_MAP | sed "s/auto\./auto_/"`

    echo "\
nisLDAPobjectDN ${_MAP}: \\
                      automountmapname=${_MAP_UNDERSCORE},?one? \\
                      objectClass=automount:
" >> $MAP_FILE
  done
fi

# Since we do not have enough information to generate
# entries for other custom maps, best we can do is to
# log this map names and ask user to take care of them.

ask_user_to_update_the_custom_map_entries_too

}


#
# List association of maps with RDNs and object classes.
#
create_nisLDAPobjectDN()
{

[ CUST_CMT_NEEDED -eq 1 ] && echo '
# nisLDAPobjectDN : It specifies the connection between group of NIS
# maps and the LDAP directory. This attribute also defines the 'order'
# of the NIS maps. When NIS maps are bulk copied to or from the DIT
# they are processed in the same order as related nisLDAPobjectDN
# attributes appear in /var/yp/NISLDAPmapping.
# The format of "nisLDAPobjectDN" is :
# 
# mapName[" "...] ":" objectDN *( ";" objectDN )
# 
# where:
# 
# objectDN        = readObjectSpec [":"[writeObjectSpec]]
# readObjectSpec  = [baseAndScope [filterAttrValList]]
# writeObjectSpec = [baseAndScope [attrValList]]
# baseAndScope    = [baseDN] ["?" [scope]]
# filterAttrValList = ["?" [filter | attrValList]]]
# scope           = "base" | "one" | "sub"
# attrValList     = attribute "=" value
#                       *("," attribute "=" value)
' >> $MAP_FILE

# List all the default entries anyway.
list_default_nisLDAPobjectDN

# List all the non-default auto.* and custom maps.
list_auto_custom_nisLDAPobjectDN

}

#
# List all the default nisLDAPattributeFromField entries
#
list_default_nisLDAPattributeFromField()
{
echo '
# Describe how named fields are mapped to DIT entries.

# audit_user
nisLDAPattributeFromField audit_user: \
			dn=("uid=%s,", rf_key ), \
			SolarisAuditAlways=alwaysAuditFlags, \
			SolarisAuditNever=neverAuditFlags

# auto.home
nisLDAPattributeFromField auto.home: \
			dn=("automountKey=%s,", rf_key ), \
			automountKey=rf_key, \
			automountInformation=value

# auto.master
nisLDAPattributeFromField auto.master: \
			dn=("automountKey=%s,", rf_key ), \
			automountKey=rf_key, \
			automountInformation=value

# auth_attr
nisLDAPattributeFromField auth_attr: \
			dn=("cn=%s,", rf_key ), \
			cn=name, \
			SolarisAttrReserved1=res1, \
			SolarisAttrReserved2=res2, \
			SolarisAttrShortDesc=short_desc, \
			SolarisAttrLongDesc=long_desc, \
			SolarisAttrKeyValue=attrs

# exec_attr. Because of the messy NIS keys special handling is required here
nisLDAPattributeFromField exec_attr: \
			dn=("cn=%s+SolarisKernelSecurityPolicy=%s\
				+SolarisProfileType=%s+SolarisProfileID=%s,", \
				name, policy,type,id), \
			("%s:*", cn)=rf_key, \
			("*:%s:*", SolarisKernelSecurityPolicy)=rf_key, \
			("*:*:%s", SolarisProfileId)=rf_key, \
			solarisProfileType=type, \
			solarisAttrReserved1=res1, \
			SolarisAttrReserved2=res2, \
			solarisAttrKeyValue=attrs

# ethers
nisLDAPattributeFromField ethers.byname: \
			dn=("cn=%s,", rf_key ), \
			macAddress=addr
nisLDAPattributeFromField ethers.byaddr: \
			dn=("cn=%s,", name ), \
			macAddress=rf_key
nisLDAPattributeFromField ethers: \
			cn=name, \
			description=rf_comment

# bootparams. Must be done after ethers
nisLDAPattributeFromField bootparams: \
			dn=("cn=%s,", rf_key ), \
			cn=rf_key, \
			(bootParameter)=(params, " ")
' >> $MAP_FILE

# group syntax is different when group.adjunct map is present.
# So, need to handle the various possibilities

_MAP=group.adjunct.byname

if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then

  # Just put the group.adjunct syntax in comment form

  echo '# group
nisLDAPattributeFromField group.byname: \
			dn=("cn=%s,", rf_key ), \
                        gidNumber=gid
nisLDAPattributeFromField group.bygid: \
		        dn=("cn=%s,", name ), \
                        gidNumber=rf_key
nisLDAPattributeFromField group: \
                        cn=name, \
                        userPassword=("{crypt}%s",passwd), \
                        (memberUid)=(users, ",")

#
# If you are using group.adjunct, comment the group section above
# and uncomment the following group and group.adjunct sections
#
# group
#nisLDAPattributeFromField group.byname: \
#			dn=("cn=%s,", rf_key ), \
#			gidNumber=gid
#nisLDAPattributeFromField group.bygid: \
#			dn=("cn=%s,", name ), \
#			gidNumber=rf_key
#nisLDAPattributeFromField group: \
#			cn=name, \
#			(memberUid)=(users, ",")

# group.adjunct
#nisLDAPattributeFromField group.adjunct.byname: \
#			dn=("cn=%s,", rf_key ), \
#			cn=name, \
#			userPassword=("{crypt}%s",passwd)
' >> $MAP_FILE

else

  # Find the domains in which group.adjunct map exists.
  find_domains $_MAP DEF_MAPS

  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then

    # All the domains have group.adjunct map.

    echo '# group
#nisLDAPattributeFromField group.byname: \
#			dn=("cn=%s,", rf_key ), \
#			gidNumber=gid
#nisLDAPattributeFromField group.bygid: \
#			dn=("cn=%s,", name ), \
#			gidNumber=rf_key
#nisLDAPattributeFromField group: \
#			cn=name, \
#			userPassword=("{crypt}%s",passwd), \
#			(memberUid)=(users, ",")

# If you are not using group.adjunct, uncomment the group section above
# and comment the following group and group.adjunct sections
#
# group
nisLDAPattributeFromField group.byname: \
			dn=("cn=%s,", rf_key ), \
			gidNumber=gid
nisLDAPattributeFromField group.bygid: \
			dn=("cn=%s,", name ), \
			gidNumber=rf_key
nisLDAPattributeFromField group: \
			cn=name, \
			(memberUid)=(users, ",")

# group.adjunct
nisLDAPattributeFromField group.adjunct.byname: \
			dn=("cn=%s,", rf_key ), \
			cn=name, \
			userPassword=("{crypt}%s",passwd)
' >> $MAP_FILE

  else
    # Not every domain has group.adjunct map.

    # First put the password syntax with domain name for domains
    # in which group.adjunct exists.

    echo "# group" >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
# domain-specific group
nisLDAPattributeFromField group.byname,${_DMN}: \\
			dn=(\"cn=%s,\", rf_key ), \\
			gidNumber=gid
nisLDAPattributeFromField group.bygid,${_DMN}: \\
			dn=(\"cn=%s,\", name ), \\
			gidNumber=rf_key
nisLDAPattributeFromField group,${_DMN}: \\
			cn=name, \\
			(memberUid)=(users, \",\")
" >> $MAP_FILE
    done

    # Now put the other group syntax. We do not need to
    # append the domain name here.

    echo '
nisLDAPattributeFromField group.byname: \
			dn=("cn=%s,", rf_key ), \
			gidNumber=gid
nisLDAPattributeFromField group.bygid: \
			dn=("cn=%s,", name ), \
			gidNumber=rf_key
nisLDAPattributeFromField group: \
			cn=name, \
			userPassword=("{crypt}%s",passwd), \
			(memberUid)=(users, ",")
' >> $MAP_FILE

    # Now we need to put the group.adjunct syntax for domains
    # in which this map exists.

    echo "# group.adjunct" >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPattributeFromField group.adjunct.byname,${_DMN}: \\
			dn=(\"cn=%s,\", rf_key ), \\
			cn=name, \\
			userPassword=(\"{crypt}%s\",passwd)
" >> $MAP_FILE
    done

  fi

fi


echo '
# hosts
# Cannot forward map hosts.byname key as the YP_MULTI entries will not work.
nisLDAPattributeFromField hosts.byname: \
                        cn=rf_searchkey
nisLDAPattributeFromField hosts.byaddr: \
                        ipHostNumber=rf_searchipkey
nisLDAPattributeFromField hosts: \
                        ipHostNumber=addr, \
			dn=("cn=%s+ipHostNumber=%s,", canonicalName, addr), \
                        cn=canonicalName, \
                        (cn)=(aliases, " "), \
                        description=rf_comment

nisLDAPattributeFromField multihosts: \
			("YP_MULTI_%s", cn)=rf_searchkey

# ipnodes
# Cannot forward map ipnodes.byname key as the YP_MULTI entries will not work.
nisLDAPattributeFromField ipnodes.byname: \
                        cn=rf_searchkey
nisLDAPattributeFromField ipnodes.byaddr: \
                        ipHostNumber=rf_searchipkey
nisLDAPattributeFromField ipnodes: \
                        ipHostNumber=addr, \
			dn=("cn=%s+ipHostNumber=%s,", canonicalName, addr), \
			cn=canonicalName, \
                        (cn)=(aliases, " "), \
                        description=rf_comment

nisLDAPattributeFromField multiipnodes: \
			("YP_MULTI_%s", cn)=rf_searchkey

#mail.aliases
nisLDAPattributeFromField mail.aliases: \
			dn=("mail=%s,", rf_key), \
			mail=rf_key, \
			(mgrprfc822mailmember)=(addresses, ",")

#mail.mapping
#Commented out because all NIS->LDAP mappings are done by mail.aliases
#nisLDAPattributeFromField mail.mapping: \
#			dn=("mail=%s,", address), \
#			mail=address, \
#			mgrprfc822mailmember=rf_key
nisLDAPattributeFromField mail.mapping: \
			mgrprfc822mailmember=rf_searchkey

# netgroup.
#
# Only need to create DIT entries for netgroup. This contains a superset of
# the information in netgroup.byhost and netgroup.byuser
nisLDAPattributeFromField netgroup: \
			dn=("cn=%s,", rf_key ), \
			(memberNisNetgroup)=group, \
			(nisNetgroupTriple)= \
					("(%s,%s,%s)", host, user, domain), \
			cn=rf_key, \
			description=rf_comment

# netid.pass
#
# Commented out because, unless remote domains (and thus /etc/netid) is
# supported, all NIS->LDAP mappings are set up from passwd.
#nisLDAPattributeFromField netid.pass: \
#			("unix.%s@*", uidNumber)=rf_key, \
#			(gidNumber)=("%s", (data), " "), \
#			description=rf_comment
nisLDAPattributeFromField netid.pass: \
			("unix.%s@*", uidNumber)=rf_searchkey

# netid.host
#
# Commented out because, unless remote domains (and thus /etc/netid) is
# supported, all NIS->LDAP mappings are set up from hosts.
#nisLDAPattributeFromField netid.host: \
#			dn=("cn=%s+ipHostNumber=%s,", data, \
#			        ldap:ipHostNumber:?one?("cn=%s", data)), \
#			ipHostNumber=ldap:ipHostNumber:?one?("cn=%s", data), \
#			("unix.%s@*", cn)=rf_key, \
#			description=rf_comment
nisLDAPattributeFromField netid.host: \
			("unix.%s@*", cn)=rf_searchkey

# netmasks.byaddr
nisLDAPattributeFromField netmasks.byaddr: \
			dn=("ipNetworkNumber=%s,", rf_ipkey ), \
			ipNetworkNumber=rf_ipkey, \
			ipNetmaskNumber=mask, \
			description=rf_comment

# networks.
nisLDAPattributeFromField networks.byname: \
			dn=("ipNetworkNumber=%s,", number ), \
			cn=name, \
			cn=rf_key
nisLDAPattributeFromField networks.byaddr: \
			dn=("ipNetworkNumber=%s,", rf_key ), \
			cn=name
nisLDAPattributeFromField networks: \
			(cn)=(aliases, " "), \
			ipNetworkNumber=number, \
			description=rf_comment
' >> $MAP_FILE


# passwd syntax is different when passwd.adjunct map is present.
# So, need to handle the various possibilities

_MAP=passwd.adjunct.byname

if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then

  # Just put the passwd.adjunct syntax in comment form

  echo '# passwd
nisLDAPattributeFromField passwd.byname: \
			dn=("uid=%s,", rf_key ), \
			uid=rf_key, \
			uidNumber=uid
nisLDAPattributeFromField passwd.byuid: \
			dn=("uid=%s,", name ), \
			uidNumber=rf_key, \
			uid=name
nisLDAPattributeFromField passwd: \
			cn=name, \
			userPassword=("{crypt}%s",passwd), \
			gidNumber=gid, \
			gecos=gecos, \
			homeDirectory=home, \
			loginShell=shell

#
# If you are using passwd.adjunct, comment the passwd section above
# and uncomment the following passwd and passwd.adjunct sections
#
# passwd
#nisLDAPattributeFromField passwd.byname: \
#			dn=("uid=%s,", rf_key ), \
#			uid=rf_key, \
#			uidNumber=uid
#nisLDAPattributeFromField passwd.byuid: \
#			dn=("uid=%s,", name ), \
#			uidNumber=rf_key, \
#			uid=name
#nisLDAPattributeFromField passwd: \
#			cn=name, \
#			gidNumber=gid, \
#			gecos=gecos, \
#			homeDirectory=home, \
#			loginShell=shell

# passwd.adjunct
#nisLDAPattributeFromField passwd.adjunct.byname: \
#			dn=("uid=%s,", rf_key ), \
#			uid=name, \
#			userPassword=("{crypt}%s",passwd)
' >> $MAP_FILE

else

  # Find the domains in which passwd.adjunct map exists.
  find_domains $_MAP DEF_MAPS

  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then

    # All the domains have passwd.adjunct map. So, put the right
    # passwd syntax and comment-in the passwd.adjunct syntax.


    echo '# passwd
#nisLDAPattributeFromField passwd.byname: \
#			dn=("uid=%s,", rf_key ), \
#			uid=rf_key, \
#			uidNumber=uid
#nisLDAPattributeFromField passwd.byuid: \
#			dn=("uid=%s,", name ), \
#			uidNumber=rf_key, \
#			uid=name
#nisLDAPattributeFromField passwd: \
#			cn=name, \
#			userPassword=("{crypt}%s",passwd), \
#			gidNumber=gid, \
#			gecos=gecos, \
#			homeDirectory=home, \
#			loginShell=shell

# If you are not using passwd.adjunct, uncomment the passwd section above
# and comment the following passwd and passwd.adjunct sections
#
# passwd
nisLDAPattributeFromField passwd.byname: \
			dn=("uid=%s,", rf_key ), \
			uid=rf_key, \
			uidNumber=uid
nisLDAPattributeFromField passwd.byuid: \
			dn=("uid=%s,", name ), \
			uidNumber=rf_key, \
			uid=name
nisLDAPattributeFromField passwd: \
			cn=name, \
			gidNumber=gid, \
			gecos=gecos, \
			homeDirectory=home, \
			loginShell=shell

# passwd.adjunct
nisLDAPattributeFromField passwd.adjunct.byname: \
			dn=("uid=%s,", rf_key ), \
			uid=name, \
			userPassword=("{crypt}%s",passwd)
' >> $MAP_FILE

  else
    # Not every domain has passwd.adjunct map.

    # First put the password syntax with domain name for domains
    # in which passwd.adjunct exists.

    echo "# passwd" >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPattributeFromField passwd.byname,${_DMN}: \\
			dn=(\"uid=%s,\", rf_key ), \\
			uid=rf_key, \\
			uidNumber=uid
nisLDAPattributeFromField passwd.byuid,${_DMN}: \\
			dn=(\"uid=%s,\", name ), \\
			uidNumber=rf_key, \\
			uid=name
nisLDAPattributeFromField passwd,${_DMN}: \\
			cn=name, \\
			gidNumber=gid, \\
			gecos=gecos, \\
			homeDirectory=home, \\
			loginShell=shell
" >> $MAP_FILE
    done

    # Now put the other passwd syntax. We do not need to
    # append the domain name here.

    echo '
nisLDAPattributeFromField passwd.byname: \
			dn=("uid=%s,", rf_key ), \
			uid=rf_key, \
			uidNumber=uid
nisLDAPattributeFromField passwd.byuid: \
			dn=("uid=%s,", name ), \
			uidNumber=rf_key, \
			uid=name
nisLDAPattributeFromField passwd: \
			cn=name, \
			userPassword=("{crypt}%s",passwd), \
			gidNumber=gid, \
			gecos=gecos, \
			homeDirectory=home, \
			loginShell=shell
' >> $MAP_FILE

    # Now we need to put the passwd.adjunct syntax for domains
    # in which this map exists.

    echo "# passwd.adjunct" >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPattributeFromField passwd.adjunct.byname,${_DMN}: \\
			dn=(\"uid=%s,\", rf_key ), \\
			uid=name, \\
			userPassword=(\"{crypt}%s\",passwd)
" >> $MAP_FILE
    done

  fi

fi

echo '
# This map is never created but yppasswd uses the mapping to extract password
# aging information from the DIT.	
nisLDAPattributeFromField ageing.byname: \
			dn=("uid=%s,", rf_key ), \
			uid=name, \
			shadowLastChange=lastchg, \
			shadowMin=min, \
			shadowMax=max, \
			shadowWarning=warn, \
			shadowInactive=inactive, \
			shadowExpire=expire, \
			shadowFlag=flag

# printers.conf.byname
nisLDAPattributeFromField printers.conf.byname: \
			dn=("printer-uri=%s,", rf_key ), \
			printer-name=rf_key, \
			(printer-aliases)=(names, "|"), \
			sun-printer-bsdaddr=(values, "*bsdaddr=%s:*"), \
			(sun-printer-kvp)=(values,":"), \
			description=rf_comment 

# prof_attr
nisLDAPattributeFromField prof_attr: \
			dn=("cn=%s,", rf_key ), \
			cn=name, \
			SolarisAttrReserved1=res1, \
			SolarisAttrReserved2=res2, \
			SolarisAttrLongDesc=desc, \
			SolarisAttrKeyValue=attrs

# project
nisLDAPattributeFromField project.byname: \
			dn=("SolarisProjectName=%s,", rf_key )
nisLDAPattributeFromField project.byprojid: \
			dn=("SolarisProjectName=%s,", name ), \
			SolarisProjectID=rf_searchkey
nisLDAPattributeFromField project: \
			SolarisProjectName=name, \
			SolarisProjectID=projID, \
			(memberUid)=(users, ","), \
			(memberGid)=(groups, ","), \
			(SolarisProjectAttr)=(attrs, ";"), \
			description=comment

# protocols
nisLDAPattributeFromField protocols.byname: \
                        ipProtocolNumber=number, \
                        cn=rf_searchkey
nisLDAPattributeFromField protocols.bynumber: \
                        ipProtocolNumber=rf_key, \
                        description=rf_comment
nisLDAPattributeFromField protocols: \
			dn=("cn=%s,", name ), \
                        (cn)=(aliases, " "), \
			cn=name

# rpc.bynumber
nisLDAPattributeFromField rpc.bynumber: \
			dn=("cn=%s,", name ), \
			oncRpcNumber=rf_key, \
                        (cn)=(aliases, " "), \
			cn=name, \
			description=rf_comment 

# services
# services.byservicename rule is only used to speed single search
nisLDAPattributeFromField services.byservicename: \
			("%s/%s", cn, ipServiceProtocol) = rf_searchkey

nisLDAPattributeFromField services.byname: \
			dn=("cn=%s+ipServiceProtocol=%s,", name, protocol ), \
     			("*/%s", ipServiceProtocol)=rf_key, \
     			("%s/*", ipServicePort)=rf_key, \
                        (cn)=(aliases, " "), \
			cn=name, \
                        description=rf_comment

# timezone.byname
nisLDAPattributeFromField timezone.byname: \
			dn=("cn=%s,", rf_key ), \
			cn=hostName, \
			nisplusTimeZone=zoneName, \
			description=comment

# user_attr
nisLDAPattributeFromField user_attr: \
			dn=("uid=%s,", rf_key ), \
			uid=rf_key, \
			SolarisUserAttr=qualifier, \
			SolarisUserReserved1=res1, \
			SolarisUserReserved2=res2, \
			SolarisAttrKeyValue=attrs

# publickey.byname
nisLDAPattributeFromField keys.host: \
			dn=("%s", ldap:dn:?one?("cn=%s", (yp:rf_key, "unix.%s@*"))), \
			nisPublicKey=publicKey, \
			nisSecretKey=secretKey

nisLDAPattributeFromField keys.pass: \
			dn=("%s", ldap:dn:?one?("uidNumber=%s", (yp:rf_key, "unix.%s@*"))), \
			nisPublicKey=publicKey, \
			nisSecretKey=secretKey

nisLDAPattributeFromField keys.nobody: \
			dn=("uid=%s,",yp:rf_key), \
			cn=rf_key, \
			nisPublicKey=publicKey, \
			nisSecretKey=secretKey

# ypservers. This derived from IPlanet implementation not RFC.
nisLDAPattributeFromField ypservers: \
			dn=("cn=%s,", rf_key), \
			cn=rf_key
' >> $MAP_FILE
}

#
# List all the non-default auto.* and custom maps.
#
list_auto_and_custom_nisLDAPattributeFromField()
{

# auto.* entries are easy. 
if [ ${#ALL_DMN_AUTO_CUST_MAPS[*]} -gt 0 ]; then
  echo "# Non-default custom auto maps (auto.*)\n" >> $MAP_FILE
fi

for _MAP in ${ALL_DMN_AUTO_CUST_MAPS[*]}
do
  echo "\
# ${_MAP}
nisLDAPattributeFromField ${_MAP}: \\
                        dn=(\"automountKey=%s,\", rf_key ), \\
                        automountKey=rf_key, \\
                        automountInformation=value
" >> $MAP_FILE
done

# Since we do not have enough information to generate
# entries for other custom maps, best we can do is to
# log this map names and ask user to take care of them.

ask_user_to_update_the_custom_map_entries_too

}


#
# List mapping of named fields to DIT entries
#
create_nisLDAPattributeFromField()
{

[ CUST_CMT_NEEDED -eq 1 ] && echo '
# nisLDAPattributeFromField : It specifies how an LDAP attribute
# value is derived from a NIS entries field values.
# 
# The format of nisLDAPattributeFromField entry is :
# mapName ":" fieldattrspec *("," fieldattrspec )
' >> $MAP_FILE

# List all the default entries anyway.
list_default_nisLDAPattributeFromField

# List all the non-default auto.* and custom maps.
list_auto_and_custom_nisLDAPattributeFromField

echo "
#
#------------------------------------------------------------------------------
#			 
" >> $MAP_FILE
}


#
# List all the default nisLDAPattributeFromField entries
#
list_default_nisLDAPfieldFromAttribute()
{
echo '
# Describe how named fields are mapped from DIT entries.

# audit_user
nisLDAPfieldFromAttribute audit_user: \
			("uid=%s,*", rf_key)=dn, \
			("uid=%s,*", name)=dn, \
			alwaysAuditFlags=SolarisAuditAlways, \
			neverAuditFlags=SolarisAuditNever

# auto.home
nisLDAPfieldFromAttribute auto.home: \
			rf_key=automountKey, \
			value=automountInformation

# auto.master
nisLDAPfieldFromAttribute auto.master: \
			rf_key=automountKey, \
			value=automountInformation

# auth_attr
nisLDAPfieldFromAttribute auth_attr: \
			rf_key=cn, \
			name=cn, \
			res1=SolarisAttrReserved1, \
			res2=SolarisAttrReserved2, \
			short_desc=SolarisAttrShortDesc, \
			long_desc=SolarisAttrLongDesc, \
			attrs=SolarisAttrKeyValue

# Exec_attr. Because of messy NIS keys special handlind is required here
nisLDAPfieldFromAttribute exec_attr: \
			rf_key=("%s:%s:%s",cn,SolarisKernelSecurityPolicy, \
				solarisProfileId), \
			name=cn, \
			policy=SolarisKernelSecurityPolicy, \
			type=SolarisProfileType, \
			res1=SolarisAttrReserved1, \
			res2=SolarisAttrReserved2, \
			id=SolarisProfileId, \
			attrs=SolarisAttrKeyValue


# ethers
nisLDAPfieldFromAttribute ethers.byname: \
			rf_key=cn
nisLDAPfieldFromAttribute ethers.byaddr: \
			rf_key=macAddress
nisLDAPfieldFromAttribute ethers: \
			name=cn, \
			addr=macAddress, \
			rf_comment=description

# bootparams. Must be done after ethers
nisLDAPfieldFromAttribute bootparams: \
			rf_key=cn, \
			params=("%s ", (bootParameter), " ")
' >> $MAP_FILE

# group syntax is different when group.adjunct map is present.
# So, need to handle the various possibilities

_MAP=group.adjunct.byname

if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then

  # Just put the group.adjunct syntax in comment form

  echo '# group
nisLDAPfieldFromAttribute group.byname: \
			rf_key=cn
nisLDAPfieldFromAttribute group.bygid: \
                        rf_key=gidNumber
nisLDAPfieldFromAttribute group: \
                        gid=gidNumber, \
                        name=cn, \
			("{crypt}%s", passwd)=userPassword, \
			users=("%s,", (memberUid), ",")

#
# If you are using group.adjunct, comment the group section above
# and uncomment the following group and group.adjunct section
#			
# group
#nisLDAPfieldFromAttribute group.byname: \
#			rf_key=cn
#nisLDAPfieldFromAttribute group.bygid: \
#			rf_key=gidNumber
#nisLDAPfieldFromAttribute group: \
#			gid=gidNumber, \
#			name=cn, \
#			passwd=("#$%s", cn), \
#			users=("%s,", (memberUid), ",")

# group.adjunct
#nisLDAPfieldFromAttribute group.adjunct.byname: \
#			rf_key=cn, \
#			name=cn, \
#			("{crypt}%s", passwd)=userPassword
' >> $MAP_FILE

else

  # Find the domains in which group.adjunct map exists.
  find_domains $_MAP DEF_MAPS

  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then

    # All the domains have group.adjunct map.


    echo '# group
#nisLDAPfieldFromAttribute group.byname: \
#			rf_key=cn
#nisLDAPfieldFromAttribute group.bygid: \
#                        rf_key=gidNumber
#nisLDAPfieldFromAttribute group: \
#                        gid=gidNumber, \
#                        name=cn, \
#			("{crypt}%s", passwd)=userPassword, \
#			users=("%s,", (memberUid), ",")

#
# If you are not using group.adjunct, comment the group section above
# and uncomment the following group and group.adjunct sections
#			
# group 
nisLDAPfieldFromAttribute group.byname: \
			rf_key=cn
nisLDAPfieldFromAttribute group.bygid: \
			rf_key=gidNumber
nisLDAPfieldFromAttribute group: \
			gid=gidNumber, \
			name=cn, \
			passwd=("#$%s", cn), \
			users=("%s,", (memberUid), ",")

#
# group.adjunct
nisLDAPfieldFromAttribute group.adjunct.byname: \
			rf_key=cn, \
			name=cn, \
			("{crypt}%s", passwd)=userPassword
' >> $MAP_FILE

  else
    # Not every domain has group.adjunct map.

    echo "# group" >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPfieldFromAttribute group.byname,${_DMN}: \\
			rf_key=cn
nisLDAPfieldFromAttribute group.bygid,${_DMN}: \\
			rf_key=gidNumber
nisLDAPfieldFromAttribute group,${_DMN}: \\
			gid=gidNumber, \\
			name=cn, \\
			passwd=(\"#$%s\", cn), \\
			users=(\"%s,\", (memberUid), \",\")
" >> $MAP_FILE
    done

    # Now put the generic group syntax. We do not need to
    # append the domain name here.

    echo '
nisLDAPfieldFromAttribute group.byname: \
			rf_key=cn
nisLDAPfieldFromAttribute group.bygid: \
                        rf_key=gidNumber
nisLDAPfieldFromAttribute group: \
                        gid=gidNumber, \
                        name=cn, \
			("{crypt}%s", passwd)=userPassword, \
			users=("%s,", (memberUid), ",")
' >> $MAP_FILE

    # Now we need to put the group.adjunct syntax for domains
    # in which this map exists.

    echo "#
# group.adjunct
# " >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPfieldFromAttribute group.adjunct.byname,${_DMN}: \\
			rf_key=cn, \\
			name=cn, \\
			(\"{crypt}%s\", passwd)=userPassword
" >> $MAP_FILE

    done

  fi

fi

echo '
# hosts
nisLDAPfieldFromAttribute hosts.byaddr: \
                        rf_ipkey=ipHostNumber
nisLDAPfieldFromAttribute hosts.byname: \
			(rf_key)=(cn)
nisLDAPfieldFromAttribute hosts: \
			("cn=%s+ipHostNumber=*", canonicalName)=dn, \
                        addr=ipHostNumber, \
			aliases=("%s ", (cn) - yp:canonicalName, " "), \
                        rf_comment=description

nisLDAPfieldFromAttribute multihosts: \
			("cn=%s+ipHostNumber=*", canonicalName)=dn, \
			(rf_key)=("YP_MULTI_%s", cn), \
			aliases=("%s ", (cn) - yp:canonicalName, " "), \
			rf_comment=description, \
			(tmp)=("%s", ipHostNumber:?one?("(&(cn=%s) \
				(ipHostNumber=*.*))", yp:canonicalName)), \
			addr=("%s,", (yp:tmp), ",")

# ipnodes
nisLDAPfieldFromAttribute ipnodes.byaddr: \
                        rf_ipkey=ipHostNumber
nisLDAPfieldFromAttribute ipnodes.byname: \
			(rf_key)=(cn)
nisLDAPfieldFromAttribute ipnodes: \
			("cn=%s+ipHostNumber=*", canonicalName)=dn, \
                        addr=ipHostNumber, \
			aliases=("%s ", (cn) - yp:canonicalName, " "), \
                        rf_comment=description

nisLDAPfieldFromAttribute multiipnodes: \
			("cn=%s+ipHostNumber=*", canonicalName)=dn, \
			(rf_key)=("YP_MULTI_%s", cn), \
			aliases=("%s ", (cn) - yp:canonicalName, " "), \
			rf_comment=description, \
			(tmp)=("%s", ipHostNumber:?one?("(&(cn=%s) \
				(ipHostNumber=*:*))", yp:canonicalName)), \
			addr=("%s,", (yp:tmp), ",")

#mail.aliases
nisLDAPfieldFromAttribute mail.aliases: \
			rf_key=mail, \
			addresses= ("%s,", (mgrprfc822mailmember), ","), \
			rf_comment=description

#mail.mapping
nisLDAPfieldFromAttribute mail.mapping: \
			rf_key=mgrprfc822mailmember, \
			address=mail, \
			rf_comment=description

# netgroup.
nisLDAPfieldFromAttribute netgroup: \
			rf_key=cn, \
			(group)=(memberNisNetgroup), \
			("(%s,%s,%s)", host, user, domain)= \
						(nisNetgroupTriple), \
			rf_comment=description

# netid.pass
nisLDAPfieldFromAttribute netid.pass: \
			number=uidNumber, \
			(tmp)=("%s", gidNumber:ou=group,?one?\
				("memberUid=%s", ldap:uid)), \
			sgid=("%s,", (yp:tmp) - gidNumber, ","), \
			data=("%s,%s", gidNumber, yp:sgid), \
			data=gidNumber, \
			(rf_key)=("unix.%s@%s", yp:number, yp:rf_domain)

# netid.host
nisLDAPfieldFromAttribute netid.host: \
			("cn=%s+ipHostNumber=*", data)=dn, \
			number=("0"), \
			(rf_key)=("unix.%s@%s", yp:data, yp:rf_domain)

# netmasks.byaddr
nisLDAPfieldFromAttribute netmasks.byaddr: \
			("ipNetworkNumber=%s,*", rf_ipkey)=dn, \
			mask=ipNetmaskNumber, \
			rf_comment=description

# networks.
nisLDAPfieldFromAttribute networks.byname: \
			(rf_key)=(cn)
nisLDAPfieldFromAttribute networks.byaddr: \
			("ipNetworkNumber=%s,*", rf_key)=dn
nisLDAPfieldFromAttribute networks: \
			name=cn, \
			aliases=("%s ", (cn) - yp:name, " "), \
			number=ipNetworkNumber, \
			rf_comment=description
' >> $MAP_FILE

# passwd syntax is different when passwd.adjunct map is present.
# So, need to handle the various possibilities

_MAP=passwd.adjunct.byname

if ! present $_MAP $ALL_DMN_DEF_MAPLIST
then

  # Just put the passwd.adjunct syntax in comment form

  echo '# passwd
nisLDAPfieldFromAttribute passwd.byname: \
			rf_key=uid
nisLDAPfieldFromAttribute passwd.byuid: \
			rf_key=uidNumber
nisLDAPfieldFromAttribute passwd: \
			name=uid, \
			uid=uidNumber, \
			("{crypt}%s", passwd)=userPassword, \
			gid=gidNumber, \
			gecos=gecos, \
			home=homeDirectory, \
			shell=loginShell 

#
# If you are using passwd.adjunct, comment the passwd section above
# and uncomment the following passwd and passwd.adjunct sections
#			
# passwd
#nisLDAPfieldFromAttribute passwd.byname: \
#			rf_key=uid
#nisLDAPfieldFromAttribute passwd.byuid: \
#			rf_key=uidNumber
#nisLDAPfieldFromAttribute passwd: \
#			name=uid, \
#			uid=uidNumber, \
#			passwd=("##%s", uid), \
#			gid=gidNumber, \
#			gecos=gecos, \
#			home=homeDirectory, \
#			shell=loginShell

# passwd.adjunct
#nisLDAPfieldFromAttribute passwd.adjunct.byname: \
#			rf_key=uid, \
#			name=uid, \
#			("{crypt}%s", passwd)=userPassword
' >> $MAP_FILE

else

  # Find the domains in which passwd.adjunct map exists.
  find_domains $_MAP DEF_MAPS

  if [ $PRESENT_COUNT -eq $N2L_DMN_CNT ]
  then

    # All the domains have passwd.adjunct map. So, put the right
    # passwd syntax and comment-in the passwd.adjunct syntax.


    echo '# passwd
#nisLDAPfieldFromAttribute passwd.byname: \
#			rf_key=uid
#nisLDAPfieldFromAttribute passwd.byuid: \
#			rf_key=uidNumber
#nisLDAPfieldFromAttribute passwd: \
#			name=uid, \
#			uid=uidNumber, \
#			("{crypt}%s", passwd)=userPassword, \
#			gid=gidNumber, \
#			gecos=gecos, \
#			home=homeDirectory, \
#			shell=loginShell 

#
# If you are not using passwd.adjunct, uncomment the passwd section
# above and comment the following passwd and passwd.adjunct sections
#			
# passwd
nisLDAPfieldFromAttribute passwd.byname: \
			rf_key=uid
nisLDAPfieldFromAttribute passwd.byuid: \
			rf_key=uidNumber
nisLDAPfieldFromAttribute passwd: \
			name=uid, \
			uid=uidNumber, \
			passwd=("##%s", uid), \
			gid=gidNumber, \
			gecos=gecos, \
			home=homeDirectory, \
			shell=loginShell

#
# passwd.adjunct Must follow passwd
#
nisLDAPfieldFromAttribute passwd.adjunct.byname: \
			rf_key=uid, \
			name=uid, \
			("{crypt}%s", passwd)=userPassword
' >> $MAP_FILE

  else
    # Not every domain has passwd.adjunct map.

    # First put the password syntax with domain name for domains
    # in which passwd.adjunct exists.

    echo "# passwd" >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPfieldFromAttribute passwd.byname,${_DMN}: \\
			rf_key=uid
nisLDAPfieldFromAttribute passwd.byuid,${_DMN}: \\
			rf_key=uidNumber
nisLDAPfieldFromAttribute passwd,${_DMN}: \\
			name=uid, \\
			uid=uidNumber, \\
			passwd=(\"##%s\", uid), \\
			gid=gidNumber, \\
			gecos=gecos, \\
			home=homeDirectory, \\
			shell=loginShell
" >> $MAP_FILE
    done

    # Now put the other passwd syntax. We do not need to
    # append the domain name here.

    echo '
nisLDAPfieldFromAttribute passwd.byname: \
			rf_key=uid
nisLDAPfieldFromAttribute passwd.byuid: \
			rf_key=uidNumber
nisLDAPfieldFromAttribute passwd: \
			name=uid, \
			uid=uidNumber, \
			("{crypt}%s", passwd)=userPassword, \
			gid=gidNumber, \
			gecos=gecos, \
			home=homeDirectory, \
			shell=loginShell 
' >> $MAP_FILE

    # Now we need to put the passwd.adjunct syntax for domains
    # in which this map exists.

    echo "#
# passwd.adjunct Must follow passwd
# " >> $MAP_FILE

    for _DMN in $PRESENT_IN_DOMAINS
    do

      echo "\
nisLDAPfieldFromAttribute passwd.adjunct.byname,${_DMN}: \\
			rf_key=uid, \\
			name=uid, \\
			(\"{crypt}%s\", passwd)=userPassword
" >> $MAP_FILE

    done

  fi

fi

echo '
# This map is never created but yppasswd uses the mapping to extract password
# ageing information from the DIT.	
nisLDAPfieldFromAttribute ageing.byname: \
			rf_key=uid, \
			name=uid, \
			lastchg=shadowLastChange, \
			min=shadowMin, \
			max=shadowMax, \
			warn=shadowWarning, \
			inactive=shadowInactive, \
			expire=shadowExpire, \
			flag=shadowFlag

# printers.conf.byname
nisLDAPfieldFromAttribute printers.conf.byname: \
			rf_key=printer-uri, \
			names=("%s|", (printer-aliases), "|"), \
			bsdaddr=("bsdaddr=%s", sun-printer-bsdaddr), \
			kvps=("%s:", (sun-printer-kvp) - yp:bsdaddr), \
			values=("%s:%s", yp:bsdaddr, yp:kvps), \
			values=("%s:", yp:bsdaddr), \
			values=yp:kvps, \
                        rf_comment=description

# prof_attr
nisLDAPfieldFromAttribute prof_attr: \
			rf_key=cn, \
			name=cn, \
			res1=SolarisAttrReserved1, \
			res2=SolarisAttrReserved2, \
			desc=SolarisAttrLongDesc, \
			attrs=SolarisAttrKeyValue

# project
nisLDAPfieldFromAttribute project.byname: \
			rf_key=SolarisProjectName
nisLDAPfieldFromAttribute project.byprojid: \
			rf_key=SolarisProjectID
nisLDAPfieldFromAttribute project: \
			name=SolarisProjectName, \
			projID=SolarisProjectID, \
			comment=description, \
			users=("%s,", (memberUid), ","), \
			groups=("%s,", (memberGid), ","), \
			attrs=("%s;", (SolarisProjectAttr), ";")

# protocols
nisLDAPfieldFromAttribute protocols.byname: \
			("cn=%s,*", rf_key)=dn, \
			(rf_key)=(cn)
nisLDAPfieldFromAttribute protocols.bynumber: \
                        rf_key=ipProtocolNumber, \
                        rf_comment=description
nisLDAPfieldFromAttribute protocols: \
			("cn=%s,*", name)=dn, \
                        number=ipProtocolNumber, \
                        aliases=("%s ", (cn) - yp:name, " ")

# rpc.bynumber
nisLDAPfieldFromAttribute rpc.bynumber: \
			rf_key=oncRpcNumber, \
			number=oncRpcNumber, \
			("cn=%s,*", name)=dn, \
                        aliases=("%s ", (cn) - yp:name, " "), \
			rf_comment=description

# services
nisLDAPfieldFromAttribute services.byname: \
			rf_key = ("%s/%s", ipServicePort, ipServiceProtocol)
nisLDAPfieldFromAttribute services.byservicename: \
			(rf_key)=("%s/%s", cn, ipServiceProtocol), \
			(rf_key)=(cn)
nisLDAPfieldFromAttribute services: \
			("cn=%s+ipServiceProtocol=*", name)=dn, \
     			protocol=ipServiceProtocol, \
     			port=ipServicePort, \
                        aliases=("%s ", (cn) - yp:name, " "), \
                        rf_comment=description

# timezone.byname
nisLDAPfieldFromAttribute timezone.byname: \
			rf_key=cn, \
			hostName=cn, \
			zoneName=nisplusTimeZone, \
			rf_comment=description

# user_attr
nisLDAPfieldFromAttribute user_attr: \
			("uid=%s,*", rf_key)=dn, \
			("uid=%s,*", user)=dn, \
			qualifier=SolarisUserAttr, \
			res1=SolarisUserReserved1, \
			res2=SolarisUserReserved2, \
			attrs=SolarisAttrKeyValue

# publickey.byname
nisLDAPfieldFromAttribute keys.host: \
			("cn=%s+ipHostNumber=*", cname)=dn, \
			rf_key=("unix.%s@%s", yp:cname, yp:rf_domain), \
			publicKey=nisPublicKey, \
			secretKey=nisSecretKey

nisLDAPfieldFromAttribute keys.pass: \
			rf_key=("unix.%s@%s", uidNumber, yp:rf_domain), \
			publicKey=nisPublicKey, \
			secretKey=nisSecretKey

nisLDAPfieldFromAttribute keys.nobody: \
			rf_key=uid, \
			publicKey=nisPublicKey, \
			secretKey=nisSecretKey

# ypservers. This derived from IPlanet implementation not RFC.
nisLDAPfieldFromAttribute ypservers: \
			rf_key=cn
' >> $MAP_FILE
}


#
# List all the non-default auto.* and custom maps.
#
list_auto_and_custom_nisLDAPfieldFromAttribute()
{

# auto.* entries are easy. 
if [ ${#ALL_DMN_AUTO_CUST_MAPS[*]} -gt 0 ]; then
  echo "# Non-default custom auto maps (auto.*)\n" >> $MAP_FILE
fi

for _MAP in ${ALL_DMN_AUTO_CUST_MAPS[*]}
do
  echo "\
# ${_MAP}
nisLDAPfieldFromAttribute ${_MAP}: \\
                        rf_key=automountKey, \\
                        value=automountInformation
" >> $MAP_FILE
done

# Since we do not have enough information to generate
# entries for other custom maps, best we can do is to
# log this map names and ask user to take care of them.

ask_user_to_update_the_custom_map_entries_too

}


#
# List mapping of named fields from DIT entries
#
create_nisLDAPfieldFromAttribute()
{

[ CUST_CMT_NEEDED -eq 1 ] && echo '
# nisLDAPfieldFromAttribute : It specifies how a NIS entries
# field values  are derived from LDAP attribute values. 
# 
# The format of nisLDAPfieldFromAttribute is :
# mapName ":" fieldattrspec *("," fieldattrspec)
' >> $MAP_FILE

# List all the default entries anyway.
list_default_nisLDAPfieldFromAttribute

# List all the non-default auto.* and custom maps.
list_auto_and_custom_nisLDAPfieldFromAttribute

echo "
#
#------------------------------------------------------------------------------
#			 
" >> $MAP_FILE
}



# Main function for creating the mapping file
create_mapping_file()
{
# Ask user the list of domains to be served by N2L
create_n2l_domain_list

# If there are no N2L domains or none selected, then exit 
if [ $N2L_DMN_CNT -eq 0 ]; then
  echo "There are no domains to serve. No mapping file generated."
  return 1
fi

while :
do
  get_ans "Enter the mapping file name (h=help):" "${MAP_FILE}"

  # If help continue, otherwise break.
  case "$ANS" in
    [Hh] | help | Help | \?) display_msg new_mapping_file_name_help ;;
                         * ) break ;;
  esac
done

MAP_FILE=${ANS}
[ $DEBUG -eq 1 ] && MAP_FILE = $MAP_FILE

# Backup existing mapping file if selected
check_back_mapping_file

# To prevent from leaving a partial mapping file in case some error
# or signal takes place which might result in machine starting in N2L
# mode at next reboot, store the output being generated in a temporary
# file first, and move it at the final destination only at the end if
# everything goes fine.

_MAP_FILE=$MAP_FILE
MAP_FILE=${TMPDIR}/${TMPMAP}.$$

echo "Generating mapping file temporarily as \"${MAP_FILE}\""

# Place copyright information
put_mapping_file_copyright_info


# Prepare various map lists for each domain
create_map_lists

# List domains and contexts
get_nisLDAPdomainContext

# List domains for which passwords should be changed
get_nisLDAPyppasswddDomains

# List databaseId mappings (aliases)
create_nisLDAPdatabaseIdMapping

# List comment character for maps
create_nisLDAPcommentChar

# List SECURE and INTERDOMAIN flags
create_nisLDAPmapFlags

# List TTL values
 create_nisLDAPentryTtl

# List name fields
create_nisLDAPnameFields

# List split fields and repeated fields seperators.
create_split_field_and_repeatedfield_seperators

# List association of maps with RDNs and object classes.
create_nisLDAPobjectDN

# List mapping of named fields to DIT entries
create_nisLDAPattributeFromField

# List mapping of named fields from DIT entries
create_nisLDAPfieldFromAttribute


# We are done, so move back the mapping file from temp. location
# to actual location.
# In case the mapping file name has a directory component which does
# not exist, then create it now, otherwise 'mv' will return error.

DIR_TO_CREATE=`dirname ${_MAP_FILE}`
mkdir -p ${DIR_TO_CREATE}

echo "Moving output from temporary file ($MAP_FILE) to actual file ($_MAP_FILE)"
mv $MAP_FILE $_MAP_FILE

# Revert back the mapping file name in case needed.
MAP_FILE=$_MAP_FILE
echo "Finished creation of mapping file ( $MAP_FILE )"

}


#
# Main function for creating config file (ypserv)
#
process_config_file()
{
# Ask for confirmation if the file name is not specified.

if [ $CONFIG_FILE_SPECIFIED -eq 0 ]; then
  display_msg no_config_file_name_specified

  get_confirm_nodef "Do you want to create the config file (y/n) ?"
  
  [ $? -eq 0 ] && return 0

  while :
  do
    get_ans "Enter the config file name (h=help):" "${CONFIG_FILE}"

    # If help continue, otherwise break.
    case "$ANS" in
      [Hh] | help | Help | \?) display_msg new_config_file_name_help ;;
                           * ) break ;;
    esac
  done

  CONFIG_FILE=${ANS}
  [ $DEBUG -eq 1 ] && CONFIG_FILE = $CONFIG_FILE

fi

# Backup existing config file if selected
check_back_config_file

# Create config file
create_config_file
}


#
# Main function for creating mapping file (NISLDAPmapping)
#
process_mapping_file()
{
# Ask for confirmation if the file name is not specified.

if [ $MAPPING_FILE_SPECIFIED -eq 0 ]; then
  display_msg no_mapping_file_name_specified

  get_confirm_nodef "Do you want to create the mapping file (y/n) ?"
  
  [ $? -eq 0 ] && return 0


fi

# Create mapping file
create_mapping_file
}

###########################################
###########	   MAIN		###########
###########################################

PROG=`basename $0`	# Program name
ABS_PROG=$0		# absolute path needed

# Only superuser should be able to run this script.
is_root_user
if [ $? -ne 0 ]; then
  echo "ERROR : Only root can run $PROG"
  exit 1
fi

# Initialize things
init

# Parse command line arguments.  
parse_arg $*

# Create config file (ypserv)
process_config_file

# Create mapping file (NISLDAPmapping).
process_mapping_file

# Cleanup temp files and directories unless debug.
[ $DEBUG -eq 0 ] && cleanup

exit 0