#! /usr/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (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 # # # ident "%Z%%M% %I% %E% SMI" # # Copyright 2003 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ypmap2src -- script to generate source files from YP maps. # # Please save a copy of this script before making any changes. proc usage { echo "Usage: $PROG [-t] [[-c custom-map-name] ...] [-d domain] -o output-directory [[source-file] ...]" echo " t - Generate source files from TRADITIONAL NIS MAPS, default is NIS2LDAP maps." echo " c - Name of the custom map for which source file needs to be generated." echo " d - Specify a different domain, default is local system domain name." echo " o - Specify the output directory where source files can be generated." echo "source-file - The name of the source file for which needs to be generated." exit 0 } proc parse_argument { while getopts "tc:d:o:" ARG { match $ARG { with t setvar N2LPREFIX = """" setvar MAP_LIST = "$NIS_ONLY_MAP_LIST" with c setvar CUST_LIST = ""$CUST_LIST $OPTARG"" with d setvar DOMAIN = "$OPTARG" setvar MAPDIR = "/var/yp/"$DOMAIN"" with o setvar OUTDIR = "$OPTARG" with * echo "ERROR : Invalid argument" usage exit 1 } } # This is to handle if "-t" is supplied after "-c" for MAP in [$CUST_LIST] { setvar CUST_MAP_LIST = ""$CUST_MAP_LIST ${N2LPREFIX}$MAP"" } if test -z $OUTDIR { echo "ERROR : output directory has to be specified." usage exit 1 } # Set source list if supplied shift $(expr $OPTIND - 1) setvar CMDLINE_SRC_LIST = "@ARGV" test $DEBUG -eq 1 && echo CMDLINE_SRC_LIST = $CMDLINE_SRC_LIST # If source(s) supplied on command line, then generate ONLY those file(s). if test $CMDLINE_SRC_LIST != "" { setvar MAP_LIST = """" setvar CMDLINE_SRCS = '1' for SRC in [$CMDLINE_SRC_LIST] { test $DEBUG -eq 1 && echo Parsing Command line SRC = $SRC match $SRC { with passwd setvar MAP = "${N2LPREFIX}passwd.byuid" setvar MAP_LIST = ""$MAP_LIST $MAP"" with group setvar MAP = "${N2LPREFIX}group.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with hosts setvar MAP = "${N2LPREFIX}hosts.byaddr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with ipnodes setvar MAP = "${N2LPREFIX}ipnodes.byaddr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with ethers setvar MAP = "${N2LPREFIX}ethers.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with networks setvar MAP = "${N2LPREFIX}networks.byaddr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with rpc setvar MAP = "${N2LPREFIX}rpc.bynumber" setvar MAP_LIST = ""$MAP_LIST $MAP"" with services setvar MAP = "${N2LPREFIX}services.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with protocols setvar MAP = "${N2LPREFIX}protocols.bynumber" setvar MAP_LIST = ""$MAP_LIST $MAP"" with netgroup setvar MAP = "${N2LPREFIX}netgroup" setvar MAP_LIST = ""$MAP_LIST $MAP"" with bootparams setvar MAP = "${N2LPREFIX}bootparams" setvar MAP_LIST = ""$MAP_LIST $MAP"" with aliases setvar MAP = "${N2LPREFIX}mail.aliases" setvar MAP_LIST = ""$MAP_LIST $MAP"" with publickey setvar MAP = "${N2LPREFIX}publickey.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with netid setvar MAP = "${N2LPREFIX}netid.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with netmasks setvar MAP = "${N2LPREFIX}netmasks.byaddr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with passwd.adjunct setvar MAP = "${N2LPREFIX}passwd.adjunct.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with group.adjunct setvar MAP = "${N2LPREFIX}group.adjunct.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with timezone setvar MAP = "${N2LPREFIX}timezone.byname" setvar MAP_LIST = ""$MAP_LIST $MAP"" with auto.* setvar MAP = "${N2LPREFIX}${SRC}" setvar MAP_LIST = ""$MAP_LIST $MAP"" with auth_attr setvar MAP = "${N2LPREFIX}auth_attr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with exec_attr setvar MAP = "${N2LPREFIX}exec_attr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with prof_attr setvar MAP = "${N2LPREFIX}prof_attr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with user_attr setvar MAP = "${N2LPREFIX}user_attr" setvar MAP_LIST = ""$MAP_LIST $MAP"" with audit_user setvar MAP = "${N2LPREFIX}audit_user" setvar MAP_LIST = ""$MAP_LIST $MAP"" with * # Not a default source, could be a custom source. # Then generate source files from all the available # DBM files for this custom source. setvar MAPFOUND = '0' for dbmfile in [$MAPDIR/${N2LPREFIX}${SRC}.dir \ $MAPDIR/${N2LPREFIX}${SRC}.*.dir] { setvar MAP = $(basename $dbmfile .dir) if test -f $MAPDIR/${MAP}.pag { setvar MAPFOUND = '1' setvar CUST_MAP_LIST = ""$CUST_MAP_LIST $MAP"" } } test $MAPFOUND -eq 0 && \ echo ERROR : No maps found for $SRC. Skipping.. } } } } proc is_root_user { match $(id) { with uid=0\(root\)* return 0 with * return 1 } } proc create_passwd { setvar SRCFILE = 'passwd' setvar SHADOW = 'shadow' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort the entries in ascending order of uid sort -n -t: -k3,3 $TMPDIR/${MAP}.cut > $TMPDIR/${MAP}.sort # If passwd.adjunct is used, the actual password is stored in # this map, and the passwd map contains "##" as the passwd. # In that case, do not generate the shadow file. setvar UID = $(head -1 $TMPDIR/${MAP}.sort | cut -f1 -d:) setvar PSWD = $(head -1 $TMPDIR/${MAP}.sort | cut -f2 -d:) if test $PSWD != "##${UID}" { #Create the shadow file with blank passwd aging information cut -f 1,2 -d: $TMPDIR/${MAP}.sort | sed 's/$/:::::::/' > $OUTDIR/$SHADOW #Make the shadow file readable to root only chmod 400 $OUTDIR/$SHADOW #Create the passwd file with "x" as the passwd awk ' BEGIN { FS = ":"; OFS = ":"} {$2 = "x"; print}' $TMPDIR/${MAP}.sort > $OUTDIR/$SRCFILE } else { cp $TMPDIR/${MAP}.sort $OUTDIR/$SRCFILE } } proc create_group { setvar SRCFILE = 'group' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort the entries in ascending order of gid sort -n -t: -k3,3 $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_hosts { setvar SRCFILE = 'hosts' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort the hosts ip addresses in ascending order sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4 $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_ipnodes { setvar SRCFILE = 'ipnodes' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut grep -v "::" $TMPDIR/${MAP}.cut >$TMPDIR/${MAP}.V4 grep "::" $TMPDIR/${MAP}.cut >$TMPDIR/${MAP}.V6 # Sort the ip addresses in ascending order sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4 $TMPDIR/${MAP}.V4 > $OUTDIR/$SRCFILE # V6 addresses due to hex chars, can't be sorted this way. # So just do the default string sort. sort $TMPDIR/${MAP}.V6 >> $OUTDIR/$SRCFILE } proc create_ethers { setvar SRCFILE = 'ethers' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort ethernet addresses based on host names sort -b -k2 $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_networks { setvar SRCFILE = 'networks' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort networks based on their names sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_rpc { setvar SRCFILE = 'rpc' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort entries in the increasing order of RPC number sort -n -k2 $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_services { setvar SRCFILE = 'services' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort entries in the increasing order of RPC number sort -n -k2 $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_protocols { setvar SRCFILE = 'protocols' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort entries in the increasing order of RPC number sort -n -k2 $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_netgroup { setvar SRCFILE = 'netgroup' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep cp $TMPDIR/${MAP}.grep $OUTDIR/$SRCFILE } proc create_bootparams { setvar SRCFILE = 'bootparams' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Sort the entries sort $TMPDIR/${MAP}.grep > $OUTDIR/$SRCFILE } proc create_aliases { setvar SRCFILE = 'aliases' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Replace first " " with ": " to make it similar to aliases sed 's/ /: /' $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.sed # Sort aliases entries alphabetically sort $TMPDIR/${MAP}.sed > $OUTDIR/$SRCFILE } proc create_publickey { setvar SRCFILE = 'publickey' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Sort entries alphabetically sort $TMPDIR/${MAP}.grep > $OUTDIR/$SRCFILE } proc create_netid { setvar SRCFILE = 'netid' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # netid source files is used to add other domain # entries. So, filter out local domain entries grep -v "@${DOMAIN}" $TMPDIR/${MAP}.grep > $OUTDIR/$SRCFILE } proc create_netmasks { setvar SRCFILE = 'netmasks' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Sort the network numbers in ascending order sort -n -t. -k1,1 -k2,2 -k3,3 -k4,4 $TMPDIR/${MAP}.grep > $OUTDIR/$SRCFILE } proc create_passwd_adjunct { setvar SRCFILE = 'passwd.adjunct' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines. It has three of them. grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME | grep -v YP_SECURE > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut ## Check if sorting is ok, or leave it as it is. # Sort the entries in alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_group_adjunct { setvar SRCFILE = 'group.adjunct' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines. It has three of them. grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME | grep -v YP_SECURE > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort the entries in alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_timezone { setvar SRCFILE = 'timezone' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort the entries in alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_auto_src { setvar SRCFILE = "$MAP" makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Sort entries alphabetically sort $TMPDIR/${MAP}.grep > $OUTDIR/$SRCFILE } proc create_auth_attr { setvar SRCFILE = 'auth_attr' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort entries in the alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_exec_attr { setvar SRCFILE = 'exec_attr' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key which is made of three fields. space is part of key cut -f 3- -d ":" $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut1 cut -f 2- -d " " $TMPDIR/${MAP}.cut1 > $TMPDIR/${MAP}.cut2 # Sort entries in the alphabetical order sort $TMPDIR/${MAP}.cut2 > $OUTDIR/$SRCFILE } proc create_prof_attr { setvar SRCFILE = 'prof_attr' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key. It is difficult here as space is part of the key. # From the "key key" part, extract "key", and then paste it with # the rest of the entry. cut -f1 -d: $TMPDIR/${MAP}.grep | awk '{ STR = $1 for (i=2; i <= NF/2; i++) { STR = STR " " $i } print STR }' > $TMPDIR/${MAP}.cut1 cut -f2- -d: $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut2 paste -d ":" $TMPDIR/${MAP}.cut1 $TMPDIR/${MAP}.cut2 > $TMPDIR/${MAP}.cut # Sort entries in the alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_user_attr { setvar SRCFILE = 'user_attr' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort entries in the alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } proc create_audit_user { setvar SRCFILE = 'audit_user' makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines. It has 3 of them. grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME | grep -v YP_SECURE > $TMPDIR/${MAP}.grep # Remove the key cut -f 2- -d " " $TMPDIR/${MAP}.grep > $TMPDIR/${MAP}.cut # Sort entries in the alphabetical order sort $TMPDIR/${MAP}.cut > $OUTDIR/$SRCFILE } ## MAIN ## setvar PROG = $(basename $0) # Only root can read the NIS maps, so no point allowing # non-root users to be able to run this script. is_root_user if test $Status -ne 0 { echo "ERROR : Only root can run $PROG" exit 1 } # Prevent non-root users from reading/writing umask 077 # Initialize default values. setvar DOMAIN = $(/usr/bin/domainname) setvar MAPDIR = "/var/yp/"$DOMAIN"" # Default to local domain setvar N2LPREFIX = 'LDAP_' setvar NIS_ONLY_MAP_LIST = ""passwd.byuid group.byname hosts.byaddr ipnodes.byaddr ethers.byname networks.byaddr rpc.bynumber services.byname protocols.bynumber netgroup bootparams mail.aliases publickey.byname netid.byname netmasks.byaddr passwd.adjunct.byname group.adjunct.byname timezone.byname auth_attr exec_attr prof_attr user_attr audit_user"" setvar NIS2LDAP_MAP_LIST = ""${N2LPREFIX}passwd.byuid ${N2LPREFIX}group.byname ${N2LPREFIX}hosts.byaddr ${N2LPREFIX}ipnodes.byaddr ${N2LPREFIX}ethers.byname ${N2LPREFIX}networks.byaddr ${N2LPREFIX}rpc.bynumber ${N2LPREFIX}services.byname ${N2LPREFIX}protocols.bynumber ${N2LPREFIX}netgroup ${N2LPREFIX}bootparams ${N2LPREFIX}mail.aliases ${N2LPREFIX}publickey.byname ${N2LPREFIX}netid.byname ${N2LPREFIX}netmasks.byaddr ${N2LPREFIX}passwd.adjunct.byname ${N2LPREFIX}group.adjunct.byname ${N2LPREFIX}timezone.byname ${N2LPREFIX}auth_attr ${N2LPREFIX}exec_attr ${N2LPREFIX}prof_attr ${N2LPREFIX}user_attr ${N2LPREFIX}audit_user"" # If auto maps exist, add them to the respective lists. for dbmfile in [$MAPDIR/auto.*.dir] { setvar MAP = $(basename $dbmfile .dir) if test -f $MAPDIR/${MAP}.pag { setvar NIS_ONLY_MAP_LIST = ""$NIS_ONLY_MAP_LIST $MAP"" } } for dbmfile in [$MAPDIR/${N2LPREFIX}auto.*.dir] { setvar MAP = $(basename $dbmfile .dir) if test -f $MAPDIR/${MAP}.pag { setvar NIS2LDAP_MAP_LIST = ""$NIS2LDAP_MAP_LIST $MAP"" } } # Default to N2L maps setvar MAP_LIST = "$NIS2LDAP_MAP_LIST" # Safe place to avoid anyone from reading sensitive data. setvar TMPDIR = ""/var/tmp/ypmap2src"" setvar DEBUG = '0' # Default to debug off setvar DEBUG = '1' setvar OUTDIR = """" setvar CUST_MAP_LIST = """" setvar CMDLINE_SRCS = '0' parse_argument $ifsjoin(ARGV) test $DEBUG -eq 1 && echo DOMAIN = $DOMAIN test $DEBUG -eq 1 && echo OUTDIR = $OUTDIR test $DEBUG -eq 1 && echo TMPDIR = $TMPDIR test $DEBUG -eq 1 && echo CUST_MAP_LIST = $CUST_MAP_LIST test $DEBUG -eq 1 && echo MAP_LIST = $MAP_LIST test $DEBUG -eq 1 && echo MAPDIR = $MAPDIR if test ! -d $MAPDIR { echo ERROR : NIS Map directory $MAPDIR does not exist. exit 1 } if test ! -d $OUTDIR { echo output directory $OUTDIR does not exist. Creating it. mkdir -p $OUTDIR if test $Status -ne 0 { echo ERROR : Failed to create output directory $OUTDIR exit 1 } } # Cleanup if the temp directory has been leftover test -d $TMPDIR && rm -rf $TMPDIR mkdir $TMPDIR if test $Status -ne 0 { echo ERROR : Failed to create temp directory $TMPDIR exit 1 } for MAP in [$MAP_LIST] { test $DEBUG -eq 1 && echo Processing MAP = $MAP if test ! -f $MAPDIR/${MAP}.dir || test ! -f $MAPDIR/${MAP}.pag { test $CMDLINE_SRCS -ne 0 && \ echo ERROR : Missing DBM file for $MAP in $MAPDIR . Skipping.. test $DEBUG -eq 1 && test $CMDLINE_SRCS -eq 0 && \ echo No DBM file for $MAP in $MAPDIR . Skipping.. continue } match $MAP { with ${N2LPREFIX}passwd.byuid create_passwd with ${N2LPREFIX}group.byname create_group with ${N2LPREFIX}hosts.byaddr create_hosts with ${N2LPREFIX}ipnodes.byaddr create_ipnodes with ${N2LPREFIX}ethers.byname create_ethers with ${N2LPREFIX}networks.byaddr create_networks with ${N2LPREFIX}rpc.bynumber create_rpc with ${N2LPREFIX}services.byname create_services with ${N2LPREFIX}protocols.bynumber create_protocols with ${N2LPREFIX}netgroup create_netgroup with ${N2LPREFIX}bootparams create_bootparams with ${N2LPREFIX}mail.aliases create_aliases with ${N2LPREFIX}publickey.byname create_publickey with ${N2LPREFIX}netid.byname create_netid with ${N2LPREFIX}netmasks.byaddr create_netmasks with ${N2LPREFIX}passwd.adjunct.byname create_passwd_adjunct with ${N2LPREFIX}group.adjunct.byname create_group_adjunct with ${N2LPREFIX}timezone.byname create_timezone with ${N2LPREFIX}auto.* create_auto_src with ${N2LPREFIX}auth_attr create_auth_attr with ${N2LPREFIX}exec_attr create_exec_attr with ${N2LPREFIX}prof_attr create_prof_attr with ${N2LPREFIX}user_attr create_user_attr with ${N2LPREFIX}audit_user create_audit_user with * # Not a default map, could be a custom map. setvar CUST_MAP_LIST = ""$CUST_MAP_LIST $MAP"" } } for MAP in [$CUST_MAP_LIST] { test $DEBUG -eq 1 && echo Processing Custom MAP = $MAP if test ! -f $MAPDIR/${MAP}.dir || test ! -f $MAPDIR/${MAP}.pag { echo ERROR : Missing DBM file for $MAP in $MAPDIR . Skipping.. continue } makedbm -u $MAPDIR/$MAP > $TMPDIR/$MAP # Remove the YP operational lines. Assuming each custom map # has only these entries (three in n2l mode as shown below, and # two in vanilla NIS mode as it does not have "YP_DOMAIN_NAME". # But that does not require any changes in the code). Modify it # appropriately in other cases. grep -v YP_LAST_MODIFIED $TMPDIR/$MAP | grep -v "YP_DOMAIN_NAME $DOMAIN" | grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep # If further processing (e.g., removing key, sorting etc.) # is required, then update the script appropriately. cp $TMPDIR/${MAP}.grep $OUTDIR/$MAP } # Leave the temp directory if debug is set test $DEBUG -eq 0 && rm -rf $TMPDIR exit 0