aboutsummaryrefslogtreecommitdiffstats
path: root/fripost-adduser
diff options
context:
space:
mode:
Diffstat (limited to 'fripost-adduser')
-rwxr-xr-xfripost-adduser23
1 files changed, 16 insertions, 7 deletions
diff --git a/fripost-adduser b/fripost-adduser
index bd73aea..a3c78a8 100755
--- a/fripost-adduser
+++ b/fripost-adduser
@@ -18,7 +18,8 @@ B<fripost-adduser> [B<--verbose>] [B<--debug>] [B<--pretend>] [I<username>]
B<fripost-adduser> adds a new virtual mailbox to the system, unless
B<--pretend> is set.
-If no I<username> or I<password> are given, the user is prompted for them.
+If I<username> or I<password> are not given, the user is prompted for
+them.
If I<username> is not fully qualified, C<fripost.org> is appended.
If I<username> is already an existing username or alias,
B<fripost-adduser> raises an error.
@@ -35,7 +36,7 @@ that I<username> is not already in the database.)
=item B<--password=>I<password>
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<password> 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.";
}