From 0467c0a622c5aa0b2b63615b2b36f31f4272bcd1 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 18 Apr 2012 02:06:01 +0200 Subject: Implemented the changes on the LDAP schema. --- lib/Fripost/Schema/Type/User.pm | 100 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 lib/Fripost/Schema/Type/User.pm (limited to 'lib/Fripost/Schema/Type/User.pm') diff --git a/lib/Fripost/Schema/Type/User.pm b/lib/Fripost/Schema/Type/User.pm new file mode 100644 index 0000000..09c3aa0 --- /dev/null +++ b/lib/Fripost/Schema/Type/User.pm @@ -0,0 +1,100 @@ +package Fripost::Schema::Type::User; + +use 5.010_000; +use warnings; +use strict; + +use base qw/Net::LDAP/; +our $VERSION = '0.01'; + + +####################################################################### + +# Search a user, and return the corresponding entries if found. If no +# user is given, returns all users. +# Filters on the value of the key `uid' only (unless it is undefined). +sub search { + my $self = shift; + + my $base = join ',', ('ou=mailboxes',$self->{_options}->{base_dn}); + + my $filter = "(ObjectClass=virtualMailbox)"; + $filter = "(&" .$filter. "(uid=" .$_[0]. ")" .")" + if defined $_[0]; + + my $res = $self->{_ldap}->search( + base => $base, + scope => 'one', + attrs => [ 'uid', 'gn' , 'sn', 'maildir', 'isActive' ], + filter => $filter + ); + die "Error: " .$res->error. "\n" if $res->code; + return $res; +} + + +# Add the given user +sub add { + my $self = shift; + my $user = shift; + + my $base = join ',', ( 'uid=' .$user->{username} + , 'ou=mailboxes' + , $self->{_options}->{base_dn} ); + + my $res = $self->{_ldap}->add( $base, + attrs => [ uid => $user->{username}, + objectClass => [ 'top', 'virtualMailbox' ], + userPassword => $user->{userPassword}, + maildir => $user->{maildir}, + isActive => $user->{isActive} + ] + ); + die "Error: " .$res->error. "\n" if $res->code; + return $res; +} + + +# Change password +sub pwd { + my $self = shift; + my $user = shift; + + my $base = join ',', ( 'uid=' .$user->{username} + , 'ou=mailboxes' + , $self->{_options}->{base_dn} ); + + my $res = $self->{_ldap}->modify( $base, + replace => [ userPassword => $user->{userPassword} ] + ); + die "Error: " .$res->error. "\n" if $res->code; + return $res; +} + + +####################################################################### + +1; + +=head1 NAME + +Fripost::Schema::Type::User - + +=head1 AUTHOR + +Guilhem Moulin C<< >> + +=head1 COPYRIGHT + +Copyright 2012 Guilhem Moulin, all rights reserved. + +=head1 LICENSE + +This program is free software; you can redistribute it and/or modify it +under the same terms as perl itself. + +=cut + +1; # End of User.pm + +__END__ -- cgit v1.2.3