From 049c0ce22117e23ca15d8df3f61dd35ba7d132d1 Mon Sep 17 00:00:00 2001 From: Kayden Tebau Date: Tue, 18 Oct 2022 10:13:00 -0700 Subject: [PATCH] Fix sshkey --- lib/unix_dog/Controller/Account.pm | 6 ++---- lib/unix_dog/Controller/Register.pm | 3 +-- lib/unix_dog/Util.pm | 12 ++++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 lib/unix_dog/Util.pm diff --git a/lib/unix_dog/Controller/Account.pm b/lib/unix_dog/Controller/Account.pm index 53a4eb4..40fc82a 100644 --- a/lib/unix_dog/Controller/Account.pm +++ b/lib/unix_dog/Controller/Account.pm @@ -28,9 +28,7 @@ sub update_account($self) { my $loginShell = $self->param('loginShell'); my $roomNumber = $self->param('roomNumber'); my $telNum = $self->param('telNum'); - my $sshKeys = $self->param('sshKeys'); - $sshKeys =~ s/\r//; - my @sshKeys = split "\n", $sshKeys; + my @sshKeys = Util::split_keys($self->param('sshKeys')); my $curPasswd = $self->param('curPasswd'); my $newPasswd = $self->param('newPasswd'); @@ -44,7 +42,7 @@ sub update_account($self) { loginShell => $loginShell, roomNumber => $roomNumber, telNum => $telNum, - sshKeys => join("\n", @sshKeys), + sshKeys => join("\r\n", @sshKeys), username => $username, ); diff --git a/lib/unix_dog/Controller/Register.pm b/lib/unix_dog/Controller/Register.pm index 86a6fa9..af80dde 100644 --- a/lib/unix_dog/Controller/Register.pm +++ b/lib/unix_dog/Controller/Register.pm @@ -28,7 +28,6 @@ sub register($self) { my $password = $self->param('password'); my $email = $self->param('email'); my $pubkeys = $self->param('pubkey'); - $pubkeys =~ s/\r//; my $bio = $self->param('bio'); my $fromIP = $self->tx->remote_address; @@ -100,7 +99,7 @@ sub register($self) { attrs => [ cn => $username, mail => $username . '@unix.dog', - sshPublicKey => (split "\n", $pubkeys), + sshPublicKey => Util::split_keys($pubkeys), objectClass => [ 'top', 'extensibleObject', diff --git a/lib/unix_dog/Util.pm b/lib/unix_dog/Util.pm new file mode 100644 index 0000000..6088a4b --- /dev/null +++ b/lib/unix_dog/Util.pm @@ -0,0 +1,12 @@ +package Util; +use strict; +use warnings FATAL => 'all'; +use experimental 'signatures'; + +sub split_keys($input) { + my @out = split /\R/, $input; + @out = grep (defined && length, @out); + return @out; +} + +1;