187416Sdes#!/usr/bin/perl -w 287416Sdes#- 3330449Seadler# SPDX-License-Identifier: BSD-3-Clause 4330449Seadler# 589289Sdes# Copyright (c) 2001,2002 Networks Associates Technologies, Inc. 687416Sdes# All rights reserved. 787416Sdes# 887416Sdes# This software was developed for the FreeBSD Project by ThinkSec AS and 987416Sdes# NAI Labs, the Security Research Division of Network Associates, Inc. 1087416Sdes# under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 1187416Sdes# DARPA CHATS research program. 1287416Sdes# 1387416Sdes# Redistribution and use in source and binary forms, with or without 1487416Sdes# modification, are permitted provided that the following conditions 1587416Sdes# are met: 1687416Sdes# 1. Redistributions of source code must retain the above copyright 1787416Sdes# notice, this list of conditions and the following disclaimer. 1887416Sdes# 2. Redistributions in binary form must reproduce the above copyright 1987416Sdes# notice, this list of conditions and the following disclaimer in the 2087416Sdes# documentation and/or other materials provided with the distribution. 2187416Sdes# 3. The name of the author may not be used to endorse or promote 2287416Sdes# products derived from this software without specific prior written 2387416Sdes# permission. 2487416Sdes# 2587416Sdes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2687416Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2787416Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2887416Sdes# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2987416Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3087416Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3187416Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3287416Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3387416Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3487416Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3587416Sdes# SUCH DAMAGE. 3687416Sdes# 3787416Sdes# $FreeBSD: stable/11/etc/pam.d/convert.pl 330449 2018-03-05 07:26:05Z eadler $ 3887416Sdes# 3987416Sdes 4087416Sdesuse strict; 4187416Sdesuse Fcntl; 4287416Sdesuse vars qw(%SERVICES); 4387416Sdes 4487416SdesMAIN:{ 4587423Sdes my $line; 4687416Sdes my $service; 4789285Sdes my $version; 4887416Sdes my $type; 4987416Sdes local *FILE; 50130151Sschweikh 5187416Sdes while (<>) { 5287416Sdes chomp(); 5387416Sdes s/\s*$//; 5487423Sdes next unless m/^(\#*)(\w+)\s+(auth|account|session|password)\s+(\S.*)$/; 5587423Sdes $line = $1.$3; 5687423Sdes $line .= "\t" x ((16 - length($line) + 7) / 8); 5787423Sdes $line .= $4; 5887423Sdes push(@{$SERVICES{$2}->{$3}}, $line); 5987416Sdes } 6087416Sdes 6187416Sdes foreach $service (keys(%SERVICES)) { 6289298Sdes $version = '$' . 'FreeBSD' . '$'; 6389285Sdes if (sysopen(FILE, $service, O_RDONLY)) { 6489285Sdes while (<FILE>) { 6589298Sdes next unless (m/(\$[F]reeBSD.*?\$)/); 6689285Sdes $version = $1; 6789285Sdes last; 6889285Sdes } 6989285Sdes close(FILE); 7089285Sdes } 7187416Sdes sysopen(FILE, $service, O_RDWR|O_CREAT|O_TRUNC) 7287416Sdes or die("$service: $!\n"); 7387416Sdes print(FILE "#\n"); 7489285Sdes print(FILE "# $version\n"); 7587416Sdes print(FILE "#\n"); 7687416Sdes print(FILE "# PAM configuration for the \"$service\" service\n"); 7787416Sdes print(FILE "#\n"); 7887416Sdes foreach $type (qw(auth account session password)) { 7987416Sdes next unless exists($SERVICES{$service}->{$type}); 8087416Sdes print(FILE "\n"); 8187416Sdes print(FILE "# $type\n"); 8287416Sdes print(FILE join("\n", @{$SERVICES{$service}->{$type}}, "")); 8387416Sdes } 8487416Sdes close(FILE); 8587416Sdes warn("$service\n"); 8687416Sdes } 87130151Sschweikh 8887416Sdes exit(0); 8987416Sdes} 90