User Tools

Site Tools


software:dovecot:archiveserver

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
software:dovecot:archiveserver [2023/09/25 14:42] rodolicosoftware:dovecot:archiveserver [2023/09/25 15:19] (current) rodolico
Line 119: Line 119:
  
 which would give us greater security. which would give us greater security.
 +
 +If you want, here is a little utility written in Perl that will do all of it for you. It takes a username and a password, then either updates or adds that information to the password file. It is NOT very friendly, and could use some cleanup, and the username/password are left in your history file, so it is insecure. Call it with <code bash>./updatePasswd username 'password'</code>
 +
 +<code perl updatePasswd>
 +#! /usr/bin/env perl
 +
 +# WARNING: This is insecure as it will leave the users password in the 
 +# bash history file
 +
 +use strict;
 +use warnings;
 +
 +my $pwfile = '/srv/vmail/passwd'; # location of the password file
 +my $user = shift;
 +my $password = shift;
 +
 +die "Usage: $0 username password\n" unless $user && $password;
 +
 +my $found = 0; # determines if user already exists
 +
 +# call doveadm to get the hash
 +my $key = `/usr/bin/doveadm pw -s ssha256 -u '$user' -p '$password'`;
 +
 +# read the password file
 +open PW,"<$pwfile" or die "Could not open the password file: $!\n";
 +my @data = <PW>;
 +close PW;
 +
 +# go through it and see if the user already exists
 +my $newLine = "$user:$key";
 +for ( my $line = 0; $line < @data; $line++ ) {
 +   my ($thisUser,$thisPass) = split( ':', $data[$line] );
 +   if ( $thisUser eq $user ) { # yes, so replace the line and mark found
 +      $data[$line] = $newLine;
 +      $found = 1;
 +      last;
 +   } # if statement
 +} # for loop
 +push @data, $newLine unless $found; # we did not find them, so add
 +chomp @data; # remove all line endings
 +
 +# write the file back out
 +open PW,">$pwfile" or die "Could not write the password file: $!\n";
 +print PW join( "\n", @data ) . "\n";
 +close PW;
 +
 +# tell user what we did
 +print "User $user ";
 +print $found ? "modified\n" : "added\n";
 +
 +1;
 +</code>
 +
 +
  
 ===== Setting up mail client ===== ===== Setting up mail client =====
software/dovecot/archiveserver.1695670927.txt.gz · Last modified: 2023/09/25 14:42 by rodolico