Skip to content

openssh: restore launchd -l functionality via iamGavinJ #28592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion net/openssh/Portfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

Check warning on line 1 in net/openssh/Portfile

View workflow job for this annotation

GitHub Actions / macos-14

port lint openssh: Warning: Unnecessary platforms line as darwin is the default

Check warning on line 1 in net/openssh/Portfile

View workflow job for this annotation

GitHub Actions / macos-15

port lint openssh: Warning: Unnecessary platforms line as darwin is the default

Check warning on line 1 in net/openssh/Portfile

View workflow job for this annotation

GitHub Actions / macos-13

port lint openssh: Warning: Unnecessary platforms line as darwin is the default

PortSystem 1.0

Expand All @@ -7,7 +7,7 @@
name openssh
version 10.0p2
distname openssh-10.0p1
revision 1
revision 2
categories net
maintainers {@artkiver gmail.com:artkiver} openmaintainer
license BSD
Expand Down Expand Up @@ -53,6 +53,7 @@
patchfiles launchd.patch \
pam.patch \
macports-config.patch \
agent.patch

# We need a couple of patches
# - pam.patch
Expand All @@ -70,6 +71,9 @@
# the order of arguments to strnvis and considers everyone else to be broken.
configure.cppflags-append -DBROKEN_STRNVIS=1

# Support Apple's launchd in ssh-agent
configure.cppflags-append -D__APPLE_LAUNCHD__

configure.ldflags-append -Wl,-search_paths_first
configure.args --with-ssl-dir=${prefix} \
--sysconfdir=${prefix}/etc/ssh \
Expand Down
162 changes: 162 additions & 0 deletions net/openssh/files/agent.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
--- a/ssh-agent.c 2025-04-09 02:02:43
+++ b/ssh-agent.c 2025-05-31 16:16:49
@@ -70,6 +70,10 @@
#include <time.h>
#include <string.h>
#include <unistd.h>
+#ifdef __APPLE_LAUNCHD__
+#include <launch.h>
+#include <AvailabilityMacros.h>
+#endif
#ifdef HAVE_UTIL_H
# include <util.h>
#endif
@@ -2220,6 +2224,9 @@
main(int ac, char **av)
{
int c_flag = 0, d_flag = 0, D_flag = 0, k_flag = 0, s_flag = 0;
+ #ifdef __APPLE_LAUNCHD__
+ int l_flag = 0;
+ #endif
int sock = -1, ch, result, saved_errno;
char *shell, *format, *fdstr, *pidstr, *agentsocket = NULL;
const char *errstr = NULL;
@@ -2256,7 +2263,11 @@
__progname = ssh_get_progname(av[0]);
seed_rng();

+#ifdef __APPLE_LAUNCHD__
+ while ((ch = getopt(ac, av, "cDdklsE:a:O:P:t:")) != -1) {
+#else
while ((ch = getopt(ac, av, "cDdksE:a:O:P:t:")) != -1) {
+#endif
switch (ch) {
case 'E':
fingerprint_hash = ssh_digest_alg_by_name(optarg);
@@ -2289,6 +2300,11 @@
fatal("-P option already specified");
allowed_providers = xstrdup(optarg);
break;
+#ifdef __APPLE_LAUNCHD__
+ case 'l':
+ l_flag++;
+ break;
+#endif
case 's':
if (c_flag)
usage();
@@ -2416,6 +2432,83 @@
* the parent.
*/
if (sock == -1) {
+
+
+#ifdef __APPLE_LAUNCHD__
+ if (l_flag) {
+#if ((defined (MAC_OS_X_VERSION_10_11)) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11))
+ int *fds = NULL;
+ size_t count = 0;
+ result = launch_activate_socket("Listeners", &fds, &count);
+
+ if (result != 0 || fds == NULL || count < 1) {
+ errno = result;
+ perror("launch_activate_socket()");
+ exit(1);
+ }
+
+ size_t i;
+ for (i = 0; i < count; i++) {
+ new_socket(AUTH_SOCKET, fds[i]);
+ }
+
+ if (fds)
+ free(fds);
+
+ goto skip2;
+#else /* ((defined (MAC_OS_X_VERSION_10_11)) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11)) */
+ launch_data_t resp, msg, tmp;
+ size_t listeners_i;
+
+ msg = launch_data_new_string(LAUNCH_KEY_CHECKIN);
+
+ resp = launch_msg(msg);
+
+ if (NULL == resp) {
+ perror("launch_msg");
+ exit(1);
+ }
+ launch_data_free(msg);
+ switch (launch_data_get_type(resp)) {
+ case LAUNCH_DATA_ERRNO:
+ errno = launch_data_get_errno(resp);
+ perror("launch_msg response");
+ exit(1);
+ case LAUNCH_DATA_DICTIONARY:
+ break;
+ default:
+ fprintf(stderr, "launch_msg unknown response");
+ exit(1);
+ }
+ tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_SOCKETS);
+
+ if (NULL == tmp) {
+ fprintf(stderr, "no sockets\n");
+ exit(1);
+ }
+
+ tmp = launch_data_dict_lookup(tmp, "Listeners");
+
+ if (NULL == tmp) {
+ fprintf(stderr, "no known listeners\n");
+ exit(1);
+ }
+
+ for (listeners_i = 0; listeners_i < launch_data_array_get_count(tmp); listeners_i++) {
+ launch_data_t obj_at_ind = launch_data_array_get_index(tmp, listeners_i);
+ new_socket(AUTH_SOCKET, launch_data_get_fd(obj_at_ind));
+ }
+
+ launch_data_free(resp);
+#endif /* ((defined (MAC_OS_X_VERSION_10_11)) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11)) */
+ } else {
+#endif
+
+
+
+
+
+
prev_mask = umask(0177);
sock = unix_listener(socket_name, SSH_LISTEN_BACKLOG, 0);
if (sock < 0) {
@@ -2424,8 +2517,20 @@
cleanup_exit(1);
}
umask(prev_mask);
+#ifdef __APPLE_LAUNCHD__
+ }
+#endif /* defined (__APPLE_LAUNCHD__) */
+
}

+#ifdef __APPLE_LAUNCHD__
+#if ((!(defined (MAC_OS_X_VERSION_10_11))) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11))
+ if (l_flag)
+ goto skip2;
+#endif /* ((!(defined (MAC_OS_X_VERSION_10_11))) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_11)) */
+#endif /* defined (__APPLE_LAUNCHD__) */
+
+
/*
* Fork, and have the parent execute the command, if any, or present
* the socket data. The child continues as the authentication agent.
@@ -2499,6 +2604,9 @@
pkcs11_init(0);
#endif
new_socket(AUTH_SOCKET, sock);
+#ifdef __APPLE_LAUNCHD__
+skip2:
+#endif
if (ac > 0)
parent_alive_interval = 10;
idtab_init();