dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / ypcmd / yp2lscripts / ypmap2src.sh
blobb52fe8e8bc3658a9bfb8de5b5f96c123c30e5509
1 #! /usr/bin/sh
3 # CDDL HEADER START
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
8 # with the License.
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]
21 # CDDL HEADER END
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.
36 usage()
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."
44 exit 0
47 parse_argument()
49 while getopts "tc:d:o:" ARG
51 case $ARG in
53 t) N2LPREFIX=""
54 MAP_LIST="$NIS_ONLY_MAP_LIST"
56 c) CUST_LIST="$CUST_LIST $OPTARG"
58 d) DOMAIN=$OPTARG
59 MAPDIR=/var/yp/"$DOMAIN"
61 o) OUTDIR=$OPTARG
63 *) echo "ERROR : Invalid argument"
64 usage
65 exit 1
67 esac
68 done
70 # This is to handle if "-t" is supplied after "-c"
71 for MAP in $CUST_LIST
73 CUST_MAP_LIST="$CUST_MAP_LIST ${N2LPREFIX}$MAP"
74 done
76 if [ -z "$OUTDIR" ]; then
77 echo "ERROR : output directory has to be specified."
78 usage
79 exit 1
82 # Set source list if supplied
83 shift `expr $OPTIND - 1`
84 CMDLINE_SRC_LIST="$@"
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
91 MAP_LIST=""
92 CMDLINE_SRCS=1
94 for SRC in $CMDLINE_SRC_LIST
96 [ $DEBUG -eq 1 ] && echo Parsing Command line SRC = $SRC
98 case $SRC in
99 passwd )
100 MAP=${N2LPREFIX}passwd.byuid
101 MAP_LIST="$MAP_LIST $MAP"
103 group )
104 MAP=${N2LPREFIX}group.byname
105 MAP_LIST="$MAP_LIST $MAP"
107 hosts )
108 MAP=${N2LPREFIX}hosts.byaddr
109 MAP_LIST="$MAP_LIST $MAP"
111 ipnodes )
112 MAP=${N2LPREFIX}ipnodes.byaddr
113 MAP_LIST="$MAP_LIST $MAP"
115 ethers )
116 MAP=${N2LPREFIX}ethers.byname
117 MAP_LIST="$MAP_LIST $MAP"
119 networks )
120 MAP=${N2LPREFIX}networks.byaddr
121 MAP_LIST="$MAP_LIST $MAP"
123 rpc )
124 MAP=${N2LPREFIX}rpc.bynumber
125 MAP_LIST="$MAP_LIST $MAP"
127 services )
128 MAP=${N2LPREFIX}services.byname
129 MAP_LIST="$MAP_LIST $MAP"
131 protocols )
132 MAP=${N2LPREFIX}protocols.bynumber
133 MAP_LIST="$MAP_LIST $MAP"
135 netgroup )
136 MAP=${N2LPREFIX}netgroup
137 MAP_LIST="$MAP_LIST $MAP"
139 bootparams )
140 MAP=${N2LPREFIX}bootparams
141 MAP_LIST="$MAP_LIST $MAP"
143 aliases )
144 MAP=${N2LPREFIX}mail.aliases
145 MAP_LIST="$MAP_LIST $MAP"
147 publickey )
148 MAP=${N2LPREFIX}publickey.byname
149 MAP_LIST="$MAP_LIST $MAP"
151 netid )
152 MAP=${N2LPREFIX}netid.byname
153 MAP_LIST="$MAP_LIST $MAP"
155 netmasks )
156 MAP=${N2LPREFIX}netmasks.byaddr
157 MAP_LIST="$MAP_LIST $MAP"
159 passwd.adjunct )
160 MAP=${N2LPREFIX}passwd.adjunct.byname
161 MAP_LIST="$MAP_LIST $MAP"
163 group.adjunct )
164 MAP=${N2LPREFIX}group.adjunct.byname
165 MAP_LIST="$MAP_LIST $MAP"
167 timezone )
168 MAP=${N2LPREFIX}timezone.byname
169 MAP_LIST="$MAP_LIST $MAP"
171 auto.* )
172 MAP=${N2LPREFIX}${SRC}
173 MAP_LIST="$MAP_LIST $MAP"
175 auth_attr )
176 MAP=${N2LPREFIX}auth_attr
177 MAP_LIST="$MAP_LIST $MAP"
179 exec_attr )
180 MAP=${N2LPREFIX}exec_attr
181 MAP_LIST="$MAP_LIST $MAP"
183 prof_attr )
184 MAP=${N2LPREFIX}prof_attr
185 MAP_LIST="$MAP_LIST $MAP"
187 user_attr )
188 MAP=${N2LPREFIX}user_attr
189 MAP_LIST="$MAP_LIST $MAP"
191 audit_user )
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.
199 MAPFOUND=0
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
206 MAPFOUND=1
207 CUST_MAP_LIST="$CUST_MAP_LIST $MAP"
209 done
211 [ $MAPFOUND -eq 0 ] && \
212 echo ERROR : No maps found for $SRC. Skipping..
214 esac
215 done
222 is_root_user()
224 case `id` in
225 uid=0\(root\)*) return 0
227 * ) return 1
229 esac
233 create_passwd()
235 SRCFILE=passwd
236 SHADOW=shadow
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
245 # Remove the key
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
269 else
270 cp $TMPDIR/${MAP}.sort $OUTDIR/$SRCFILE
276 create_group()
278 SRCFILE=group
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
287 # Remove the key
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
295 create_hosts()
297 SRCFILE=hosts
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
306 # Remove the key
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
314 create_ipnodes()
316 SRCFILE=ipnodes
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
325 # Remove the key
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
340 create_ethers()
342 SRCFILE=ethers
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
351 # Remove the key
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
359 create_networks()
361 SRCFILE=networks
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
370 # Remove the key
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
378 create_rpc()
380 SRCFILE=rpc
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
389 # Remove the key
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
397 create_services()
399 SRCFILE=services
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
408 # Remove the key
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
416 create_protocols()
418 SRCFILE=protocols
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
427 # Remove the key
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
435 create_netgroup()
437 SRCFILE=netgroup
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
450 create_bootparams()
452 SRCFILE=bootparams
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
461 # Sort the entries
462 sort $TMPDIR/${MAP}.grep > $OUTDIR/$SRCFILE
466 create_aliases()
468 SRCFILE=aliases
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
485 create_publickey()
487 SRCFILE=publickey
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
501 create_netid()
503 SRCFILE=netid
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
518 create_netmasks()
520 SRCFILE=netmasks
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
545 # Remove the key
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
565 # Remove the key
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
573 create_timezone()
575 SRCFILE=timezone
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
584 # Remove the key
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
592 create_auto_src()
594 SRCFILE=$MAP
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
608 create_auth_attr()
610 SRCFILE=auth_attr
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
619 # Remove the key
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
627 create_exec_attr()
629 SRCFILE=exec_attr
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
647 create_prof_attr()
649 SRCFILE=prof_attr
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 |
662 awk '{
663 STR = $1
664 for (i=2; i <= NF/2; i++) {
665 STR = STR " " $i
667 print STR
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
678 create_user_attr()
680 SRCFILE=user_attr
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
689 # Remove the key
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
697 create_audit_user()
699 SRCFILE=audit_user
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
708 # Remove the key
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
716 ## MAIN ##
718 PROG=`basename $0`
720 # Only root can read the NIS maps, so no point allowing
721 # non-root users to be able to run this script.
722 is_root_user
723 if [ $? -ne 0 ]; then
724 echo "ERROR : Only root can run $PROG"
725 exit 1
728 # Prevent non-root users from reading/writing
729 umask 077
731 # Initialize default values.
732 DOMAIN=`/usr/bin/domainname`
733 MAPDIR=/var/yp/"$DOMAIN" # Default to local domain
734 N2LPREFIX=LDAP_
736 NIS_ONLY_MAP_LIST="passwd.byuid
737 group.byname
738 hosts.byaddr
739 ipnodes.byaddr
740 ethers.byname
741 networks.byaddr
742 rpc.bynumber
743 services.byname
744 protocols.bynumber
745 netgroup
746 bootparams
747 mail.aliases
748 publickey.byname
749 netid.byname
750 netmasks.byaddr
751 passwd.adjunct.byname
752 group.adjunct.byname
753 timezone.byname
754 auth_attr
755 exec_attr
756 prof_attr
757 user_attr
758 audit_user"
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
769 ${N2LPREFIX}netgroup
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"
792 done
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"
800 done
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
809 DEBUG=1
810 OUTDIR=""
811 CUST_MAP_LIST=""
812 CMDLINE_SRCS=0
815 parse_argument $*
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.
826 exit 1
829 if [ ! -d "$OUTDIR" ]; then
830 echo output directory $OUTDIR does not exist. Creating it.
831 mkdir -p $OUTDIR
832 if [ $? -ne 0 ]; then
833 echo ERROR : Failed to create output directory $OUTDIR
834 exit 1
838 # Cleanup if the temp directory has been leftover
839 [ -d "$TMPDIR" ] && rm -rf $TMPDIR
840 mkdir $TMPDIR
841 if [ $? -ne 0 ]; then
842 echo ERROR : Failed to create temp directory $TMPDIR
843 exit 1
847 for MAP in $MAP_LIST
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..
858 continue
861 case $MAP in
862 ${N2LPREFIX}passwd.byuid )
863 create_passwd
865 ${N2LPREFIX}group.byname )
866 create_group
868 ${N2LPREFIX}hosts.byaddr )
869 create_hosts
871 ${N2LPREFIX}ipnodes.byaddr )
872 create_ipnodes
874 ${N2LPREFIX}ethers.byname )
875 create_ethers
877 ${N2LPREFIX}networks.byaddr )
878 create_networks
880 ${N2LPREFIX}rpc.bynumber )
881 create_rpc
883 ${N2LPREFIX}services.byname )
884 create_services
886 ${N2LPREFIX}protocols.bynumber )
887 create_protocols
889 ${N2LPREFIX}netgroup )
890 create_netgroup
892 ${N2LPREFIX}bootparams )
893 create_bootparams
895 ${N2LPREFIX}mail.aliases )
896 create_aliases
898 ${N2LPREFIX}publickey.byname )
899 create_publickey
901 ${N2LPREFIX}netid.byname )
902 create_netid
904 ${N2LPREFIX}netmasks.byaddr )
905 create_netmasks
907 ${N2LPREFIX}passwd.adjunct.byname )
908 create_passwd_adjunct
910 ${N2LPREFIX}group.adjunct.byname )
911 create_group_adjunct
913 ${N2LPREFIX}timezone.byname )
914 create_timezone
916 ${N2LPREFIX}auto.* )
917 create_auto_src
919 ${N2LPREFIX}auth_attr )
920 create_auth_attr
922 ${N2LPREFIX}exec_attr )
923 create_exec_attr
925 ${N2LPREFIX}prof_attr )
926 create_prof_attr
928 ${N2LPREFIX}user_attr )
929 create_user_attr
931 ${N2LPREFIX}audit_user )
932 create_audit_user
934 *) # Not a default map, could be a custom map.
935 CUST_MAP_LIST="$CUST_MAP_LIST $MAP"
937 esac
938 done
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..
947 continue
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
966 done
968 # Leave the temp directory if debug is set
969 [ $DEBUG -eq 0 ] && rm -rf $TMPDIR
971 exit 0