1*219cf81bSBrad Davis#!/usr/bin/perl -w 2*219cf81bSBrad Davis#- 3*219cf81bSBrad Davis# SPDX-License-Identifier: BSD-3-Clause 4*219cf81bSBrad Davis# 5*219cf81bSBrad Davis# Copyright (c) 2001,2002 Networks Associates Technologies, Inc. 6*219cf81bSBrad Davis# All rights reserved. 7*219cf81bSBrad Davis# 8*219cf81bSBrad Davis# This software was developed for the FreeBSD Project by ThinkSec AS and 9*219cf81bSBrad Davis# NAI Labs, the Security Research Division of Network Associates, Inc. 10*219cf81bSBrad Davis# under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 11*219cf81bSBrad Davis# DARPA CHATS research program. 12*219cf81bSBrad Davis# 13*219cf81bSBrad Davis# Redistribution and use in source and binary forms, with or without 14*219cf81bSBrad Davis# modification, are permitted provided that the following conditions 15*219cf81bSBrad Davis# are met: 16*219cf81bSBrad Davis# 1. Redistributions of source code must retain the above copyright 17*219cf81bSBrad Davis# notice, this list of conditions and the following disclaimer. 18*219cf81bSBrad Davis# 2. Redistributions in binary form must reproduce the above copyright 19*219cf81bSBrad Davis# notice, this list of conditions and the following disclaimer in the 20*219cf81bSBrad Davis# documentation and/or other materials provided with the distribution. 21*219cf81bSBrad Davis# 3. The name of the author may not be used to endorse or promote 22*219cf81bSBrad Davis# products derived from this software without specific prior written 23*219cf81bSBrad Davis# permission. 24*219cf81bSBrad Davis# 25*219cf81bSBrad Davis# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 26*219cf81bSBrad Davis# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27*219cf81bSBrad Davis# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28*219cf81bSBrad Davis# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 29*219cf81bSBrad Davis# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30*219cf81bSBrad Davis# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31*219cf81bSBrad Davis# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32*219cf81bSBrad Davis# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33*219cf81bSBrad Davis# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34*219cf81bSBrad Davis# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35*219cf81bSBrad Davis# SUCH DAMAGE. 36*219cf81bSBrad Davis# 37*219cf81bSBrad Davis# 38*219cf81bSBrad Davis 39*219cf81bSBrad Davisuse strict; 40*219cf81bSBrad Davisuse Fcntl; 41*219cf81bSBrad Davisuse vars qw(%SERVICES); 42*219cf81bSBrad Davis 43*219cf81bSBrad DavisMAIN:{ 44*219cf81bSBrad Davis my $line; 45*219cf81bSBrad Davis my $service; 46*219cf81bSBrad Davis my $version; 47*219cf81bSBrad Davis my $type; 48*219cf81bSBrad Davis local *FILE; 49*219cf81bSBrad Davis 50*219cf81bSBrad Davis while (<>) { 51*219cf81bSBrad Davis chomp(); 52*219cf81bSBrad Davis s/\s*$//; 53*219cf81bSBrad Davis next unless m/^(\#*)(\w+)\s+(auth|account|session|password)\s+(\S.*)$/; 54*219cf81bSBrad Davis $line = $1.$3; 55*219cf81bSBrad Davis $line .= "\t" x ((16 - length($line) + 7) / 8); 56*219cf81bSBrad Davis $line .= $4; 57*219cf81bSBrad Davis push(@{$SERVICES{$2}->{$3}}, $line); 58*219cf81bSBrad Davis } 59*219cf81bSBrad Davis 60*219cf81bSBrad Davis foreach $service (keys(%SERVICES)) { 61*219cf81bSBrad Davis $version = '$' . 'FreeBSD' . '$'; 62*219cf81bSBrad Davis if (sysopen(FILE, $service, O_RDONLY)) { 63*219cf81bSBrad Davis while (<FILE>) { 64*219cf81bSBrad Davis next unless (m/(\$[F]reeBSD.*?\$)/); 65*219cf81bSBrad Davis $version = $1; 66*219cf81bSBrad Davis last; 67*219cf81bSBrad Davis } 68*219cf81bSBrad Davis close(FILE); 69*219cf81bSBrad Davis } 70*219cf81bSBrad Davis sysopen(FILE, $service, O_RDWR|O_CREAT|O_TRUNC) 71*219cf81bSBrad Davis or die("$service: $!\n"); 72*219cf81bSBrad Davis print(FILE "#\n"); 73*219cf81bSBrad Davis print(FILE "# $version\n"); 74*219cf81bSBrad Davis print(FILE "#\n"); 75*219cf81bSBrad Davis print(FILE "# PAM configuration for the \"$service\" service\n"); 76*219cf81bSBrad Davis print(FILE "#\n"); 77*219cf81bSBrad Davis foreach $type (qw(auth account session password)) { 78*219cf81bSBrad Davis next unless exists($SERVICES{$service}->{$type}); 79*219cf81bSBrad Davis print(FILE "\n"); 80*219cf81bSBrad Davis print(FILE "# $type\n"); 81*219cf81bSBrad Davis print(FILE join("\n", @{$SERVICES{$service}->{$type}}, "")); 82*219cf81bSBrad Davis } 83*219cf81bSBrad Davis close(FILE); 84*219cf81bSBrad Davis warn("$service\n"); 85*219cf81bSBrad Davis } 86*219cf81bSBrad Davis 87*219cf81bSBrad Davis exit(0); 88*219cf81bSBrad Davis} 89