#!/usr/bin/perl -w # # $Id: group2ldif.pl,v 1.5 2003/01/13 05:28:42 jmates Exp $ # # Copyright (c) 2001, Jeremy Mates. This script is free software; # you can redistribute it and/or modify it under the same terms as # Perl itself. # # Run perldoc(1) on this file for additional documentation. # ###################################################################### # # REQUIREMENTS require 5; use strict; ###################################################################### # # MODULES use Carp; # better error reporting use Getopt::Std; # command line option processing ###################################################################### # # VARIABLES my $VERSION; ($VERSION = '$Revision: 1.5 $ ') =~ s/[^0-9.]//g; my (%opts); ###################################################################### # # MAIN # parse command-line options getopts('h?d:', \%opts); help() if exists $opts{'h'} or exists $opts{'?'}; while (my ($name,$passwd,$gid,$members) = getgrent()) { print "dn: cn=$name,$opts{d}\n" if exists $opts{d}; print "cn: $name\n"; print "objectclass: posixGroup\n"; # default to crypt, but also handle md5,blowfish crypts # in RFC 2307 fashion my $pw_hash = 'crypt'; $pw_hash = 'md5' if q/$1$/ eq substr $passwd, 0, 3; $pw_hash = 'altscheme' if q/$2$/ eq substr $passwd, 0, 3; print "userPassword: {$pw_hash}$passwd\n"; print "gidnumber: $gid\n"; print "memberuid: $_\n" for split /\s+/, $members; print "\n"; } exit; ###################################################################### # # SUBROUTINES # a generic help blarb sub help { print <<"HELP"; Usage: $0 [opts] Parses getgrent() results into RFC 2307-ish LDIF format. Options for version $VERSION: -h/-? Display this message -d dn Use specified dn in output. (Default: no dn entry.) Run perldoc(1) on this script for additional documentation. HELP exit; } ###################################################################### # # DOCUMENTATION =head1 NAME group2ldif.pl - converts system group data into LDIF records =head1 SYNOPSIS To create RFC 2307-ish output with a custom C field: $ group2ldif.pl -d 'ou=groups,dc=example,dc=org' dn: cn=wheel,ou=groups,dc=example,dc=org cn: wheel objectclass: posixGroup userPassword: {crypt}* gidnumber: 0 ... =head1 DESCRIPTION =head2 Overview This script produces RFC 2307-ish LDIF records to STDOUT using any data obtained by the getgrent() function call in perl. =head2 Normal Usage $ group2ldif.pl [options] See L<"OPTIONS"> for details on the command line switches supported. =head1 OPTIONS This script currently supports the following command line switches: =over 4 =item B<-h>, B<-?> Prints a brief usage note about the script. =item B<-d>, I Include a C line, with the specified distinguished name data I appended to the group name. =back =head1 ENVIRONMENT Relies on system returning "reasonable" data from the getgrent() function-- should work properly on unix systems. Unknown what will happen under MacPerl (on pre-X Mac OS) or ActiveState Perl (for legacy Microsoft OS). =head1 BUGS =head2 Reporting Bugs Newer versions of this script may be available from: http://sial.org/code/perl/ If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome. =head2 Known Issues No known bugs. =head1 SEE ALSO perl(1), RFC 2307, RFC 2849 =head1 AUTHOR Jeremy Mates, http://sial.org/contact/ =head1 COPYRIGHT Copyright (c) 2001, Jeremy Mates. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 VERSION $Id: group2ldif.pl,v 1.5 2003/01/13 05:28:42 jmates Exp $ =cut