Skip to content

Commit

Permalink
- (djm) OpenBSD CVS Sync
Browse files Browse the repository at this point in the history
   - [email protected] 2003/06/02 09:17:34
     [auth2-hostbased.c auth.c auth-options.c auth-rhosts.c auth-rh-rsa.c]
     [canohost.c monitor.c servconf.c servconf.h session.c sshd_config]
     [sshd_config.5]
     deprecate VerifyReverseMapping since it's dangerous if combined
     with IP based access control as noted by Mike Harding; replace with
     a UseDNS option, UseDNS is on by default and includes the
     VerifyReverseMapping check; with itojun@, provos@, jakob@ and deraadt@
     ok deraadt@, djm@
 - (djm) Fix portable-specific uses of verify_reverse_mapping too
  • Loading branch information
djmdjm committed Jun 3, 2003
1 parent 3527625 commit 3a961dc
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 68 deletions.
13 changes: 12 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
20030603
- (djm) Replace setproctitle replacement with code derived from
UCB sendmail
- (djm) OpenBSD CVS Sync
- [email protected] 2003/06/02 09:17:34
[auth2-hostbased.c auth.c auth-options.c auth-rhosts.c auth-rh-rsa.c]
[canohost.c monitor.c servconf.c servconf.h session.c sshd_config]
[sshd_config.5]
deprecate VerifyReverseMapping since it's dangerous if combined
with IP based access control as noted by Mike Harding; replace with
a UseDNS option, UseDNS is on by default and includes the
VerifyReverseMapping check; with itojun@, provos@, jakob@ and deraadt@
ok deraadt@, djm@
- (djm) Fix portable-specific uses of verify_reverse_mapping too

20030602
- (djm) Fix segv from bad reordering in auth-pam.c
Expand Down Expand Up @@ -1648,4 +1659,4 @@
save auth method before monitor_reset_key_state(); bugzilla bug #284;
ok provos@

$Id: ChangeLog,v 1.2764 2003/06/03 00:14:28 djm Exp $
$Id: ChangeLog,v 1.2765 2003/06/03 00:25:48 djm Exp $
4 changes: 2 additions & 2 deletions auth-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: auth-options.c,v 1.27 2003/04/08 20:21:28 itojun Exp $");
RCSID("$OpenBSD: auth-options.c,v 1.28 2003/06/02 09:17:34 markus Exp $");

#include "xmalloc.h"
#include "match.h"
Expand Down Expand Up @@ -173,7 +173,7 @@ auth_parse_options(struct passwd *pw, char *opts, char *file, u_long linenum)
if (strncasecmp(opts, cp, strlen(cp)) == 0) {
const char *remote_ip = get_remote_ipaddr();
const char *remote_host = get_canonical_hostname(
options.verify_reverse_mapping);
options.use_dns);
char *patterns = xmalloc(strlen(opts) + 1);

opts += strlen(cp);
Expand Down
5 changes: 2 additions & 3 deletions auth-pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

/* Based on $FreeBSD: src/crypto/openssh/auth2-pam-freebsd.c,v 1.11 2003/03/31 13:48:18 des Exp $ */
#include "includes.h"
RCSID("$Id: auth-pam.c,v 1.63 2003/06/02 01:04:39 djm Exp $");
RCSID("$Id: auth-pam.c,v 1.64 2003/06/03 00:25:48 djm Exp $");

#ifdef USE_PAM
#include <security/pam_appl.h>
Expand Down Expand Up @@ -299,8 +299,7 @@ sshpam_init(const char *user)
sshpam_handle = NULL;
return (-1);
}
pam_rhost = get_remote_name_or_ip(utmp_len,
options.verify_reverse_mapping);
pam_rhost = get_remote_name_or_ip(utmp_len, options.use_dns);
debug("PAM: setting PAM_RHOST to \"%s\"", pam_rhost);
sshpam_err = pam_set_item(sshpam_handle, PAM_RHOST, pam_rhost);
if (sshpam_err != PAM_SUCCESS) {
Expand Down
16 changes: 9 additions & 7 deletions auth-passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,24 @@ auth_password(Authctxt *authctxt, const char *password)
HANDLE hToken = cygwin_logon_user(pw, password);

if (hToken == INVALID_HANDLE_VALUE)
return 0;
return (0);
cygwin_set_impersonation_token(hToken);
return 1;
return (1);
}
# endif
# ifdef WITH_AIXAUTHENTICATE
authsuccess = (authenticate(pw->pw_name,password,&reenter,&authmsg) == 0);

if (authsuccess)
if (authsuccess) {
/* We don't have a pty yet, so just label the line as "ssh" */
if (loginsuccess(authctxt->user,
get_canonical_hostname(options.verify_reverse_mapping),
"ssh", &aixloginmsg) < 0)
aixloginmsg = NULL;
get_canonical_hostname(options.use_dns),
"ssh", &aixloginmsg) < 0) {
aixloginmsg = NULL;
}
}

return(authsuccess);
return (authsuccess);
# endif
# ifdef KRB4
if (options.kerberos_authentication == 1) {
Expand Down
4 changes: 2 additions & 2 deletions auth-rh-rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: auth-rh-rsa.c,v 1.35 2003/04/08 20:21:28 itojun Exp $");
RCSID("$OpenBSD: auth-rh-rsa.c,v 1.36 2003/06/02 09:17:34 markus Exp $");

#include "packet.h"
#include "uidswap.h"
Expand Down Expand Up @@ -63,7 +63,7 @@ auth_rhosts_rsa(struct passwd *pw, char *cuser, Key *client_host_key)
client_host_key->rsa == NULL)
return 0;

chost = (char *)get_canonical_hostname(options.verify_reverse_mapping);
chost = (char *)get_canonical_hostname(options.use_dns);
debug("Rhosts RSA authentication: canonical host %.900s", chost);

if (!PRIVSEP(auth_rhosts_rsa_key_allowed(pw, cuser, chost, client_host_key))) {
Expand Down
4 changes: 2 additions & 2 deletions auth-rhosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: auth-rhosts.c,v 1.30 2003/05/17 03:25:58 itojun Exp $");
RCSID("$OpenBSD: auth-rhosts.c,v 1.31 2003/06/02 09:17:34 markus Exp $");

#include "packet.h"
#include "uidswap.h"
Expand Down Expand Up @@ -156,7 +156,7 @@ auth_rhosts(struct passwd *pw, const char *client_user)
{
const char *hostname, *ipaddr;

hostname = get_canonical_hostname(options.verify_reverse_mapping);
hostname = get_canonical_hostname(options.use_dns);
ipaddr = get_remote_ipaddr();
return auth_rhosts2(pw, client_user, hostname, ipaddr);
}
Expand Down
4 changes: 2 additions & 2 deletions auth-sia.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ auth_sia_password(Authctxt *authctxt, char *pass)
SIAENTITY *ent = NULL;
const char *host;

host = get_canonical_hostname(options.verify_reverse_mapping);
host = get_canonical_hostname(options.use_dns);

if (!authctxt->user || pass == NULL || pass[0] == '\0')
return (0);
Expand Down Expand Up @@ -81,7 +81,7 @@ session_setup_sia(struct passwd *pw, char *tty)
SIAENTITY *ent = NULL;
const char *host;

host = get_canonical_hostname(options.verify_reverse_mapping);
host = get_canonical_hostname(options.use_dns);

if (sia_ses_init(&ent, saved_argc, saved_argv, host, pw->pw_name,
tty, 0, NULL) != SIASUCCESS)
Expand Down
4 changes: 2 additions & 2 deletions auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: auth.c,v 1.47 2003/04/08 20:21:28 itojun Exp $");
RCSID("$OpenBSD: auth.c,v 1.48 2003/06/02 09:17:34 markus Exp $");

#ifdef HAVE_LOGIN_H
#include <login.h>
Expand Down Expand Up @@ -141,7 +141,7 @@ allowed_user(struct passwd * pw)
}

if (options.num_deny_users > 0 || options.num_allow_users > 0) {
hostname = get_canonical_hostname(options.verify_reverse_mapping);
hostname = get_canonical_hostname(options.use_dns);
ipaddr = get_remote_ipaddr();
}

Expand Down
4 changes: 2 additions & 2 deletions auth2-hostbased.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: auth2-hostbased.c,v 1.3 2003/04/08 20:21:28 itojun Exp $");
RCSID("$OpenBSD: auth2-hostbased.c,v 1.4 2003/06/02 09:17:34 markus Exp $");

#include "ssh2.h"
#include "xmalloc.h"
Expand Down Expand Up @@ -136,7 +136,7 @@ hostbased_key_allowed(struct passwd *pw, const char *cuser, char *chost,
HostStatus host_status;
int len;

resolvedname = get_canonical_hostname(options.verify_reverse_mapping);
resolvedname = get_canonical_hostname(options.use_dns);
ipaddr = get_remote_ipaddr();

debug2("userauth_hostbased: chost %s resolvedname %s ipaddr %s",
Expand Down
44 changes: 27 additions & 17 deletions canohost.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: canohost.c,v 1.36 2003/04/08 20:21:28 itojun Exp $");
RCSID("$OpenBSD: canohost.c,v 1.37 2003/06/02 09:17:34 markus Exp $");

#include "packet.h"
#include "xmalloc.h"
Expand All @@ -27,7 +27,7 @@ static void check_ip_options(int, char *);
*/

static char *
get_remote_hostname(int socket, int verify_reverse_mapping)
get_remote_hostname(int socket, int use_dns)
{
struct sockaddr_storage from;
int i;
Expand Down Expand Up @@ -72,6 +72,9 @@ get_remote_hostname(int socket, int verify_reverse_mapping)
NULL, 0, NI_NUMERICHOST) != 0)
fatal("get_remote_hostname: getnameinfo NI_NUMERICHOST failed");

if (!use_dns)
return xstrdup(ntop);

if (from.ss_family == AF_INET)
check_ip_options(socket, ntop);

Expand All @@ -80,24 +83,31 @@ get_remote_hostname(int socket, int verify_reverse_mapping)
if (getnameinfo((struct sockaddr *)&from, fromlen, name, sizeof(name),
NULL, 0, NI_NAMEREQD) != 0) {
/* Host name not found. Use ip address. */
#if 0
logit("Could not reverse map address %.100s.", ntop);
#endif
return xstrdup(ntop);
}

/* Got host name. */
name[sizeof(name) - 1] = '\0';
/*
* if reverse lookup result looks like a numeric hostname,
* someone is trying to trick us by PTR record like following:
* 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5
*/
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(name, "0", &hints, &ai) == 0) {
logit("Nasty PTR record \"%s\" is set up for %s, ignoring",
name, ntop);
freeaddrinfo(ai);
return xstrdup(ntop);
}

/*
* Convert it to all lowercase (which is expected by the rest
* of this software).
*/
for (i = 0; name[i]; i++)
if (isupper(name[i]))
name[i] = tolower(name[i]);

if (!verify_reverse_mapping)
return xstrdup(name);
/*
* Map it back to an IP address and check that the given
* address actually is an address of this host. This is
Expand Down Expand Up @@ -180,14 +190,14 @@ check_ip_options(int socket, char *ipaddr)
*/

const char *
get_canonical_hostname(int verify_reverse_mapping)
get_canonical_hostname(int use_dns)
{
static char *canonical_host_name = NULL;
static int verify_reverse_mapping_done = 0;
static int use_dns_done = 0;

/* Check if we have previously retrieved name with same option. */
if (canonical_host_name != NULL) {
if (verify_reverse_mapping_done != verify_reverse_mapping)
if (use_dns_done != use_dns)
xfree(canonical_host_name);
else
return canonical_host_name;
Expand All @@ -196,11 +206,11 @@ get_canonical_hostname(int verify_reverse_mapping)
/* Get the real hostname if socket; otherwise return UNKNOWN. */
if (packet_connection_is_on_socket())
canonical_host_name = get_remote_hostname(
packet_get_connection_in(), verify_reverse_mapping);
packet_get_connection_in(), use_dns);
else
canonical_host_name = xstrdup("UNKNOWN");

verify_reverse_mapping_done = verify_reverse_mapping;
use_dns_done = use_dns;
return canonical_host_name;
}

Expand Down Expand Up @@ -294,11 +304,11 @@ get_remote_ipaddr(void)
}

const char *
get_remote_name_or_ip(u_int utmp_len, int verify_reverse_mapping)
get_remote_name_or_ip(u_int utmp_len, int use_dns)
{
static const char *remote = "";
if (utmp_len > 0)
remote = get_canonical_hostname(verify_reverse_mapping);
remote = get_canonical_hostname(use_dns);
if (utmp_len == 0 || strlen(remote) > utmp_len)
remote = get_remote_ipaddr();
return remote;
Expand Down
4 changes: 2 additions & 2 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: monitor.c,v 1.41 2003/05/24 09:30:40 djm Exp $");
RCSID("$OpenBSD: monitor.c,v 1.42 2003/06/02 09:17:34 markus Exp $");

#include <openssl/dh.h>

Expand Down Expand Up @@ -1157,7 +1157,7 @@ mm_record_login(Session *s, struct passwd *pw)
}
/* Record that there was a login on that tty from the remote host. */
record_login(s->pid, s->tty, pw->pw_name, pw->pw_uid,
get_remote_name_or_ip(utmp_len, options.verify_reverse_mapping),
get_remote_name_or_ip(utmp_len, options.use_dns),
(struct sockaddr *)&from, fromlen);
}

Expand Down
19 changes: 10 additions & 9 deletions servconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

#include "includes.h"
RCSID("$OpenBSD: servconf.c,v 1.121 2003/05/15 14:02:47 jakob Exp $");
RCSID("$OpenBSD: servconf.c,v 1.122 2003/06/02 09:17:34 markus Exp $");

#if defined(KRB4)
#include <krb.h>
Expand Down Expand Up @@ -116,7 +116,7 @@ initialize_server_options(ServerOptions *options)
options->max_startups_rate = -1;
options->max_startups = -1;
options->banner = NULL;
options->verify_reverse_mapping = -1;
options->use_dns = -1;
options->client_alive_interval = -1;
options->client_alive_count_max = -1;
options->authorized_keys_file = NULL;
Expand Down Expand Up @@ -232,8 +232,8 @@ fill_default_server_options(ServerOptions *options)
options->max_startups_rate = 100; /* 100% */
if (options->max_startups_begin == -1)
options->max_startups_begin = options->max_startups;
if (options->verify_reverse_mapping == -1)
options->verify_reverse_mapping = 0;
if (options->use_dns == -1)
options->use_dns = 1;
if (options->client_alive_interval == -1)
options->client_alive_interval = 0;
if (options->client_alive_count_max == -1)
Expand Down Expand Up @@ -282,7 +282,7 @@ typedef enum {
sAllowUsers, sDenyUsers, sAllowGroups, sDenyGroups,
sIgnoreUserKnownHosts, sCiphers, sMacs, sProtocol, sPidFile,
sGatewayPorts, sPubkeyAuthentication, sXAuthLocation, sSubsystem, sMaxStartups,
sBanner, sVerifyReverseMapping, sHostbasedAuthentication,
sBanner, sUseDNS, sHostbasedAuthentication,
sHostbasedUsesNameFromPacketOnly, sClientAliveInterval,
sClientAliveCountMax, sAuthorizedKeysFile, sAuthorizedKeysFile2,
sUsePrivilegeSeparation,
Expand Down Expand Up @@ -366,8 +366,9 @@ static struct {
{ "subsystem", sSubsystem },
{ "maxstartups", sMaxStartups },
{ "banner", sBanner },
{ "verifyreversemapping", sVerifyReverseMapping },
{ "reversemappingcheck", sVerifyReverseMapping },
{ "usedns", sUseDNS },
{ "verifyreversemapping", sDeprecated },
{ "reversemappingcheck", sDeprecated },
{ "clientaliveinterval", sClientAliveInterval },
{ "clientalivecountmax", sClientAliveCountMax },
{ "authorizedkeysfile", sAuthorizedKeysFile },
Expand Down Expand Up @@ -723,8 +724,8 @@ process_server_config_line(ServerOptions *options, char *line,
intptr = &options->gateway_ports;
goto parse_flag;

case sVerifyReverseMapping:
intptr = &options->verify_reverse_mapping;
case sUseDNS:
intptr = &options->use_dns;
goto parse_flag;

case sLogFacility:
Expand Down
4 changes: 2 additions & 2 deletions servconf.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: servconf.h,v 1.60 2003/05/15 01:48:10 jakob Exp $ */
/* $OpenBSD: servconf.h,v 1.61 2003/06/02 09:17:34 markus Exp $ */

/*
* Author: Tatu Ylonen <[email protected]>
Expand Down Expand Up @@ -112,7 +112,7 @@ typedef struct {
int max_startups_rate;
int max_startups;
char *banner; /* SSH-2 banner message */
int verify_reverse_mapping; /* cross-check ip and dns */
int use_dns;
int client_alive_interval; /*
* poke the client this often to
* see if it's still there
Expand Down
Loading

0 comments on commit 3a961dc

Please sign in to comment.