|
26 | 26 | #include "shadowlog_internal.h" |
27 | 27 | #include "string/sprintf/aprintf.h" |
28 | 28 | #include "string/strcmp/streq.h" |
| 29 | +#include "string/strcmp/strprefix.h" |
29 | 30 | #include "string/strerrno.h" |
30 | 31 |
|
31 | 32 |
|
@@ -257,38 +258,32 @@ static shadowtcb_status unlink_suffs (const char *user) |
257 | 258 | static shadowtcb_status |
258 | 259 | rmdir_leading(const char *relpath) |
259 | 260 | { |
260 | | - char *ind, *dir, *path; |
| 261 | + char *ind, *path, *p; |
261 | 262 | shadowtcb_status ret = SHADOWTCB_SUCCESS; |
262 | 263 |
|
263 | | - path = strdup(relpath); |
| 264 | + path = aprintf(TCB_DIR "/%s", relpath); |
264 | 265 | if (path == NULL) |
265 | 266 | goto oom; |
266 | 267 |
|
| 268 | + p = strprefix(path, TCB_DIR "/"); |
267 | 269 |
|
268 | | - while ((ind = strrchr (path, '/'))) { |
| 270 | + while ((ind = strrchr(p, '/'))) { |
269 | 271 | stpcpy(ind, ""); |
270 | | - dir = aprintf(TCB_DIR "/%s", path); |
271 | | - if (dir == NULL) |
272 | | - goto free_path; |
273 | 272 |
|
274 | | - if (rmdir (dir) != 0) { |
| 273 | + if (rmdir(path) != 0) { |
275 | 274 | if (errno != ENOTEMPTY) { |
276 | 275 | fprintf (shadow_logfd, |
277 | 276 | _("%s: Cannot remove directory %s: %s\n"), |
278 | | - shadow_progname, dir, strerrno()); |
| 277 | + shadow_progname, path, strerrno()); |
279 | 278 | ret = SHADOWTCB_FAILURE; |
280 | 279 | } |
281 | | - free (dir); |
282 | 280 | break; |
283 | 281 | } |
284 | | - free (dir); |
285 | 282 | } |
286 | 283 |
|
287 | 284 | free(path); |
288 | 285 | return ret; |
289 | 286 |
|
290 | | -free_path: |
291 | | - free(path); |
292 | 287 | oom: |
293 | 288 | OUT_OF_MEMORY; |
294 | 289 | return SHADOWTCB_FAILURE; |
|
0 commit comments