On Sat, Jan 08, 2005 at 12:10:04AM +0100, Sylvain Beucler wrote:
> On Fri, Jan 07, 2005 at 10:50:13PM +0100, Mathieu Roy wrote:
> > > I guess we're ready for the merge now.
> > 
> > I'll do a last test tomorrow morning and I'll do it (I usually make
> > directly a backup of the tree, just in case).
> > 
> > Regards,
> 
> By the way, there is also an upgrade script to fix the ssh keys w/o
> trailing newline. I attach it.
> 
> For the script to be applied cleanly in the future, it may be needed
> to fix something in SetUserSettings (see comments).

This version makes less call to the DB and actually work.

Btw, we upgraded Savannah yesterday.

-- 
Sylvain
#!/usr/bin/perl
# Add a tailing new line '###' in table user, field authorized_keys
#
# Copyright (C) 2005  Sylvain Beucler
#
# This file is part of Savane.
# 
# Savane is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Savane is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Savane; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Add a tailing '###' in table user, field authorized_keys

# Previous version of Savane did not add a trailing new line in
# authorized_keys, causing the .ssh/authorized_keys file to be
# recreated at each cron job - with no harm but additional CPU and HD
# usage

use strict;
use Savannah;

my $debug = 1;

my @pairs = GetDB('user', 'authorized_keys not like "%###"', 'user_name, 
authorized_keys');
my %keys;
foreach my $pair (@pairs) {
    my ($user, @keylist) = split(",", $pair);
    my $allkeys = join("", @keylist);
    $keys{$user} = $allkeys;
    if($allkeys and not $allkeys =~ /\#\#\#$/) {
        print "$user\n" if $debug; # if you want to get a list of fixed users
        # a user can put ' in the SSH key comment and break the SQL command
        $allkeys =~ s/'/\\'/; # hmmm, maybe SetUserSettings should rather do 
that by itself
        SetUserSettings($user, "authorized_keys", $allkeys . "###");
    }
}

Reply via email to