aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/utility.c b/utility.c
index 21d69b6e8..b2228f0cb 100644
--- a/utility.c
+++ b/utility.c
@@ -544,4 +544,127 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
544 544
545#endif 545#endif
546 546
547
548
549#if defined (BB_TAR) || defined (BB_MKDIR)
550/*
551 * Attempt to create the directories along the specified path, except for
552 * the final component. The mode is given for the final directory only,
553 * while all previous ones get default protections. Errors are not reported
554 * here, as failures to restore files can be reported later.
555 */
556extern void createPath (const char *name, int mode)
557{
558 char *cp;
559 char *cpOld;
560 char buf[NAME_MAX];
561
562 strcpy (buf, name);
563
564 cp = strchr (buf, '/');
565
566 while (cp) {
567 cpOld = cp;
568 cp = strchr (cp + 1, '/');
569
570 *cpOld = '\0';
571
572 if (mkdir (buf, cp ? 0777 : mode) == 0)
573 printf ("Directory \"%s\" created\n", buf);
574
575 *cpOld = '/';
576 }
577}
578#endif
579
580
581
582#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR)
583/* [ugoa]{+|-|=}[rwxstl] */
584extern int parse_mode( const char* s, mode_t* theMode)
585{
586 mode_t or;
587 mode_t and;
588 mode_t mode = 0;
589 mode_t groups = S_ISVTX;
590 char type;
591 char c;
592
593 do {
594 for ( ; ; ) {
595 switch ( c = *s++ ) {
596 case '\0':
597 return (FALSE);
598 case 'u':
599 groups |= S_ISUID|S_IRWXU;
600 continue;
601 case 'g':
602 groups |= S_ISGID|S_IRWXG;
603 continue;
604 case 'o':
605 groups |= S_IRWXO;
606 continue;
607 case 'a':
608 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
609 continue;
610 case '+':
611 case '=':
612 case '-':
613 type = c;
614 if ( groups == S_ISVTX ) /* The default is "all" */
615 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
616 break;
617 default:
618 if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) {
619 and = 0;
620 or = strtol(--s, 0, 010);
621 return (TRUE);
622 }
623 else
624 return (FALSE);
625 }
626 break;
627 }
628
629 while ( (c = *s++) != '\0' ) {
630 switch ( c ) {
631 case ',':
632 break;
633 case 'r':
634 mode |= S_IRUSR|S_IRGRP|S_IROTH;
635 continue;
636 case 'w':
637 mode |= S_IWUSR|S_IWGRP|S_IWOTH;
638 continue;
639 case 'x':
640 mode |= S_IXUSR|S_IXGRP|S_IXOTH;
641 continue;
642 case 's':
643 mode |= S_IXGRP|S_ISUID|S_ISGID;
644 continue;
645 case 't':
646 mode |= S_ISVTX;
647 continue;
648 default:
649 return (FALSE);
650 }
651 break;
652 }
653 switch ( type ) {
654 case '=':
655 and &= ~(groups);
656 /* fall through */
657 case '+':
658 or |= mode & groups;
659 break;
660 case '-':
661 and &= ~(mode & groups);
662 or &= and;
663 break;
664 }
665 } while ( c == ',' );
666 return (TRUE);
667}
668#endif
669
547/* END CODE */ 670/* END CODE */