[openssh-commits] [openssh] 02/03: upstream: add sshkey_save_public(), to save a public key; ok

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Jan 3 09:43:31 AEDT 2020


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 878ba4350d57e905d6bb1865d8ff31bdfe5deab4
Author: djm at openbsd.org <djm at openbsd.org>
Date:   Thu Jan 2 22:38:33 2020 +0000

    upstream: add sshkey_save_public(), to save a public key; ok
    
    markus@
    
    OpenBSD-Commit-ID: 5d6f96a966d10d7fa689ff9aa9e1d6767ad5a076
---
 authfile.c | 33 ++++++++++++++++++++++++++++++++-
 authfile.h |  4 +++-
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/authfile.c b/authfile.c
index 37341189..bf22d63e 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: authfile.c,v 1.135 2019/09/03 08:30:47 djm Exp $ */
+/* $OpenBSD: authfile.c,v 1.136 2020/01/02 22:38:33 djm Exp $ */
 /*
  * Copyright (c) 2000, 2013 Markus Friedl.  All rights reserved.
  *
@@ -550,3 +550,34 @@ sshkey_advance_past_options(char **cpp)
 	return (*cp == '\0' && quoted) ? -1 : 0;
 }
 
+/* Save a public key */
+int
+sshkey_save_public(const struct sshkey *key, const char *path,
+    const char *comment)
+{
+	int fd, oerrno;
+	FILE *f = NULL;
+	int r = SSH_ERR_INTERNAL_ERROR;
+
+	if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)
+		return SSH_ERR_SYSTEM_ERROR;
+	if ((f = fdopen(fd, "w")) == NULL) {
+		r = SSH_ERR_SYSTEM_ERROR;
+		goto fail;
+	}
+	if ((r = sshkey_write(key, f)) != 0)
+		goto fail;
+	fprintf(f, " %s\n", comment);
+	if (ferror(f) || fclose(f) != 0) {
+		r = SSH_ERR_SYSTEM_ERROR;
+ fail:
+		oerrno = errno;
+		if (f != NULL)
+			fclose(f);
+		else
+			close(fd);
+		errno = oerrno;
+		return r;
+	}
+	return 0;
+}
diff --git a/authfile.h b/authfile.h
index 9c8a95a0..a2840cf8 100644
--- a/authfile.h
+++ b/authfile.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: authfile.h,v 1.23 2019/09/03 08:30:47 djm Exp $ */
+/* $OpenBSD: authfile.h,v 1.24 2020/01/02 22:38:33 djm Exp $ */
 
 /*
  * Copyright (c) 2000, 2013 Markus Friedl.  All rights reserved.
@@ -49,5 +49,7 @@ int sshkey_perm_ok(int, const char *);
 int sshkey_in_file(struct sshkey *, const char *, int, int);
 int sshkey_check_revoked(struct sshkey *key, const char *revoked_keys_file);
 int sshkey_advance_past_options(char **cpp);
+int sshkey_save_public(const struct sshkey *key, const char *path,
+    const char *comment);
 
 #endif

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list