Remove unneeded conditions and logic, fix bug where ownership didnt

change.
Dont use bb_make_directory it doesnt have the features, and its ugly to
work around it.
This commit is contained in:
Glenn L McGrath 2004-01-23 10:57:00 +00:00
parent 475820c9de
commit 578eff5066

View File

@ -42,12 +42,12 @@
extern int install_main(int argc, char **argv) extern int install_main(int argc, char **argv)
{ {
struct stat statbuf; struct stat statbuf;
mode_t mode = 0755; mode_t mode;
uid_t uid = -1; uid_t uid;
gid_t gid = -1; gid_t gid;
char *gid_str; char *gid_str = "-1";
char *uid_str; char *uid_str = "-1";
char *mode_str; char *mode_str = "0755";
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE; int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
int ret = EXIT_SUCCESS; int ret = EXIT_SUCCESS;
int flags; int flags;
@ -60,39 +60,40 @@ extern int install_main(int argc, char **argv)
if (flags & INSTALL_OPT_PRESERVE_TIME) { if (flags & INSTALL_OPT_PRESERVE_TIME) {
copy_flags |= FILEUTILS_PRESERVE_STATUS; copy_flags |= FILEUTILS_PRESERVE_STATUS;
} }
if (flags & INSTALL_OPT_GROUP) { bb_parse_mode(mode_str, &mode);
gid = get_ug_id(gid_str, my_getgrnam); gid = get_ug_id(gid_str, my_getgrnam);
} uid = get_ug_id(uid_str, my_getpwnam);
if (flags & INSTALL_OPT_MODE) { umask(0);
bb_parse_mode(mode_str, &mode);
}
if (flags & INSTALL_OPT_OWNER) {
uid = get_ug_id(uid_str, my_getpwnam);
}
/* Create directories */ /* Create directories
* dont use bb_make_directory() as it cant change uid or gid
* perhaps bb_make_directory() should be improved.
*/
if (flags & INSTALL_OPT_DIRECTORY) { if (flags & INSTALL_OPT_DIRECTORY) {
for (argv += optind; *argv; argv++) { for (argv += optind; *argv; argv++) {
unsigned char *dir_name = *argv; char *old_argv_ptr = *argv + 1;
unsigned char *argv_ptr; char *argv_ptr;
ret |= bb_make_directory(dir_name, mode, FILEUTILS_RECUR);
do { do {
argv_ptr = strrchr(dir_name, '/'); argv_ptr = strchr(old_argv_ptr, '/');
old_argv_ptr = argv_ptr;
/* Skip the "." and ".." directories */
if ((dir_name[0] == '.') && ((dir_name[1] == '\0') || ((dir_name[1] == '.') && (dir_name[2] == '\0')))) {
break;
}
if (lchown(dir_name, uid, gid) == -1) {
bb_perror_msg("cannot change ownership of %s", argv_ptr);
ret |= EXIT_FAILURE;
}
if (argv_ptr) { if (argv_ptr) {
*argv_ptr = '\0'; *argv_ptr = '\0';
old_argv_ptr++;
} }
} while (argv_ptr); if ((mkdir(*argv, mode) == -1) && (errno != EEXIST)) {
bb_perror_msg("coulnt create %s", *argv);
ret = EXIT_FAILURE;
break;
}
else if (lchown(*argv, uid, gid) == -1) {
bb_perror_msg("cannot change ownership of %s", *argv);
ret = EXIT_FAILURE;
break;
}
if (argv_ptr) {
*argv_ptr = '/';
}
} while (old_argv_ptr);
} }
return(ret); return(ret);
} }
@ -111,18 +112,18 @@ extern int install_main(int argc, char **argv)
/* Set the file mode */ /* Set the file mode */
if (chmod(dest, mode) == -1) { if (chmod(dest, mode) == -1) {
bb_perror_msg("cannot change permissions of %s", dest); bb_perror_msg("cannot change permissions of %s", dest);
ret |= EXIT_FAILURE; ret = EXIT_FAILURE;
} }
/* Set the user and group id */ /* Set the user and group id */
if (lchown(dest, uid, gid) == -1) { if (lchown(dest, uid, gid) == -1) {
bb_perror_msg("cannot change ownership of %s", dest); bb_perror_msg("cannot change ownership of %s", dest);
ret |= EXIT_FAILURE; ret = EXIT_FAILURE;
} }
if (flags & INSTALL_OPT_STRIP) { if (flags & INSTALL_OPT_STRIP) {
if (execlp("strip", "strip", dest, NULL) == -1) { if (execlp("strip", "strip", dest, NULL) == -1) {
bb_error_msg("strip failed"); bb_error_msg("strip failed");
ret |= EXIT_FAILURE; ret = EXIT_FAILURE;
} }
} }
} }