1 #!/bin/sh 2 # 3 # CDDL HEADER START 4 # 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. 9 # 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. 14 # 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] 20 # 21 # CDDL HEADER END 22 # 23 # 24 # ident "%Z%%M% %I% %E% SMI" 25 # 26 # Copyright (c) 2001 by Sun Microsystems, Inc. 27 # All rights reserved. 28 # 29 # This script serves two purposes. First, it saves the original copy 30 # of ftpaccess if there is one, and writes a log entry if this action 31 # was taken. 32 # Second, it parses the etc/default file for BANNER and UMASK directives 33 # and re-writes the values into the etc/inet/ftpaccess file IFF the 34 # basename of the file is ftpaccess (just in case this class script is 35 # reused for other files). 36 # 37 38 tag=new 39 CLEANUP_FILE=/tmp/CLEANUP 40 # 41 # By default, remove the default/ftpd file. If expansions cause 42 # problems, this option will be turned off. 43 RMDEFAULT=1 44 defaultfile=/etc/default/ftpd 45 defaultpath=${PKG_INSTALL_ROOT}${defaultfile} 46 bannermsg="Could not update greeting directive" 47 resolvmsg="Please manually convert BANNER in %s into greeting text in %s and then remove %s" 48 49 if [ -f $defaultpath ]; then 50 # Check for UMASK and BANNER strings in the default/ftpd file 51 # The UMASK string should be all numeric, but is still correctly 52 # parsed if there are trailing non-numeric characters. Also 53 # note that only trailing characters and dumped 54 # It is still OK to delete the DEFAULT file as any value 55 # other than numeric was previously ignored. 56 57 defumask=`sed -n '/^[ ]*UMASK=.*$/{ 58 s/^[ ]*UMASK=\([0-9]*\).*/\1/p 59 q 60 }' $defaultpath` 61 62 # The BANNER value is a little more complex, as we need to look 63 # at each character for the "Special" characters: "`", "$", "\". 64 # Note that the special characters need to be inline below, and 65 # must each be escaped inside the single quotes. 66 67 banner=`sed -n '/^[ ]*BANNER=.*$/{ 68 s/^[ ]*BANNER=//p 69 q 70 }' $defaultpath` 71 greeting=`echo "$banner" | sed "s/^[\'\"]//" | sed "s/[\'\"]$//"` 72 73 if [ -n "$banner" ]; then 74 echo "$greeting" | egrep -s '[\$\`\\]' 75 RMDEFAULT=$? 76 if [ $RMDEFAULT -eq 0 ]; then 77 greeting="" 78 fi 79 fi 80 fi 81 82 while read src dest; do 83 # 84 # Put the defumask and greeting values into the ftpaccess file 85 # 86 target=`basename $src` 87 if [ $target = ftpaccess ]; then 88 edit=$src 89 if [ -n "$greeting" ]; then 90 nawk '$1 == "greeting" \ 91 {print "greeting text " greeting; next}\ 92 {print $0}' greeting="$greeting" $edit > /tmp/d1.$$ 93 94 edit=/tmp/d1.$$ 95 fi 96 if [ -n "$defumask" ]; then 97 cat $edit > /tmp/d2.$$ 98 echo "defumask $defumask" >> /tmp/d2.$$ 99 edit=/tmp/d2.$$ 100 fi 101 src=$edit 102 if [ $RMDEFAULT -eq 0 ]; then 103 printf "%s: $bannermsg\n" $dest >> $CLEANUP_FILE 104 printf "%s: $resolvmsg\n" $dest $defaultfile $dest \ 105 $defaultfile >> $CLEANUP_FILE 106 else 107 rm -f $defaultpath 108 fi 109 fi 110 if [ ! -f $dest ]; then 111 cp $src $dest 112 else 113 cmp -s $src $dest 114 if [ $? -ne 0 ]; then 115 cp $src $dest.$tag 116 echo "EXISTING_FILE_PRESERVED: $dest $dest.$tag" \ 117 >> $CLEANUP_FILE 118 fi 119 fi 120 rm -f /tmp/d1.$$ /tmp/d2.$$ 121 done 122 123 exit 0 124