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. --- fripost-adduser | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'fripost-adduser') diff --git a/fripost-adduser b/fripost-adduser index bd73aea..a3c78a8 100755 --- a/fripost-adduser +++ b/fripost-adduser @@ -18,7 +18,8 @@ B [B<--verbose>] [B<--debug>] [B<--pretend>] [I] B adds a new virtual mailbox to the system, unless B<--pretend> is set. -If no I or I are given, the user is prompted for them. +If I or I are not given, the user is prompted for +them. If I is not fully qualified, C is appended. If I is already an existing username or alias, B raises an error. @@ -35,7 +36,7 @@ that I is not already in the database.) =item B<--password=>I By default, the user is prompted for his/her new password, which is -hashed, salted and then inserted added to the LDAP entry. +hashed, salted and then added to the LDAP entry. By using B<--password>, I is inserted RAW in the database. This can be useful if the user does not want to give the clear copy but only a hash, for example. @@ -147,12 +148,14 @@ GetOptions( sub dsay { say STDERR @_ if $conf->{debug}; } sub vsay { say STDERR @_ if $conf->{verbose} || $conf->{debug}; } + # Connect to the LDAP server my $ldap = Fripost::Schema->new( $conf ); # Define the new user my $user; +my ($domain, $login); { my $username; if (defined $ARGV[0]) { @@ -163,7 +166,8 @@ my $user; else { $username = prompt_email("New username: ", 'is_user'); } - my ($domain, $login) = split /\@/, $username, 2; + # TODO: Ensure that the domain is valid. + ($login, $domain) = split /\@/, $username, 2; my $maildir = "$domain/$login/Maildir/"; # Trailing slash important my $isActive = 'TRUE'; my ($userPassword, $clearPassword); @@ -171,7 +175,7 @@ my $user; $userPassword = $conf->{password}; } else { - $clearPassword = 'hop'; #prompt_password(); + $clearPassword = prompt_password(); $userPassword = hash( undef, undef, $clearPassword ); } @@ -190,11 +194,12 @@ my $user; } -# Check if the username already exists, or is an existing alias. { + # Ensure that the username doesn't already exist. die "Error: User `" .$user->{username}. "' already exists.\n" if $ldap->user->search($user->{username})->count; + # Ensure that the username doesn't correspond to an existing alias. my $res = $ldap->alias->search({ address => $user->{username} }); if ($res->count) { print STDERR "Error: Alias `" .$user->{username}. "' already exists. "; @@ -203,9 +208,13 @@ my $user; say STDERR ".)"; exit 1; } - exit 1; + + # Warn if the domain is unknown. + warn "WARN: Unknown domain `" .$domain. "'.\n" + unless $ldap->domain->search({ domain => $domain })->count; } + ## Insert the new user if ($conf->{pretend}) { vsay "Did not create user since we are pretending."; @@ -213,7 +222,7 @@ if ($conf->{pretend}) { else { my %user = %$user; delete $user{clearPassword}; - $ldap->addUser(\%user); + $ldap->user->add(\%user); say "New account $user{username} added."; } -- cgit v1.2.3