| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: walk.c,v 1.34 2024/04/23 22:12:16 christos Exp $ */ | | 1 | /* $NetBSD: walk.c,v 1.35 2024/04/23 22:12:48 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2001 Wasabi Systems, Inc. | | 4 | * Copyright (c) 2001 Wasabi Systems, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Written by Luke Mewburn for Wasabi Systems, Inc. | | 7 | * Written by Luke Mewburn for Wasabi Systems, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -31,27 +31,27 @@ | | | @@ -31,27 +31,27 @@ |
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | * POSSIBILITY OF SUCH DAMAGE. | | 35 | * POSSIBILITY OF SUCH DAMAGE. |
36 | */ | | 36 | */ |
37 | | | 37 | |
38 | #if HAVE_NBTOOL_CONFIG_H | | 38 | #if HAVE_NBTOOL_CONFIG_H |
39 | #include "nbtool_config.h" | | 39 | #include "nbtool_config.h" |
40 | #endif | | 40 | #endif |
41 | | | 41 | |
42 | #include <sys/cdefs.h> | | 42 | #include <sys/cdefs.h> |
43 | #if defined(__RCSID) && !defined(__lint) | | 43 | #if defined(__RCSID) && !defined(__lint) |
44 | __RCSID("$NetBSD: walk.c,v 1.34 2024/04/23 22:12:16 christos Exp $"); | | 44 | __RCSID("$NetBSD: walk.c,v 1.35 2024/04/23 22:12:48 christos Exp $"); |
45 | #endif /* !__lint */ | | 45 | #endif /* !__lint */ |
46 | | | 46 | |
47 | #include <sys/param.h> | | 47 | #include <sys/param.h> |
48 | #include <sys/stat.h> | | 48 | #include <sys/stat.h> |
49 | | | 49 | |
50 | #include <assert.h> | | 50 | #include <assert.h> |
51 | #include <errno.h> | | 51 | #include <errno.h> |
52 | #include <fcntl.h> | | 52 | #include <fcntl.h> |
53 | #include <stdio.h> | | 53 | #include <stdio.h> |
54 | #include <dirent.h> | | 54 | #include <dirent.h> |
55 | #include <stdlib.h> | | 55 | #include <stdlib.h> |
56 | #include <string.h> | | 56 | #include <string.h> |
57 | #include <unistd.h> | | 57 | #include <unistd.h> |
| @@ -144,26 +144,35 @@ walk_dir(const char *root, const char *d | | | @@ -144,26 +144,35 @@ walk_dir(const char *root, const char *d |
144 | dot = 0; | | 144 | dot = 0; |
145 | } | | 145 | } |
146 | if (debug & DEBUG_WALK_DIR_NODE) | | 146 | if (debug & DEBUG_WALK_DIR_NODE) |
147 | printf("scanning %s/%s/%s\n", root, dir, name); | | 147 | printf("scanning %s/%s/%s\n", root, dir, name); |
148 | if (snprintf(path + len, sizeof(path) - len, "/%s", name) >= | | 148 | if (snprintf(path + len, sizeof(path) - len, "/%s", name) >= |
149 | (int)sizeof(path) - len) | | 149 | (int)sizeof(path) - len) |
150 | errx(EXIT_FAILURE, "Pathname too long."); | | 150 | errx(EXIT_FAILURE, "Pathname too long."); |
151 | if (follow) { | | 151 | if (follow) { |
152 | if (stat(path, &stbuf) == -1) | | 152 | if (stat(path, &stbuf) == -1) |
153 | err(EXIT_FAILURE, "Can't stat `%s'", path); | | 153 | err(EXIT_FAILURE, "Can't stat `%s'", path); |
154 | } else { | | 154 | } else { |
155 | if (lstat(path, &stbuf) == -1) | | 155 | if (lstat(path, &stbuf) == -1) |
156 | err(EXIT_FAILURE, "Can't lstat `%s'", path); | | 156 | err(EXIT_FAILURE, "Can't lstat `%s'", path); |
| | | 157 | /* As symlink permission bits vary between filesystems |
| | | 158 | (ie. 0755 on FFS/NetBSD, 0777 for ext[234]/Linux), |
| | | 159 | force them to 0755. */ |
| | | 160 | if (S_ISLNK(stbuf.st_mode)) { |
| | | 161 | stbuf.st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); |
| | | 162 | stbuf.st_mode |= S_IRWXU |
| | | 163 | | S_IRGRP | S_IXGRP |
| | | 164 | | S_IROTH | S_IXOTH; |
| | | 165 | } |
157 | } | | 166 | } |
158 | #ifdef S_ISSOCK | | 167 | #ifdef S_ISSOCK |
159 | if (S_ISSOCK(stbuf.st_mode & S_IFMT)) { | | 168 | if (S_ISSOCK(stbuf.st_mode & S_IFMT)) { |
160 | if (debug & DEBUG_WALK_DIR_NODE) | | 169 | if (debug & DEBUG_WALK_DIR_NODE) |
161 | printf(" skipping socket %s\n", path); | | 170 | printf(" skipping socket %s\n", path); |
162 | continue; | | 171 | continue; |
163 | } | | 172 | } |
164 | #endif | | 173 | #endif |
165 | | | 174 | |
166 | if (join != NULL) { | | 175 | if (join != NULL) { |
167 | cur = join->next; | | 176 | cur = join->next; |
168 | for (;;) { | | 177 | for (;;) { |
169 | if (cur == NULL || strcmp(cur->name, name) == 0) | | 178 | if (cur == NULL || strcmp(cur->name, name) == 0) |