From owner-svn-soc-all@FreeBSD.ORG Fri Jul 5 22:02:02 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id E2F29494 for ; Fri, 5 Jul 2013 22:02:02 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id D4635179E for ; Fri, 5 Jul 2013 22:02:02 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r65M22qv053463 for ; Fri, 5 Jul 2013 22:02:02 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r65M22Lf053454 for svn-soc-all@FreeBSD.org; Fri, 5 Jul 2013 22:02:02 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 5 Jul 2013 22:02:02 GMT Message-Id: <201307052202.r65M22Lf053454@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r254192 - soc2013/dpl/head/contrib/bzip2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jul 2013 22:02:03 -0000 Author: dpl Date: Fri Jul 5 22:02:02 2013 New Revision: 254192 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254192 Log: Start adapting stat,lstat and utime to be used with fds, fstatat() and futimes() Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c Modified: soc2013/dpl/head/contrib/bzip2/bzip2.c ============================================================================== --- soc2013/dpl/head/contrib/bzip2/bzip2.c Fri Jul 5 21:41:05 2013 (r254191) +++ soc2013/dpl/head/contrib/bzip2/bzip2.c Fri Jul 5 22:02:02 2013 (r254192) @@ -75,8 +75,9 @@ # include # define PATH_SEP '/' -# define MY_LSTAT lstat -# define MY_STAT stat +# define MY_LSTAT fstatat +# define MY_STAT fstatat +# define MY_STATS stat # define MY_S_ISREG S_ISREG # define MY_S_ISDIR S_ISDIR @@ -223,8 +224,8 @@ Int32 workFactor; #if CAPSICUM -#define IN_FILENO fileno(outStr) -#define OUT_FILENO fileno(inStr) +#define IN_FILENO fileno(inStr) +#define OUT_FILENO fileno(outStr) void limitfd(int); FILE *inStr; FILE *outStr; @@ -678,24 +679,21 @@ void limitfd(int fd) { - cap_rights_t rights = 0; + cap_rights_t rights; - if (fd == IN_FILENO) - rights |= CAP_READ; - else if (fd == OUT_FILENO) - rights |= CAP_WRITE; + if (fd == OUT_FILENO) + rights = CAP_READ|CAP_FSTAT|CAP_WRITE|CAP_FCHMOD|CAP_FCHOWN|CAP_FUTIMES; + else if (fd == IN_FILENO) + rights = CAP_WRITE|CAP_READ|CAP_FSTAT; else if (fd == STDERR_FILENO) - rights |= CAP_WRITE; - else - abort(); -/* + rights = CAP_WRITE; + if (cap_rights_limit(fd, rights) < 0 && errno != ENOSYS){ fprintf ( stderr, "%s: Couldn't limit rights for descriptor %d: %s.\n", progName, fd, strerror(errno)); setExit(1); exit(exitValue); } -*/ } #endif @@ -732,7 +730,7 @@ void cleanUpAndFail ( Int32 ec ) { IntNative retVal; - struct MY_STAT statBuf; + struct MY_STATS statBuf; if ( srcMode == SM_F2F && opMode != OM_TEST @@ -1023,12 +1021,12 @@ if in doubt, return True --*/ static -Bool notAStandardFile ( Char* name ) +Bool notAStandardFile (int fd ) { IntNative i; - struct MY_STAT statBuf; + struct MY_STATS statBuf; - i = MY_LSTAT ( name, &statBuf ); + i = MY_LSTAT ( fd, &statBuf ); if (i != 0) return True; if (MY_S_ISREG(statBuf.st_mode)) return False; return True; @@ -1040,12 +1038,12 @@ rac 11/21/98 see if file has hard links to it --*/ static -Int32 countHardLinks ( Char* name ) +Int32 countHardLinks ( int fd ) { IntNative i; struct MY_STAT statBuf; - i = MY_LSTAT ( name, &statBuf ); + i = MY_LSTAT ( fd, &statBuf ); if (i != 0) return 0; return (statBuf.st_nlink - 1); } @@ -1241,7 +1239,7 @@ return; } } - if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) { + if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( IN_FILENO )) { if (noisy) fprintf ( stderr, "%s: Input file %s is not a normal file.\n", progName, inName ); @@ -1259,7 +1257,7 @@ } } if ( srcMode == SM_F2F && !forceOverwrite && - (n=countHardLinks ( inName )) > 0) { + (n=countHardLinks ( IN_FILENO )) > 0) { fprintf ( stderr, "%s: Input file %s has %d other link%s.\n", progName, inName, n, n > 1 ? "s" : "" ); setExit(1); @@ -1350,17 +1348,15 @@ wait(NULL); return; } else if (forkpid == 0){ - limitfd(fileno(inStr)); - limitfd(fileno(outStr)); + limitfd(IN_FILENO)); + limitfd(OUT_FILENO); limitfd(STDERR_FILENO); -/* - if (cap_enter() < 0){ + if (cap_enter() < 0 && errno != ENOSYS){ fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); } -*/ # endif /*--- Now the input and output handles are sane. Do the Biz. ---*/ outputHandleJustInCase = outStr; @@ -1451,7 +1447,7 @@ return; } } - if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) { + if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( IN_FILENO )) { if (noisy) fprintf ( stderr, "%s: Input file %s is not a normal file.\n", progName, inName ); @@ -1476,7 +1472,7 @@ } } if ( srcMode == SM_F2F && !forceOverwrite && - (n=countHardLinks ( inName ) ) > 0) { + (n=countHardLinks ( IN_FILENO ) ) > 0) { fprintf ( stderr, "%s: Input file %s has %d other link%s.\n", progName, inName, n, n > 1 ? "s" : "" ); setExit(1); @@ -1559,17 +1555,16 @@ wait(NULL); return; } else if (forkpid == 0){ - limitfd(fileno(inStr)); - limitfd(fileno(outStr)); + limitfd(IN_FILENO); + limitfd(OUT_FILENO); limitfd(STDERR_FILENO); -/* - if (cap_enter() < 0){ + if (cap_enter() < 0 && errno != ENOSYS){ fprintf ( stderr, "%s: Couldn't enter capability mode: %s.\n", progName, strerror(errno) ); setExit(1); exit(exitValue); + } -*/ # endif /*--- Now the input and output handles are sane. Do the Biz. ---*/ outputHandleJustInCase = outStr;