ssh: fix AddAuthorizedKeys file handling
ssh: fix AddAuthorizedKeys file handling

The code for AddAuthorizedKeys opens the authorized_keys file in append
mode ('a+') and then proceeds to read all lines to detect duplicate
keys. This works fine in Python 2, because open(…, 'a+') will set the
file offset to 0. However, using append mode in Python 3 causes the
offset to be set to the end of the file, breaking existing code.

There are two ways out of this: switch to read/write mode ('r+'),
which should work as we're reading the whole file first, before writing
anything; or explicitly seek to the beginning of the file before reading
anything. Since we're updating the file in-place, the latter will be
more robust, as it preserve the atomic write characteristics of
O_APPEND, so use that.

Signed-off-by: Apollon Oikonomopoulos <ed81ed0a45ccd5c8869bda52e38353a6299ee39e@dmesg.gr>

mbakke/ganeti,ganeti/ganeti,mbakke/ganeti,ganeti/ganeti,mbakke/ganeti,ganeti/ganeti