head	1.2;
access;
symbols
	netbsd-11:1.2.0.2;
locks; strict;
comment	@ * @;


1.2
date	2026.10.07.20.15.03;	author christos;	state Exp;
branches
	1.2.2.1;
next	1.1;
commitid	Xd9UhfD3WogWhAYG;

1.1
date	2026.10.07.17.32.07;	author christos;	state Exp;
branches;
next	;
commitid	bfGeT3ACqbH0ozYG;

1.2.2.1
date	2026.10.07.20.15.03;	author martin;	state dead;
branches;
next	1.2.2.2;
commitid	EKBVguwnnYsXPK0H;

1.2.2.2
date	2026.10.24.17.33.05;	author martin;	state Exp;
branches;
next	;
commitid	EKBVguwnnYsXPK0H;


desc
@@


1.2
log
@Make this work like OpenBSD.
@
text
@/*	$NetBSD: getexecpath.c,v 1.1 2026/10/07 17:32:07 christos Exp $	*/
/*-
 * Copyright (c) 2026 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <dlfcn.h>
#include <string.h>
#include <errno.h>
#include <elf.h>

#include "getexecpath.h"

int
getexecpath(char *buf, size_t len)
{
	const AuxInfo *aux;

	for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux)
		if (aux->a_type == AT_SUN_EXECNAME) {
			if (strlcpy(buf, (void *)(intptr_t)aux->a_v, len) < len)
				return 0;
			errno = ERANGE;
			return -1;
		}
	errno = ENOENT;
	return -1;
}

#ifdef TEST
#include <stdio.h>
#include <err.h>
#include <stdlib.h>
#include <limits.h>

int
main(void)
{
	char buf[PATH_MAX];
	if (getexecpath(buf, sizeof(buf)) == -1)
		err(EXIT_FAILURE, "Can't get path");
	printf("%s\n", buf);
	return 0;
}
#endif
@


1.2.2.1
log
@file getexecpath.c was added on branch netbsd-11 on 2026-10-24 17:33:05 +0000
@
text
@d1 69
@


1.2.2.2
log
@Pull up the following, requested by christos in ticket #550:

	crypto/external/bsd/openssh/lib/ssh.expsym.builtin up to 1.1
	crypto/external/bsd/openssh/lib/ssh.expsym.common up to 1.1
	crypto/external/bsd/openssh/lib/ssh.expsym.openssl up to 1.1
	crypto/external/bsd/openssh/dist/ssh-mldsa-eddsa.c up to 1.3
	crypto/external/bsd/openssh/dist/kexmlkem768ecdh.c up to 1.2
	crypto/external/bsd/openssh/dist/getexecpath.c  up to 1.2
	crypto/external/bsd/openssh/dist/getexecpath.h  up to 1.1
	crypto/external/bsd/openssh/dist/libcrux-mlkem-mldsa.c up to 1.2
	crypto/external/bsd/openssh/dist/libcrux_internal.h up to 1.3
	crypto/external/bsd/openssh/dist/mlkem_mldsa.sh up to 1.1.1.1
	crypto/external/bsd/openssh/dist/libcrux_mlkem768_sha3.h delete
	crypto/external/bsd/openssh/dist/mlkem768.sh    delete
	crypto/external/bsd/openssh/lib/ssh.expsym      delete
	crypto/external/bsd/openssh/Makefile.inc        up to 1.21
	crypto/external/bsd/openssh/dist/PROTOCOL.agent up to 1.20
	crypto/external/bsd/openssh/dist/addr.h         up to 1.2
	crypto/external/bsd/openssh/dist/auth-options.c up to 1.31
	crypto/external/bsd/openssh/dist/auth-pam.c     up to 1.30
	crypto/external/bsd/openssh/dist/auth.c         up to 1.41
	crypto/external/bsd/openssh/dist/auth.h         up to 1.28
	crypto/external/bsd/openssh/dist/auth2-chall.c  up to 1.23
	crypto/external/bsd/openssh/dist/auth2-gss.c    up to 1.20
	crypto/external/bsd/openssh/dist/auth2-hostbased.c up to 1.28
	crypto/external/bsd/openssh/dist/auth2-pubkey.c up to 1.40
	crypto/external/bsd/openssh/dist/auth2.c        up to 1.37
	crypto/external/bsd/openssh/dist/authfd.c       up to 1.30
	crypto/external/bsd/openssh/dist/authfile.c     up to 1.32
	crypto/external/bsd/openssh/dist/chacha.c       up to 1.7
	crypto/external/bsd/openssh/dist/channels.c     up to 1.50
	crypto/external/bsd/openssh/dist/channels.h     up to 1.33
	crypto/external/bsd/openssh/dist/cipher.c       up to 1.28
	crypto/external/bsd/openssh/dist/cipher.h       up to 1.18
	crypto/external/bsd/openssh/dist/clientloop.c   up to 1.47
	crypto/external/bsd/openssh/dist/clientloop.h   up to 1.21
	crypto/external/bsd/openssh/dist/crypto_api.h   up to 1.10
	crypto/external/bsd/openssh/dist/digest.h       up to 1.4
	crypto/external/bsd/openssh/dist/ed25519-openssl.c up to 1.3
	crypto/external/bsd/openssh/dist/ed25519.c      up to 1.9
	crypto/external/bsd/openssh/dist/ed25519.sh     up to 1.1.1.4
	crypto/external/bsd/openssh/dist/gss-genr.c     up to 1.18
	crypto/external/bsd/openssh/dist/gss-serv.c     up to 1.19
	crypto/external/bsd/openssh/dist/kex-names.c    up to 1.6
	crypto/external/bsd/openssh/dist/kex.c          up to 1.42
	crypto/external/bsd/openssh/dist/kex.h          up to 1.31
	crypto/external/bsd/openssh/dist/kexecdh.c      up to 1.11
	crypto/external/bsd/openssh/dist/kexgen.c       up to 1.12
	crypto/external/bsd/openssh/dist/kexgexc.c      up to 1.20
	crypto/external/bsd/openssh/dist/kexmlkem768x25519.c up to 1.5
	crypto/external/bsd/openssh/dist/mac.c          up to 1.19
	crypto/external/bsd/openssh/dist/match.c        up to 1.18
	crypto/external/bsd/openssh/dist/misc-agent.c   up to 1.4
	crypto/external/bsd/openssh/dist/misc.c         up to 1.43
	crypto/external/bsd/openssh/dist/misc.h         up to 1.34
	crypto/external/bsd/openssh/dist/monitor.c      up to 1.53
	crypto/external/bsd/openssh/dist/monitor_wrap.c up to 1.41
	crypto/external/bsd/openssh/dist/monitor_wrap.h up to 1.28
	crypto/external/bsd/openssh/dist/mux.c          up to 1.41
	crypto/external/bsd/openssh/dist/myproposal.h   up to 1.29
	crypto/external/bsd/openssh/dist/packet.c       up to 1.59
	crypto/external/bsd/openssh/dist/packet.h       up to 1.31
	crypto/external/bsd/openssh/dist/pathnames.h    up to 1.20
	crypto/external/bsd/openssh/dist/readconf.c     up to 1.53
	crypto/external/bsd/openssh/dist/readconf.h     up to 1.39
	crypto/external/bsd/openssh/dist/scp.1          up to 1.34
	crypto/external/bsd/openssh/dist/scp.c          up to 1.47
	crypto/external/bsd/openssh/dist/servconf.c     up to 1.54
	crypto/external/bsd/openssh/dist/servconf.h     up to 1.36
	crypto/external/bsd/openssh/dist/serverloop.c   up to 1.41
	crypto/external/bsd/openssh/dist/session.c      up to 1.47
	crypto/external/bsd/openssh/dist/sftp-client.c  up to 1.41
	crypto/external/bsd/openssh/dist/sftp-client.h  up to 1.21
	crypto/external/bsd/openssh/dist/sftp-server.8  up to 1.16
	crypto/external/bsd/openssh/dist/sftp-server.c  up to 1.34
	crypto/external/bsd/openssh/dist/sftp-usergroup.c up to 1.4
	crypto/external/bsd/openssh/dist/sftp-usergroup.h up to 1.2
	crypto/external/bsd/openssh/dist/sftp.1         up to 1.32
	crypto/external/bsd/openssh/dist/sftp.c         up to 1.46
	crypto/external/bsd/openssh/dist/sk-api.h       up to 1.2
	crypto/external/bsd/openssh/dist/sk-usbhid.c    up to 1.13
	crypto/external/bsd/openssh/dist/srclimit.h     up to 1.2
	crypto/external/bsd/openssh/dist/ssh-add.1      up to 1.24
	crypto/external/bsd/openssh/dist/ssh-add.c      up to 1.36
	crypto/external/bsd/openssh/dist/ssh-agent.1    up to 1.23
	crypto/external/bsd/openssh/dist/ssh-agent.c    up to 1.48
	crypto/external/bsd/openssh/dist/ssh-ed25519-sk.c up to 1.7
	crypto/external/bsd/openssh/dist/ssh-ed25519.c  up to 1.14
	crypto/external/bsd/openssh/dist/ssh-gss.h      up to 1.12
	crypto/external/bsd/openssh/dist/ssh-keygen.1   up to 1.44
	crypto/external/bsd/openssh/dist/ssh-keygen.c   up to 1.53
	crypto/external/bsd/openssh/dist/ssh-keyscan.1  up to 1.21
	crypto/external/bsd/openssh/dist/ssh-keyscan.c  up to 1.39
	crypto/external/bsd/openssh/dist/ssh-keysign.8  up to 1.16
	crypto/external/bsd/openssh/dist/ssh-keysign.c  up to 1.30
	crypto/external/bsd/openssh/dist/ssh-sk.h       up to 1.2
	crypto/external/bsd/openssh/dist/ssh.1          up to 1.45
	crypto/external/bsd/openssh/dist/ssh.c          up to 1.51
	crypto/external/bsd/openssh/dist/ssh_api.c      up to 1.21
	crypto/external/bsd/openssh/dist/ssh_config.5   up to 1.48
	crypto/external/bsd/openssh/dist/sshbuf-io.c    up to 1.3
	crypto/external/bsd/openssh/dist/sshbuf.h       up to 1.24
	crypto/external/bsd/openssh/dist/sshconnect.c   up to 1.44
	crypto/external/bsd/openssh/dist/sshconnect.h   up to 1.21
	crypto/external/bsd/openssh/dist/sshconnect2.c  up to 1.55
	crypto/external/bsd/openssh/dist/sshd-auth.c    up to 1.9
	crypto/external/bsd/openssh/dist/sshd-session.c up to 1.18
	crypto/external/bsd/openssh/dist/sshd.8         up to 1.36
	crypto/external/bsd/openssh/dist/sshd.c         up to 1.59
	crypto/external/bsd/openssh/dist/sshd_config    up to 1.31
	crypto/external/bsd/openssh/dist/sshd_config.5  up to 1.51
	crypto/external/bsd/openssh/dist/ssherr-libcrypto.c up to 1.2
	crypto/external/bsd/openssh/dist/ssherr-nolibcrypto.c up to 1.2
	crypto/external/bsd/openssh/dist/ssherr.c       up to 1.13
	crypto/external/bsd/openssh/dist/ssherr.h       up to 1.7
	crypto/external/bsd/openssh/dist/sshkey.c       up to 1.39
	crypto/external/bsd/openssh/dist/sshkey.h       up to 1.28
	crypto/external/bsd/openssh/dist/sshpty.c       up to 1.10
	crypto/external/bsd/openssh/dist/sshpty.h       up to 1.8
	crypto/external/bsd/openssh/dist/sshsig.h       up to 1.2
	crypto/external/bsd/openssh/dist/version.h      up to 1.55
	crypto/external/bsd/openssh/dist/moduli-gen/moduli.2048 up to 1.23
	crypto/external/bsd/openssh/dist/moduli-gen/moduli.3072 up to 1.25
	crypto/external/bsd/openssh/dist/moduli-gen/moduli.4096 up to 1.25
	crypto/external/bsd/openssh/dist/moduli-gen/moduli.6144 up to 1.25
	crypto/external/bsd/openssh/dist/moduli-gen/moduli.7680 up to 1.25
	crypto/external/bsd/openssh/dist/moduli-gen/moduli.8192 up to 1.25
	crypto/external/bsd/openssh/lib/Makefile        up to 1.55
	crypto/external/bsd/openssh/lib/shlib_version   up to 1.44
	crypto/external/bsd/openssh/libexec/Makefile    up to 1.4
	distrib/sets/lists/base/shl.mi			1.1052
	distrib/sets/lists/debug/shl.mi			1.416
	doc/3RDPARTY					(manually edited)

Import OpenSSH 10.6
@
text
@a0 69
/*	$NetBSD: getexecpath.c,v 1.2 2026/10/07 20:15:03 christos Exp $	*/
/*-
 * Copyright (c) 2026 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <dlfcn.h>
#include <string.h>
#include <errno.h>
#include <elf.h>

#include "getexecpath.h"

int
getexecpath(char *buf, size_t len)
{
	const AuxInfo *aux;

	for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux)
		if (aux->a_type == AT_SUN_EXECNAME) {
			if (strlcpy(buf, (void *)(intptr_t)aux->a_v, len) < len)
				return 0;
			errno = ERANGE;
			return -1;
		}
	errno = ENOENT;
	return -1;
}

#ifdef TEST
#include <stdio.h>
#include <err.h>
#include <stdlib.h>
#include <limits.h>

int
main(void)
{
	char buf[PATH_MAX];
	if (getexecpath(buf, sizeof(buf)) == -1)
		err(EXIT_FAILURE, "Can't get path");
	printf("%s\n", buf);
	return 0;
}
#endif
@


1.1
log
@Merge changes between OpenSSH-10.5 and OpenSSH-10.6
@
text
@d1 1
a1 1
/*	$NetBSD$	*/
d45 4
a48 2
			strlcpy(buf, (void *)(intptr_t)aux->a_v, len);
			return 0;
d58 2
d63 1
a63 1
	char buf[1024];
@

