summaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-20 07:03:36 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-20 07:03:36 +0000
commitce8f3b99339fb954204329971ed25efc950fed26 (patch)
tree1f7509e6b8604061a688adb4d8299c3a4b79bdc9 /utility.c
parentb9b421c186cf6a9e575770a1c5fb46b6bdd3424a (diff)
downloadbusybox-w32-ce8f3b99339fb954204329971ed25efc950fed26.tar.gz
busybox-w32-ce8f3b99339fb954204329971ed25efc950fed26.tar.bz2
busybox-w32-ce8f3b99339fb954204329971ed25efc950fed26.zip
Fixed chmod and friends.
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/utility.c b/utility.c
index 826cfbfee..fa9849160 100644
--- a/utility.c
+++ b/utility.c
@@ -32,7 +32,7 @@
32#include <utime.h> 32#include <utime.h>
33#include <sys/stat.h> 33#include <sys/stat.h>
34#include <unistd.h> 34#include <unistd.h>
35 35#include <ctype.h>
36 36
37/* volatile so gcc knows this is the enod of the line */ 37/* volatile so gcc knows this is the enod of the line */
38volatile void usage(const char *usage) 38volatile void usage(const char *usage)
@@ -558,13 +558,17 @@ extern void createPath (const char *name, int mode)
558 558
559 559
560#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR) 560#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR)
561/* [ugoa]{+|-|=}[rwxstl] */ 561/* [ugoa]{+|-|=}[rwxst] */
562extern int parse_mode( const char* s, mode_t* theMode) 562
563
564
565extern int
566parse_mode( const char* s, mode_t* theMode)
563{ 567{
564 mode_t or; 568 mode_t andMode = S_ISVTX|S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
565 mode_t and; 569 mode_t orMode = 0;
566 mode_t mode = 0; 570 mode_t mode = 0;
567 mode_t groups = S_ISVTX; 571 mode_t groups = 0;
568 char type; 572 char type;
569 char c; 573 char c;
570 574
@@ -572,7 +576,7 @@ extern int parse_mode( const char* s, mode_t* theMode)
572 for ( ; ; ) { 576 for ( ; ; ) {
573 switch ( c = *s++ ) { 577 switch ( c = *s++ ) {
574 case '\0': 578 case '\0':
575 return (FALSE); 579 return -1;
576 case 'u': 580 case 'u':
577 groups |= S_ISUID|S_IRWXU; 581 groups |= S_ISUID|S_IRWXU;
578 continue; 582 continue;
@@ -589,13 +593,15 @@ extern int parse_mode( const char* s, mode_t* theMode)
589 case '=': 593 case '=':
590 case '-': 594 case '-':
591 type = c; 595 type = c;
592 if ( groups == S_ISVTX ) /* The default is "all" */ 596 if ( groups == 0 ) /* The default is "all" */
593 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO; 597 groups |= S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO;
594 break; 598 break;
595 default: 599 default:
596 if ( c >= '0' && c <= '7' && mode == 0 && groups == S_ISVTX ) { 600 if ( isdigit(c) && c >= '0' && c <= '7' && mode == 0 && groups == 0 ) {
597 and = 0; 601 andMode = 0;
598 or = strtol(--s, 0, 010); 602 orMode = strtol(--s, NULL, 8);
603 *theMode &= andMode;
604 *theMode |= orMode;
599 return (TRUE); 605 return (TRUE);
600 } 606 }
601 else 607 else
@@ -621,28 +627,34 @@ extern int parse_mode( const char* s, mode_t* theMode)
621 mode |= S_IXGRP|S_ISUID|S_ISGID; 627 mode |= S_IXGRP|S_ISUID|S_ISGID;
622 continue; 628 continue;
623 case 't': 629 case 't':
624 mode |= S_ISVTX; 630 mode |= 0;
625 continue; 631 continue;
626 default: 632 default:
627 return (FALSE); 633 *theMode &= andMode;
634 *theMode |= orMode;
635 return( TRUE);
628 } 636 }
629 break; 637 break;
630 } 638 }
631 switch ( type ) { 639 switch ( type ) {
632 case '=': 640 case '=':
633 and &= ~(groups); 641 andMode &= ~(groups);
634 /* fall through */ 642 /* fall through */
635 case '+': 643 case '+':
636 or |= mode & groups; 644 orMode |= mode & groups;
637 break; 645 break;
638 case '-': 646 case '-':
639 and &= ~(mode & groups); 647 andMode &= ~(mode & groups);
640 or &= and; 648 orMode &= andMode;
641 break; 649 break;
642 } 650 }
643 } while ( c == ',' ); 651 } while ( c == ',' );
652 *theMode &= andMode;
653 *theMode |= orMode;
644 return (TRUE); 654 return (TRUE);
645} 655}
656
657
646#endif 658#endif
647 659
648 660