#!/usr/bin/perl -w
#
# $Revision: 1.2 $ $Date: 2012-07-26 17:06:39-04 $
# $Source: /home/vogelke/bin/RCS/smbcanon,v $
# $Host: sys7.com $
# $UUID: d5ef6384-07a5-3dc0-96eb-f2b3fd091ca3 $
#
#<smbcanon: read smb.conf file, print canonical settings for comparison.

my $str;
my $stanza;
my $key;
my $setting;
my %data;

while (<>) {
    # remove junk.
    chomp;
    s/#.*//;
    s/\s\s*$//g;
    s/^\s\s*//g;
    s/\s\s*/ /g;
    next unless length;

    # allow continuation lines.
    if (s/\\\s*$//) {
        $str = <>;
        $str =~ s/^\s*//g;
        $_ .= $str;
        redo unless eof();
    }

    # save file in form "stanza.key = setting",
    # i.e. "global.log-file = xx"
    if (/\[(.*)\]/) {
        $stanza = $1;
    }

    if (/=/) {
        ($key, $setting) = split(/=/, $_, 2);
        $key =~ s/\s\s*$//g;
        $key =~ s/\s/-/g;

        $setting = "" unless defined($setting);
        $_ = $setting;
        s/,\s/,/g;
        s/^\s\s*//g;
        $_ = 'Yes' if /^yes$/i;
        $_ = 'No' if /^no$/i;
        $data{$stanza . '.' . $key} = $_;
    }
}

# Dump results.

foreach (sort keys %data) {
    print "$_: $data{$_}\n";
}

exit(0);
