]> andersk Git - openssh.git/blobdiff - auth-rh-rsa.c
Thinko
[openssh.git] / auth-rh-rsa.c
index 9c71715e2f117a32d3b99766a9fb5e5a3150b53d..345a7b66f2e5e8f5fa2106597ce5a8964ca4cc99 100644 (file)
@@ -21,16 +21,16 @@ RCSID("$Id$");
 #include "ssh.h"
 #include "xmalloc.h"
 #include "uidswap.h"
+#include "servconf.h"
 
 /* Tries to authenticate the user using the .rhosts file and the host using
-   its host key.  Returns true if authentication succeeds. 
-   .rhosts and .shosts will be ignored if ignore_rhosts is non-zero. */
+   its host key.  Returns true if authentication succeeds. */
 
 int auth_rhosts_rsa(struct passwd *pw, const char *client_user,
                    unsigned int client_host_key_bits,
-                   BIGNUM *client_host_key_e, BIGNUM *client_host_key_n,
-                   int ignore_rhosts, int strict_modes)
+                   BIGNUM *client_host_key_e, BIGNUM *client_host_key_n)
 {
+  extern ServerOptions options;
   const char *canonical_hostname;
   HostStatus host_status;
   BIGNUM *ke, *kn;
@@ -38,7 +38,7 @@ int auth_rhosts_rsa(struct passwd *pw, const char *client_user,
   debug("Trying rhosts with RSA host authentication for %.100s", client_user);
 
   /* Check if we would accept it using rhosts authentication. */
-  if (!auth_rhosts(pw, client_user, ignore_rhosts, strict_modes))
+  if (!auth_rhosts(pw, client_user))
     return 0;
 
   canonical_hostname = get_canonical_hostname();
@@ -53,8 +53,32 @@ int auth_rhosts_rsa(struct passwd *pw, const char *client_user,
   host_status = check_host_in_hostfile(SSH_SYSTEM_HOSTFILE, canonical_hostname,
                                       client_host_key_bits, client_host_key_e,
                                       client_host_key_n, ke, kn);
+
+  /* Check user host file unless ignored. */
+  if (host_status != HOST_OK && !options.ignore_user_known_hosts) {
+    struct stat st;
+    char *user_hostfile = tilde_expand_filename(SSH_USER_HOSTFILE, pw->pw_uid);
+    /* Check file permissions of SSH_USER_HOSTFILE,
+       auth_rsa() did already check pw->pw_dir, but there is a race XXX */
+    if (options.strict_modes &&
+       (stat(user_hostfile, &st) == 0) &&
+       ((st.st_uid != 0 && st.st_uid != pw->pw_uid) ||
+       (st.st_mode & 022) != 0)) {
+       log("Rhosts RSA authentication refused for %.100s: bad owner or modes for %.200s",
+          pw->pw_name, user_hostfile);
+    } else {
+      /* XXX race between stat and the following open() */
+      temporarily_use_uid(pw->pw_uid);
+      host_status = check_host_in_hostfile(user_hostfile, canonical_hostname,
+                                          client_host_key_bits, client_host_key_e,
+                                          client_host_key_n, ke, kn);
+      restore_uid();
+    }
+    xfree(user_hostfile);
+  }
   BN_free(ke);
   BN_free(kn);
+
   if (host_status != HOST_OK) {
     /* The host key was not found. */
     debug("Rhosts with RSA host authentication denied: unknown or invalid host key");
This page took 0.07708 seconds and 4 git commands to generate.