Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/coreutils/install.c

    r1765 r2725  
    44 * SELinux support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
    55 *
    6  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    7  *
    8  * TODO: -d option, need a way of recursively making directories and changing
    9  *           owner/group, will probably modify bb_make_directory(...)
     6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    107 */
    11 
    12 #include <libgen.h>
    13 #include <getopt.h> /* struct option */
    148
    159#include "libbb.h"
     
    2115    "preserve-timestamps\0" No_argument       "p"
    2216    "strip\0"               No_argument       "s"
    23     "group\0"               No_argument      "g"
    24     "mode\0"                No_argument      "m"
    25     "owner\0"               No_argument      "o"
     17    "group\0"               Required_argument "g"
     18    "mode\0"                Required_argument "m"
     19    "owner\0"               Required_argument "o"
    2620/* autofs build insists of using -b --suffix=.orig */
    2721/* TODO? (short option for --suffix is -S) */
     
    5751    if (lsetfilecon(path, scontext) < 0) {
    5852        if (errno != ENOTSUP) {
    59             bb_perror_msg("warning: failed to change context of %s to %s", path, scontext);
     53            bb_perror_msg("warning: can't change context"
     54                    " of %s to %s", path, scontext);
    6055        }
    6156    }
     
    6762#endif
    6863
    69 int install_main(int argc, char **argv);
     64int install_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    7065int install_main(int argc, char **argv)
    7166{
     
    7974    const char *mode_str;
    8075    int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
    81     int flags;
     76    int opts;
     77    int min_args = 1;
    8278    int ret = EXIT_SUCCESS;
    83     int isdir;
     79    int isdir = 0;
    8480#if ENABLE_SELINUX
    8581    security_context_t scontext;
     
    9086        OPT_v             = 1 << 1,
    9187        OPT_b             = 1 << 2,
    92         OPT_DIRECTORY     = 1 << 3,
    93         OPT_PRESERVE_TIME = 1 << 4,
    94         OPT_STRIP         = 1 << 5,
    95         OPT_GROUP         = 1 << 6,
    96         OPT_MODE          = 1 << 7,
    97         OPT_OWNER         = 1 << 8,
    98 #if ENABLE_SELINUX
    99         OPT_SET_SECURITY_CONTEXT = 1 << 9,
    100         OPT_PRESERVE_SECURITY_CONTEXT = 1 << 10,
     88        OPT_MKDIR_LEADING = 1 << 3,
     89        OPT_DIRECTORY     = 1 << 4,
     90        OPT_PRESERVE_TIME = 1 << 5,
     91        OPT_STRIP         = 1 << 6,
     92        OPT_GROUP         = 1 << 7,
     93        OPT_MODE          = 1 << 8,
     94        OPT_OWNER         = 1 << 9,
     95#if ENABLE_SELINUX
     96        OPT_SET_SECURITY_CONTEXT = 1 << 10,
     97        OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
    10198#endif
    10299    };
     
    105102    applet_long_options = install_longopts;
    106103#endif
    107     opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
     104    opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
    108105    /* -c exists for backwards compatibility, it's needed */
    109106    /* -v is ignored ("print name of each created directory") */
    110107    /* -b is ignored ("make a backup of each existing destination file") */
    111     flags = getopt32(argv, "cvb" "dpsg:m:o:" USE_SELINUX("Z:"),
    112             &gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext));
     108    opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
     109            &gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
    113110    argc -= optind;
    114111    argv += optind;
    115112
    116113#if ENABLE_SELINUX
    117     if (flags & (OPT_PRESERVE_SECURITY_CONTEXT|OPT_SET_SECURITY_CONTEXT)) {
     114    if (opts & (OPT_PRESERVE_SECURITY_CONTEXT|OPT_SET_SECURITY_CONTEXT)) {
    118115        selinux_or_die();
    119116        use_default_selinux_context = 0;
    120         if (flags & OPT_PRESERVE_SECURITY_CONTEXT) {
     117        if (opts & OPT_PRESERVE_SECURITY_CONTEXT) {
    121118            copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
    122119        }
    123         if (flags & OPT_SET_SECURITY_CONTEXT) {
     120        if (opts & OPT_SET_SECURITY_CONTEXT) {
    124121            setfscreatecon_or_die(scontext);
    125122            copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
     
    128125#endif
    129126
    130     /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
    131     if (flags & OPT_PRESERVE_TIME) {
     127    /* preserve access and modification time, this is GNU behaviour,
     128     * BSD only preserves modification time */
     129    if (opts & OPT_PRESERVE_TIME) {
    132130        copy_flags |= FILEUTILS_PRESERVE_STATUS;
    133131    }
    134     mode = 0666;
    135     if (flags & OPT_MODE)
     132    mode = 0755; /* GNU coreutils 6.10 compat */
     133    if (opts & OPT_MODE)
    136134        bb_parse_mode(mode_str, &mode);
    137     uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
    138     gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
    139     if (flags & (OPT_OWNER|OPT_GROUP))
    140         umask(0);
    141 
    142     /* Create directories
    143      * don't use bb_make_directory() as it can't change uid or gid
    144      * perhaps bb_make_directory() should be improved.
    145      */
    146     if (flags & OPT_DIRECTORY) {
    147         while ((arg = *argv++) != NULL) {
    148             char *slash = arg;
    149             while (1) {
    150                 slash = strchr(slash + 1, '/');
    151                 if (slash)
    152                     *slash = '\0';
    153                 if (mkdir(arg, mode | 0111) == -1) {
    154                     if (errno != EEXIST) {
    155                         bb_perror_msg("cannot create %s", arg);
    156                         ret = EXIT_FAILURE;
    157                         break;
    158                     }
    159                 } /* dir was created, chown? */
    160                 else if ((flags & (OPT_OWNER|OPT_GROUP))
    161                  && lchown(arg, uid, gid) == -1
    162                 ) {
    163                     bb_perror_msg("cannot change ownership of %s", arg);
    164                     ret = EXIT_FAILURE;
    165                     break;
    166                 }
    167                 if (!slash)
    168                     break;
    169                 *slash = '/';
    170             }
    171         }
    172         return ret;
    173     }
    174 
    175     if (argc < 2)
     135    uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
     136    gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
     137
     138    last = argv[argc - 1];
     139    if (!(opts & OPT_DIRECTORY)) {
     140        argv[argc - 1] = NULL;
     141        min_args++;
     142
     143        /* coreutils install resolves link in this case, don't use lstat */
     144        isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
     145    }
     146
     147    if (argc < min_args)
    176148        bb_show_usage();
    177 
    178     last = argv[argc - 1];
    179     argv[argc - 1] = NULL;
    180     /* coreutils install resolves link in this case, don't use lstat */
    181     isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
    182149
    183150    while ((arg = *argv++) != NULL) {
    184151        char *dest = last;
    185         if (isdir)
    186             dest = concat_path_file(last, basename(arg));
    187         if (copy_file(arg, dest, copy_flags)) {
    188             /* copy is not made */
    189             ret = EXIT_FAILURE;
    190             goto next;
    191         }
    192 
    193         /* Set the file mode */
    194         if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
    195             bb_perror_msg("cannot change permissions of %s", dest);
     152        if (opts & OPT_DIRECTORY) {
     153            dest = arg;
     154            /* GNU coreutils 6.9 does not set uid:gid
     155             * on intermediate created directories
     156             * (only on last one) */
     157            if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
     158                ret = EXIT_FAILURE;
     159                goto next;
     160            }
     161        } else {
     162            if (opts & OPT_MKDIR_LEADING) {
     163                char *ddir = xstrdup(dest);
     164                bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
     165                /* errors are not checked. copy_file
     166                 * will fail if dir is not created. */
     167                free(ddir);
     168            }
     169            if (isdir)
     170                dest = concat_path_file(last, bb_basename(arg));
     171            if (copy_file(arg, dest, copy_flags) != 0) {
     172                /* copy is not made */
     173                ret = EXIT_FAILURE;
     174                goto next;
     175            }
     176            if (opts & OPT_STRIP) {
     177                char *args[4];
     178                args[0] = (char*)"strip";
     179                args[1] = (char*)"-p"; /* -p --preserve-dates */
     180                args[2] = dest;
     181                args[3] = NULL;
     182                if (spawn_and_wait(args)) {
     183                    bb_perror_msg("strip");
     184                    ret = EXIT_FAILURE;
     185                }
     186            }
     187        }
     188
     189        /* Set the file mode (always, not only with -m).
     190         * GNU coreutils 6.10 is not affected by umask. */
     191        if (chmod(dest, mode) == -1) {
     192            bb_perror_msg("can't change %s of %s", "permissions", dest);
    196193            ret = EXIT_FAILURE;
    197194        }
     
    201198#endif
    202199        /* Set the user and group id */
    203         if ((flags & (OPT_OWNER|OPT_GROUP))
     200        if ((opts & (OPT_OWNER|OPT_GROUP))
    204201         && lchown(dest, uid, gid) == -1
    205202        ) {
    206             bb_perror_msg("cannot change ownership of %s", dest);
     203            bb_perror_msg("can't change %s of %s", "ownership", dest);
    207204            ret = EXIT_FAILURE;
    208         }
    209         if (flags & OPT_STRIP) {
    210             char *args[3];
    211             args[0] = (char*)"strip";
    212             args[1] = dest;
    213             args[2] = NULL;
    214             if (spawn_and_wait(args)) {
    215                 bb_perror_msg("strip");
    216                 ret = EXIT_FAILURE;
    217             }
    218205        }
    219206 next:
Note: See TracChangeset for help on using the changeset viewer.