diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-06 15:22:24 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-04-06 15:23:26 +0200 |
commit | 4f0b540d08f5912b273c427218cc665512b12de5 (patch) | |
tree | 061a0c4a01fccfe31c88e01e5d50616f5e6b96cb | |
parent | 0d6e3ad663adc327597f07fdcabd6ac545864d41 (diff) | |
download | busybox-w32-4f0b540d08f5912b273c427218cc665512b12de5.tar.gz busybox-w32-4f0b540d08f5912b273c427218cc665512b12de5.tar.bz2 busybox-w32-4f0b540d08f5912b273c427218cc665512b12de5.zip |
modprobe: do not descend into /etc/modprobe.d/DIR/. Closes 8686
Also expanded comments in recursive_action.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/recursive_action.c | 46 | ||||
-rw-r--r-- | modutils/modprobe.c | 9 |
2 files changed, 38 insertions, 17 deletions
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index b5cf7c0ab..8f2b8b932 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c | |||
@@ -30,24 +30,37 @@ static int FAST_FUNC true_action(const char *fileName UNUSED_PARAM, | |||
30 | return TRUE; | 30 | return TRUE; |
31 | } | 31 | } |
32 | 32 | ||
33 | /* fileAction return value of 0 on any file in directory will make | 33 | /* fileName is (l)stat'ed (depending on ACTION_FOLLOWLINKS[_L0]). |
34 | * recursive_action() return 0, but it doesn't stop directory traversal | 34 | * |
35 | * If it is a file: fileAction in run on it, its return value is returned. | ||
36 | * | ||
37 | * In case we are in a recursive invocation (see below): | ||
38 | * normally, fileAction should return 1 (TRUE) to indicate that | ||
39 | * everything is okay and processing should continue. | ||
40 | * fileAction return value of 0 (FALSE) on any file in directory will make | ||
41 | * recursive_action() also return 0, but it doesn't stop directory traversal | ||
35 | * (fileAction/dirAction will be called on each file). | 42 | * (fileAction/dirAction will be called on each file). |
36 | * | 43 | * |
37 | * If !ACTION_RECURSE, dirAction is called on the directory and its | 44 | * [TODO: maybe introduce -1 to mean "stop traversal NOW and return"] |
45 | * | ||
46 | * If it is a directory: | ||
47 | * | ||
48 | * If !ACTION_RECURSE, dirAction is called and its | ||
38 | * return value is returned from recursive_action(). No recursion. | 49 | * return value is returned from recursive_action(). No recursion. |
39 | * | 50 | * |
40 | * If ACTION_RECURSE, recursive_action() is called on each directory. | 51 | * If ACTION_RECURSE, directory is opened, and recursive_action() is called |
52 | * on each file/subdirectory. | ||
41 | * If any one of these calls returns 0, current recursive_action() returns 0. | 53 | * If any one of these calls returns 0, current recursive_action() returns 0. |
42 | * | 54 | * |
55 | * If !ACTION_DEPTHFIRST, dirAction is called before recurse. | ||
56 | * Return value of 0 (FALSE) is an error: prevents recursion, | ||
57 | * the warning is printed (unless ACTION_QUIET) and recursive_action() returns 0. | ||
58 | * Return value of 2 (SKIP) prevents recursion, instead recursive_action() | ||
59 | * returns 1 (TRUE, no error). | ||
60 | * | ||
43 | * If ACTION_DEPTHFIRST, dirAction is called after recurse. | 61 | * If ACTION_DEPTHFIRST, dirAction is called after recurse. |
44 | * If it returns 0, the warning is printed and recursive_action() returns 0. | 62 | * If it returns 0, the warning is printed and recursive_action() returns 0. |
45 | * | 63 | * |
46 | * If !ACTION_DEPTHFIRST, dirAction is called before we recurse. | ||
47 | * Return value of 0 (FALSE) or 2 (SKIP) prevents recursion | ||
48 | * into that directory, instead recursive_action() returns 0 (if FALSE) | ||
49 | * or 1 (if SKIP) | ||
50 | * | ||
51 | * ACTION_FOLLOWLINKS mainly controls handling of links to dirs. | 64 | * ACTION_FOLLOWLINKS mainly controls handling of links to dirs. |
52 | * 0: lstat(statbuf). Calls fileAction on link name even if points to dir. | 65 | * 0: lstat(statbuf). Calls fileAction on link name even if points to dir. |
53 | * 1: stat(statbuf). Calls dirAction and optionally recurse on link to dir. | 66 | * 1: stat(statbuf). Calls dirAction and optionally recurse on link to dir. |
@@ -105,7 +118,7 @@ int FAST_FUNC recursive_action(const char *fileName, | |||
105 | 118 | ||
106 | if (!(flags & ACTION_DEPTHFIRST)) { | 119 | if (!(flags & ACTION_DEPTHFIRST)) { |
107 | status = dirAction(fileName, &statbuf, userData, depth); | 120 | status = dirAction(fileName, &statbuf, userData, depth); |
108 | if (!status) | 121 | if (status == FALSE) |
109 | goto done_nak_warn; | 122 | goto done_nak_warn; |
110 | if (status == SKIP) | 123 | if (status == SKIP) |
111 | return TRUE; | 124 | return TRUE; |
@@ -121,24 +134,23 @@ int FAST_FUNC recursive_action(const char *fileName, | |||
121 | status = TRUE; | 134 | status = TRUE; |
122 | while ((next = readdir(dir)) != NULL) { | 135 | while ((next = readdir(dir)) != NULL) { |
123 | char *nextFile; | 136 | char *nextFile; |
137 | int s; | ||
124 | 138 | ||
125 | nextFile = concat_subpath_file(fileName, next->d_name); | 139 | nextFile = concat_subpath_file(fileName, next->d_name); |
126 | if (nextFile == NULL) | 140 | if (nextFile == NULL) |
127 | continue; | 141 | continue; |
142 | |||
128 | /* process every file (NB: ACTION_RECURSE is set in flags) */ | 143 | /* process every file (NB: ACTION_RECURSE is set in flags) */ |
129 | if (!recursive_action(nextFile, flags, fileAction, dirAction, | 144 | s = recursive_action(nextFile, flags, fileAction, dirAction, |
130 | userData, depth + 1)) | 145 | userData, depth + 1); |
146 | if (s == FALSE) | ||
131 | status = FALSE; | 147 | status = FALSE; |
132 | // s = recursive_action(nextFile, flags, fileAction, dirAction, | ||
133 | // userData, depth + 1); | ||
134 | free(nextFile); | 148 | free(nextFile); |
135 | //#define RECURSE_RESULT_ABORT 3 | 149 | //#define RECURSE_RESULT_ABORT -1 |
136 | // if (s == RECURSE_RESULT_ABORT) { | 150 | // if (s == RECURSE_RESULT_ABORT) { |
137 | // closedir(dir); | 151 | // closedir(dir); |
138 | // return s; | 152 | // return s; |
139 | // } | 153 | // } |
140 | // if (s == FALSE) | ||
141 | // status = FALSE; | ||
142 | } | 154 | } |
143 | closedir(dir); | 155 | closedir(dir); |
144 | 156 | ||
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index c82eaa8d8..51ede9204 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
@@ -252,6 +252,15 @@ static int FAST_FUNC config_file_action(const char *filename, | |||
252 | if (base[0] == '.') | 252 | if (base[0] == '.') |
253 | goto error; | 253 | goto error; |
254 | 254 | ||
255 | /* "man modprobe.d" from kmod version 22 suggests | ||
256 | * that we shouldn't recurse into /etc/modprobe.d/dir/ | ||
257 | * _subdirectories_: | ||
258 | */ | ||
259 | if (depth > 1) | ||
260 | return SKIP; /* stop recursing */ | ||
261 | //TODO: instead, can use dirAction in recursive_action() to SKIP dirs | ||
262 | //on depth == 1 level. But that's more code... | ||
263 | |||
255 | /* In dir recursion, skip files that do not end with a ".conf" | 264 | /* In dir recursion, skip files that do not end with a ".conf" |
256 | * depth==0: read_config("modules.{symbols,alias}") must work, | 265 | * depth==0: read_config("modules.{symbols,alias}") must work, |
257 | * "include FILE_NOT_ENDING_IN_CONF" must work too. | 266 | * "include FILE_NOT_ENDING_IN_CONF" must work too. |