Merge lp:~kermit666/ubuntu/precise/ssh-import-id/newline-fix into lp:~ssh-import-id/ssh-import-id/trunk.broke

Proposed by Dražen Lučanin on 2012-03-29
Status: Merged
Merged at revision: 48
Proposed branch: lp:~kermit666/ubuntu/precise/ssh-import-id/newline-fix
Merge into: lp:~ssh-import-id/ssh-import-id/trunk.broke
Diff against target: 39 lines (+10/-4)
1 file modified
ssh-import-id (+10/-4)
To merge this branch: bzr merge lp:~kermit666/ubuntu/precise/ssh-import-id/newline-fix
Reviewer Review Type Date Requested Status
Dustin Kirkland  2012-04-04 Pending
ssh-import-id 2012-03-29 Pending
Review via email: mp+100000@code.launchpad.net

Description of the Change

In the current version, the authorized_keys file created doesn't contain any newlines between items and because of this my public key isn't recognized. After manually adding newlines between items, it started to work.

Because of this I wrote this patch to do this automatically. The sed command to remove all the newlines is still there, so that there won't be an uncontrolled number of newlines, but instead exactly 2 lines between each item. The patch has two benefits:
- fixes my bug, my key is now recognized
- makes the authorized_keys file more easily readable

The validation check still works.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ssh-import-id'
2--- ssh-import-id 2012-03-03 14:31:02 +0000
3+++ ssh-import-id 2012-03-29 18:43:32 +0000
4@@ -58,18 +58,23 @@
5
6 validate_keys() {
7 # Prune blank lines, join lines that don't start with ^ssh-
8- # remove invalid characters
9+ # remove invalid characters and add a controlled number of newlines
10+ # (for readabililty and because items mustn't be in the same line)
11 LC_COLLATE=C \
12 sed -i -e '/^$/d' \
13- -e '/^\r/d' \
14+ -e '/^\r/d' \
15 -e ':join /^ssh-/!{ N; s/[\n\r]//g ; b join }' \
16- -e 's/[^a-zA-Z0-9@: .\/=+-]//g' "$1"
17+ -e 's/[^a-zA-Z0-9@: .\/=+-]//g' "$1" \
18+ -e '/^ssh-/a\\n'
19 # Count lines
20 lines=$(wc -l < "${1}")
21 # Count valid keys
22 keys=$(grep -c "^ssh-[dr]s[sa] [a-zA-Z0-9: .\/=+-]\+ " "$1")
23+ # Multiply by 3 to account for 2 newlines after every item
24+ keysmult=$(($keys * 3))
25+ #keysmult=$[keys*3]
26 # Validate counts match, and >0
27- [ $lines -gt 0 ] && [ $keys -eq $lines ]
28+ [ $lines -gt 0 ] && [ $keysmult -eq $lines ]
29 }
30
31 get_authkeypath() {
32@@ -138,6 +143,7 @@
33 fi
34 echo >> "$tmp" # needed for wc
35 if ! validate_keys "$tmp"; then
36+ #cat $tmp
37 warn "Invalid keys at [$url]"
38 rc=$(($rc+1));
39 continue

Subscribers

People subscribed via source and target branches