ypmap2src.sh revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# 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
# 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.
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
}
{
do
t) N2LPREFIX=""
;;
c) CUST_LIST="$CUST_LIST $OPTARG"
;;
;;
;;
*) echo "ERROR : Invalid argument"
exit 1
;;
esac
done
# This is to handle if "-t" is supplied after "-c"
for MAP in $CUST_LIST
do
CUST_MAP_LIST="$CUST_MAP_LIST ${N2LPREFIX}$MAP"
done
echo "ERROR : output directory has to be specified."
exit 1
fi
# Set source list if supplied
CMDLINE_SRC_LIST="$@"
[ $DEBUG -eq 1 ] && echo CMDLINE_SRC_LIST = $CMDLINE_SRC_LIST
# If source(s) supplied on command line, then generate ONLY those file(s).
MAP_LIST=""
for SRC in $CMDLINE_SRC_LIST
do
passwd )
;;
group )
;;
hosts )
;;
ipnodes )
;;
ethers )
;;
networks )
;;
rpc )
;;
services )
;;
;;
netgroup )
;;
;;
aliases )
;;
;;
netid )
;;
netmasks )
;;
;;
;;
timezone )
;;
auto.* )
;;
;;
;;
;;
;;
;;
*) # Not a default source, could be a custom source.
# Then generate source files from all the available
# DBM files for this custom source.
MAPFOUND=0
do
MAPFOUND=1
fi
done
;;
esac
done
fi
}
{
;;
* ) return 1
;;
esac
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort the entries in ascending order of uid
# If passwd.adjunct is used, the actual password is stored in
# this map, and the passwd map contains "##<uid>" as the passwd.
# In that case, do not generate the shadow file.
#Create the shadow file with blank passwd aging information
#Make the shadow file readable to root only
#Create the passwd file with "x" as the passwd
awk ' BEGIN { FS = ":"; OFS = ":"}
else
fi
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort the entries in ascending order of gid
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort the hosts ip addresses in ascending order
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort the ip addresses in ascending order
# V6 addresses due to hex chars, can't be sorted this way.
# So just do the default string sort.
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort ethernet addresses based on host names
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort networks based on their names
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort entries in the increasing order of RPC number
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort entries in the increasing order of RPC number
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort entries in the increasing order of RPC number
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Sort the entries
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Replace first " " with ": " to make it similar to aliases
# Sort aliases entries alphabetically
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Sort entries alphabetically
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# netid source files is used to add other domain
# entries. So, filter out local domain entries
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Sort the network numbers in ascending order
}
{
# Remove the YP operational lines. It has three of them.
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
# Remove the key
## Check if sorting is ok, or leave it as it is.
# Sort the entries in alphabetical order
}
{
# Remove the YP operational lines. It has three of them.
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
# Remove the key
# Sort the entries in alphabetical order
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort the entries in alphabetical order
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Sort entries alphabetically
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort entries in the alphabetical order
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key which is made of three fields. space is part of key
# Sort entries in the alphabetical order
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
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.
awk '{
STR = $1
for (i=2; i <= NF/2; i++) {
STR = STR " " $i
}
print STR
# Sort entries in the alphabetical order
}
{
# Remove the YP operational lines
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
grep -v YP_MASTER_NAME > $TMPDIR/${MAP}.grep
# Remove the key
# Sort entries in the alphabetical order
}
{
# Remove the YP operational lines. It has 3 of them.
grep -v YP_LAST_MODIFIED $TMPDIR/$MAP |
# Remove the key
# Sort entries in the alphabetical order
}
## MAIN ##
# Only root can read the NIS maps, so no point allowing
# non-root users to be able to run this script.
if [ $? -ne 0 ]; then
echo "ERROR : Only root can run $PROG"
exit 1
fi
umask 077
# Initialize default values.
DOMAIN=`/usr/bin/domainname`
netgroup
bootparams
auth_attr
exec_attr
prof_attr
user_attr
audit_user"
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.
do
fi
done
do
fi
done
# Default to N2L maps
# Safe place to avoid anyone from reading sensitive data.
DEBUG=1
OUTDIR=""
if [ ! -d "$MAPDIR" ]; then
exit 1
fi
if [ ! -d "$OUTDIR" ]; then
if [ $? -ne 0 ]; then
exit 1
fi
fi
# Cleanup if the temp directory has been leftover
if [ $? -ne 0 ]; then
exit 1
fi
do
continue
fi
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;
${N2LPREFIX}bootparams )
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;
;;
${N2LPREFIX}audit_user )
;;
*) # Not a default map, could be a custom map.
;;
esac
done
do
continue
fi
# 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.
# If further processing (e.g., removing key, sorting etc.)
# is required, then update the script appropriately.
done
# Leave the temp directory if debug is set
exit 0