code_junkie

How can I edit Kerberos 5 configuration files with Perl?

Nov 13th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. pam = {
  2. debug = false
  3. ticket_lifetime = 36000
  4. renew_lifetime = 36000
  5. forwardable = true
  6. krb4_convert = false
  7. }
  8.  
  9. [domain_realm]
  10. .example.com = EXAMPLE.COM
  11. example.com = EXAMPLE.COM
  12.  
  13. [appdefaults]
  14. pam = {
  15. debug = false
  16. ticket_lifetime = 36000
  17. renew_lifetime = 36000
  18. forwardable = true
  19. krb4_convert = false
  20. }
  21.  
  22. #!/usr/bin/perl -w
  23. use strict;
  24.  
  25. my %conf;
  26. my $section;
  27.  
  28. while (<>) {
  29. if (/^s*(S*)s*=s*{s*$/) {
  30. $section = $1;
  31. $conf{$section} = {};
  32. } elsif (/^s*(S*)s*=s*(S*)s*$/) {
  33. my $key = $1;
  34. my $value = $2;
  35. if ($section) {
  36. $conf{$section}{$key}=$value;
  37. }
  38. }
  39. }
  40.  
  41. foreach (keys %conf) {
  42. $section = $_;
  43. foreach (keys %{$conf{$section}}) {
  44. print "$section:$_:$conf{$section}{$_}n";
  45. }
  46. }
Add Comment
Please, Sign In to add comment