[228] | 1 | /*-
|
---|
| 2 | * Copyright (c) 1990, 1993, 1994
|
---|
| 3 | * The Regents of the University of California. All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | * 1. Redistributions of source code must retain the above copyright
|
---|
| 9 | * notice, this list of conditions and the following disclaimer.
|
---|
| 10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 12 | * documentation and/or other materials provided with the distribution.
|
---|
| 13 | * 4. Neither the name of the University nor the names of its contributors
|
---|
| 14 | * may be used to endorse or promote products derived from this software
|
---|
| 15 | * without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 27 | * SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | #if 0
|
---|
| 31 | #ifndef lint
|
---|
| 32 | static const char copyright[] =
|
---|
| 33 | "@(#) Copyright (c) 1990, 1993, 1994\n\
|
---|
| 34 | The Regents of the University of California. All rights reserved.\n";
|
---|
| 35 | #endif /* not lint */
|
---|
| 36 |
|
---|
| 37 | #ifndef lint
|
---|
| 38 | static char sccsid[] = "@(#)rm.c 8.5 (Berkeley) 4/18/94";
|
---|
| 39 | #endif /* not lint */
|
---|
| 40 | #include <sys/cdefs.h>
|
---|
[2466] | 41 | /*__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.47 2004/04/06 20:06:50 markm Exp $");*/
|
---|
[370] | 42 | #endif
|
---|
[228] | 43 |
|
---|
[3192] | 44 |
|
---|
| 45 | /*********************************************************************************************************************************
|
---|
| 46 | * Header Files *
|
---|
| 47 | *********************************************************************************************************************************/
|
---|
[3216] | 48 | #define FAKES_NO_GETOPT_H /* bird */
|
---|
[2113] | 49 | #include "config.h"
|
---|
[228] | 50 | #include <sys/stat.h>
|
---|
[2546] | 51 | #if !defined(_MSC_VER) && !defined(__HAIKU__)
|
---|
[809] | 52 | # include <sys/param.h>
|
---|
[3109] | 53 | # ifndef __gnu_hurd__
|
---|
| 54 | # include <sys/mount.h>
|
---|
| 55 | # endif
|
---|
[375] | 56 | #endif
|
---|
[228] | 57 |
|
---|
[370] | 58 | #include "err.h"
|
---|
[228] | 59 | #include <errno.h>
|
---|
| 60 | #include <fcntl.h>
|
---|
[3148] | 61 | #include "fts.h"
|
---|
[228] | 62 | #include <grp.h>
|
---|
| 63 | #include <pwd.h>
|
---|
| 64 | #include <stdio.h>
|
---|
| 65 | #include <stdlib.h>
|
---|
| 66 | #include <string.h>
|
---|
[2546] | 67 | #ifndef __HAIKU__
|
---|
| 68 | # include <sysexits.h>
|
---|
| 69 | #endif
|
---|
[228] | 70 | #include <unistd.h>
|
---|
[1553] | 71 | #include <ctype.h>
|
---|
[3216] | 72 | #include "getopt_r.h"
|
---|
[2546] | 73 | #ifdef __HAIKU__
|
---|
| 74 | # include "haikufakes.h"
|
---|
| 75 | #endif
|
---|
[3062] | 76 | #ifdef __NetBSD__
|
---|
| 77 | # include <util.h>
|
---|
| 78 | # define fflagstostr(flags) flags_to_string(flags, "")
|
---|
| 79 | #endif
|
---|
[2713] | 80 | #ifdef KBUILD_OS_WINDOWS
|
---|
| 81 | # ifdef _MSC_VER
|
---|
| 82 | # include "mscfakes.h"
|
---|
| 83 | # endif
|
---|
| 84 | # include "nt/ntunlink.h"
|
---|
| 85 | /* Use the special unlink implementation to do rmdir too. */
|
---|
| 86 | # undef rmdir
|
---|
| 87 | # define rmdir(a_pszPath) birdUnlinkForced(a_pszPath)
|
---|
[809] | 88 | #endif
|
---|
[1578] | 89 | #if defined(__OS2__) || defined(_MSC_VER)
|
---|
| 90 | # include <direct.h>
|
---|
| 91 | # include <limits.h>
|
---|
[1598] | 92 | #endif
|
---|
[1183] | 93 | #include "kmkbuiltin.h"
|
---|
[1598] | 94 | #include "kbuild_protection.h"
|
---|
[3101] | 95 | #include "k/kDefs.h" /* for K_OS */
|
---|
[1183] | 96 |
|
---|
[3192] | 97 |
|
---|
| 98 | /*********************************************************************************************************************************
|
---|
| 99 | * Defined Constants And Macros *
|
---|
| 100 | *********************************************************************************************************************************/
|
---|
[2713] | 101 | #if defined(__EMX__) || defined(KBUILD_OS_WINDOWS)
|
---|
[1550] | 102 | # define IS_SLASH(ch) ( (ch) == '/' || (ch) == '\\' )
|
---|
| 103 | # define HAVE_DOS_PATHS 1
|
---|
[1551] | 104 | # define DEFAULT_PROTECTION_DEPTH 1
|
---|
[1550] | 105 | #else
|
---|
| 106 | # define IS_SLASH(ch) ( (ch) == '/' )
|
---|
| 107 | # undef HAVE_DOS_PATHS
|
---|
[1551] | 108 | # define DEFAULT_PROTECTION_DEPTH 2
|
---|
[1550] | 109 | #endif
|
---|
[1183] | 110 |
|
---|
[269] | 111 | #ifdef __EMX__
|
---|
| 112 | #undef S_IFWHT
|
---|
[341] | 113 | #undef S_ISWHT
|
---|
[269] | 114 | #endif
|
---|
[228] | 115 | #ifndef S_IFWHT
|
---|
| 116 | #define S_IFWHT 0
|
---|
| 117 | #define S_ISWHT(s) 0
|
---|
| 118 | #define undelete(s) (-1)
|
---|
| 119 | #endif
|
---|
| 120 |
|
---|
[3192] | 121 | #if 1
|
---|
| 122 | #define CUR_LINE_H2(x) "[line " #x "]"
|
---|
| 123 | #define CUR_LINE_H1(x) CUR_LINE_H2(x)
|
---|
| 124 | #define CUR_LINE() CUR_LINE_H1(__LINE__)
|
---|
| 125 | #else
|
---|
| 126 | # define CUR_LINE()
|
---|
| 127 | #endif
|
---|
[228] | 128 |
|
---|
[3192] | 129 |
|
---|
| 130 | /*********************************************************************************************************************************
|
---|
| 131 | * Structures and Typedefs *
|
---|
| 132 | *********************************************************************************************************************************/
|
---|
| 133 | typedef struct RMINSTANCE
|
---|
| 134 | {
|
---|
| 135 | PKMKBUILTINCTX pCtx;
|
---|
| 136 | int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
|
---|
[2713] | 137 | #ifdef KBUILD_OS_WINDOWS
|
---|
[3192] | 138 | int fUseNtDeleteFile;
|
---|
[2713] | 139 | #endif
|
---|
[3192] | 140 | uid_t uid;
|
---|
| 141 | KBUILDPROTECTION g_ProtData;
|
---|
| 142 | } RMINSTANCE;
|
---|
| 143 | typedef RMINSTANCE *PRMINSTANCE;
|
---|
[228] | 144 |
|
---|
| 145 |
|
---|
[3192] | 146 | /*********************************************************************************************************************************
|
---|
| 147 | * Global Variables *
|
---|
| 148 | *********************************************************************************************************************************/
|
---|
[1183] | 149 | static struct option long_options[] =
|
---|
| 150 | {
|
---|
| 151 | { "help", no_argument, 0, 261 },
|
---|
| 152 | { "version", no_argument, 0, 262 },
|
---|
[1550] | 153 | { "disable-protection", no_argument, 0, 263 },
|
---|
[1551] | 154 | { "enable-protection", no_argument, 0, 264 },
|
---|
| 155 | { "enable-full-protection", no_argument, 0, 265 },
|
---|
| 156 | { "disable-full-protection", no_argument, 0, 266 },
|
---|
| 157 | { "protection-depth", required_argument, 0, 267 },
|
---|
[2713] | 158 | #ifdef KBUILD_OS_WINDOWS
|
---|
| 159 | { "nt-delete-file", no_argument, 0, 268 },
|
---|
| 160 | #endif
|
---|
[1183] | 161 | { 0, 0, 0, 0 },
|
---|
| 162 | };
|
---|
| 163 |
|
---|
| 164 |
|
---|
[3192] | 165 | /*********************************************************************************************************************************
|
---|
| 166 | * Internal Functions *
|
---|
| 167 | *********************************************************************************************************************************/
|
---|
| 168 | extern void bsd_strmode(mode_t mode, char *p); /* strmode.c */
|
---|
[228] | 169 |
|
---|
[3192] | 170 | static int check(PRMINSTANCE, char *, char *, struct stat *);
|
---|
| 171 | static void checkdot(PRMINSTANCE, char **);
|
---|
| 172 | static int rm_file(PRMINSTANCE, char **);
|
---|
| 173 | static int rm_overwrite(PRMINSTANCE, char *, struct stat *);
|
---|
| 174 | static int rm_tree(PRMINSTANCE, char **);
|
---|
| 175 | static int usage(PKMKBUILTINCTX, int);
|
---|
[1183] | 176 |
|
---|
| 177 |
|
---|
[3192] | 178 |
|
---|
[228] | 179 | /*
|
---|
| 180 | * rm --
|
---|
| 181 | * This rm is different from historic rm's, but is expected to match
|
---|
| 182 | * POSIX 1003.2 behavior. The most visible difference is that -f
|
---|
| 183 | * has two specific effects now, ignore non-existent files and force
|
---|
| 184 | * file removal.
|
---|
| 185 | */
|
---|
| 186 | int
|
---|
[3192] | 187 | kmk_builtin_rm(int argc, char *argv[], char **envp, PKMKBUILTINCTX pCtx)
|
---|
[228] | 188 | {
|
---|
[3192] | 189 | RMINSTANCE This;
|
---|
[3216] | 190 | struct getopt_state_r gos;
|
---|
[228] | 191 | int ch, rflag;
|
---|
| 192 |
|
---|
[3192] | 193 | /* Init global instance data */
|
---|
| 194 | This.pCtx = pCtx;
|
---|
| 195 | This.dflag = 0;
|
---|
| 196 | This.eval = 0;
|
---|
| 197 | This.fflag = 0;
|
---|
| 198 | This.iflag = 0;
|
---|
| 199 | This.Pflag = 0;
|
---|
| 200 | This.vflag = 0;
|
---|
| 201 | This.Wflag = 0;
|
---|
| 202 | This.stdin_ok = 0;
|
---|
[2713] | 203 | #ifdef KBUILD_OS_WINDOWS
|
---|
[3192] | 204 | This.fUseNtDeleteFile = 0;
|
---|
[2713] | 205 | #endif
|
---|
[3192] | 206 | This.uid = 0;
|
---|
| 207 | kBuildProtectionInit(&This.g_ProtData, pCtx);
|
---|
[375] | 208 |
|
---|
[3192] | 209 | rflag = 0;
|
---|
[3216] | 210 | getopt_initialize_r(&gos, argc, argv, "dfiPRvW", long_options, envp, pCtx);
|
---|
| 211 | while ((ch = getopt_long_r(&gos, NULL)) != -1)
|
---|
[3192] | 212 | switch (ch) {
|
---|
[228] | 213 | case 'd':
|
---|
[3192] | 214 | This.dflag = 1;
|
---|
[228] | 215 | break;
|
---|
| 216 | case 'f':
|
---|
[3192] | 217 | This.fflag = 1;
|
---|
| 218 | This.iflag = 0;
|
---|
[228] | 219 | break;
|
---|
| 220 | case 'i':
|
---|
[3192] | 221 | This.fflag = 0;
|
---|
| 222 | This.iflag = 1;
|
---|
[228] | 223 | break;
|
---|
| 224 | case 'P':
|
---|
[3192] | 225 | This.Pflag = 1;
|
---|
[228] | 226 | break;
|
---|
| 227 | case 'R':
|
---|
[1550] | 228 | #if 0
|
---|
[228] | 229 | case 'r': /* Compatibility. */
|
---|
[1551] | 230 | #endif
|
---|
[228] | 231 | rflag = 1;
|
---|
| 232 | break;
|
---|
| 233 | case 'v':
|
---|
[3192] | 234 | This.vflag = 1;
|
---|
[228] | 235 | break;
|
---|
[269] | 236 | #ifdef FTS_WHITEOUT
|
---|
[228] | 237 | case 'W':
|
---|
[3192] | 238 | This.Wflag = 1;
|
---|
[228] | 239 | break;
|
---|
[269] | 240 | #endif
|
---|
[1183] | 241 | case 261:
|
---|
[3192] | 242 | kBuildProtectionTerm(&This.g_ProtData);
|
---|
| 243 | usage(pCtx, 0);
|
---|
[1183] | 244 | return 0;
|
---|
| 245 | case 262:
|
---|
[3192] | 246 | kBuildProtectionTerm(&This.g_ProtData);
|
---|
[1183] | 247 | return kbuild_version(argv[0]);
|
---|
[1550] | 248 | case 263:
|
---|
[3192] | 249 | kBuildProtectionDisable(&This.g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE);
|
---|
[1550] | 250 | break;
|
---|
[1551] | 251 | case 264:
|
---|
[3192] | 252 | kBuildProtectionEnable(&This.g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE);
|
---|
[1551] | 253 | break;
|
---|
| 254 | case 265:
|
---|
[3192] | 255 | kBuildProtectionEnable(&This.g_ProtData, KBUILDPROTECTIONTYPE_FULL);
|
---|
[1551] | 256 | break;
|
---|
| 257 | case 266:
|
---|
[3192] | 258 | kBuildProtectionDisable(&This.g_ProtData, KBUILDPROTECTIONTYPE_FULL);
|
---|
[1551] | 259 | break;
|
---|
| 260 | case 267:
|
---|
[3216] | 261 | if (kBuildProtectionSetDepth(&This.g_ProtData, gos.optarg)) {
|
---|
[3192] | 262 | kBuildProtectionTerm(&This.g_ProtData);
|
---|
[1598] | 263 | return 1;
|
---|
| 264 | }
|
---|
[1551] | 265 | break;
|
---|
[2713] | 266 | #ifdef KBUILD_OS_WINDOWS
|
---|
| 267 | case 268:
|
---|
[3192] | 268 | This.fUseNtDeleteFile = 1;
|
---|
[2713] | 269 | break;
|
---|
| 270 | #endif
|
---|
[1183] | 271 | case '?':
|
---|
[228] | 272 | default:
|
---|
[3192] | 273 | kBuildProtectionTerm(&This.g_ProtData);
|
---|
| 274 | return usage(pCtx, 1);
|
---|
[228] | 275 | }
|
---|
[3216] | 276 | argc -= gos.optind;
|
---|
| 277 | argv += gos.optind;
|
---|
[228] | 278 |
|
---|
| 279 | if (argc < 1) {
|
---|
[3192] | 280 | kBuildProtectionTerm(&This.g_ProtData);
|
---|
| 281 | if (This.fflag)
|
---|
[228] | 282 | return (0);
|
---|
[3192] | 283 | return usage(pCtx, 1);
|
---|
[228] | 284 | }
|
---|
| 285 |
|
---|
[3192] | 286 | if (!kBuildProtectionScanEnv(&This.g_ProtData, envp, "KMK_RM_")) {
|
---|
| 287 | checkdot(&This, argv);
|
---|
| 288 | This.uid = geteuid();
|
---|
[1598] | 289 |
|
---|
| 290 | if (*argv) {
|
---|
[3192] | 291 | This.stdin_ok = isatty(STDIN_FILENO);
|
---|
[1598] | 292 | if (rflag)
|
---|
[3192] | 293 | This.eval |= rm_tree(&This, argv);
|
---|
[1598] | 294 | else
|
---|
[3192] | 295 | This.eval |= rm_file(&This, argv);
|
---|
[1551] | 296 | }
|
---|
| 297 | } else {
|
---|
[3192] | 298 | This.eval = 1;
|
---|
[228] | 299 | }
|
---|
| 300 |
|
---|
[3192] | 301 | kBuildProtectionTerm(&This.g_ProtData);
|
---|
| 302 | return This.eval;
|
---|
[228] | 303 | }
|
---|
| 304 |
|
---|
[3192] | 305 | #ifdef KMK_BUILTIN_STANDALONE
|
---|
| 306 | int main(int argc, char **argv, char **envp)
|
---|
| 307 | {
|
---|
| 308 | KMKBUILTINCTX Ctx = { "kmk_rm", NULL };
|
---|
| 309 | return kmk_builtin_rm(argc, argv, envp, &Ctx);
|
---|
| 310 | }
|
---|
| 311 | #endif
|
---|
| 312 |
|
---|
[1550] | 313 | static int
|
---|
[3192] | 314 | rm_tree(PRMINSTANCE pThis, char **argv)
|
---|
[228] | 315 | {
|
---|
| 316 | FTS *fts;
|
---|
| 317 | FTSENT *p;
|
---|
| 318 | int needstat;
|
---|
| 319 | int flags;
|
---|
| 320 | int rval;
|
---|
| 321 |
|
---|
| 322 | /*
|
---|
[1551] | 323 | * Check up front before anything is deleted. This will not catch
|
---|
[1550] | 324 | * everything, but we'll check the individual items later.
|
---|
| 325 | */
|
---|
[1598] | 326 | int i;
|
---|
| 327 | for (i = 0; argv[i]; i++) {
|
---|
[3192] | 328 | if (kBuildProtectionEnforce(&pThis->g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE, argv[i])) {
|
---|
[1598] | 329 | return 1;
|
---|
[1550] | 330 | }
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | /*
|
---|
[228] | 334 | * Remove a file hierarchy. If forcing removal (-f), or interactive
|
---|
| 335 | * (-i) or can't ask anyway (stdin_ok), don't stat the file.
|
---|
| 336 | */
|
---|
[3192] | 337 | needstat = !pThis->uid || (!pThis->fflag && !pThis->iflag && pThis->stdin_ok);
|
---|
[228] | 338 |
|
---|
| 339 | /*
|
---|
| 340 | * If the -i option is specified, the user can skip on the pre-order
|
---|
| 341 | * visit. The fts_number field flags skipped directories.
|
---|
| 342 | */
|
---|
| 343 | #define SKIPPED 1
|
---|
| 344 |
|
---|
| 345 | flags = FTS_PHYSICAL;
|
---|
[3216] | 346 | #ifndef KMK_BUILTIN_STANDALONE
|
---|
| 347 | flags |= FTS_NOCHDIR; /* Must not change the directory from inside kmk! */
|
---|
| 348 | #endif
|
---|
[228] | 349 | if (!needstat)
|
---|
| 350 | flags |= FTS_NOSTAT;
|
---|
[269] | 351 | #ifdef FTS_WHITEOUT
|
---|
[3192] | 352 | if (pThis->Wflag)
|
---|
[228] | 353 | flags |= FTS_WHITEOUT;
|
---|
[269] | 354 | #endif
|
---|
[370] | 355 | if (!(fts = fts_open(argv, flags, NULL))) {
|
---|
[3192] | 356 | return err(pThis->pCtx, 1, "fts_open");
|
---|
[370] | 357 | }
|
---|
[228] | 358 | while ((p = fts_read(fts)) != NULL) {
|
---|
[2466] | 359 | const char *operation = "chflags";
|
---|
[228] | 360 | switch (p->fts_info) {
|
---|
| 361 | case FTS_DNR:
|
---|
[3192] | 362 | if (!pThis->fflag || p->fts_errno != ENOENT)
|
---|
| 363 | pThis->eval = errx(pThis->pCtx, 1, "fts: %s: %s" CUR_LINE() "\n",
|
---|
| 364 | p->fts_path, strerror(p->fts_errno));
|
---|
[228] | 365 | continue;
|
---|
| 366 | case FTS_ERR:
|
---|
[1550] | 367 | fts_close(fts);
|
---|
[3192] | 368 | return errx(pThis->pCtx, 1, "fts: %s: %s " CUR_LINE(), p->fts_path, strerror(p->fts_errno));
|
---|
[228] | 369 | case FTS_NS:
|
---|
| 370 | /*
|
---|
| 371 | * Assume that since fts_read() couldn't stat the
|
---|
| 372 | * file, it can't be unlinked.
|
---|
| 373 | */
|
---|
| 374 | if (!needstat)
|
---|
| 375 | break;
|
---|
[3192] | 376 | if (!pThis->fflag || p->fts_errno != ENOENT)
|
---|
| 377 | pThis->eval = errx(pThis->pCtx, 1, "fts: %s: %s " CUR_LINE() "\n",
|
---|
| 378 | p->fts_path, strerror(p->fts_errno));
|
---|
[228] | 379 | continue;
|
---|
| 380 | case FTS_D:
|
---|
| 381 | /* Pre-order: give user chance to skip. */
|
---|
[3192] | 382 | if (!pThis->fflag && !check(pThis, p->fts_path, p->fts_accpath, p->fts_statp)) {
|
---|
[228] | 383 | (void)fts_set(fts, p, FTS_SKIP);
|
---|
| 384 | p->fts_number = SKIPPED;
|
---|
| 385 | }
|
---|
[3102] | 386 | #ifdef UF_APPEND
|
---|
[3192] | 387 | else if (!pThis->uid &&
|
---|
[228] | 388 | (p->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
|
---|
| 389 | !(p->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
|
---|
| 390 | chflags(p->fts_accpath,
|
---|
| 391 | p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)) < 0)
|
---|
| 392 | goto err;
|
---|
| 393 | #endif
|
---|
| 394 | continue;
|
---|
| 395 | case FTS_DP:
|
---|
| 396 | /* Post-order: see if user skipped. */
|
---|
| 397 | if (p->fts_number == SKIPPED)
|
---|
| 398 | continue;
|
---|
| 399 | break;
|
---|
| 400 | default:
|
---|
[3192] | 401 | if (!pThis->fflag && !check(pThis, p->fts_path, p->fts_accpath, p->fts_statp))
|
---|
[228] | 402 | continue;
|
---|
| 403 | }
|
---|
| 404 |
|
---|
[1551] | 405 | /*
|
---|
[1550] | 406 | * Protect against deleting root files and directories.
|
---|
| 407 | */
|
---|
[3192] | 408 | if (kBuildProtectionEnforce(&pThis->g_ProtData, KBUILDPROTECTIONTYPE_RECURSIVE, p->fts_accpath)) {
|
---|
[1550] | 409 | fts_close(fts);
|
---|
[1598] | 410 | return 1;
|
---|
[1550] | 411 | }
|
---|
| 412 |
|
---|
[228] | 413 | rval = 0;
|
---|
| 414 | #ifdef UF_APPEND
|
---|
[3192] | 415 | if (!pThis->uid &&
|
---|
[228] | 416 | (p->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
|
---|
| 417 | !(p->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)))
|
---|
| 418 | rval = chflags(p->fts_accpath,
|
---|
| 419 | p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
|
---|
| 420 | #endif
|
---|
| 421 | if (rval == 0) {
|
---|
| 422 | /*
|
---|
| 423 | * If we can't read or search the directory, may still be
|
---|
| 424 | * able to remove it. Don't print out the un{read,search}able
|
---|
| 425 | * message unless the remove fails.
|
---|
| 426 | */
|
---|
| 427 | switch (p->fts_info) {
|
---|
| 428 | case FTS_DP:
|
---|
| 429 | case FTS_DNR:
|
---|
[2995] | 430 | #ifdef KBUILD_OS_WINDOWS
|
---|
| 431 | if (p->fts_parent->fts_dirfd != NT_FTS_INVALID_HANDLE_VALUE) {
|
---|
| 432 | rval = birdUnlinkForcedEx(p->fts_parent->fts_dirfd, p->fts_name);
|
---|
| 433 | } else {
|
---|
| 434 | rval = birdUnlinkForced(p->fts_accpath);
|
---|
| 435 | }
|
---|
| 436 | #else
|
---|
[228] | 437 | rval = rmdir(p->fts_accpath);
|
---|
[2995] | 438 | #endif
|
---|
[3192] | 439 | if (rval == 0 || (pThis->fflag && errno == ENOENT)) {
|
---|
| 440 | if (rval == 0 && pThis->vflag)
|
---|
| 441 | kmk_builtin_ctx_printf(pThis->pCtx, 0, "%s\n", p->fts_path);
|
---|
[2912] | 442 | #if defined(KMK) && defined(KBUILD_OS_WINDOWS)
|
---|
| 443 | if (rval == 0) {
|
---|
| 444 | extern int dir_cache_deleted_directory(const char *pszDir);
|
---|
| 445 | dir_cache_deleted_directory(p->fts_accpath);
|
---|
| 446 | }
|
---|
| 447 | #endif
|
---|
[228] | 448 | continue;
|
---|
| 449 | }
|
---|
[2912] | 450 | operation = "rmdir";
|
---|
[228] | 451 | break;
|
---|
| 452 |
|
---|
[269] | 453 | #ifdef FTS_W
|
---|
[228] | 454 | case FTS_W:
|
---|
| 455 | rval = undelete(p->fts_accpath);
|
---|
[3192] | 456 | if (rval == 0 && (pThis->fflag && errno == ENOENT)) {
|
---|
[3228] | 457 | if (pThis->vflag)
|
---|
[3192] | 458 | kmk_builtin_ctx_printf(pThis->pCtx, 0, "%s\n", p->fts_path);
|
---|
[228] | 459 | continue;
|
---|
| 460 | }
|
---|
[2466] | 461 | operation = "undelete";
|
---|
[228] | 462 | break;
|
---|
[269] | 463 | #endif
|
---|
[228] | 464 |
|
---|
| 465 | case FTS_NS:
|
---|
| 466 | /*
|
---|
| 467 | * Assume that since fts_read() couldn't stat
|
---|
| 468 | * the file, it can't be unlinked.
|
---|
| 469 | */
|
---|
[3192] | 470 | if (pThis->fflag)
|
---|
[228] | 471 | continue;
|
---|
| 472 | /* FALLTHROUGH */
|
---|
| 473 | default:
|
---|
[3192] | 474 | if (pThis->Pflag)
|
---|
| 475 | if (!rm_overwrite(pThis, p->fts_accpath, NULL))
|
---|
[228] | 476 | continue;
|
---|
[2713] | 477 | #ifdef KBUILD_OS_WINDOWS
|
---|
[2995] | 478 | if (p->fts_parent->fts_dirfd != NT_FTS_INVALID_HANDLE_VALUE) {
|
---|
[3350] | 479 | if (p->fts_info != FTS_SL && p->fts_info != FTS_SLNONE) {
|
---|
| 480 | rval = birdUnlinkForcedFastEx(p->fts_parent->fts_dirfd, p->fts_name);
|
---|
| 481 | } else { /* NtDeleteFile doesn't work on directory links, so slow symlink deletion: */
|
---|
| 482 | rval = birdUnlinkForcedEx(p->fts_parent->fts_dirfd, p->fts_name);
|
---|
| 483 | }
|
---|
[2995] | 484 | } else {
|
---|
[3350] | 485 | if (p->fts_info != FTS_SL && p->fts_info != FTS_SLNONE) {
|
---|
| 486 | rval = birdUnlinkForcedFast(p->fts_accpath);
|
---|
| 487 | } else { /* NtDeleteFile doesn't work on directory links, so slow symlink deletion: */
|
---|
| 488 | rval = birdUnlinkForced(p->fts_accpath);
|
---|
| 489 | }
|
---|
[2995] | 490 | }
|
---|
[2713] | 491 | #else
|
---|
[228] | 492 | rval = unlink(p->fts_accpath);
|
---|
[375] | 493 | #endif
|
---|
[370] | 494 |
|
---|
[3192] | 495 | if (rval == 0 || (pThis->fflag && errno == ENOENT)) {
|
---|
| 496 | if (rval == 0 && pThis->vflag)
|
---|
| 497 | kmk_builtin_ctx_printf(pThis->pCtx, 0, "%s\n", p->fts_path);
|
---|
[228] | 498 | continue;
|
---|
| 499 | }
|
---|
[2466] | 500 | operation = "unlink";
|
---|
| 501 | break;
|
---|
[228] | 502 | }
|
---|
| 503 | }
|
---|
[1553] | 504 | #ifdef UF_APPEND
|
---|
[228] | 505 | err:
|
---|
[1553] | 506 | #endif
|
---|
[3192] | 507 | pThis->eval = errx(pThis->pCtx, 1, "%s: %s failed: %s " CUR_LINE() "\n", p->fts_path, operation, strerror(errno));
|
---|
[228] | 508 | }
|
---|
| 509 | if (errno) {
|
---|
[3192] | 510 | pThis->eval = errx(pThis->pCtx, 1, "fts_read: %s " CUR_LINE() "\n", strerror(errno));
|
---|
[1550] | 511 | }
|
---|
| 512 | fts_close(fts);
|
---|
[3192] | 513 | return pThis->eval;
|
---|
[228] | 514 | }
|
---|
| 515 |
|
---|
[1598] | 516 | static int
|
---|
[3192] | 517 | rm_file(PRMINSTANCE pThis, char **argv)
|
---|
[228] | 518 | {
|
---|
| 519 | struct stat sb;
|
---|
| 520 | int rval;
|
---|
| 521 | char *f;
|
---|
| 522 |
|
---|
| 523 | /*
|
---|
[1551] | 524 | * Check up front before anything is deleted.
|
---|
| 525 | */
|
---|
[1598] | 526 | int i;
|
---|
| 527 | for (i = 0; argv[i]; i++) {
|
---|
[3192] | 528 | if (kBuildProtectionEnforce(&pThis->g_ProtData, KBUILDPROTECTIONTYPE_FULL, argv[i]))
|
---|
[1598] | 529 | return 1;
|
---|
[1551] | 530 | }
|
---|
| 531 |
|
---|
| 532 | /*
|
---|
[228] | 533 | * Remove a file. POSIX 1003.2 states that, by default, attempting
|
---|
| 534 | * to remove a directory is an error, so must always stat the file.
|
---|
| 535 | */
|
---|
| 536 | while ((f = *argv++) != NULL) {
|
---|
[2466] | 537 | const char *operation = "?";
|
---|
[228] | 538 | /* Assume if can't stat the file, can't unlink it. */
|
---|
| 539 | if (lstat(f, &sb)) {
|
---|
[269] | 540 | #ifdef FTS_WHITEOUT
|
---|
[3192] | 541 | if (pThis->Wflag) {
|
---|
[228] | 542 | sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR;
|
---|
| 543 | } else {
|
---|
[269] | 544 | #else
|
---|
| 545 | {
|
---|
| 546 | #endif
|
---|
[3192] | 547 | if (!pThis->fflag || errno != ENOENT)
|
---|
| 548 | pThis->eval = errx(pThis->pCtx, 1, "%s: lstat failed: %s " CUR_LINE() "\n",
|
---|
| 549 | f, strerror(errno));
|
---|
[228] | 550 | continue;
|
---|
| 551 | }
|
---|
[269] | 552 | #ifdef FTS_WHITEOUT
|
---|
[3192] | 553 | } else if (pThis->Wflag) {
|
---|
[3247] | 554 | errx(pThis->pCtx, 1, "%s: %s\n", f, strerror(EEXIST));
|
---|
[3192] | 555 | pThis->eval = 1;
|
---|
[228] | 556 | continue;
|
---|
[269] | 557 | #endif
|
---|
[228] | 558 | }
|
---|
| 559 |
|
---|
[3192] | 560 | if (S_ISDIR(sb.st_mode) && !pThis->dflag) {
|
---|
| 561 | pThis->eval = errx(pThis->pCtx, 1, "%s: is a directory\n", f);
|
---|
[228] | 562 | continue;
|
---|
| 563 | }
|
---|
[3192] | 564 | if (!pThis->fflag && !S_ISWHT(sb.st_mode) && !check(pThis, f, f, &sb))
|
---|
[228] | 565 | continue;
|
---|
| 566 | rval = 0;
|
---|
| 567 | #ifdef UF_APPEND
|
---|
[3228] | 568 | if (!pThis->uid &&
|
---|
[228] | 569 | (sb.st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
|
---|
| 570 | !(sb.st_flags & (SF_APPEND|SF_IMMUTABLE)))
|
---|
| 571 | rval = chflags(f, sb.st_flags & ~(UF_APPEND|UF_IMMUTABLE));
|
---|
| 572 | #endif
|
---|
| 573 | if (rval == 0) {
|
---|
[2466] | 574 | if (S_ISWHT(sb.st_mode)) {
|
---|
[228] | 575 | rval = undelete(f);
|
---|
[2466] | 576 | operation = "undelete";
|
---|
| 577 | } else if (S_ISDIR(sb.st_mode)) {
|
---|
[228] | 578 | rval = rmdir(f);
|
---|
[2466] | 579 | operation = "rmdir";
|
---|
| 580 | } else {
|
---|
[3192] | 581 | if (pThis->Pflag)
|
---|
| 582 | if (!rm_overwrite(pThis, f, &sb))
|
---|
[228] | 583 | continue;
|
---|
[2713] | 584 | #ifndef KBUILD_OS_WINDOWS
|
---|
[228] | 585 | rval = unlink(f);
|
---|
[2713] | 586 | operation = "unlink";
|
---|
| 587 | #else
|
---|
[3192] | 588 | if (pThis->fUseNtDeleteFile) {
|
---|
[2713] | 589 | rval = birdUnlinkForcedFast(f);
|
---|
| 590 | operation = "NtDeleteFile";
|
---|
| 591 | } else {
|
---|
| 592 | rval = birdUnlinkForced(f);
|
---|
| 593 | operation = "unlink";
|
---|
[370] | 594 | }
|
---|
[375] | 595 | #endif
|
---|
[228] | 596 | }
|
---|
| 597 | }
|
---|
[3192] | 598 | if (rval && (!pThis->fflag || errno != ENOENT))
|
---|
| 599 | pThis->eval = errx(pThis->pCtx, 1, "%s: %s failed: %s" CUR_LINE() "\n", f, operation, strerror(errno));
|
---|
| 600 | if (pThis->vflag && rval == 0)
|
---|
| 601 | kmk_builtin_ctx_printf(pThis->pCtx, 0, "%s\n", f);
|
---|
[228] | 602 | }
|
---|
[3192] | 603 | return pThis->eval;
|
---|
[228] | 604 | }
|
---|
| 605 |
|
---|
| 606 | /*
|
---|
| 607 | * rm_overwrite --
|
---|
| 608 | * Overwrite the file 3 times with varying bit patterns.
|
---|
| 609 | *
|
---|
| 610 | * XXX
|
---|
| 611 | * This is a cheap way to *really* delete files. Note that only regular
|
---|
| 612 | * files are deleted, directories (and therefore names) will remain.
|
---|
| 613 | * Also, this assumes a fixed-block file system (like FFS, or a V7 or a
|
---|
| 614 | * System V file system). In a logging file system, you'll have to have
|
---|
| 615 | * kernel support.
|
---|
| 616 | */
|
---|
| 617 | static int
|
---|
[3192] | 618 | rm_overwrite(PRMINSTANCE pThis, char *file, struct stat *sbp)
|
---|
[228] | 619 | {
|
---|
| 620 | struct stat sb;
|
---|
| 621 | #ifdef HAVE_FSTATFS
|
---|
| 622 | struct statfs fsb;
|
---|
| 623 | #endif
|
---|
| 624 | off_t len;
|
---|
| 625 | int bsize, fd, wlen;
|
---|
| 626 | char *buf = NULL;
|
---|
[2466] | 627 | const char *operation = "lstat";
|
---|
[3192] | 628 | int error;
|
---|
[228] | 629 |
|
---|
| 630 | fd = -1;
|
---|
| 631 | if (sbp == NULL) {
|
---|
| 632 | if (lstat(file, &sb))
|
---|
| 633 | goto err;
|
---|
| 634 | sbp = &sb;
|
---|
| 635 | }
|
---|
| 636 | if (!S_ISREG(sbp->st_mode))
|
---|
| 637 | return (1);
|
---|
[2466] | 638 | operation = "open";
|
---|
[3192] | 639 | if ((fd = open(file, O_WRONLY | KMK_OPEN_NO_INHERIT, 0)) == -1)
|
---|
[228] | 640 | goto err;
|
---|
| 641 | #ifdef HAVE_FSTATFS
|
---|
| 642 | if (fstatfs(fd, &fsb) == -1)
|
---|
| 643 | goto err;
|
---|
| 644 | bsize = MAX(fsb.f_iosize, 1024);
|
---|
| 645 | #elif defined(HAVE_ST_BLKSIZE)
|
---|
| 646 | bsize = MAX(sb.st_blksize, 1024);
|
---|
| 647 | #else
|
---|
| 648 | bsize = 1024;
|
---|
| 649 | #endif
|
---|
[3192] | 650 | if ((buf = malloc(bsize)) == NULL) {
|
---|
| 651 | err(pThis->pCtx, 1, "%s: malloc", file);
|
---|
| 652 | close(fd);
|
---|
| 653 | return 1;
|
---|
| 654 | }
|
---|
[228] | 655 |
|
---|
| 656 | #define PASS(byte) { \
|
---|
[2466] | 657 | operation = "write"; \
|
---|
[228] | 658 | memset(buf, byte, bsize); \
|
---|
| 659 | for (len = sbp->st_size; len > 0; len -= wlen) { \
|
---|
| 660 | wlen = len < bsize ? len : bsize; \
|
---|
| 661 | if (write(fd, buf, wlen) != wlen) \
|
---|
| 662 | goto err; \
|
---|
| 663 | } \
|
---|
| 664 | }
|
---|
| 665 | PASS(0xff);
|
---|
[2466] | 666 | operation = "fsync/lseek";
|
---|
[228] | 667 | if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
|
---|
| 668 | goto err;
|
---|
| 669 | PASS(0x00);
|
---|
[2466] | 670 | operation = "fsync/lseek";
|
---|
[228] | 671 | if (fsync(fd) || lseek(fd, (off_t)0, SEEK_SET))
|
---|
| 672 | goto err;
|
---|
| 673 | PASS(0xff);
|
---|
| 674 | if (!fsync(fd) && !close(fd)) {
|
---|
| 675 | free(buf);
|
---|
| 676 | return (1);
|
---|
| 677 | }
|
---|
[2466] | 678 | operation = "fsync/close";
|
---|
[228] | 679 |
|
---|
[3192] | 680 | err: pThis->eval = 1;
|
---|
| 681 | error = errno;
|
---|
[228] | 682 | if (buf)
|
---|
| 683 | free(buf);
|
---|
| 684 | if (fd != -1)
|
---|
| 685 | close(fd);
|
---|
[3192] | 686 | errx(pThis->pCtx, 1, "%s: %s: %s: %s" CUR_LINE() "\n", operation, pThis->pCtx->pszProgName, file, strerror(error));
|
---|
[228] | 687 | return (0);
|
---|
| 688 | }
|
---|
| 689 |
|
---|
| 690 |
|
---|
| 691 | static int
|
---|
[3192] | 692 | check(PRMINSTANCE pThis, char *path, char *name, struct stat *sp)
|
---|
[228] | 693 | {
|
---|
| 694 | int ch, first;
|
---|
| 695 | char modep[15], *flagsp;
|
---|
| 696 |
|
---|
| 697 | /* Check -i first. */
|
---|
[3192] | 698 | if (pThis->iflag)
|
---|
| 699 | (void)fprintf(stderr, "%s: remove %s? ", pThis->pCtx->pszProgName, path);
|
---|
[228] | 700 | else {
|
---|
| 701 | /*
|
---|
| 702 | * If it's not a symbolic link and it's unwritable and we're
|
---|
| 703 | * talking to a terminal, ask. Symbolic links are excluded
|
---|
| 704 | * because their permissions are meaningless. Check stdin_ok
|
---|
| 705 | * first because we may not have stat'ed the file.
|
---|
| 706 | * Also skip this check if the -P option was specified because
|
---|
| 707 | * we will not be able to overwrite file contents and will
|
---|
| 708 | * barf later.
|
---|
| 709 | */
|
---|
[3192] | 710 | if (!pThis->stdin_ok || S_ISLNK(sp->st_mode) || pThis->Pflag ||
|
---|
[228] | 711 | (!access(name, W_OK) &&
|
---|
| 712 | #ifdef SF_APPEND
|
---|
| 713 | !(sp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
|
---|
[3192] | 714 | (!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !pThis->uid))
|
---|
[228] | 715 | #else
|
---|
| 716 | 1)
|
---|
| 717 | #endif
|
---|
| 718 | )
|
---|
| 719 | return (1);
|
---|
[1710] | 720 | bsd_strmode(sp->st_mode, modep);
|
---|
[3109] | 721 | #if defined(SF_APPEND) && K_OS != K_OS_GNU_KFBSD && K_OS != K_OS_GNU_HURD
|
---|
[3192] | 722 | if ((flagsp = fflagstostr(sp->st_flags)) == NULL) {
|
---|
| 723 | err(pThis->pCtx, 1, "fflagstostr");
|
---|
| 724 | flagsp = "<bad-fflagstostr>";
|
---|
| 725 | }
|
---|
[1598] | 726 | (void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ",
|
---|
| 727 | modep + 1, modep[9] == ' ' ? "" : " ",
|
---|
| 728 | user_from_uid(sp->st_uid, 0),
|
---|
| 729 | group_from_gid(sp->st_gid, 0),
|
---|
| 730 | *flagsp ? flagsp : "", *flagsp ? " " : "",
|
---|
| 731 | path);
|
---|
[228] | 732 | free(flagsp);
|
---|
| 733 | #else
|
---|
[1598] | 734 | (void)flagsp;
|
---|
| 735 | (void)fprintf(stderr, "override %s%s %d/%d for %s? ",
|
---|
| 736 | modep + 1, modep[9] == ' ' ? "" : " ",
|
---|
| 737 | sp->st_uid, sp->st_gid, path);
|
---|
[228] | 738 | #endif
|
---|
| 739 | }
|
---|
| 740 | (void)fflush(stderr);
|
---|
| 741 |
|
---|
| 742 | first = ch = getchar();
|
---|
| 743 | while (ch != '\n' && ch != EOF)
|
---|
| 744 | ch = getchar();
|
---|
| 745 | return (first == 'y' || first == 'Y');
|
---|
| 746 | }
|
---|
| 747 |
|
---|
| 748 | #define ISDOT(a) ((a)[0] == '.' && (!(a)[1] || ((a)[1] == '.' && !(a)[2])))
|
---|
| 749 | static void
|
---|
[3192] | 750 | checkdot(PRMINSTANCE pThis, char **argv)
|
---|
[228] | 751 | {
|
---|
| 752 | char *p, **save, **t;
|
---|
| 753 | int complained;
|
---|
| 754 |
|
---|
| 755 | complained = 0;
|
---|
| 756 | for (t = argv; *t;) {
|
---|
[1550] | 757 | #ifdef HAVE_DOS_PATHS
|
---|
| 758 | const char *tmp = p = *t;
|
---|
| 759 | while (*tmp) {
|
---|
| 760 | switch (*tmp) {
|
---|
| 761 | case '/':
|
---|
| 762 | case '\\':
|
---|
| 763 | case ':':
|
---|
| 764 | p = (char *)tmp + 1;
|
---|
| 765 | break;
|
---|
| 766 | }
|
---|
| 767 | tmp++;
|
---|
| 768 | }
|
---|
| 769 | #else
|
---|
[228] | 770 | if ((p = strrchr(*t, '/')) != NULL)
|
---|
| 771 | ++p;
|
---|
| 772 | else
|
---|
| 773 | p = *t;
|
---|
[1550] | 774 | #endif
|
---|
[228] | 775 | if (ISDOT(p)) {
|
---|
| 776 | if (!complained++)
|
---|
[3192] | 777 | warnx(pThis->pCtx, "\".\" and \"..\" may not be removed\n");
|
---|
| 778 | pThis->eval = 1;
|
---|
[228] | 779 | for (save = t; (t[0] = t[1]) != NULL; ++t)
|
---|
| 780 | continue;
|
---|
| 781 | t = save;
|
---|
| 782 | } else
|
---|
| 783 | ++t;
|
---|
| 784 | }
|
---|
| 785 | }
|
---|
| 786 |
|
---|
| 787 | static int
|
---|
[3192] | 788 | usage(PKMKBUILTINCTX pCtx, int fIsErr)
|
---|
[228] | 789 | {
|
---|
[3192] | 790 | kmk_builtin_ctx_printf(pCtx, fIsErr,
|
---|
| 791 | "usage: %s [options] file ...\n"
|
---|
| 792 | " or: %s --help\n"
|
---|
| 793 | " or: %s --version\n"
|
---|
| 794 | "\n"
|
---|
| 795 | "Options:\n"
|
---|
| 796 | " -f\n"
|
---|
| 797 | " Attempt to remove files without prompting, regardless of the file\n"
|
---|
| 798 | " permission. Ignore non-existing files. Overrides previous -i's.\n"
|
---|
| 799 | " -i\n"
|
---|
| 800 | " Prompt for each file. Always.\n"
|
---|
| 801 | " -d\n"
|
---|
| 802 | " Attempt to remove directories as well as other kinds of files.\n"
|
---|
| 803 | " -P\n"
|
---|
| 804 | " Overwrite regular files before deleting; three passes: ff,0,ff\n"
|
---|
| 805 | " -R\n"
|
---|
| 806 | " Attempt to remove the file hierachy rooted in each file argument.\n"
|
---|
| 807 | " This option implies -d and file protection.\n"
|
---|
| 808 | " -v\n"
|
---|
| 809 | " Be verbose, show files as they are removed.\n"
|
---|
| 810 | " -W\n"
|
---|
[3618] | 811 | " Undelete white-out files.\n"
|
---|
[3192] | 812 | " --disable-protection\n"
|
---|
| 813 | " Will disable the protection file protection applied with -R.\n"
|
---|
| 814 | " --enable-protection\n"
|
---|
| 815 | " Will enable the protection file protection applied with -R.\n"
|
---|
| 816 | " --enable-full-protection\n"
|
---|
| 817 | " Will enable the protection file protection for all operations.\n"
|
---|
| 818 | " --disable-full-protection\n"
|
---|
| 819 | " Will disable the protection file protection for all operations.\n"
|
---|
| 820 | " --protection-depth\n"
|
---|
| 821 | " Number or path indicating the file protection depth. Default: %d\n"
|
---|
| 822 | "\n"
|
---|
| 823 | "Environment:\n"
|
---|
| 824 | " KMK_RM_DISABLE_PROTECTION\n"
|
---|
| 825 | " Same as --disable-protection. Overrides command line.\n"
|
---|
| 826 | " KMK_RM_ENABLE_PROTECTION\n"
|
---|
| 827 | " Same as --enable-protection. Overrides everyone else.\n"
|
---|
| 828 | " KMK_RM_ENABLE_FULL_PROTECTION\n"
|
---|
| 829 | " Same as --enable-full-protection. Overrides everyone else.\n"
|
---|
| 830 | " KMK_RM_DISABLE_FULL_PROTECTION\n"
|
---|
| 831 | " Same as --disable-full-protection. Overrides command line.\n"
|
---|
| 832 | " KMK_RM_PROTECTION_DEPTH\n"
|
---|
| 833 | " Same as --protection-depth. Overrides command line.\n"
|
---|
| 834 | "\n"
|
---|
| 835 | "The file protection of the top %d layers of the file hierarchy is there\n"
|
---|
| 836 | "to try prevent makefiles from doing bad things to your system. This\n"
|
---|
| 837 | "protection is not bulletproof, but should help prevent you from shooting\n"
|
---|
| 838 | "yourself in the foot.\n"
|
---|
| 839 | ,
|
---|
| 840 | pCtx->pszProgName, pCtx->pszProgName, pCtx->pszProgName,
|
---|
| 841 | kBuildProtectionDefaultDepth(), kBuildProtectionDefaultDepth());
|
---|
[228] | 842 | return EX_USAGE;
|
---|
| 843 | }
|
---|
[3192] | 844 |
|
---|