|
|
9070b3 |
diff -up openssh/misc.c.keycat openssh/misc.c
|
|
|
9070b3 |
--- openssh/misc.c.keycat 2015-06-24 10:57:50.158849606 +0200
|
|
|
9070b3 |
+++ openssh/misc.c 2015-06-24 11:04:23.989868638 +0200
|
|
|
9070b3 |
@@ -966,6 +966,13 @@ subprocess(const char *tag, struct passw
|
|
|
9070b3 |
error("%s: dup2: %s", tag, strerror(errno));
|
|
|
9070b3 |
_exit(1);
|
|
|
9070b3 |
}
|
|
|
9070b3 |
+#ifdef WITH_SELINUX
|
|
|
9070b3 |
+ if (sshd_selinux_setup_env_variables() < 0) {
|
|
|
9070b3 |
+ error ("failed to copy environment: %s",
|
|
|
9070b3 |
+ strerror(errno));
|
|
|
9070b3 |
+ _exit(127);
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+#endif
|
|
|
9070b3 |
if (env != NULL)
|
|
|
9070b3 |
execve(av[0], av, env);
|
|
|
9070b3 |
else
|
|
|
9070b3 |
diff -up openssh/HOWTO.ssh-keycat.keycat openssh/HOWTO.ssh-keycat
|
|
|
9070b3 |
--- openssh/HOWTO.ssh-keycat.keycat 2015-06-24 10:57:50.157849608 +0200
|
|
|
9070b3 |
+++ openssh/HOWTO.ssh-keycat 2015-06-24 10:57:50.157849608 +0200
|
|
|
9070b3 |
@@ -0,0 +1,12 @@
|
|
|
9070b3 |
+The ssh-keycat retrieves the content of the ~/.ssh/authorized_keys
|
|
|
9070b3 |
+of an user in any environment. This includes environments with
|
|
|
9070b3 |
+polyinstantiation of home directories and SELinux MLS policy enabled.
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+To use ssh-keycat, set these options in /etc/ssh/sshd_config file:
|
|
|
9070b3 |
+ AuthorizedKeysCommand /usr/libexec/openssh/ssh-keycat
|
|
|
9070b3 |
+ AuthorizedKeysCommandUser root
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+Do not forget to enable public key authentication:
|
|
|
9070b3 |
+ PubkeyAuthentication yes
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+
|
|
|
9070b3 |
diff -up openssh/Makefile.in.keycat openssh/Makefile.in
|
|
|
9070b3 |
--- openssh/Makefile.in.keycat 2015-06-24 10:57:50.152849621 +0200
|
|
|
9070b3 |
+++ openssh/Makefile.in 2015-06-24 10:57:50.157849608 +0200
|
|
|
9070b3 |
@@ -27,6 +27,7 @@ SFTP_SERVER=$(libexecdir)/sftp-server
|
|
|
9070b3 |
ASKPASS_PROGRAM=$(libexecdir)/ssh-askpass
|
|
|
9070b3 |
SFTP_SERVER=$(libexecdir)/sftp-server
|
|
|
9070b3 |
SSH_KEYSIGN=$(libexecdir)/ssh-keysign
|
|
|
9070b3 |
+SSH_KEYCAT=$(libexecdir)/ssh-keycat
|
|
|
9070b3 |
SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper
|
|
|
9070b3 |
SSH_SK_HELPER=$(libexecdir)/ssh-sk-helper
|
|
|
9070b3 |
PRIVSEP_PATH=@PRIVSEP_PATH@
|
|
|
9070b3 |
@@ -52,6 +52,7 @@ K5LIBS=@K5LIBS@
|
|
|
9070b3 |
K5LIBS=@K5LIBS@
|
|
|
9070b3 |
GSSLIBS=@GSSLIBS@
|
|
|
9070b3 |
SSHDLIBS=@SSHDLIBS@
|
|
|
9070b3 |
+KEYCATLIBS=@KEYCATLIBS@
|
|
|
9070b3 |
LIBEDIT=@LIBEDIT@
|
|
|
9070b3 |
LIBFIDO2=@LIBFIDO2@
|
|
|
9070b3 |
AR=@AR@
|
|
|
9070b3 |
@@ -65,7 +66,7 @@ EXEEXT=@EXEEXT@
|
|
|
9070b3 |
|
|
|
9070b3 |
.SUFFIXES: .lo
|
|
|
9070b3 |
|
|
|
9070b3 |
-TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-sk-helper$(EXEEXT)
|
|
|
9070b3 |
+TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-sk-helper$(EXEEXT) ssh-keycat$(EXEEXT)
|
|
|
9070b3 |
|
|
|
9070b3 |
XMSS_OBJS=\
|
|
|
9070b3 |
ssh-xmss.o \
|
|
|
9070b3 |
@@ -190,6 +191,9 @@ ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT)
|
|
|
9070b3 |
ssh-sk-helper$(EXEEXT): $(LIBCOMPAT) libssh.a $(SKHELPER_OBJS)
|
|
|
9070b3 |
$(LD) -o $@ $(SKHELPER_OBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS) $(LIBFIDO2)
|
|
|
9070b3 |
|
|
|
9070b3 |
+ssh-keycat$(EXEEXT): $(LIBCOMPAT) $(SSHDOBJS) libssh.a ssh-keycat.o uidswap.o
|
|
|
9070b3 |
+ $(LD) -o $@ ssh-keycat.o uidswap.o $(LDFLAGS) -lssh -lopenbsd-compat $(KEYCATLIBS) $(LIBS)
|
|
|
9070b3 |
+
|
|
|
9070b3 |
ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a $(SSHKEYSCAN_OBJS)
|
|
|
9070b3 |
$(LD) -o $@ $(SSHKEYSCAN_OBJS) $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
|
|
|
9070b3 |
|
|
|
9070b3 |
@@ -321,6 +325,7 @@ install-files:
|
|
|
9070b3 |
$(INSTALL) -m 4711 $(STRIP_OPT) ssh-keysign$(EXEEXT) $(DESTDIR)$(SSH_KEYSIGN)$(EXEEXT)
|
|
|
9070b3 |
$(INSTALL) -m 0755 $(STRIP_OPT) ssh-pkcs11-helper$(EXEEXT) $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT)
|
|
|
9070b3 |
$(INSTALL) -m 0755 $(STRIP_OPT) ssh-sk-helper$(EXEEXT) $(DESTDIR)$(SSH_SK_HELPER)$(EXEEXT)
|
|
|
9070b3 |
+ $(INSTALL) -m 0755 $(STRIP_OPT) ssh-keycat$(EXEEXT) $(DESTDIR)$(libexecdir)/ssh-keycat$(EXEEXT)
|
|
|
9070b3 |
$(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT)
|
|
|
9070b3 |
$(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
|
|
|
9070b3 |
$(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
|
|
|
9070b3 |
diff -up openssh/openbsd-compat/port-linux.h.keycat openssh/openbsd-compat/port-linux.h
|
|
|
9070b3 |
--- openssh/openbsd-compat/port-linux.h.keycat 2015-06-24 10:57:50.150849626 +0200
|
|
|
9070b3 |
+++ openssh/openbsd-compat/port-linux.h 2015-06-24 10:57:50.160849601 +0200
|
|
|
9070b3 |
@@ -25,8 +25,10 @@ void ssh_selinux_setup_pty(char *, const
|
|
|
9070b3 |
void ssh_selinux_change_context(const char *);
|
|
|
9070b3 |
void ssh_selinux_setfscreatecon(const char *);
|
|
|
9070b3 |
|
|
|
9070b3 |
+int sshd_selinux_enabled(void);
|
|
|
9070b3 |
void sshd_selinux_copy_context(void);
|
|
|
9070b3 |
void sshd_selinux_setup_exec_context(char *);
|
|
|
9070b3 |
+int sshd_selinux_setup_env_variables(void);
|
|
|
9070b3 |
#endif
|
|
|
9070b3 |
|
|
|
9070b3 |
#ifdef LINUX_OOM_ADJUST
|
|
|
9070b3 |
diff -up openssh/openbsd-compat/port-linux-sshd.c.keycat openssh/openbsd-compat/port-linux-sshd.c
|
|
|
9070b3 |
--- openssh/openbsd-compat/port-linux-sshd.c.keycat 2015-06-24 10:57:50.150849626 +0200
|
|
|
9070b3 |
+++ openssh/openbsd-compat/port-linux-sshd.c 2015-06-24 10:57:50.159849603 +0200
|
|
|
9070b3 |
@@ -54,6 +54,20 @@ extern Authctxt *the_authctxt;
|
|
|
9070b3 |
extern int inetd_flag;
|
|
|
9070b3 |
extern int rexeced_flag;
|
|
|
9070b3 |
|
|
|
9070b3 |
+/* Wrapper around is_selinux_enabled() to log its return value once only */
|
|
|
9070b3 |
+int
|
|
|
9070b3 |
+sshd_selinux_enabled(void)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ static int enabled = -1;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (enabled == -1) {
|
|
|
9070b3 |
+ enabled = (is_selinux_enabled() == 1);
|
|
|
9070b3 |
+ debug("SELinux support %s", enabled ? "enabled" : "disabled");
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ return (enabled);
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
/* Send audit message */
|
|
|
9070b3 |
static int
|
|
|
9070b3 |
sshd_selinux_send_audit_message(int success, security_context_t default_context,
|
|
|
9070b3 |
@@ -308,7 +322,7 @@ sshd_selinux_getctxbyname(char *pwname,
|
|
|
9070b3 |
|
|
|
9070b3 |
/* Setup environment variables for pam_selinux */
|
|
|
9070b3 |
static int
|
|
|
9070b3 |
-sshd_selinux_setup_pam_variables(void)
|
|
|
9070b3 |
+sshd_selinux_setup_variables(int(*set_it)(char *, const char *))
|
|
|
9070b3 |
{
|
|
|
9070b3 |
const char *reqlvl;
|
|
|
9070b3 |
char *role;
|
|
|
9070b3 |
@@ -319,16 +333,16 @@ sshd_selinux_setup_pam_variables(void)
|
|
|
9070b3 |
|
|
|
9070b3 |
ssh_selinux_get_role_level(&role, &reqlvl);
|
|
|
9070b3 |
|
|
|
9070b3 |
- rv = do_pam_putenv("SELINUX_ROLE_REQUESTED", role ? role : "");
|
|
|
9070b3 |
+ rv = set_it("SELINUX_ROLE_REQUESTED", role ? role : "");
|
|
|
9070b3 |
|
|
|
9070b3 |
if (inetd_flag && !rexeced_flag) {
|
|
|
9070b3 |
use_current = "1";
|
|
|
9070b3 |
} else {
|
|
|
9070b3 |
use_current = "";
|
|
|
9070b3 |
- rv = rv || do_pam_putenv("SELINUX_LEVEL_REQUESTED", reqlvl ? reqlvl: "");
|
|
|
9070b3 |
+ rv = rv || set_it("SELINUX_LEVEL_REQUESTED", reqlvl ? reqlvl: "");
|
|
|
9070b3 |
}
|
|
|
9070b3 |
|
|
|
9070b3 |
- rv = rv || do_pam_putenv("SELINUX_USE_CURRENT_RANGE", use_current);
|
|
|
9070b3 |
+ rv = rv || set_it("SELINUX_USE_CURRENT_RANGE", use_current);
|
|
|
9070b3 |
|
|
|
9070b3 |
if (role != NULL)
|
|
|
9070b3 |
free(role);
|
|
|
9070b3 |
@@ -336,6 +350,24 @@ sshd_selinux_setup_pam_variables(void)
|
|
|
9070b3 |
return rv;
|
|
|
9070b3 |
}
|
|
|
9070b3 |
|
|
|
9070b3 |
+static int
|
|
|
9070b3 |
+sshd_selinux_setup_pam_variables(void)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ return sshd_selinux_setup_variables(do_pam_putenv);
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+static int
|
|
|
9070b3 |
+do_setenv(char *name, const char *value)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ return setenv(name, value, 1);
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+int
|
|
|
9070b3 |
+sshd_selinux_setup_env_variables(void)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ return sshd_selinux_setup_variables(do_setenv);
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
/* Set the execution context to the default for the specified user */
|
|
|
9070b3 |
void
|
|
|
9070b3 |
sshd_selinux_setup_exec_context(char *pwname)
|
|
|
9070b3 |
@@ -344,7 +376,7 @@ sshd_selinux_setup_exec_context(char *pw
|
|
|
9070b3 |
int r = 0;
|
|
|
9070b3 |
security_context_t default_ctx = NULL;
|
|
|
9070b3 |
|
|
|
9070b3 |
- if (!ssh_selinux_enabled())
|
|
|
9070b3 |
+ if (!sshd_selinux_enabled())
|
|
|
9070b3 |
return;
|
|
|
9070b3 |
|
|
|
9070b3 |
if (options.use_pam) {
|
|
|
9070b3 |
@@ -415,7 +447,7 @@ sshd_selinux_copy_context(void)
|
|
|
9070b3 |
{
|
|
|
9070b3 |
security_context_t *ctx;
|
|
|
9070b3 |
|
|
|
9070b3 |
- if (!ssh_selinux_enabled())
|
|
|
9070b3 |
+ if (!sshd_selinux_enabled())
|
|
|
9070b3 |
return;
|
|
|
9070b3 |
|
|
|
9070b3 |
if (getexeccon((security_context_t *)&ctx) != 0) {
|
|
|
9070b3 |
diff -up openssh/platform.c.keycat openssh/platform.c
|
|
|
9070b3 |
--- openssh/platform.c.keycat 2015-06-24 10:57:50.147849633 +0200
|
|
|
9070b3 |
+++ openssh/platform.c 2015-06-24 10:57:50.160849601 +0200
|
|
|
9070b3 |
@@ -103,7 +103,7 @@ platform_setusercontext(struct passwd *p
|
|
|
9070b3 |
{
|
|
|
9070b3 |
#ifdef WITH_SELINUX
|
|
|
9070b3 |
/* Cache selinux status for later use */
|
|
|
9070b3 |
- (void)ssh_selinux_enabled();
|
|
|
9070b3 |
+ (void)sshd_selinux_enabled();
|
|
|
9070b3 |
#endif
|
|
|
9070b3 |
|
|
|
9070b3 |
#ifdef USE_SOLARIS_PROJECTS
|
|
|
9070b3 |
diff -up openssh/ssh-keycat.c.keycat openssh/ssh-keycat.c
|
|
|
9070b3 |
--- openssh/ssh-keycat.c.keycat 2015-06-24 10:57:50.161849599 +0200
|
|
|
9070b3 |
+++ openssh/ssh-keycat.c 2015-06-24 10:57:50.161849599 +0200
|
|
|
9070b3 |
@@ -0,0 +1,241 @@
|
|
|
9070b3 |
+/*
|
|
|
9070b3 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
9070b3 |
+ * modification, are permitted provided that the following conditions
|
|
|
9070b3 |
+ * are met:
|
|
|
9070b3 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
9070b3 |
+ * notice, and the entire permission notice in its entirety,
|
|
|
9070b3 |
+ * including the disclaimer of warranties.
|
|
|
9070b3 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
9070b3 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
9070b3 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
9070b3 |
+ * 3. The name of the author may not be used to endorse or promote
|
|
|
9070b3 |
+ * products derived from this software without specific prior
|
|
|
9070b3 |
+ * written permission.
|
|
|
9070b3 |
+ *
|
|
|
9070b3 |
+ * ALTERNATIVELY, this product may be distributed under the terms of
|
|
|
9070b3 |
+ * the GNU Public License, in which case the provisions of the GPL are
|
|
|
9070b3 |
+ * required INSTEAD OF the above restrictions. (This clause is
|
|
|
9070b3 |
+ * necessary due to a potential bad interaction between the GPL and
|
|
|
9070b3 |
+ * the restrictions contained in a BSD-style copyright.)
|
|
|
9070b3 |
+ *
|
|
|
9070b3 |
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
9070b3 |
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
9070b3 |
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
9070b3 |
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
9070b3 |
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
9070b3 |
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
9070b3 |
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
9070b3 |
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
9070b3 |
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
9070b3 |
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
9070b3 |
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
9070b3 |
+ */
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+/*
|
|
|
9070b3 |
+ * Copyright (c) 2011 Red Hat, Inc.
|
|
|
9070b3 |
+ * Written by Tomas Mraz <tmraz@redhat.com>
|
|
|
9070b3 |
+*/
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+#define _GNU_SOURCE
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+#include "config.h"
|
|
|
9070b3 |
+#include <stdio.h>
|
|
|
9070b3 |
+#include <stdlib.h>
|
|
|
9070b3 |
+#include <string.h>
|
|
|
9070b3 |
+#include <sys/types.h>
|
|
|
9070b3 |
+#include <sys/stat.h>
|
|
|
9070b3 |
+#include <pwd.h>
|
|
|
9070b3 |
+#include <fcntl.h>
|
|
|
9070b3 |
+#include <unistd.h>
|
|
|
9070b3 |
+#ifdef HAVE_STDINT_H
|
|
|
9070b3 |
+#include <stdint.h>
|
|
|
9070b3 |
+#endif
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+#include <security/pam_appl.h>
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+#include "uidswap.h"
|
|
|
9070b3 |
+#include "misc.h"
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+#define ERR_USAGE 1
|
|
|
9070b3 |
+#define ERR_PAM_START 2
|
|
|
9070b3 |
+#define ERR_OPEN_SESSION 3
|
|
|
9070b3 |
+#define ERR_CLOSE_SESSION 4
|
|
|
9070b3 |
+#define ERR_PAM_END 5
|
|
|
9070b3 |
+#define ERR_GETPWNAM 6
|
|
|
9070b3 |
+#define ERR_MEMORY 7
|
|
|
9070b3 |
+#define ERR_OPEN 8
|
|
|
9070b3 |
+#define ERR_FILE_MODE 9
|
|
|
9070b3 |
+#define ERR_FDOPEN 10
|
|
|
9070b3 |
+#define ERR_STAT 11
|
|
|
9070b3 |
+#define ERR_WRITE 12
|
|
|
9070b3 |
+#define ERR_PAM_PUTENV 13
|
|
|
9070b3 |
+#define BUFLEN 4096
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+/* Just ignore the messages in the conversation function */
|
|
|
9070b3 |
+static int
|
|
|
9070b3 |
+dummy_conv(int num_msg, const struct pam_message **msgm,
|
|
|
9070b3 |
+ struct pam_response **response, void *appdata_ptr)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ struct pam_response *rsp;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ (void)msgm;
|
|
|
9070b3 |
+ (void)appdata_ptr;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (num_msg <= 0)
|
|
|
9070b3 |
+ return PAM_CONV_ERR;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ /* Just allocate the array as empty responses */
|
|
|
9070b3 |
+ rsp = calloc (num_msg, sizeof (struct pam_response));
|
|
|
9070b3 |
+ if (rsp == NULL)
|
|
|
9070b3 |
+ return PAM_CONV_ERR;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ *response = rsp;
|
|
|
9070b3 |
+ return PAM_SUCCESS;
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+static struct pam_conv conv = {
|
|
|
9070b3 |
+ dummy_conv,
|
|
|
9070b3 |
+ NULL
|
|
|
9070b3 |
+};
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+char *
|
|
|
9070b3 |
+make_auth_keys_name(const struct passwd *pwd)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ char *fname;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (asprintf(&fname, "%s/.ssh/authorized_keys", pwd->pw_dir) < 0)
|
|
|
9070b3 |
+ return NULL;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ return fname;
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+int
|
|
|
9070b3 |
+dump_keys(const char *user)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ struct passwd *pwd;
|
|
|
9070b3 |
+ int fd = -1;
|
|
|
9070b3 |
+ FILE *f = NULL;
|
|
|
9070b3 |
+ char *fname = NULL;
|
|
|
9070b3 |
+ int rv = 0;
|
|
|
9070b3 |
+ char buf[BUFLEN];
|
|
|
9070b3 |
+ size_t len;
|
|
|
9070b3 |
+ struct stat st;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if ((pwd = getpwnam(user)) == NULL) {
|
|
|
9070b3 |
+ return ERR_GETPWNAM;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if ((fname = make_auth_keys_name(pwd)) == NULL) {
|
|
|
9070b3 |
+ return ERR_MEMORY;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ temporarily_use_uid(pwd);
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if ((fd = open(fname, O_RDONLY|O_NONBLOCK|O_NOFOLLOW, 0)) < 0) {
|
|
|
9070b3 |
+ rv = ERR_OPEN;
|
|
|
9070b3 |
+ goto fail;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (fstat(fd, &st) < 0) {
|
|
|
9070b3 |
+ rv = ERR_STAT;
|
|
|
9070b3 |
+ goto fail;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (!S_ISREG(st.st_mode) ||
|
|
|
9070b3 |
+ (st.st_uid != pwd->pw_uid && st.st_uid != 0)) {
|
|
|
9070b3 |
+ rv = ERR_FILE_MODE;
|
|
|
9070b3 |
+ goto fail;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ unset_nonblock(fd);
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if ((f = fdopen(fd, "r")) == NULL) {
|
|
|
9070b3 |
+ rv = ERR_FDOPEN;
|
|
|
9070b3 |
+ goto fail;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ fd = -1;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ while ((len = fread(buf, 1, sizeof(buf), f)) > 0) {
|
|
|
9070b3 |
+ rv = fwrite(buf, 1, len, stdout) != len ? ERR_WRITE : 0;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+fail:
|
|
|
9070b3 |
+ if (fd != -1)
|
|
|
9070b3 |
+ close(fd);
|
|
|
9070b3 |
+ if (f != NULL)
|
|
|
9070b3 |
+ fclose(f);
|
|
|
9070b3 |
+ free(fname);
|
|
|
9070b3 |
+ restore_uid();
|
|
|
9070b3 |
+ return rv;
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+static const char *env_names[] = { "SELINUX_ROLE_REQUESTED",
|
|
|
9070b3 |
+ "SELINUX_LEVEL_REQUESTED",
|
|
|
9070b3 |
+ "SELINUX_USE_CURRENT_RANGE"
|
|
|
9070b3 |
+};
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+extern char **environ;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+int
|
|
|
9070b3 |
+set_pam_environment(pam_handle_t *pamh)
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ int i;
|
|
|
9070b3 |
+ size_t j;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ for (j = 0; j < sizeof(env_names)/sizeof(env_names[0]); ++j) {
|
|
|
9070b3 |
+ int len = strlen(env_names[j]);
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ for (i = 0; environ[i] != NULL; ++i) {
|
|
|
9070b3 |
+ if (strncmp(env_names[j], environ[i], len) == 0 &&
|
|
|
9070b3 |
+ environ[i][len] == '=') {
|
|
|
9070b3 |
+ if (pam_putenv(pamh, environ[i]) != PAM_SUCCESS)
|
|
|
9070b3 |
+ return ERR_PAM_PUTENV;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ return 0;
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+int
|
|
|
9070b3 |
+main(int argc, char *argv[])
|
|
|
9070b3 |
+{
|
|
|
9070b3 |
+ pam_handle_t *pamh = NULL;
|
|
|
9070b3 |
+ int retval;
|
|
|
9070b3 |
+ int ev = 0;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ if (argc != 2) {
|
|
|
9070b3 |
+ fprintf(stderr, "Usage: %s <user-name>\n", argv[0]);
|
|
|
9070b3 |
+ return ERR_USAGE;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ retval = pam_start("ssh-keycat", argv[1], &conv, &pamh);
|
|
|
9070b3 |
+ if (retval != PAM_SUCCESS) {
|
|
|
9070b3 |
+ return ERR_PAM_START;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ ev = set_pam_environment(pamh);
|
|
|
9070b3 |
+ if (ev != 0)
|
|
|
9070b3 |
+ goto finish;
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ retval = pam_open_session(pamh, PAM_SILENT);
|
|
|
9070b3 |
+ if (retval != PAM_SUCCESS) {
|
|
|
9070b3 |
+ ev = ERR_OPEN_SESSION;
|
|
|
9070b3 |
+ goto finish;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ ev = dump_keys(argv[1]);
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+ retval = pam_close_session(pamh, PAM_SILENT);
|
|
|
9070b3 |
+ if (retval != PAM_SUCCESS) {
|
|
|
9070b3 |
+ ev = ERR_CLOSE_SESSION;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+
|
|
|
9070b3 |
+finish:
|
|
|
9070b3 |
+ retval = pam_end (pamh,retval);
|
|
|
9070b3 |
+ if (retval != PAM_SUCCESS) {
|
|
|
9070b3 |
+ ev = ERR_PAM_END;
|
|
|
9070b3 |
+ }
|
|
|
9070b3 |
+ return ev;
|
|
|
9070b3 |
+}
|
|
|
9070b3 |
diff --git a/configure.ac b/configure.ac
|
|
|
9070b3 |
index 3bbccfd..6481f1f 100644
|
|
|
9070b3 |
--- a/configure.ac
|
|
|
9070b3 |
+++ b/configure.ac
|
|
|
9070b3 |
@@ -2952,6 +2952,7 @@ AC_ARG_WITH([pam],
|
|
|
9070b3 |
PAM_MSG="yes"
|
|
|
9070b3 |
|
|
|
9070b3 |
SSHDLIBS="$SSHDLIBS -lpam"
|
|
|
9070b3 |
+ KEYCATLIBS="$KEYCATLIBS -lpam"
|
|
|
9070b3 |
AC_DEFINE([USE_PAM], [1],
|
|
|
9070b3 |
[Define if you want to enable PAM support])
|
|
|
9070b3 |
|
|
|
9070b3 |
@@ -3105,6 +3106,7 @@
|
|
|
9070b3 |
;;
|
|
|
9070b3 |
*)
|
|
|
9070b3 |
SSHDLIBS="$SSHDLIBS -ldl"
|
|
|
9070b3 |
+ KEYCATLIBS="$KEYCATLIBS -ldl"
|
|
|
9070b3 |
;;
|
|
|
9070b3 |
esac
|
|
|
9070b3 |
fi
|
|
|
9070b3 |
@@ -4042,6 +4044,7 @@ AC_ARG_WITH([selinux],
|
|
|
9070b3 |
fi ]
|
|
|
9070b3 |
)
|
|
|
9070b3 |
AC_SUBST([SSHDLIBS])
|
|
|
9070b3 |
+AC_SUBST([KEYCATLIBS])
|
|
|
9070b3 |
|
|
|
9070b3 |
# Check whether user wants Kerberos 5 support
|
|
|
9070b3 |
KRB5_MSG="no"
|
|
|
9070b3 |
@@ -5031,6 +5034,9 @@ fi
|
|
|
9070b3 |
if test ! -z "${SSHDLIBS}"; then
|
|
|
9070b3 |
echo " +for sshd: ${SSHDLIBS}"
|
|
|
9070b3 |
fi
|
|
|
9070b3 |
+if test ! -z "${KEYCATLIBS}"; then
|
|
|
9070b3 |
+echo " +for ssh-keycat: ${KEYCATLIBS}"
|
|
|
9070b3 |
+fi
|
|
|
9070b3 |
|
|
|
9070b3 |
echo ""
|
|
|
9070b3 |
|