Skip to content

Commit 03e3de4

Browse files
committed
upstream: Start the process of splitting sshd into separate
binaries. This step splits sshd into a listener and a session binary. More splits are planned. After this changes, the listener binary will validate the configuration, load the hostkeys, listen on port 22 and manage MaxStartups only. All session handling will be performed by a new sshd-session binary that the listener fork+execs. This reduces the listener process to the minimum necessary and sets us up for future work on the sshd-session binary. feedback/ok markus@ deraadt@ NB. if you're updating via source, please restart sshd after installing, otherwise you run the risk of locking yourself out. OpenBSD-Commit-ID: 43c04a1ab96cdbdeb53d2df0125a6d42c5f19934
1 parent 1c0d813 commit 03e3de4

33 files changed

+2096
-1931
lines changed

auth-pam.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static struct pam_conv store_conv = { sshpam_store_conv, NULL };
668668
void
669669
sshpam_cleanup(void)
670670
{
671-
if (sshpam_handle == NULL || (use_privsep && !mm_is_monitor()))
671+
if (sshpam_handle == NULL || !mm_is_monitor())
672672
return;
673673
debug("PAM: cleanup");
674674
pam_set_item(sshpam_handle, PAM_CONV, (const void *)&null_conv);
@@ -705,7 +705,8 @@ sshpam_init(struct ssh *ssh, Authctxt *authctxt)
705705
fatal("%s: called initially with no "
706706
"packet context", __func__);
707707
}
708-
} if (sshpam_handle != NULL) {
708+
}
709+
if (sshpam_handle != NULL) {
709710
/* We already have a PAM context; check if the user matches */
710711
sshpam_err = pam_get_item(sshpam_handle,
711712
PAM_USER, (sshpam_const void **)ptr_pam_user);
@@ -1101,20 +1102,15 @@ do_pam_account(void)
11011102
}
11021103

11031104
void
1104-
do_pam_setcred(int init)
1105+
do_pam_setcred(void)
11051106
{
11061107
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
11071108
(const void *)&store_conv);
11081109
if (sshpam_err != PAM_SUCCESS)
11091110
fatal("PAM: failed to set PAM_CONV: %s",
11101111
pam_strerror(sshpam_handle, sshpam_err));
1111-
if (init) {
1112-
debug("PAM: establishing credentials");
1113-
sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
1114-
} else {
1115-
debug("PAM: reinitializing credentials");
1116-
sshpam_err = pam_setcred(sshpam_handle, PAM_REINITIALIZE_CRED);
1117-
}
1112+
debug("PAM: establishing credentials");
1113+
sshpam_err = pam_setcred(sshpam_handle, PAM_ESTABLISH_CRED);
11181114
if (sshpam_err == PAM_SUCCESS) {
11191115
sshpam_cred_established = 1;
11201116
return;
@@ -1127,6 +1123,7 @@ do_pam_setcred(int init)
11271123
pam_strerror(sshpam_handle, sshpam_err));
11281124
}
11291125

1126+
#if 0
11301127
static int
11311128
sshpam_tty_conv(int n, sshpam_const struct pam_message **msg,
11321129
struct pam_response **resp, void *data)
@@ -1182,6 +1179,7 @@ sshpam_tty_conv(int n, sshpam_const struct pam_message **msg,
11821179
}
11831180

11841181
static struct pam_conv tty_conv = { sshpam_tty_conv, NULL };
1182+
#endif
11851183

11861184
/*
11871185
* XXX this should be done in the authentication phase, but ssh1 doesn't
@@ -1190,8 +1188,8 @@ static struct pam_conv tty_conv = { sshpam_tty_conv, NULL };
11901188
void
11911189
do_pam_chauthtok(void)
11921190
{
1193-
if (use_privsep)
1194-
fatal("Password expired (unable to change with privsep)");
1191+
fatal("Password expired");
1192+
#if 0
11951193
sshpam_err = pam_set_item(sshpam_handle, PAM_CONV,
11961194
(const void *)&tty_conv);
11971195
if (sshpam_err != PAM_SUCCESS)
@@ -1202,6 +1200,7 @@ do_pam_chauthtok(void)
12021200
if (sshpam_err != PAM_SUCCESS)
12031201
fatal("PAM: pam_chauthtok(): %s",
12041202
pam_strerror(sshpam_handle, sshpam_err));
1203+
#endif
12051204
}
12061205

12071206
void

auth-pam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void start_pam(struct ssh *);
3131
void finish_pam(void);
3232
u_int do_pam_account(void);
3333
void do_pam_session(struct ssh *);
34-
void do_pam_setcred(int );
34+
void do_pam_setcred(void);
3535
void do_pam_chauthtok(void);
3636
int do_pam_putenv(char *, char *);
3737
char ** fetch_pam_environment(void);

auth-rhosts.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: auth-rhosts.c,v 1.57 2022/12/09 00:17:40 dtucker Exp $ */
1+
/* $OpenBSD: auth-rhosts.c,v 1.58 2024/05/17 00:30:23 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -46,7 +46,6 @@
4646

4747
/* import */
4848
extern ServerOptions options;
49-
extern int use_privsep;
5049

5150
/*
5251
* This function processes an rhosts-style file (.rhosts, .shosts, or

auth.c

Lines changed: 7 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $ */
22
/*
33
* Copyright (c) 2000 Markus Friedl. All rights reserved.
44
*
@@ -79,7 +79,6 @@
7979
/* import */
8080
extern ServerOptions options;
8181
extern struct include_list includes;
82-
extern int use_privsep;
8382
extern struct sshbuf *loginmsg;
8483
extern struct passwd *privsep_pw;
8584
extern struct sshauthopt *auth_opts;
@@ -272,7 +271,7 @@ auth_log(struct ssh *ssh, int authenticated, int partial,
272271
const char *authmsg;
273272
char *extra = NULL;
274273

275-
if (use_privsep && !mm_is_monitor() && !authctxt->postponed)
274+
if (!mm_is_monitor() && !authctxt->postponed)
276275
return;
277276

278277
/* Raise logging level */
@@ -472,14 +471,14 @@ getpwnamallow(struct ssh *ssh, const char *user)
472471
struct connection_info *ci;
473472
u_int i;
474473

475-
ci = get_connection_info(ssh, 1, options.use_dns);
474+
ci = server_get_connection_info(ssh, 1, options.use_dns);
476475
ci->user = user;
477476
parse_server_match_config(&options, &includes, ci);
478477
log_change_level(options.log_level);
479478
log_verbose_reset();
480479
for (i = 0; i < options.num_log_verbose; i++)
481480
log_verbose_add(options.log_verbose[i]);
482-
process_permitopen(ssh, &options);
481+
server_process_permitopen(ssh);
483482

484483
#if defined(_AIX) && defined(HAVE_SETAUTHDB)
485484
aix_setauthdb(user);
@@ -637,97 +636,6 @@ fakepw(void)
637636
return (&fake);
638637
}
639638

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-
731639
/*
732640
* Return the canonical name of the host in the other side of the current
733641
* 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)
741649

742650
if (!use_dns)
743651
return ssh_remote_ipaddr(ssh);
744-
else if (dnsname != NULL)
745-
return dnsname;
746-
else {
747-
dnsname = remote_hostname(ssh);
652+
if (dnsname != NULL)
748653
return dnsname;
749-
}
654+
dnsname = ssh_remote_hostname(ssh);
655+
return dnsname;
750656
}
751657

752658
/* These functions link key/cert options to the auth framework */

auth.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: auth.h,v 1.106 2022/06/15 16:08:25 djm Exp $ */
1+
/* $OpenBSD: auth.h,v 1.107 2024/05/17 00:30:23 djm Exp $ */
22

33
/*
44
* Copyright (c) 2000 Markus Friedl. All rights reserved.
@@ -104,11 +104,15 @@ struct Authctxt {
104104
* the client.
105105
*/
106106

107+
struct authmethod_cfg {
108+
const char *name;
109+
const char *synonym;
110+
int *enabled;
111+
};
112+
107113
struct Authmethod {
108-
char *name;
109-
char *synonym;
114+
struct authmethod_cfg *cfg;
110115
int (*userauth)(struct ssh *, const char *);
111-
int *enabled;
112116
};
113117

114118
/*

0 commit comments

Comments
 (0)