convert.pl revision 87416
187416Sdes#!/usr/bin/perl -w
287416Sdes#-
387416Sdes# Copyright (c) 2001 Networks Associates Technologies, Inc.
487416Sdes# All rights reserved.
587416Sdes#
687416Sdes# This software was developed for the FreeBSD Project by ThinkSec AS and
787416Sdes# NAI Labs, the Security Research Division of Network Associates, Inc.
887416Sdes# under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
987416Sdes# DARPA CHATS research program.
1087416Sdes#
1187416Sdes# Redistribution and use in source and binary forms, with or without
1287416Sdes# modification, are permitted provided that the following conditions
1387416Sdes# are met:
1487416Sdes# 1. Redistributions of source code must retain the above copyright
1587416Sdes#    notice, this list of conditions and the following disclaimer.
1687416Sdes# 2. Redistributions in binary form must reproduce the above copyright
1787416Sdes#    notice, this list of conditions and the following disclaimer in the
1887416Sdes#    documentation and/or other materials provided with the distribution.
1987416Sdes# 3. The name of the author may not be used to endorse or promote
2087416Sdes#    products derived from this software without specific prior written
2187416Sdes#    permission.
2287416Sdes#
2387416Sdes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2487416Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2587416Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2687416Sdes# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2787416Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2887416Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2987416Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3087416Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3187416Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3287416Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3387416Sdes# SUCH DAMAGE.
3487416Sdes#
3587416Sdes# $FreeBSD: head/etc/pam.d/convert.pl 87416 2001-12-05 20:58:39Z des $
3687416Sdes#
3787416Sdes
3887416Sdesuse strict;
3987416Sdesuse Fcntl;
4087416Sdesuse vars qw(%SERVICES);
4187416Sdes
4287416SdesMAIN:{
4387416Sdes    my $service;
4487416Sdes    my $type;
4587416Sdes    local *FILE;
4687416Sdes
4787416Sdes    while (<>) {
4887416Sdes	chomp();
4987416Sdes	s/\s*$//;
5087416Sdes	next unless m/^\#*(\w+)\s+(auth|account|session|password)\s+(\S.*)$/;
5187416Sdes	push(@{$SERVICES{$1}->{$2}}, $_);
5287416Sdes    }
5387416Sdes
5487416Sdes    foreach $service (keys(%SERVICES)) {
5587416Sdes	sysopen(FILE, $service, O_RDWR|O_CREAT|O_TRUNC)
5687416Sdes	    or die("$service: $!\n");
5787416Sdes	print(FILE "#\n");
5887416Sdes	print(FILE "# \$FreeBSD\$\n");
5987416Sdes	print(FILE "#\n");
6087416Sdes	print(FILE "# PAM configuration for the \"$service\" service\n");
6187416Sdes	print(FILE "#\n");
6287416Sdes	foreach $type (qw(auth account session password)) {
6387416Sdes	    next unless exists($SERVICES{$service}->{$type});
6487416Sdes	    print(FILE "\n");
6587416Sdes	    print(FILE "# $type\n");
6687416Sdes	    print(FILE join("\n", @{$SERVICES{$service}->{$type}}, ""));
6787416Sdes	}
6887416Sdes	close(FILE);
6987416Sdes	warn("$service\n");
7087416Sdes    }
7187416Sdes
7287416Sdes    exit(0);
7387416Sdes}
74