1*86d7f5d3SJohn Marino#! /bin/sh 2*86d7f5d3SJohn Marino# 3*86d7f5d3SJohn Marino# Copyright (c) 2005 The DragonFly Project. All rights reserved. 4*86d7f5d3SJohn Marino# 5*86d7f5d3SJohn Marino# This code is derived from software contributed to The DragonFly Project 6*86d7f5d3SJohn Marino# by Joerg Sonnenberger <joerg@bec.de> 7*86d7f5d3SJohn Marino# 8*86d7f5d3SJohn Marino# Redistribution and use in source and binary forms, with or without 9*86d7f5d3SJohn Marino# modification, are permitted provided that the following conditions 10*86d7f5d3SJohn Marino# are met: 11*86d7f5d3SJohn Marino# 12*86d7f5d3SJohn Marino# 1. Redistributions of source code must retain the above copyright 13*86d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer. 14*86d7f5d3SJohn Marino# 2. Redistributions in binary form must reproduce the above copyright 15*86d7f5d3SJohn Marino# notice, this list of conditions and the following disclaimer in 16*86d7f5d3SJohn Marino# the documentation and/or other materials provided with the 17*86d7f5d3SJohn Marino# distribution. 18*86d7f5d3SJohn Marino# 3. Neither the name of The DragonFly Project nor the names of its 19*86d7f5d3SJohn Marino# contributors may be used to endorse or promote products derived 20*86d7f5d3SJohn Marino# from this software without specific, prior written permission. 21*86d7f5d3SJohn Marino# 22*86d7f5d3SJohn Marino# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23*86d7f5d3SJohn Marino# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24*86d7f5d3SJohn Marino# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25*86d7f5d3SJohn Marino# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26*86d7f5d3SJohn Marino# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27*86d7f5d3SJohn Marino# INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 28*86d7f5d3SJohn Marino# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29*86d7f5d3SJohn Marino# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30*86d7f5d3SJohn Marino# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31*86d7f5d3SJohn Marino# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32*86d7f5d3SJohn Marino# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33*86d7f5d3SJohn Marino# SUCH DAMAGE. 34*86d7f5d3SJohn Marino# 35*86d7f5d3SJohn Marino# $DragonFly: src/etc/pam.d/convert.sh,v 1.1 2005/07/22 18:20:43 joerg Exp $ 36*86d7f5d3SJohn Marino 37*86d7f5d3SJohn Marinoif [ $# -ge 1 ] 38*86d7f5d3SJohn Marinothen 39*86d7f5d3SJohn Marino dir="$1" 40*86d7f5d3SJohn Marinoelse 41*86d7f5d3SJohn Marino dir=/etc/pam.d 42*86d7f5d3SJohn Marinofi 43*86d7f5d3SJohn Marinoif [ $# = 2 ] 44*86d7f5d3SJohn Marinothen 45*86d7f5d3SJohn Marino file="$2" 46*86d7f5d3SJohn Marinoelse 47*86d7f5d3SJohn Marino file=/etc/pam.conf 48*86d7f5d3SJohn Marinofi 49*86d7f5d3SJohn Marinoif [ $# -gt 2 ] 50*86d7f5d3SJohn Marinothen 51*86d7f5d3SJohn Marino echo "Usage: $0 [ output directory ] [ input file ]" 52*86d7f5d3SJohn Marino echo "Default output is /etc/pam.d, default input is /etc/pam.conf" 53*86d7f5d3SJohn Marino exit 1 54*86d7f5d3SJohn Marinofi 55*86d7f5d3SJohn Marino 56*86d7f5d3SJohn Marinoawk '/^([#[:space:]]*)([[:alnum:]_]+)[[:space:]]+(auth|account|session|password)[[:space:]]+([^[:space:]].*)$/ { 57*86d7f5d3SJohn Marino match($0, /[#[:space:]]*/) 58*86d7f5d3SJohn Marino prefix = substr($0, 0, RLENGTH) 59*86d7f5d3SJohn Marino $0 = substr($0, RLENGTH + 1) 60*86d7f5d3SJohn Marino match($0, /[[:alnum:]_]+/) 61*86d7f5d3SJohn Marino name = substr($0, 0, RLENGTH) 62*86d7f5d3SJohn Marino $0 = substr($0, RLENGTH + 1) 63*86d7f5d3SJohn Marino match($0, /[[:space:]]+/) 64*86d7f5d3SJohn Marino $0 = substr($0, RLENGTH + 1) 65*86d7f5d3SJohn Marino match($0, /(auth|account|session|password)/) 66*86d7f5d3SJohn Marino type = substr($0, 0, RLENGTH) 67*86d7f5d3SJohn Marino $0 = substr($0, RLENGTH + 1) 68*86d7f5d3SJohn Marino match($0, /[[:space:]]+/) 69*86d7f5d3SJohn Marino arg = substr($0, RLENGTH + 1) 70*86d7f5d3SJohn Marino 71*86d7f5d3SJohn Marino line = prefix type 72*86d7f5d3SJohn Marino tabs = ((16 - length(line)) / 8) 73*86d7f5d3SJohn Marino for (i = 0; i < tabs; i++) 74*86d7f5d3SJohn Marino line = line "\t" 75*86d7f5d3SJohn Marino if ((name, type) in content) 76*86d7f5d3SJohn Marino content[name, type] = content[name, type] "\n" line arg 77*86d7f5d3SJohn Marino else 78*86d7f5d3SJohn Marino content[name, type] = line arg 79*86d7f5d3SJohn Marino services[name] = name 80*86d7f5d3SJohn Marino} 81*86d7f5d3SJohn Marino 82*86d7f5d3SJohn MarinoEND { 83*86d7f5d3SJohn Marino 'fdir=\"$dir\"' 84*86d7f5d3SJohn Marino 85*86d7f5d3SJohn Marino split("auth account session password", types, " ") 86*86d7f5d3SJohn Marino for (service in services) { 87*86d7f5d3SJohn Marino fname = fdir "/" service 88*86d7f5d3SJohn Marino system("rm -f " fname) 89*86d7f5d3SJohn Marino print "#\n# $DragonFly: src/etc/pam.d/convert.sh,v 1.1 2005/07/22 18:20:43 joerg Exp $\n#\n# PAM configuration for the \"" service "\" service\n#\n" >> fname 90*86d7f5d3SJohn Marino for (type in types) 91*86d7f5d3SJohn Marino if ((service, types[type]) in content) 92*86d7f5d3SJohn Marino print content[service, types[type]] >> fname 93*86d7f5d3SJohn Marino close(fname) 94*86d7f5d3SJohn Marino } 95*86d7f5d3SJohn Marino}' < $file 96