convert.pl revision 302408
1139790Simp#!/usr/bin/perl -w
2223528Smarcel#-
3145389Smarcel# Copyright (c) 2001,2002 Networks Associates Technologies, Inc.
466458Sdfr# All rights reserved.
566458Sdfr#
666458Sdfr# This software was developed for the FreeBSD Project by ThinkSec AS and
766458Sdfr# NAI Labs, the Security Research Division of Network Associates, Inc.
8145389Smarcel# under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
966458Sdfr# DARPA CHATS research program.
1066458Sdfr#
1166458Sdfr# Redistribution and use in source and binary forms, with or without
1266458Sdfr# modification, are permitted provided that the following conditions
1366458Sdfr# are met:
1466458Sdfr# 1. Redistributions of source code must retain the above copyright
15145389Smarcel#    notice, this list of conditions and the following disclaimer.
16145389Smarcel# 2. Redistributions in binary form must reproduce the above copyright
17145389Smarcel#    notice, this list of conditions and the following disclaimer in the
18145389Smarcel#    documentation and/or other materials provided with the distribution.
19145389Smarcel# 3. The name of the author may not be used to endorse or promote
20145389Smarcel#    products derived from this software without specific prior written
21145389Smarcel#    permission.
22145389Smarcel#
23145389Smarcel# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24145389Smarcel# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2566458Sdfr# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2666458Sdfr# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27118414Smarcel# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28118414Smarcel# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2966458Sdfr# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3066458Sdfr# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3166458Sdfr# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32205234Smarcel# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33270296Semaste# SUCH DAMAGE.
34205234Smarcel#
35205234Smarcel# $FreeBSD: stable/11/etc/pam.d/convert.pl 130151 2004-06-06 11:46:29Z schweikh $
36223526Smarcel#
3766458Sdfr
3866458Sdfruse strict;
3966458Sdfruse Fcntl;
40223526Smarceluse vars qw(%SERVICES);
4166458Sdfr
42118414SmarcelMAIN:{
4366458Sdfr    my $line;
44118414Smarcel    my $service;
45205234Smarcel    my $version;
46205234Smarcel    my $type;
47200889Smarcel    local *FILE;
48205665Smarcel
4966458Sdfr    while (<>) {
50223526Smarcel	chomp();
51223526Smarcel	s/\s*$//;
52223526Smarcel	next unless m/^(\#*)(\w+)\s+(auth|account|session|password)\s+(\S.*)$/;
53118414Smarcel	$line = $1.$3;
54223526Smarcel	$line .= "\t" x ((16 - length($line) + 7) / 8);
55205234Smarcel	$line .= $4;
56205234Smarcel	push(@{$SERVICES{$2}->{$3}}, $line);
5792667Speter    }
58118414Smarcel
5966458Sdfr    foreach $service (keys(%SERVICES)) {
6066458Sdfr	$version = '$' . 'FreeBSD' . '$';
6166458Sdfr	if (sysopen(FILE, $service, O_RDONLY)) {
6266458Sdfr		while (<FILE>) {
63118414Smarcel			next unless (m/(\$[F]reeBSD.*?\$)/);
6466458Sdfr			$version = $1;
65115178Smarcel			last;
6666458Sdfr		}
6766458Sdfr		close(FILE);
68205234Smarcel	}
69118414Smarcel	sysopen(FILE, $service, O_RDWR|O_CREAT|O_TRUNC)
70118414Smarcel	    or die("$service: $!\n");
71118414Smarcel	print(FILE "#\n");
72118414Smarcel	print(FILE "# $version\n");
7392667Speter	print(FILE "#\n");
7466458Sdfr	print(FILE "# PAM configuration for the \"$service\" service\n");
75205234Smarcel	print(FILE "#\n");
76205234Smarcel	foreach $type (qw(auth account session password)) {
77205234Smarcel	    next unless exists($SERVICES{$service}->{$type});
78223526Smarcel	    print(FILE "\n");
79268195Smarcel	    print(FILE "# $type\n");
80223526Smarcel	    print(FILE join("\n", @{$SERVICES{$service}->{$type}}, ""));
81223526Smarcel	}
82205234Smarcel	close(FILE);
83205234Smarcel	warn("$service\n");
84223526Smarcel    }
85205234Smarcel
86223526Smarcel    exit(0);
87223526Smarcel}
88205234Smarcel