1
- /* $OpenBSD: auth.c,v 1.160 2023/03/05 05:34:09 dtucker Exp $ */
1
+ /* $OpenBSD: auth.c,v 1.161 2024/05/17 00:30:23 djm Exp $ */
2
2
/*
3
3
* Copyright (c) 2000 Markus Friedl. All rights reserved.
4
4
*
79
79
/* import */
80
80
extern ServerOptions options ;
81
81
extern struct include_list includes ;
82
- extern int use_privsep ;
83
82
extern struct sshbuf * loginmsg ;
84
83
extern struct passwd * privsep_pw ;
85
84
extern struct sshauthopt * auth_opts ;
@@ -272,7 +271,7 @@ auth_log(struct ssh *ssh, int authenticated, int partial,
272
271
const char * authmsg ;
273
272
char * extra = NULL ;
274
273
275
- if (use_privsep && !mm_is_monitor () && !authctxt -> postponed )
274
+ if (!mm_is_monitor () && !authctxt -> postponed )
276
275
return ;
277
276
278
277
/* Raise logging level */
@@ -472,14 +471,14 @@ getpwnamallow(struct ssh *ssh, const char *user)
472
471
struct connection_info * ci ;
473
472
u_int i ;
474
473
475
- ci = get_connection_info (ssh , 1 , options .use_dns );
474
+ ci = server_get_connection_info (ssh , 1 , options .use_dns );
476
475
ci -> user = user ;
477
476
parse_server_match_config (& options , & includes , ci );
478
477
log_change_level (options .log_level );
479
478
log_verbose_reset ();
480
479
for (i = 0 ; i < options .num_log_verbose ; i ++ )
481
480
log_verbose_add (options .log_verbose [i ]);
482
- process_permitopen (ssh , & options );
481
+ server_process_permitopen (ssh );
483
482
484
483
#if defined(_AIX ) && defined(HAVE_SETAUTHDB )
485
484
aix_setauthdb (user );
@@ -637,97 +636,6 @@ fakepw(void)
637
636
return (& fake );
638
637
}
639
638
640
- /*
641
- * Returns the remote DNS hostname as a string. The returned string must not
642
- * be freed. NB. this will usually trigger a DNS query the first time it is
643
- * called.
644
- * This function does additional checks on the hostname to mitigate some
645
- * attacks on based on conflation of hostnames and IP addresses.
646
- */
647
-
648
- static char *
649
- remote_hostname (struct ssh * ssh )
650
- {
651
- struct sockaddr_storage from ;
652
- socklen_t fromlen ;
653
- struct addrinfo hints , * ai , * aitop ;
654
- char name [NI_MAXHOST ], ntop2 [NI_MAXHOST ];
655
- const char * ntop = ssh_remote_ipaddr (ssh );
656
-
657
- /* Get IP address of client. */
658
- fromlen = sizeof (from );
659
- memset (& from , 0 , sizeof (from ));
660
- if (getpeername (ssh_packet_get_connection_in (ssh ),
661
- (struct sockaddr * )& from , & fromlen ) == -1 ) {
662
- debug ("getpeername failed: %.100s" , strerror (errno ));
663
- return xstrdup (ntop );
664
- }
665
-
666
- ipv64_normalise_mapped (& from , & fromlen );
667
- if (from .ss_family == AF_INET6 )
668
- fromlen = sizeof (struct sockaddr_in6 );
669
-
670
- debug3 ("Trying to reverse map address %.100s." , ntop );
671
- /* Map the IP address to a host name. */
672
- if (getnameinfo ((struct sockaddr * )& from , fromlen , name , sizeof (name ),
673
- NULL , 0 , NI_NAMEREQD ) != 0 ) {
674
- /* Host name not found. Use ip address. */
675
- return xstrdup (ntop );
676
- }
677
-
678
- /*
679
- * if reverse lookup result looks like a numeric hostname,
680
- * someone is trying to trick us by PTR record like following:
681
- * 1.1.1.10.in-addr.arpa. IN PTR 2.3.4.5
682
- */
683
- memset (& hints , 0 , sizeof (hints ));
684
- hints .ai_socktype = SOCK_DGRAM ; /*dummy*/
685
- hints .ai_flags = AI_NUMERICHOST ;
686
- if (getaddrinfo (name , NULL , & hints , & ai ) == 0 ) {
687
- logit ("Nasty PTR record \"%s\" is set up for %s, ignoring" ,
688
- name , ntop );
689
- freeaddrinfo (ai );
690
- return xstrdup (ntop );
691
- }
692
-
693
- /* Names are stored in lowercase. */
694
- lowercase (name );
695
-
696
- /*
697
- * Map it back to an IP address and check that the given
698
- * address actually is an address of this host. This is
699
- * necessary because anyone with access to a name server can
700
- * define arbitrary names for an IP address. Mapping from
701
- * name to IP address can be trusted better (but can still be
702
- * fooled if the intruder has access to the name server of
703
- * the domain).
704
- */
705
- memset (& hints , 0 , sizeof (hints ));
706
- hints .ai_family = from .ss_family ;
707
- hints .ai_socktype = SOCK_STREAM ;
708
- if (getaddrinfo (name , NULL , & hints , & aitop ) != 0 ) {
709
- logit ("reverse mapping checking getaddrinfo for %.700s "
710
- "[%s] failed." , name , ntop );
711
- return xstrdup (ntop );
712
- }
713
- /* Look for the address from the list of addresses. */
714
- for (ai = aitop ; ai ; ai = ai -> ai_next ) {
715
- if (getnameinfo (ai -> ai_addr , ai -> ai_addrlen , ntop2 ,
716
- sizeof (ntop2 ), NULL , 0 , NI_NUMERICHOST ) == 0 &&
717
- (strcmp (ntop , ntop2 ) == 0 ))
718
- break ;
719
- }
720
- freeaddrinfo (aitop );
721
- /* If we reached the end of the list, the address was not there. */
722
- if (ai == NULL ) {
723
- /* Address not found for the host name. */
724
- logit ("Address %.100s maps to %.600s, but this does not "
725
- "map back to the address." , ntop , name );
726
- return xstrdup (ntop );
727
- }
728
- return xstrdup (name );
729
- }
730
-
731
639
/*
732
640
* Return the canonical name of the host in the other side of the current
733
641
* connection. The host name is cached, so it is efficient to call this
@@ -741,12 +649,10 @@ auth_get_canonical_hostname(struct ssh *ssh, int use_dns)
741
649
742
650
if (!use_dns )
743
651
return ssh_remote_ipaddr (ssh );
744
- else if (dnsname != NULL )
745
- return dnsname ;
746
- else {
747
- dnsname = remote_hostname (ssh );
652
+ if (dnsname != NULL )
748
653
return dnsname ;
749
- }
654
+ dnsname = ssh_remote_hostname (ssh );
655
+ return dnsname ;
750
656
}
751
657
752
658
/* These functions link key/cert options to the auth framework */
0 commit comments