5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # ident "%Z%%M% %I% %E% SMI"
26 # Copyright 2003 Sun Microsystems, Inc. All rights reserved.
27 # Use is subject to license terms.
29 # ypmap2src -- script to generate source files from YP maps.
33 # Please save a copy of this script before making any changes.
38 echo "Usage: $PROG [-t] [[-c custom-map-name] ...] [-d domain] -o output-directory [[source-file] ...]"
39 echo " t - Generate source files from TRADITIONAL NIS MAPS, default is NIS2LDAP maps."
40 echo " c - Name of the custom map for which source file needs to be generated."
41 echo " d - Specify a different domain, default is local system domain name."
42 echo " o - Specify the output directory where source files can be generated."
43 echo "source-file - The name of the source file for which needs to be generated."
49 while getopts "tc:d:o:" ARG
54 MAP_LIST
="$NIS_ONLY_MAP_LIST"
56 c
) CUST_LIST
="$CUST_LIST $OPTARG"
59 MAPDIR
=/var
/yp
/"$DOMAIN"
63 *) echo "ERROR : Invalid argument"
70 # This is to handle if "-t" is supplied after "-c"
73 CUST_MAP_LIST
="$CUST_MAP_LIST ${N2LPREFIX}$MAP"
76 if [ -z "$OUTDIR" ]; then
77 echo "ERROR : output directory has to be specified."
82 # Set source list if supplied
83 shift `expr $OPTIND - 1`
86 [ $DEBUG -eq 1 ] && echo CMDLINE_SRC_LIST
= $CMDLINE_SRC_LIST
88 # If source(s) supplied on command line, then generate ONLY those file(s).
90 if [ "$CMDLINE_SRC_LIST" != "" ]; then
94 for SRC
in $CMDLINE_SRC_LIST
96 [ $DEBUG -eq 1 ] && echo Parsing Command line SRC
= $SRC
100 MAP
=${N2LPREFIX}passwd.byuid
101 MAP_LIST
="$MAP_LIST $MAP"
104 MAP
=${N2LPREFIX}group.byname
105 MAP_LIST
="$MAP_LIST $MAP"
108 MAP
=${N2LPREFIX}hosts.byaddr
109 MAP_LIST
="$MAP_LIST $MAP"
112 MAP
=${N2LPREFIX}ipnodes.byaddr
113 MAP_LIST
="$MAP_LIST $MAP"
116 MAP
=${N2LPREFIX}ethers.byname
117 MAP_LIST
="$MAP_LIST $MAP"
120 MAP
=${N2LPREFIX}networks.byaddr
121 MAP_LIST
="$MAP_LIST $MAP"
124 MAP
=${N2LPREFIX}rpc.bynumber
125 MAP_LIST
="$MAP_LIST $MAP"
128 MAP
=${N2LPREFIX}services.byname
129 MAP_LIST
="$MAP_LIST $MAP"
132 MAP
=${N2LPREFIX}protocols.bynumber
133 MAP_LIST
="$MAP_LIST $MAP"
136 MAP
=${N2LPREFIX}netgroup
137 MAP_LIST
="$MAP_LIST $MAP"
140 MAP
=${N2LPREFIX}bootparams
141 MAP_LIST
="$MAP_LIST $MAP"
144 MAP
=${N2LPREFIX}mail.aliases
145 MAP_LIST
="$MAP_LIST $MAP"
148 MAP
=${N2LPREFIX}publickey.byname
149 MAP_LIST
="$MAP_LIST $MAP"
152 MAP
=${N2LPREFIX}netid.byname
153 MAP_LIST
="$MAP_LIST $MAP"
156 MAP
=${N2LPREFIX}netmasks.byaddr
157 MAP_LIST
="$MAP_LIST $MAP"
160 MAP
=${N2LPREFIX}passwd.adjunct.byname
161 MAP_LIST
="$MAP_LIST $MAP"
164 MAP
=${N2LPREFIX}group.adjunct.byname
165 MAP_LIST
="$MAP_LIST $MAP"
168 MAP
=${N2LPREFIX}timezone.byname
169 MAP_LIST
="$MAP_LIST $MAP"
172 MAP
=${N2LPREFIX}${SRC}
173 MAP_LIST
="$MAP_LIST $MAP"
176 MAP
=${N2LPREFIX}auth_attr
177 MAP_LIST
="$MAP_LIST $MAP"
180 MAP
=${N2LPREFIX}exec_attr
181 MAP_LIST
="$MAP_LIST $MAP"
184 MAP
=${N2LPREFIX}prof_attr
185 MAP_LIST
="$MAP_LIST $MAP"
188 MAP
=${N2LPREFIX}user_attr
189 MAP_LIST
="$MAP_LIST $MAP"
192 MAP
=${N2LPREFIX}audit_user
193 MAP_LIST
="$MAP_LIST $MAP"
195 *) # Not a default source, could be a custom source.
196 # Then generate source files from all the available
197 # DBM files for this custom source.
201 for dbmfile
in $MAPDIR/${N2LPREFIX}${SRC}.dir \
202 $MAPDIR/${N2LPREFIX}${SRC}.
*.dir
204 MAP
=`basename $dbmfile .dir`
205 if [ -f $MAPDIR/${MAP}.pag
]; then
207 CUST_MAP_LIST
="$CUST_MAP_LIST $MAP"
211 [ $MAPFOUND -eq 0 ] && \
212 echo ERROR
: No maps found
for $SRC. Skipping..
225 uid
=0\
(root\
)*) return 0
238 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
240 # Remove the YP operational lines
241 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
242 grep -v "YP_DOMAIN_NAME $DOMAIN" |
243 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
246 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
248 # Sort the entries in ascending order of uid
249 sort -n -t: -k3,3 $TMPDIR/${MAP}.cut
> $TMPDIR/${MAP}.
sort
251 # If passwd.adjunct is used, the actual password is stored in
252 # this map, and the passwd map contains "##<uid>" as the passwd.
253 # In that case, do not generate the shadow file.
255 UID
=`head -1 $TMPDIR/${MAP}.sort | cut -f1 -d:`
256 PSWD
=`head -1 $TMPDIR/${MAP}.sort | cut -f2 -d:`
257 if [ "$PSWD" != "##${UID}" ]; then
259 #Create the shadow file with blank passwd aging information
260 cut
-f 1,2 -d: $TMPDIR/${MAP}.
sort |
261 sed 's/$/:::::::/' > $OUTDIR/$SHADOW
263 #Make the shadow file readable to root only
264 chmod 400 $OUTDIR/$SHADOW
266 #Create the passwd file with "x" as the passwd
267 awk ' BEGIN { FS = ":"; OFS = ":"}
268 {$2 = "x"; print}' $TMPDIR/${MAP}.
sort > $OUTDIR/$SRCFILE
270 cp $TMPDIR/${MAP}.
sort $OUTDIR/$SRCFILE
280 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
282 # Remove the YP operational lines
283 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
284 grep -v "YP_DOMAIN_NAME $DOMAIN" |
285 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
288 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
290 # Sort the entries in ascending order of gid
291 sort -n -t: -k3,3 $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
299 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
301 # Remove the YP operational lines
302 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
303 grep -v "YP_DOMAIN_NAME $DOMAIN" |
304 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
307 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
309 # Sort the hosts ip addresses in ascending order
310 sort -n -t.
-k1,1 -k2,2 -k3,3 -k4,4 $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
318 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
320 # Remove the YP operational lines
321 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
322 grep -v "YP_DOMAIN_NAME $DOMAIN" |
323 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
326 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
328 grep -v "::" $TMPDIR/${MAP}.cut
>$TMPDIR/${MAP}.V4
329 grep "::" $TMPDIR/${MAP}.cut
>$TMPDIR/${MAP}.V6
331 # Sort the ip addresses in ascending order
332 sort -n -t.
-k1,1 -k2,2 -k3,3 -k4,4 $TMPDIR/${MAP}.V4
> $OUTDIR/$SRCFILE
334 # V6 addresses due to hex chars, can't be sorted this way.
335 # So just do the default string sort.
336 sort $TMPDIR/${MAP}.V6
>> $OUTDIR/$SRCFILE
344 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
346 # Remove the YP operational lines
347 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
348 grep -v "YP_DOMAIN_NAME $DOMAIN" |
349 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
352 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
354 # Sort ethernet addresses based on host names
355 sort -b -k2 $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
363 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
365 # Remove the YP operational lines
366 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
367 grep -v "YP_DOMAIN_NAME $DOMAIN" |
368 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
371 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
373 # Sort networks based on their names
374 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
382 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
384 # Remove the YP operational lines
385 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
386 grep -v "YP_DOMAIN_NAME $DOMAIN" |
387 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
390 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
392 # Sort entries in the increasing order of RPC number
393 sort -n -k2 $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
401 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
403 # Remove the YP operational lines
404 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
405 grep -v "YP_DOMAIN_NAME $DOMAIN" |
406 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
409 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
411 # Sort entries in the increasing order of RPC number
412 sort -n -k2 $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
420 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
422 # Remove the YP operational lines
423 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
424 grep -v "YP_DOMAIN_NAME $DOMAIN" |
425 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
428 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
430 # Sort entries in the increasing order of RPC number
431 sort -n -k2 $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
439 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
441 # Remove the YP operational lines
442 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
443 grep -v "YP_DOMAIN_NAME $DOMAIN" |
444 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
446 cp $TMPDIR/${MAP}.
grep $OUTDIR/$SRCFILE
454 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
456 # Remove the YP operational lines
457 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
458 grep -v "YP_DOMAIN_NAME $DOMAIN" |
459 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
462 sort $TMPDIR/${MAP}.
grep > $OUTDIR/$SRCFILE
470 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
472 # Remove the YP operational lines
473 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
474 grep -v "YP_DOMAIN_NAME $DOMAIN" |
475 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
477 # Replace first " " with ": " to make it similar to aliases
478 sed 's/ /: /' $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.
sed
480 # Sort aliases entries alphabetically
481 sort $TMPDIR/${MAP}.
sed > $OUTDIR/$SRCFILE
489 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
491 # Remove the YP operational lines
492 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
493 grep -v "YP_DOMAIN_NAME $DOMAIN" |
494 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
496 # Sort entries alphabetically
497 sort $TMPDIR/${MAP}.
grep > $OUTDIR/$SRCFILE
505 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
507 # Remove the YP operational lines
508 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
509 grep -v "YP_DOMAIN_NAME $DOMAIN" |
510 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
512 # netid source files is used to add other domain
513 # entries. So, filter out local domain entries
514 grep -v "@${DOMAIN}" $TMPDIR/${MAP}.
grep > $OUTDIR/$SRCFILE
522 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
524 # Remove the YP operational lines
525 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
526 grep -v "YP_DOMAIN_NAME $DOMAIN" |
527 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
529 # Sort the network numbers in ascending order
530 sort -n -t.
-k1,1 -k2,2 -k3,3 -k4,4 $TMPDIR/${MAP}.
grep > $OUTDIR/$SRCFILE
534 create_passwd_adjunct
()
536 SRCFILE
=passwd.adjunct
538 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
540 # Remove the YP operational lines. It has three of them.
541 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
542 grep -v "YP_DOMAIN_NAME $DOMAIN" |
543 grep -v YP_MASTER_NAME |
grep -v YP_SECURE
> $TMPDIR/${MAP}.
grep
546 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
548 ## Check if sorting is ok, or leave it as it is.
549 # Sort the entries in alphabetical order
550 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
554 create_group_adjunct
()
556 SRCFILE
=group.adjunct
558 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
560 # Remove the YP operational lines. It has three of them.
561 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
562 grep -v "YP_DOMAIN_NAME $DOMAIN" |
563 grep -v YP_MASTER_NAME |
grep -v YP_SECURE
> $TMPDIR/${MAP}.
grep
566 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
568 # Sort the entries in alphabetical order
569 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
577 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
579 # Remove the YP operational lines
580 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
581 grep -v "YP_DOMAIN_NAME $DOMAIN" |
582 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
585 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
587 # Sort the entries in alphabetical order
588 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
596 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
598 # Remove the YP operational lines
599 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
600 grep -v "YP_DOMAIN_NAME $DOMAIN" |
601 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
603 # Sort entries alphabetically
604 sort $TMPDIR/${MAP}.
grep > $OUTDIR/$SRCFILE
612 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
614 # Remove the YP operational lines
615 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
616 grep -v "YP_DOMAIN_NAME $DOMAIN" |
617 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
620 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
622 # Sort entries in the alphabetical order
623 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
631 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
633 # Remove the YP operational lines
634 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
635 grep -v "YP_DOMAIN_NAME $DOMAIN" |
636 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
638 # Remove the key which is made of three fields. space is part of key
639 cut
-f 3- -d ":" $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut1
640 cut
-f 2- -d " " $TMPDIR/${MAP}.cut1
> $TMPDIR/${MAP}.cut2
642 # Sort entries in the alphabetical order
643 sort $TMPDIR/${MAP}.cut2
> $OUTDIR/$SRCFILE
651 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
653 # Remove the YP operational lines
654 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
655 grep -v "YP_DOMAIN_NAME $DOMAIN" |
656 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
658 # Remove the key. It is difficult here as space is part of the key.
659 # From the "key key" part, extract "key", and then paste it with
660 # the rest of the entry.
661 cut
-f1 -d: $TMPDIR/${MAP}.
grep |
664 for (i=2; i <= NF/2; i++) {
668 }' > $TMPDIR/${MAP}.cut1
670 cut
-f2- -d: $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut2
671 paste -d ":" $TMPDIR/${MAP}.cut1 $TMPDIR/${MAP}.cut2 > $TMPDIR/${MAP}.cut
673 # Sort entries in the alphabetical order
674 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
682 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
684 # Remove the YP operational lines
685 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
686 grep -v "YP_DOMAIN_NAME $DOMAIN" |
687 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
690 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
692 # Sort entries in the alphabetical order
693 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
701 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
703 # Remove the YP operational lines. It has 3 of them.
704 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
705 grep -v "YP_DOMAIN_NAME $DOMAIN" |
706 grep -v YP_MASTER_NAME |
grep -v YP_SECURE
> $TMPDIR/${MAP}.
grep
709 cut
-f 2- -d " " $TMPDIR/${MAP}.
grep > $TMPDIR/${MAP}.cut
711 # Sort entries in the alphabetical order
712 sort $TMPDIR/${MAP}.cut
> $OUTDIR/$SRCFILE
720 # Only root can read the NIS maps, so no point allowing
721 # non-root users to be able to run this script.
723 if [ $?
-ne 0 ]; then
724 echo "ERROR : Only root can run $PROG"
728 # Prevent non-root users from reading/writing
731 # Initialize default values.
732 DOMAIN
=`/usr/bin/domainname`
733 MAPDIR
=/var
/yp
/"$DOMAIN" # Default to local domain
736 NIS_ONLY_MAP_LIST
="passwd.byuid
751 passwd.adjunct.byname
760 NIS2LDAP_MAP_LIST
="${N2LPREFIX}passwd.byuid
761 ${N2LPREFIX}group.byname
762 ${N2LPREFIX}hosts.byaddr
763 ${N2LPREFIX}ipnodes.byaddr
764 ${N2LPREFIX}ethers.byname
765 ${N2LPREFIX}networks.byaddr
766 ${N2LPREFIX}rpc.bynumber
767 ${N2LPREFIX}services.byname
768 ${N2LPREFIX}protocols.bynumber
770 ${N2LPREFIX}bootparams
771 ${N2LPREFIX}mail.aliases
772 ${N2LPREFIX}publickey.byname
773 ${N2LPREFIX}netid.byname
774 ${N2LPREFIX}netmasks.byaddr
775 ${N2LPREFIX}passwd.adjunct.byname
776 ${N2LPREFIX}group.adjunct.byname
777 ${N2LPREFIX}timezone.byname
778 ${N2LPREFIX}auth_attr
779 ${N2LPREFIX}exec_attr
780 ${N2LPREFIX}prof_attr
781 ${N2LPREFIX}user_attr
782 ${N2LPREFIX}audit_user"
785 # If auto maps exist, add them to the respective lists.
786 for dbmfile
in $MAPDIR/auto.
*.dir
788 MAP
=`basename $dbmfile .dir`
789 if [ -f $MAPDIR/${MAP}.pag
]; then
790 NIS_ONLY_MAP_LIST
="$NIS_ONLY_MAP_LIST $MAP"
794 for dbmfile
in $MAPDIR/${N2LPREFIX}auto.
*.dir
796 MAP
=`basename $dbmfile .dir`
797 if [ -f $MAPDIR/${MAP}.pag
]; then
798 NIS2LDAP_MAP_LIST
="$NIS2LDAP_MAP_LIST $MAP"
802 # Default to N2L maps
803 MAP_LIST
="$NIS2LDAP_MAP_LIST"
805 # Safe place to avoid anyone from reading sensitive data.
806 TMPDIR
="/var/tmp/ypmap2src"
808 DEBUG
=0 # Default to debug off
817 [ $DEBUG -eq 1 ] && echo DOMAIN
= $DOMAIN
818 [ $DEBUG -eq 1 ] && echo OUTDIR
= $OUTDIR
819 [ $DEBUG -eq 1 ] && echo TMPDIR
= $TMPDIR
820 [ $DEBUG -eq 1 ] && echo CUST_MAP_LIST
= $CUST_MAP_LIST
821 [ $DEBUG -eq 1 ] && echo MAP_LIST
= $MAP_LIST
823 [ $DEBUG -eq 1 ] && echo MAPDIR
= $MAPDIR
824 if [ ! -d "$MAPDIR" ]; then
825 echo ERROR
: NIS Map directory
$MAPDIR does not exist.
829 if [ ! -d "$OUTDIR" ]; then
830 echo output directory
$OUTDIR does not exist. Creating it.
832 if [ $?
-ne 0 ]; then
833 echo ERROR
: Failed to create output directory
$OUTDIR
838 # Cleanup if the temp directory has been leftover
839 [ -d "$TMPDIR" ] && rm -rf $TMPDIR
841 if [ $?
-ne 0 ]; then
842 echo ERROR
: Failed to create temp directory
$TMPDIR
849 [ $DEBUG -eq 1 ] && echo Processing MAP
= $MAP
851 if [ ! -f $MAPDIR/${MAP}.dir
] ||
[ ! -f $MAPDIR/${MAP}.pag
]; then
853 [ $CMDLINE_SRCS -ne 0 ] && \
854 echo ERROR
: Missing DBM
file for $MAP in $MAPDIR . Skipping..
856 [ $DEBUG -eq 1 ] && [ $CMDLINE_SRCS -eq 0 ] && \
857 echo No DBM
file for $MAP in $MAPDIR . Skipping..
862 ${N2LPREFIX}passwd.byuid
)
865 ${N2LPREFIX}group.byname
)
868 ${N2LPREFIX}hosts.byaddr
)
871 ${N2LPREFIX}ipnodes.byaddr
)
874 ${N2LPREFIX}ethers.byname
)
877 ${N2LPREFIX}networks.byaddr
)
880 ${N2LPREFIX}rpc.bynumber
)
883 ${N2LPREFIX}services.byname
)
886 ${N2LPREFIX}protocols.bynumber
)
889 ${N2LPREFIX}netgroup
)
892 ${N2LPREFIX}bootparams
)
895 ${N2LPREFIX}mail.aliases
)
898 ${N2LPREFIX}publickey.byname
)
901 ${N2LPREFIX}netid.byname
)
904 ${N2LPREFIX}netmasks.byaddr
)
907 ${N2LPREFIX}passwd.adjunct.byname
)
908 create_passwd_adjunct
910 ${N2LPREFIX}group.adjunct.byname
)
913 ${N2LPREFIX}timezone.byname
)
919 ${N2LPREFIX}auth_attr
)
922 ${N2LPREFIX}exec_attr
)
925 ${N2LPREFIX}prof_attr
)
928 ${N2LPREFIX}user_attr
)
931 ${N2LPREFIX}audit_user
)
934 *) # Not a default map, could be a custom map.
935 CUST_MAP_LIST
="$CUST_MAP_LIST $MAP"
941 for MAP
in $CUST_MAP_LIST
943 [ $DEBUG -eq 1 ] && echo Processing Custom MAP
= $MAP
945 if [ ! -f $MAPDIR/${MAP}.dir
] ||
[ ! -f $MAPDIR/${MAP}.pag
]; then
946 echo ERROR
: Missing DBM
file for $MAP in $MAPDIR . Skipping..
950 makedbm
-u $MAPDIR/$MAP > $TMPDIR/$MAP
952 # Remove the YP operational lines. Assuming each custom map
953 # has only these entries (three in n2l mode as shown below, and
954 # two in vanilla NIS mode as it does not have "YP_DOMAIN_NAME".
955 # But that does not require any changes in the code). Modify it
956 # appropriately in other cases.
958 grep -v YP_LAST_MODIFIED
$TMPDIR/$MAP |
959 grep -v "YP_DOMAIN_NAME $DOMAIN" |
960 grep -v YP_MASTER_NAME
> $TMPDIR/${MAP}.
grep
962 # If further processing (e.g., removing key, sorting etc.)
963 # is required, then update the script appropriately.
964 cp $TMPDIR/${MAP}.
grep $OUTDIR/$MAP
968 # Leave the temp directory if debug is set
969 [ $DEBUG -eq 0 ] && rm -rf $TMPDIR