[alt.sources] Something missing in chmode.c ?

rpinchback@watpix.waterloo.edu (Reid M. Pinchback) (06/07/89)

The file whoami.h is included in line 22 of the chmode.c program, but
this is not a standard include file (at least not at U of Waterloo).
Is this an oversight in the submission, or a reliance on a System V
characteristic, or what?  Could somebody post the contents of this
file, or describe what the consequences are of not including it are?


   Reid M. Pinchback

tale@pawl.rpi.edu (David C Lawrence) (06/07/89)

<10152@watcgl.waterloo.edu>, rpinchback@watpix.waterloo.edu (Reid M Pinchback):
> The file whoami.h is included in line 22 of the chmode.c program, but
> this is not a standard include file (at least not at U of Waterloo).
> Is this an oversight in the submission, or a reliance on a System V
> characteristic, or what?  Could somebody post the contents of this
> file, or describe what the consequences are of not including it are?

<whoami.h> is not in the SYSV that I know; it was, I believe, in
TOPS-20 (twenex) systems.  For what I could tell by glancing at the
code for chmode I could not see anything that looks like it would have
come out of whoami.h, unless that is where chmod is declared.

For those few people who actually thought that permit.c, which I
posted about a week ago, was worth saving this patch corrects an
oversight which caused it to core dump if you tried to set the sticky
bit when you weren't the superuser and it was compiled with "gcc -g".
In the wee hours of the morning I had only made space for the stat
struct pointer and not the whole struct itself.  Oh well.

I should probably change the SYSV comments (about not being sure
whether it was SYSV-ok) since I finally did get on a SYSV machine and
try it.  It worked fine but, for the machine I was on, would never set
the sticky bit on anything (including directories).  I wasn't
superuser and I wasn't sure whether non-superuser can set the sticky
bit for SYSV anything.  Strangely enough it always told me that it
couldn't set the sticky bit and I am not sure how it made it through
the tests to get to the message (presumably it should have told me it
was working on directories).  I didn't ponder on it for more than 30
seconds or so though because the 3b2 I was on didn't even have a
debugger that I could find.  AT&T lint doesn't like that second arg to
stat, but BSD doesn't say anything about it.  (Can someone tell me why?)

% diff -c src/permit.c.orig src/permit.c
*** src/permit.c.orig	Sat Jun  3 20:37:26 1989
--- src/permit.c	Sat Jun  3 15:00:41 1989
***************
*** 3,10 ****
   * Author          : David C Lawrence          <tale@pawl.rpi.edu>
   * Created On      : Sat Jun  3 03:32:10 1989
   * Last Modified By: David C Lawrence
!  * Last Modified On: Sat Jun  3 04:04:08 1989
!  * Update Count    : 4
   * Status          : Works just fine for BSD/Sun, maybe SYSV
   */
  
--- 3,10 ----
   * Author          : David C Lawrence          <tale@pawl.rpi.edu>
   * Created On      : Sat Jun  3 03:32:10 1989
   * Last Modified By: David C Lawrence
!  * Last Modified On: Sat Jun  3 15:00:41 1989
!  * Update Count    : 5
   * Status          : Works just fine for BSD/Sun, maybe SYSV
   */
  
***************
*** 107,113 ****
  
  {
    int permission, rc=0;
!   struct stat *statbuf;
  
    if (argc < 3 || strlen(argv[1]) != 9) {
      (void)fprintf(stderr,"Usage: %s 9-char-permission file(s)\n",argv[0]);
--- 107,113 ----
  
  {
    int permission, rc=0;
!   struct stat statbuf;
  
    if (argc < 3 || strlen(argv[1]) != 9) {
      (void)fprintf(stderr,"Usage: %s 9-char-permission file(s)\n",argv[0]);
***************
*** 124,133 ****
        (void)fprintf(stderr,"%s: %s: %s\n",pname,argv[argc],sys_errlist[errno]);
        rc++;
      } else {
!       (void)stat(argv[argc], statbuf); /* since chmod succeeded, stat should */
        /* could possibly check here for clearing of setgid, too */
        if ((geteuid() != 0) && (permission & S_ISVTX) &&
!           !(statbuf->st_mode & S_IFDIR)) {
          (void)fprintf(stderr,
                        "%s: couldn't set sticky bit for %s\n",pname,argv[argc]);
          rc++;
--- 124,133 ----
        (void)fprintf(stderr,"%s: %s: %s\n",pname,argv[argc],sys_errlist[errno]);
        rc++;
      } else {
!       (void)stat(argv[argc],&statbuf); /* since chmod succeeded, stat should */
        /* could possibly check here for clearing of setgid, too */
        if ((geteuid() != 0) && (permission & S_ISVTX) &&
!           !(statbuf.st_mode & S_IFDIR)) {
          (void)fprintf(stderr,
                        "%s: couldn't set sticky bit for %s\n",pname,argv[argc]);
          rc++;
--
 (setq mail '("tale@pawl.rpi.edu" "tale@itsgw.rpi.edu" "tale@rpitsmts.bitnet"))
  "I realize the Internet isn't the whole world, but it is the center of it."
                                                        -- Greg Woods

tale@pawl.rpi.edu (David C Lawrence) (06/08/89)

Many thanks to Guy Harris for clearing me up regarding the SYSV issues
and what is really the correct test for a directory (the one I used
was bogus).  His comments were very educational and I appreciate them.

Now I think everything here is correct.  If you applied the small
patch I gave yesterday then you can apply this one without any
problems.  If you just threw the whole permit.c (and chmode.c) away,
I'm not surprised because "chmod 754 prog" still seems quicker for me
to type than "chmod rwxr-xr-- prog".  It is handy though when you know
what the permission should look like but you're tired and out of
caffeine and now the dishwasher is overflowing so you can't remember
either the octal or mnemonic for rwsr-lr-x.  My dishwasher hasn't
overflowed in at least two years though ....

% diff -c permit.c.old permit.c
*** /home/h/tale/src/permit.c.old	Wed Jun  7 19:40:11 1989
--- /home/h/tale/src/permit.c	Wed Jun  7 19:34:22 1989
***************
*** 3,19 ****
   * Author          : David C Lawrence          <tale@pawl.rpi.edu>
   * Created On      : Sat Jun  3 03:32:10 1989
   * Last Modified By: David C Lawrence
!  * Last Modified On: Sat Jun  3 15:00:41 1989
!  * Update Count    : 5
!  * Status          : Works just fine for BSD/Sun, maybe SYSV
   */
  
  /*
   * Usage is: permit rwxrwxrwx-pattern file(s)
   *
!  * This deals fine with all current permission schemes on Sun/BSD
!  * (and mostly on SYSV) systems of which I am aware. I'm not sure
!  * how portable it is beyond that.
   *
   * It will accept patterns like rwsr-S--t (bozotic, I realize) without
   * complaint and try to permit accordingly. It even gives you a warning
--- 3,25 ----
   * Author          : David C Lawrence          <tale@pawl.rpi.edu>
   * Created On      : Sat Jun  3 03:32:10 1989
   * Last Modified By: David C Lawrence
!  * Last Modified On: Wed Jun  7 19:34:22 1989
!  * Update Count    : 7
!  * Status          : Works just fine for BSD/SYSV
   */
  
+ /* History
+  * 7-Jun-1989		David C Lawrence
+  *    Last Modified: Wed Jun  7 19:29:37 1989 #7 (David C Lawrence) 
+  *    Fixed the test to see if a directory was being chmod'ed
+  *    Everything should be fine for SYSV now (Thanks Guy!)
+  */
+ 
  /*
   * Usage is: permit rwxrwxrwx-pattern file(s)
   *
!  * This deals fine with all current permission schemes on SYSV/BSD
!  * systems of which I am aware. I'm not sure how portable it is beyond that.
   *
   * It will accept patterns like rwsr-S--t (bozotic, I realize) without
   * complaint and try to permit accordingly. It even gives you a warning
***************
*** 20,29 ****
   * message if you try to set the sticky bit on a file without being
   * the superuser (the regular chmod doesn't).
   *
-  * Caveat: I couldn't get to a SYSV machine to try this out; I
-  * have a feeling sticky bit stuff might be wrong there, but I am
-  * not sure.
-  *
   * BUGS: none that I know of at the moment, but it does have really
   *       dorky error messages.
   */
--- 26,31 ----
***************
*** 71,77 ****
        break;
      case 'S':
      case 's':
!     case 'l':                   /* 'l' is SYSV 'S' for setgid (?) */
        if (loop%3 != 2 || loop == 8 || (ch == 'l' && loop != 5)) {
          (void)fprintf(stderr,"%s: 's'et[ug]id permission misplaced\n",pname);
          exit(99);
--- 73,79 ----
        break;
      case 'S':
      case 's':
!     case 'l':                   /* 'l' is SYSV 'S' for group permission */
        if (loop%3 != 2 || loop == 8 || (ch == 'l' && loop != 5)) {
          (void)fprintf(stderr,"%s: 's'et[ug]id permission misplaced\n",pname);
          exit(99);
***************
*** 127,133 ****
        (void)stat(argv[argc],&statbuf); /* since chmod succeeded, stat should */
        /* could possibly check here for clearing of setgid, too */
        if ((geteuid() != 0) && (permission & S_ISVTX) &&
!           !(statbuf.st_mode & S_IFDIR)) {
          (void)fprintf(stderr,
                        "%s: couldn't set sticky bit for %s\n",pname,argv[argc]);
          rc++;
--- 129,135 ----
        (void)stat(argv[argc],&statbuf); /* since chmod succeeded, stat should */
        /* could possibly check here for clearing of setgid, too */
        if ((geteuid() != 0) && (permission & S_ISVTX) &&
!           ((statbuf.st_mode & S_IFDIR) != S_IFDIR)) {
          (void)fprintf(stderr,
                        "%s: couldn't set sticky bit for %s\n",pname,argv[argc]);
          rc++;
***************
*** 136,139 ****
--- 138,142 ----
    }
    /* exit with the number of files we were not able to permit as requested */
    exit(rc);
+ /*NOTREACHED*/
  }

--
 (setq mail '("tale@pawl.rpi.edu" "tale@itsgw.rpi.edu" "tale@rpitsmts.bitnet"))
  "I realize the Internet isn't the whole world, but it is the center of it."
                                                        -- Greg Woods