lddstub.c (7c478bd9) lddstub.c (5aefb655)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
22/*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26#pragma ident "%Z%%M% %I% %E% SMI"
27
28
29#include <unistd.h>
30#include <strings.h>
31#include <limits.h>
32#include <dlfcn.h>
33#include "_conv.h"
34#include "lddstub_msg.h"
35
24 * Use is subject to license terms.
25 */
26#pragma ident "%Z%%M% %I% %E% SMI"
27
28
29#include <unistd.h>
30#include <strings.h>
31#include <limits.h>
32#include <dlfcn.h>
33#include "_conv.h"
34#include "lddstub_msg.h"
35
36static char orgstub[PATH_MAX];
37static char orgstub64[PATH_MAX];
38static int orgflag;
39static int orgflag64;
40
41#ifdef NEED_OWN_STRLCAT
42/*
43 * Appends src to the dstsize buffer at dst. The append will never
44 * overflow the destination buffer and the buffer will always be null
45 * terminated. Never reference beyond &bst[dstsize-1] when computing
46 * the length of the pre-existing string.
47 */
48size_t
49strlcat(char *dst, const char *src, size_t dstsize)
50{
51 char *df = dst;
52 size_t left = dstsize;
53 size_t l1;
54 size_t l2 = strlen(src);
55 size_t copied;
56
57 while (left-- != 0 && *df != '\0')
58 df++;
59 l1 = df - dst;
60 if (dstsize == l1)
61 return (l1 + l2);
62
63 copied = l1 + l2 >= dstsize ? dstsize - l1 - 1 : l2;
64 memcpy(dst + l1, src, copied);
65 dst[l1+copied] = '\0';
66 return (l1 + l2);
67}
68#endif
69
70static int
71originlddstub(char *buffer, const char *orgfile)
72{
73 int len;
74
75 if (dlinfo(RTLD_SELF, RTLD_DI_ORIGIN, (void *)buffer) == -1)
76 return (-1);
77 if (strlcat(buffer, orgfile, PATH_MAX) >= PATH_MAX)
78 return (-1);
79 if ((len = resolvepath(buffer, buffer, (PATH_MAX - 1))) == -1)
80 return (-1);
81 buffer[len] = '\0';
36static int
37originlddstub(char *buffer, const char *orgfile)
38{
39 int len;
40
41 if (dlinfo(RTLD_SELF, RTLD_DI_ORIGIN, (void *)buffer) == -1)
42 return (-1);
43 if (strlcat(buffer, orgfile, PATH_MAX) >= PATH_MAX)
44 return (-1);
45 if ((len = resolvepath(buffer, buffer, (PATH_MAX - 1))) == -1)
46 return (-1);
47 buffer[len] = '\0';
82 if (access(orgstub, X_OK) == -1)
48 if (access(buffer, X_OK) == -1)
83 return (-1);
84
49 return (-1);
50
85 return (0);
51 return (1);
86}
87
52}
53
54static char orgstub[PATH_MAX], orgstub64[PATH_MAX];
55static int orgflag, orgflag64;
56
88/*
89 * Determine what lddstub to run.
90 */
91const char *
92conv_lddstub(int class)
93{
94 const char *stub;
95

--- 32 unchanged lines hidden ---
57/*
58 * Determine what lddstub to run.
59 */
60const char *
61conv_lddstub(int class)
62{
63 const char *stub;
64

--- 32 unchanged lines hidden ---