diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-28 05:44:47 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-28 05:44:47 +0000 |
| commit | 5a4b69f8a10fff8f08a97e0dd4b6de40d36f671f (patch) | |
| tree | 34292ef12cab59b118e91a6c58844ae25f1bee94 /coreutils | |
| parent | d823e460f09b4f6e77cf07670dececfddafafd04 (diff) | |
| download | busybox-w32-5a4b69f8a10fff8f08a97e0dd4b6de40d36f671f.tar.gz busybox-w32-5a4b69f8a10fff8f08a97e0dd4b6de40d36f671f.tar.bz2 busybox-w32-5a4b69f8a10fff8f08a97e0dd4b6de40d36f671f.zip | |
bb_xget[pw/gr]nam were horribly misnamed - fixed.
uidgid_get -> get_uidgid, add additional param
(numeric_ok). Make chown use it.
chown: fix "chown user: ...."
install: fix incorrect use of bb_xget[pw/gr]nam
git-svn-id: svn://busybox.net/trunk/busybox@17095 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/chown.c | 28 | ||||
| -rw-r--r-- | coreutils/id.c | 4 | ||||
| -rw-r--r-- | coreutils/install.c | 82 |
3 files changed, 63 insertions, 51 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c index fddce7cf1..a45348a24 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
| @@ -54,32 +54,38 @@ static int fileAction(const char *fileName, struct stat *statbuf, | |||
| 54 | 54 | ||
| 55 | int chown_main(int argc, char **argv) | 55 | int chown_main(int argc, char **argv) |
| 56 | { | 56 | { |
| 57 | int retval = EXIT_SUCCESS; | ||
| 58 | char *groupName; | 57 | char *groupName; |
| 58 | int retval = EXIT_SUCCESS; | ||
| 59 | 59 | ||
| 60 | opt_complementary = "-2"; | 60 | opt_complementary = "-2"; |
| 61 | getopt32(argc, argv, OPT_STR); | 61 | getopt32(argc, argv, OPT_STR); |
| 62 | argv += optind; | ||
| 62 | 63 | ||
| 63 | if (OPT_NODEREF) chown_func = lchown; | 64 | if (OPT_NODEREF) chown_func = lchown; |
| 64 | 65 | ||
| 65 | argv += optind; | ||
| 66 | |||
| 67 | /* First, check if there is a group name here */ | 66 | /* First, check if there is a group name here */ |
| 68 | groupName = strchr(*argv, '.'); | 67 | groupName = strchr(*argv, '.'); /* deprecated? */ |
| 69 | if (!groupName) { | 68 | if (!groupName) { |
| 70 | groupName = strchr(*argv, ':'); | 69 | groupName = strchr(*argv, ':'); |
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | /* Check for the username and groupname */ | 72 | /* First, try parsing "user[:[group]]" */ |
| 74 | if (groupName) { | 73 | if (!groupName) { /* "user" */ |
| 75 | *groupName++ = '\0'; | 74 | uid = get_ug_id(*argv, xuname2uid); |
| 76 | gid = get_ug_id(groupName, bb_xgetgrnam); | 75 | } else if (groupName == *argv) { /* ":group" */ |
| 76 | gid = get_ug_id(groupName + 1, xgroup2gid); | ||
| 77 | } else { | ||
| 78 | struct bb_uidgid_t ugid; | ||
| 79 | if (!groupName[1]) /* "user:" */ | ||
| 80 | *groupName = '\0'; | ||
| 81 | if (!get_uidgid(&ugid, *argv, 1)) | ||
| 82 | bb_error_msg_and_die("unknown user/group %s", *argv); | ||
| 83 | uid = ugid.uid; | ||
| 84 | gid = ugid.gid; | ||
| 77 | } | 85 | } |
| 78 | if (--groupName != *argv) | ||
| 79 | uid = get_ug_id(*argv, bb_xgetpwnam); | ||
| 80 | ++argv; | ||
| 81 | 86 | ||
| 82 | /* Ok, ready to do the deed now */ | 87 | /* Ok, ready to do the deed now */ |
| 88 | argv++; | ||
| 83 | do { | 89 | do { |
| 84 | if (!recursive_action(*argv, | 90 | if (!recursive_action(*argv, |
| 85 | OPT_RECURSE, // recurse | 91 | OPT_RECURSE, // recurse |
diff --git a/coreutils/id.c b/coreutils/id.c index 66874a71e..35f945dba 100644 --- a/coreutils/id.c +++ b/coreutils/id.c | |||
| @@ -62,8 +62,8 @@ int id_main(int argc, char **argv) | |||
| 62 | 62 | ||
| 63 | if (argv[optind]) { | 63 | if (argv[optind]) { |
| 64 | p = getpwnam(argv[optind]); | 64 | p = getpwnam(argv[optind]); |
| 65 | /* bb_xgetpwnam is needed because it exits on failure */ | 65 | /* xuname2uid is needed because it exits on failure */ |
| 66 | uid = bb_xgetpwnam(argv[optind]); | 66 | uid = xuname2uid(argv[optind]); |
| 67 | gid = p->pw_gid; | 67 | gid = p->pw_gid; |
| 68 | /* in this case PRINT_REAL is the same */ | 68 | /* in this case PRINT_REAL is the same */ |
| 69 | } | 69 | } |
diff --git a/coreutils/install.c b/coreutils/install.c index 3e003905e..aa7e8bf2b 100644 --- a/coreutils/install.c +++ b/coreutils/install.c | |||
| @@ -13,58 +13,62 @@ | |||
| 13 | #include <libgen.h> | 13 | #include <libgen.h> |
| 14 | #include <getopt.h> /* struct option */ | 14 | #include <getopt.h> /* struct option */ |
| 15 | 15 | ||
| 16 | #define INSTALL_OPT_CMD 1 | ||
| 17 | #define INSTALL_OPT_DIRECTORY 2 | ||
| 18 | #define INSTALL_OPT_PRESERVE_TIME 4 | ||
| 19 | #define INSTALL_OPT_STRIP 8 | ||
| 20 | #define INSTALL_OPT_GROUP 16 | ||
| 21 | #define INSTALL_OPT_MODE 32 | ||
| 22 | #define INSTALL_OPT_OWNER 64 | ||
| 23 | |||
| 24 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS | 16 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS |
| 25 | static const struct option install_long_options[] = { | 17 | static const struct option install_long_options[] = { |
| 26 | { "directory", 0, NULL, 'd' }, | 18 | { "directory", 0, NULL, 'd' }, |
| 27 | { "preserve-timestamps", 0, NULL, 'p' }, | 19 | { "preserve-timestamps", 0, NULL, 'p' }, |
| 28 | { "strip", 0, NULL, 's' }, | 20 | { "strip", 0, NULL, 's' }, |
| 29 | { "group", 0, NULL, 'g' }, | 21 | { "group", 0, NULL, 'g' }, |
| 30 | { "mode", 0, NULL, 'm' }, | 22 | { "mode", 0, NULL, 'm' }, |
| 31 | { "owner", 0, NULL, 'o' }, | 23 | { "owner", 0, NULL, 'o' }, |
| 32 | { 0, 0, 0, 0 } | 24 | { 0, 0, 0, 0 } |
| 33 | }; | 25 | }; |
| 34 | #endif | 26 | #endif |
| 35 | 27 | ||
| 36 | int install_main(int argc, char **argv) | 28 | int install_main(int argc, char **argv) |
| 37 | { | 29 | { |
| 30 | struct stat statbuf; | ||
| 38 | mode_t mode; | 31 | mode_t mode; |
| 39 | uid_t uid; | 32 | uid_t uid; |
| 40 | gid_t gid; | 33 | gid_t gid; |
| 41 | char *gid_str = "-1"; | 34 | const char *gid_str; |
| 42 | char *uid_str = "-1"; | 35 | const char *uid_str; |
| 43 | char *mode_str = "0755"; | 36 | const char *mode_str; |
| 44 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; | 37 | int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; |
| 45 | int ret = EXIT_SUCCESS, flags, i, isdir; | 38 | int ret = EXIT_SUCCESS, flags, i, isdir; |
| 46 | 39 | ||
| 40 | enum { | ||
| 41 | OPT_CMD = 0x1, | ||
| 42 | OPT_DIRECTORY = 0x2, | ||
| 43 | OPT_PRESERVE_TIME = 0x4, | ||
| 44 | OPT_STRIP = 0x8, | ||
| 45 | OPT_GROUP = 0x10, | ||
| 46 | OPT_MODE = 0x20, | ||
| 47 | OPT_OWNER = 0x40, | ||
| 48 | }; | ||
| 49 | |||
| 47 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS | 50 | #if ENABLE_FEATURE_INSTALL_LONG_OPTIONS |
| 48 | applet_long_options = install_long_options; | 51 | applet_long_options = install_long_options; |
| 49 | #endif | 52 | #endif |
| 50 | opt_complementary = "?:s--d:d--s"; | 53 | opt_complementary = "?:s--d:d--s"; |
| 51 | /* -c exists for backwards compatibility, its needed */ | 54 | /* -c exists for backwards compatibility, its needed */ |
| 52 | flags = getopt32(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */ | 55 | flags = getopt32(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); |
| 53 | 56 | ||
| 54 | /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */ | 57 | /* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */ |
| 55 | if (flags & INSTALL_OPT_PRESERVE_TIME) { | 58 | if (flags & OPT_PRESERVE_TIME) { |
| 56 | copy_flags |= FILEUTILS_PRESERVE_STATUS; | 59 | copy_flags |= FILEUTILS_PRESERVE_STATUS; |
| 57 | } | 60 | } |
| 58 | bb_parse_mode(mode_str, &mode); | 61 | mode = 0666; |
| 59 | gid = get_ug_id(gid_str, bb_xgetgrnam); | 62 | if (flags & OPT_MODE) bb_parse_mode(mode_str, &mode); |
| 60 | uid = get_ug_id(uid_str, bb_xgetpwnam); | 63 | uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid(); |
| 61 | umask(0); | 64 | gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid(); |
| 65 | if (flags & (OPT_OWNER|OPT_GROUP)) umask(0); | ||
| 62 | 66 | ||
| 63 | /* Create directories | 67 | /* Create directories |
| 64 | * don't use bb_make_directory() as it can't change uid or gid | 68 | * don't use bb_make_directory() as it can't change uid or gid |
| 65 | * perhaps bb_make_directory() should be improved. | 69 | * perhaps bb_make_directory() should be improved. |
| 66 | */ | 70 | */ |
| 67 | if (flags & INSTALL_OPT_DIRECTORY) { | 71 | if (flags & OPT_DIRECTORY) { |
| 68 | for (argv += optind; *argv; argv++) { | 72 | for (argv += optind; *argv; argv++) { |
| 69 | char *old_argv_ptr = *argv + 1; | 73 | char *old_argv_ptr = *argv + 1; |
| 70 | char *argv_ptr; | 74 | char *argv_ptr; |
| @@ -75,14 +79,16 @@ int install_main(int argc, char **argv) | |||
| 75 | *argv_ptr = '\0'; | 79 | *argv_ptr = '\0'; |
| 76 | old_argv_ptr++; | 80 | old_argv_ptr++; |
| 77 | } | 81 | } |
| 78 | if (mkdir(*argv, mode) == -1) { | 82 | if (mkdir(*argv, mode | 0111) == -1) { |
| 79 | if (errno != EEXIST) { | 83 | if (errno != EEXIST) { |
| 80 | bb_perror_msg("cannot create %s", *argv); | 84 | bb_perror_msg("cannot create %s", *argv); |
| 81 | ret = EXIT_FAILURE; | 85 | ret = EXIT_FAILURE; |
| 82 | break; | 86 | break; |
| 83 | } | 87 | } |
| 84 | } | 88 | } |
| 85 | else if (lchown(*argv, uid, gid) == -1) { | 89 | if ((flags & (OPT_OWNER|OPT_GROUP)) |
| 90 | && lchown(*argv, uid, gid) == -1 | ||
| 91 | ) { | ||
| 86 | bb_perror_msg("cannot change ownership of %s", *argv); | 92 | bb_perror_msg("cannot change ownership of %s", *argv); |
| 87 | ret = EXIT_FAILURE; | 93 | ret = EXIT_FAILURE; |
| 88 | break; | 94 | break; |
| @@ -95,36 +101,36 @@ int install_main(int argc, char **argv) | |||
| 95 | return ret; | 101 | return ret; |
| 96 | } | 102 | } |
| 97 | 103 | ||
| 98 | { | 104 | isdir = lstat(argv[argc - 1], &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode); |
| 99 | struct stat statbuf; | 105 | |
| 100 | isdir = lstat(argv[argc - 1], &statbuf)<0 | ||
| 101 | ? 0 : S_ISDIR(statbuf.st_mode); | ||
| 102 | } | ||
| 103 | for (i = optind; i < argc - 1; i++) { | 106 | for (i = optind; i < argc - 1; i++) { |
| 104 | char *dest; | 107 | char *dest; |
| 105 | 108 | ||
| 106 | dest = argv[argc - 1]; | 109 | dest = argv[argc - 1]; |
| 107 | if (isdir) dest = concat_path_file(argv[argc - 1], basename(argv[i])); | 110 | if (isdir) |
| 111 | dest = concat_path_file(argv[argc - 1], basename(argv[i])); | ||
| 108 | ret |= copy_file(argv[i], dest, copy_flags); | 112 | ret |= copy_file(argv[i], dest, copy_flags); |
| 109 | 113 | ||
| 110 | /* Set the file mode */ | 114 | /* Set the file mode */ |
| 111 | if (chmod(dest, mode) == -1) { | 115 | if ((flags & OPT_MODE) && chmod(dest, mode) == -1) { |
| 112 | bb_perror_msg("cannot change permissions of %s", dest); | 116 | bb_perror_msg("cannot change permissions of %s", dest); |
| 113 | ret = EXIT_FAILURE; | 117 | ret = EXIT_FAILURE; |
| 114 | } | 118 | } |
| 115 | 119 | ||
| 116 | /* Set the user and group id */ | 120 | /* Set the user and group id */ |
| 117 | if (lchown(dest, uid, gid) == -1) { | 121 | if ((flags & (OPT_OWNER|OPT_GROUP)) |
| 122 | && lchown(dest, uid, gid) == -1 | ||
| 123 | ) { | ||
| 118 | bb_perror_msg("cannot change ownership of %s", dest); | 124 | bb_perror_msg("cannot change ownership of %s", dest); |
| 119 | ret = EXIT_FAILURE; | 125 | ret = EXIT_FAILURE; |
| 120 | } | 126 | } |
| 121 | if (flags & INSTALL_OPT_STRIP) { | 127 | if (flags & OPT_STRIP) { |
| 122 | if (execlp("strip", "strip", dest, NULL) == -1) { | 128 | if (execlp("strip", "strip", dest, NULL) == -1) { |
| 123 | bb_error_msg("strip failed"); | 129 | bb_perror_msg("strip"); |
| 124 | ret = EXIT_FAILURE; | 130 | ret = EXIT_FAILURE; |
| 125 | } | 131 | } |
| 126 | } | 132 | } |
| 127 | if(ENABLE_FEATURE_CLEAN_UP && isdir) free(dest); | 133 | if (ENABLE_FEATURE_CLEAN_UP && isdir) free(dest); |
| 128 | } | 134 | } |
| 129 | 135 | ||
| 130 | return ret; | 136 | return ret; |
