dstconvert: Patch to change owner/group/mode on new file to same as old

Lenny Tropiano lenny at icus.islp.ny.us
Fri Apr 7 02:39:39 AEST 1989


In article <656 at icus.islp.ny.us>, lenny at icus.islp.ny.us (Lenny Tropiano) writes:
> Here's a small patch to dstconvert that will make sure that it will work
> with *any* non-shared libaries compiled binary. This means if it was loaded
> with the -N, -z, etc.. switched, now the magic flag bits are masked, and
> then checked.  Mike Levin (magnus!levin) sent me his version, I modified
> it slightly to work like /bin/file does with the /etc/magic checking.
> 

Here's another enhancement that will help those people (like me) remember
to change the mode, owner, and group of the new file.  This enhancement
follows the previous patch (posted to this group) and will change the
modes of the new binary to match the old binary.  Then the mv(1) command
can be used and will keep the modes the same.

NOTE:  Found another file that needs to be converted for those who have
DOS-73 boards.   /usr/bin/DOS-73.

I'm sure there are more, I'll do an exhaustive search and post my results.

-Lenny

-- Feed to patch -- -- Feed to patch -- -- Feed to patch -- -- Feed to patch --
*** o.dstconvert.c	Thu Apr  6 12:07:34 1989
--- dstconvert.c	Thu Apr  6 12:31:09 1989
***************
*** 5,10
  ** E-Mail address:  ...!icus!lenny -or- lenny at icus.islp.ny.us           **
  ** Organization:    ICUS Software Systems     (c)1989                   **
  ** Date:            March 30, 1989                                      **
  **                                                                      **
  **************************************************************************
  **                                                                      **

--- 5,12 -----
  ** E-Mail address:  ...!icus!lenny -or- lenny at icus.islp.ny.us           **
  ** Organization:    ICUS Software Systems     (c)1989                   **
  ** Date:            March 30, 1989                                      **
+ ** Revision History:   April 5th - Check for any type of binary magic   **
+ **                     April 6th - Change the owners and permissions    **
  **                                                                      **
  **************************************************************************
  **                                                                      **
***************
*** 29,34
  \************************************************************************/
  
  #include <stdio.h>
  
  char	buffer[BUFSIZ];		/* big buffer */
  char	*progname;		/* program name */

--- 31,38 -----
  \************************************************************************/
  
  #include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
  
  char	buffer[BUFSIZ];		/* big buffer */
  char	*progname;		/* program name */
***************
*** 78,83
  	}
  
  	changed_flag = convert_dst(infp, outfp);
  	if (changed_flag == 1) {
  		printf("%s: converted to new daylight savings file format.\n",
  			progname);

--- 82,90 -----
  	}
  
  	changed_flag = convert_dst(infp, outfp);
+ 
+ 	fclose(infp);
+ 
  	if (changed_flag == 1) {
  		printf("%s: converted to new daylight savings file format.\n",
  			progname);
***************
*** 81,86
  	if (changed_flag == 1) {
  		printf("%s: converted to new daylight savings file format.\n",
  			progname);
  	} else if (changed_flag == -1) {
  		fprintf(stderr,"%s: file already converted to new daylight savings file format.\n",
  			progname);

--- 88,95 -----
  	if (changed_flag == 1) {
  		printf("%s: converted to new daylight savings file format.\n",
  			progname);
+ 		fclose(outfp);
+ 		change_file_stats(infile, outfile);
  	} else if (changed_flag == -1) {
  		fprintf(stderr,"%s: file already converted to new daylight savings file format.\n",
  			progname);
***************
*** 95,103
  		exit(1);
  	}
  
- 	fclose(infp);
- 	fclose(outfp);
- 
  	exit(0);
  
  }

--- 104,109 -----
  		exit(1);
  	}
  
  	exit(0);
  
  }
***************
*** 161,165
  			ch2 = ch3;
  			ch3 = fgetc(infp);
  		}
  	}
  }

--- 167,197 -----
  			ch2 = ch3;
  			ch3 = fgetc(infp);
  		}
+ 	}
+ }
+ 
+ change_file_stats(infile, outfile)
+ char *infile, *outfile;
+ {
+ 	struct	stat	statbuf;	/* file modes */
+ 	ushort	owner, group;		/* owner and group */
+ 	ushort	mode;			/* permission */
+ 
+ 	if (stat(infile, &statbuf) == -1) {
+ 		perror("Can't stat(2)");
+ 		exit(1);
+ 	}
+ 	owner = statbuf.st_uid;
+ 	group = statbuf.st_gid;
+ 	mode =  statbuf.st_mode;
+ 
+ 	if (chmod(outfile, mode) == -1) {
+ 		perror("Can't chmod(2)");
+ 		exit(1);
+ 	}
+ 
+ 	if (chown(outfile, owner, group) == -1) {
+ 		perror("Can't chown(2)");
+ 		exit(1);
  	}
  }
-- 
Lenny Tropiano             ICUS Software Systems         [w] +1 (516) 582-5525
lenny at icus.islp.ny.us      Telex; 154232428 ICUS         [h] +1 (516) 968-8576
{talcott,decuac,boulder,hombre,pacbell,sbcs}!icus!lenny  attmail!icus!lenny
        ICUS Software Systems -- PO Box 1; Islip Terrace, NY  11752



More information about the Comp.sys.att mailing list