Created
May 8, 2025 07:03
-
-
Save al3xtjames/cadb016bf2c518b7fe80264e30e7b3f2 to your computer and use it in GitHub Desktop.
launchd socket activation patch for OpenSSH 10.0p1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/ssh-agent.c b/ssh-agent.c | |
index c27c5a956..47eeada58 100644 | |
--- a/ssh-agent.c | |
+++ b/ssh-agent.c | |
@@ -70,6 +70,9 @@ | |
#include <time.h> | |
#include <string.h> | |
#include <unistd.h> | |
+#ifdef __APPLE_LAUNCHD__ | |
+#include <launch.h> | |
+#endif | |
#ifdef HAVE_UTIL_H | |
# include <util.h> | |
#endif | |
@@ -2220,6 +2223,9 @@ int | |
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 +2262,11 @@ main(int ac, char **av) | |
__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 +2299,11 @@ main(int ac, char **av) | |
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(); | |
@@ -2415,6 +2430,29 @@ main(int ac, char **av) | |
* Create socket early so it will exist before command gets run from | |
* the parent. | |
*/ | |
+#ifdef __APPLE_LAUNCHD__ | |
+ if (l_flag) { | |
+ 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 { | |
+#endif | |
if (sock == -1) { | |
prev_mask = umask(0177); | |
sock = unix_listener(socket_name, SSH_LISTEN_BACKLOG, 0); | |
@@ -2423,6 +2461,9 @@ main(int ac, char **av) | |
*socket_name = '\0'; /* Don't unlink existing file */ | |
cleanup_exit(1); | |
} | |
+#ifdef __APPLE_LAUNCHD__ | |
+ } | |
+#endif | |
umask(prev_mask); | |
} | |
@@ -2499,6 +2540,9 @@ skip: | |
pkcs11_init(0); | |
#endif | |
new_socket(AUTH_SOCKET, sock); | |
+#ifdef __APPLE_LAUNCHD__ | |
+skip2: | |
+#endif | |
if (ac > 0) | |
parent_alive_interval = 10; | |
idtab_init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment