diff options
author | ivan <ivan> | 2005-04-20 06:41:39 +0000 |
---|---|---|
committer | ivan <ivan> | 2005-04-20 06:41:39 +0000 |
commit | f7ac8653683327aee6f5e825c49f09d751e0c352 (patch) | |
tree | d009a8426ad5554ae6fcbcef5e1c28b6a5760583 /FS | |
parent | 71d7d7881aa44061b9dac239d539e5ed3340e8a6 (diff) |
add vpopmail defaults to acct_sql export
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/part_export/acct_sql.pm | 50 | ||||
-rw-r--r-- | FS/FS/svc_acct.pm | 28 |
2 files changed, 60 insertions, 18 deletions
diff --git a/FS/FS/part_export/acct_sql.pm b/FS/FS/part_export/acct_sql.pm index fb0299c52..a4320e491 100644 --- a/FS/FS/part_export/acct_sql.pm +++ b/FS/FS/part_export/acct_sql.pm @@ -18,7 +18,23 @@ tie my %options, 'Tie::IxHash', type => 'textarea', }, 'primary_key' => { label => 'Database primary key' }, + 'crypt' => { label => 'Password encryption', + type=>'select', options=>[qw(crypt md5)], + default=>'crypt', + }, +; + +tie my %vpopmail_map, 'Tie::IxHash', + 'pw_name' => 'username', + 'pw_domain' => 'domain', + 'pw_passwd' => 'crypt_password', + 'pw_uid' => 'uid', + 'pw_gid' => 'gid', + 'pw_gecos' => 'finger', + 'pw_dir' => 'dir', + 'pw_shell' => 'shell', ; +my $vpopmail_map = join('\n', map "$_ $vpopmail_map{$_}", keys %vpopmail_map ); tie my %postfix_courierimap_mailbox_map, 'Tie::IxHash', 'username' => 'email', @@ -46,23 +62,27 @@ my $postfix_courierimap_alias_map = %info = ( 'svc' => 'svc_acct', 'desc' => 'Real-time export of accounts to SQL databases '. - '(Postfix+Courier IMAP, others?)', + '(vpopmail, Postfix+Courier IMAP, others?)', 'options' => \%options, 'nodomain' => '', 'notes' => <<END -Export accounts (svc_acct records) to SQL databases. Written for -Postfix+Courier IMAP but intended to be generally useful for generic SQL -exports, eventually. +Export accounts (svc_acct records) to SQL databases. Currently has default +configurations for vpopmail and Postfix+Courier IMAP but intended to be +configurable for other schemas as well. -<BR><BR>In contrast to sqlmail, this is newer and less well tested, and -currently less flexible. It is intended to export just svc_acct records only, -rather than a single export for svc_acct, svc_forward and svc_domain records, -to export in "default" formats rather than configure the MTA or POP/IMAP server -for a Freeside-specific schema, and possibly to be configured for different -mail server setups through some subclassing rather than options. +<BR><BR>In contrast to sqlmail, this is intended to export just svc_acct +records only, rather than a single export for svc_acct, svc_forward and +svc_domain records, to export in "default" database schemas rather than +configure the MTA or POP/IMAP server for a Freeside-specific schema, and +to be configured for different mail server setups. <BR><BR>Use these buttons for some useful presets: <UL> + <li><INPUT TYPE="button" VALUE="vpopmail" onClick=' + this.form.table.value = "vpopmail"; + this.form.schema.value = "$vpopmail_map"; + this.form.primary_key.value = "pw_name, pw_domain"; + '> <LI><INPUT TYPE="button" VALUE="postfix_courierimap_mailbox" onClick=' this.form.table.value = "mailbox"; this.form.schema.value = "$postfix_courierimap_mailbox_map"; @@ -90,7 +110,10 @@ sub _export_insert { my %map = $self->_map; my %record = map { my $value = $map{$_}; - $_ => $svc_acct->$value(); + my @arg = (); + push @arg, $self->option('crypt') + if $_ eq 'crypt_password' && $self->option('crypt'); + $_ => $svc_acct->$value(@arg); } keys %map; my $err_or_queue = @@ -113,7 +136,10 @@ sub _export_replace { my $keymap = $map{$self->option('primary_key')}; my %record = map { my $value = $map{$_}; - $_ => $new->$value(); + my @arg = (); + push @arg, $self->option('crypt') + if $_ eq 'crypt_password' && $self->option('crypt'); + $_ => $new->$value(@arg); } keys %map; my $err_or_queue = $self->acct_sql_queue( diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 267116a55..d806fe9bc 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -15,7 +15,7 @@ use vars qw( @ISA $DEBUG $me $conf $skip_fuzzyfiles @saltset @pw_set ); use Carp; use Fcntl qw(:flock); -use Crypt::PasswdMD5; +use Crypt::PasswdMD5 1.2; use FS::UID qw( datasrc ); use FS::Conf; use FS::Record qw( qsearch qsearchs fields dbh dbdef ); @@ -1273,11 +1273,18 @@ sub check_password { } -=item crypt_password +=item crypt_password [ DEFAULT_ENCRYPTION_TYPE ] Returns an encrypted password, either by passing through an encrypted password in the database or by encrypting a plaintext password from the database. +The optional DEFAULT_ENCRYPTION_TYPE parameter can be set to I<crypt> (classic +UNIX DES crypt), I<md5> (md5 crypt supported by most modern Linux and BSD +distrubtions), or (eventually) I<blowfish> (blowfish hashing supported by +OpenBSD, SuSE, other Linux distibutions with pam_unix2, etc.). The default +encryption type is only used if the password is not already encrypted in the +database. + =cut sub crypt_password { @@ -1288,10 +1295,19 @@ sub crypt_password { || $self->_password =~ /^\$(1|2a?)\$/ ) { $self->_password; } else { - crypt( - $self->_password, - $saltset[int(rand(64))].$saltset[int(rand(64))] - ); + my $encryption = scalar(@_) ? shift : 'crypt'; + if ( $encryption eq 'crypt' ) { + crypt( + $self->_password, + $saltset[int(rand(64))].$saltset[int(rand(64))] + ); + } elsif ( $encryption eq 'md5' ) { + unix_md5_crypt( $self->_password ); + } elsif ( $encryption eq 'blowfish' ) { + die "unknown encryption method $encryption"; + } else { + die "unknown encryption method $encryption"; + } } } |