source: MondoRescue/branches/stable/mindi-busybox/coreutils/chmod.c@ 1770

Last change on this file since 1770 was 1770, checked in by Bruno Cornec, 16 years ago
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File size: 3.9 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chmod implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
8 * to correctly parse '-rwxgoa'
9 *
10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 */
12
13/* BB_AUDIT SUSv3 compliant */
14/* BB_AUDIT GNU defects - unsupported long options. */
15/* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
16
17#include "libbb.h"
18
19/* This is a NOEXEC applet. Be very careful! */
20
21
22#define OPT_RECURSE (option_mask32 & 1)
23#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0))
24#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
25#define OPT_QUIET (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
26#define OPT_STR "R" USE_DESKTOP("vcf")
27
28/* coreutils:
29 * chmod never changes the permissions of symbolic links; the chmod
30 * system call cannot change their permissions. This is not a problem
31 * since the permissions of symbolic links are never used.
32 * However, for each symbolic link listed on the command line, chmod changes
33 * the permissions of the pointed-to file. In contrast, chmod ignores
34 * symbolic links encountered during recursive directory traversals.
35 */
36
37static int fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
38{
39 mode_t newmode;
40
41 /* match coreutils behavior */
42 if (depth == 0) {
43 /* statbuf holds lstat result, but we need stat (follow link) */
44 if (stat(fileName, statbuf))
45 goto err;
46 } else { /* depth > 0: skip links */
47 if (S_ISLNK(statbuf->st_mode))
48 return TRUE;
49 }
50 newmode = statbuf->st_mode;
51
52 if (!bb_parse_mode((char *)param, &newmode))
53 bb_error_msg_and_die("invalid mode: %s", (char *)param);
54
55 if (chmod(fileName, newmode) == 0) {
56 if (OPT_VERBOSE
57 || (OPT_CHANGED && statbuf->st_mode != newmode)
58 ) {
59 printf("mode of '%s' changed to %04o (%s)\n", fileName,
60 newmode & 07777, bb_mode_string(newmode)+1);
61 }
62 return TRUE;
63 }
64 err:
65 if (!OPT_QUIET)
66 bb_perror_msg("%s", fileName);
67 return FALSE;
68}
69
70int chmod_main(int argc, char **argv);
71int chmod_main(int argc, char **argv)
72{
73 int retval = EXIT_SUCCESS;
74 char *arg, **argp;
75 char *smode;
76
77 /* Convert first encountered -r into ar, -w into aw etc
78 * so that getopt would not eat it */
79 argp = argv;
80 while ((arg = *++argp)) {
81 /* Mode spec must be the first arg (sans -R etc) */
82 /* (protect against mishandling e.g. "chmod 644 -r") */
83 if (arg[0] != '-') {
84 arg = NULL;
85 break;
86 }
87 /* An option. Not a -- or valid option? */
88 if (arg[1] && !strchr("-"OPT_STR, arg[1])) {
89 arg[0] = 'a';
90 break;
91 }
92 }
93
94 /* Parse options */
95 opt_complementary = "-2";
96 getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
97 argv += optind;
98
99 /* Restore option-like mode if needed */
100 if (arg) arg[0] = '-';
101
102 /* Ok, ready to do the deed now */
103 smode = *argv++;
104 do {
105 if (!recursive_action(*argv,
106 OPT_RECURSE, // recurse
107 fileAction, // file action
108 fileAction, // dir action
109 smode, // user data
110 0) // depth
111 ) {
112 retval = EXIT_FAILURE;
113 }
114 } while (*++argv);
115
116 return retval;
117}
118
119/*
120Security: chmod is too important and too subtle.
121This is a test script (busybox chmod versus coreutils).
122Run it in empty directory.
123
124#!/bin/sh
125t1="/tmp/busybox chmod"
126t2="/usr/bin/chmod"
127create() {
128 rm -rf $1; mkdir $1
129 (
130 cd $1 || exit 1
131 mkdir dir
132 >up
133 >file
134 >dir/file
135 ln -s dir linkdir
136 ln -s file linkfile
137 ln -s ../up dir/up
138 )
139}
140tst() {
141 (cd test1; $t1 $1)
142 (cd test2; $t2 $1)
143 (cd test1; ls -lR) >out1
144 (cd test2; ls -lR) >out2
145 echo "chmod $1" >out.diff
146 if ! diff -u out1 out2 >>out.diff; then exit 1; fi
147 rm out.diff
148}
149echo "If script produced 'out.diff' file, then at least one testcase failed"
150create test1; create test2
151tst "a+w file"
152tst "a-w dir"
153tst "a+w linkfile"
154tst "a-w linkdir"
155tst "-R a+w file"
156tst "-R a-w dir"
157tst "-R a+w linkfile"
158tst "-R a-w linkdir"
159tst "a-r,a+x linkfile"
160*/
Note: See TracBrowser for help on using the repository browser.