4

kerberos 構成ファイル (つまり ) を解析 (および書き込み) する Perl モジュールに遭遇した人はいます/etc/krb5.confか? Config::GeneralConfig::Autoなどのかなりの数の解析モジュールを見てきましたが、次のようなネストされた構造を処理できるものはないようです。

pam = {
  debug = false
  ticket_lifetime = 36000
  renew_lifetime = 36000
  forwardable = true
  krb4_convert = false
}

またINI、次のような -style セクションも処理する必要があります。

[domain_realm]
 .example.com = EXAMPLE.COM
 example.com = EXAMPLE.COM

[appdefaults]
 pam = {
   debug = false
   ticket_lifetime = 36000
   renew_lifetime = 36000
   forwardable = true
   krb4_convert = false
 }

形式の詳細については、krb5 conf ドキュメントを参照してください。

私は自分のパーサーを書いているところですが、他の誰かが素敵でエレガントなモジュールを既に書いているのであれば、そうする必要はありません。

4

1 に答える 1

3

I guess if it takes about 10 minutes to write a parser, it is probably not so interesting to make it a module. Here's a piece of code that probably does the job (disclaimer: I don't know anything about the config format for Kerberos, the code is based on what you posted here).

#!/usr/bin/perl -w
use strict;

my %conf;
my $section;

while (<>) {
    if (/^\s*(\S*)\s*=\s*\{\s*$/) {
        $section = $1;
        $conf{$section} = {};
    } elsif (/^\s*(\S*)\s*=\s*(\S*)\s*$/) {
        my $key = $1;
        my $value = $2;
        if ($section) {
            $conf{$section}{$key}=$value;
        }
    }
}

foreach (keys %conf) {
    $section = $_;
    foreach (keys %{$conf{$section}}) {
        print "$section:$_:$conf{$section}{$_}\n";
    }
}

EDIT: Parsing the ini format is not difficult either. You will just need to add a few more if's in the while loop, and make the data structure %conf slightly more complicated. Instead of a hash of hash, you will need a hash of hash of hash, where the first level key is the keyword in [...], and the second level is what I wrote here (for "pam = {").

于 2009-01-07T01:51:07.407 に答える