From owner-svn-soc-all@FreeBSD.ORG Sat Sep 7 20:44:42 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]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B8230FB0 for ; Sat, 7 Sep 2013 20:44:42 +0000 (UTC) (envelope-from dpl@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 988302496 for ; Sat, 7 Sep 2013 20:44:42 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r87Kigde066000 for ; Sat, 7 Sep 2013 20:44:42 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r87KigCB065996 for svn-soc-all@FreeBSD.org; Sat, 7 Sep 2013 20:44:42 GMT (envelope-from dpl@FreeBSD.org) Date: Sat, 7 Sep 2013 20:44:42 GMT Message-Id: <201309072044.r87KigCB065996@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: r257100 - soc2013/dpl/head/contrib/xz/src/xz 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: Sat, 07 Sep 2013 20:44:42 -0000 Author: dpl Date: Sat Sep 7 20:44:42 2013 New Revision: 257100 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257100 Log: Updated xz to cope with the new Capsicum interface. Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c soc2013/dpl/head/contrib/xz/src/xz/file_io.h soc2013/dpl/head/contrib/xz/src/xz/main.c Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.c Sat Sep 7 19:43:39 2013 (r257099) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.c Sat Sep 7 20:44:42 2013 (r257100) @@ -1013,42 +1013,27 @@ if( opt_mode != MODE_TEST ) io_open_dest(pairs[i]); #if defined(CAPSICUM) - limitfd(pairs[i]); + limitpair(pairs[i]); #endif } return pairs; } #if defined(CAPSICUM) +void limitfd(int, unsigned long long); + extern void -limitfd(file_pair *pair) +limitpair(file_pair *pair) { - cap_rights_t rights; + if(pair->dir_fd != -1 ) + limitfd(pair->dir_fd, CAP_FSTATAT|CAP_UNLINKAT|CAP_LOOKUP); - if(pair->dir_fd != -1 ){ - rights = CAP_FSTATAT|CAP_UNLINKAT|CAP_LOOKUP; - if (cap_rights_limit(pair->dir_fd, rights) < 0 && errno != ENOSYS){ - message_error("%s: %s", pair->dest_name, strerror(errno)); - exit(E_ERROR); - } - } + if(pair->src_fd != -1 ) + limitfd(pair->src_fd, CAP_READ|CAP_SEEK); - if(pair->src_fd != -1 ){ - rights = CAP_READ|CAP_SEEK; - if (cap_rights_limit(pair->src_fd, rights) < 0 && errno != ENOSYS){ - message_error("%s: %s", pair->src_name, strerror(errno)); - exit(E_ERROR); - } - } + if(pair->dest_fd != -1 ) + limitfd(pair->dest_fd, CAP_WRITE|CAP_FSTAT|CAP_FCHOWN|CAP_FCHMOD|CAP_FUTIMES); - if(pair->dest_fd != -1 ){ - rights = CAP_WRITE|CAP_FSTAT|CAP_FCHOWN - |CAP_FCHMOD|CAP_FUTIMES; - if (cap_rights_limit(pair->dest_fd, rights) < 0 && errno != ENOSYS){ - message_error("%s: %s", pair->dest_name, strerror(errno)); - exit(E_ERROR); - } - } return; } @@ -1057,36 +1042,35 @@ { cap_rights_t rights; - if( cap_rights_get(STDIN_FILENO, &rights) < 0 && errno != ENOSYS) { - message_error("%d: %s", STDIN_FILENO, strerror(errno)); - exit(E_ERROR); - } else if (rights == 0) { - if (cap_rights_limit(STDIN_FILENO, CAP_WRITE) < 0 && errno != ENOSYS){ - message_error("%d: %s", STDIN_FILENO, strerror(errno)); - exit(E_ERROR); - } - } + cap_rights_init(&rights); + limitfd( STDIN_FILENO, CAP_READ); + limitfd( STDOUT_FILENO, CAP_WRITE); + limitfd( STDERR_FILENO, CAP_WRITE); - if( cap_rights_get(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS) { - message_error("%d: %s", STDOUT_FILENO, strerror(errno)); + if (cap_enter() < 0 && errno != ENOSYS) { + message_error("cap_enter: %s", strerror(errno)); exit(E_ERROR); - } else if (rights == 0) { - if (cap_rights_limit(STDOUT_FILENO, CAP_WRITE) < 0 && errno != ENOSYS){ - message_error("%d: %s", STDOUT_FILENO, strerror(errno)); - exit(E_ERROR); - } } - if (cap_rights_limit(STDERR_FILENO, CAP_WRITE) < 0 && errno != ENOSYS){ - message_error("%d: %s", STDERR_FILENO, strerror(errno)); - exit(E_ERROR); - } + return; +} - if (cap_enter() < 0 && errno != ENOSYS){ - message_error("cap_enter: %s", strerror(errno)); +void +limitfd(int fd, unsigned long long cap) +{ + cap_rights_t rights; + + cap_rights_init(&rights); + cap_rights_set(&rights, cap); + + if( cap_rights_get(fd, &rights) < 0 && errno != ENOSYS) { + message_error("%d: %s", fd, strerror(errno)); exit(E_ERROR); + } else { + if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS){ + message_error("%d: %s", STDIN_FILENO, strerror(errno)); + exit(E_ERROR); + } } - - return; } -#endif +#endif /* CAPSICUM */ Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.h ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.h Sat Sep 7 19:43:39 2013 (r257099) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.h Sat Sep 7 20:44:42 2013 (r257100) @@ -106,7 +106,7 @@ /// \brief Limits fd using FreeBSD's Capsicum framework. /// /// \param fd File descriptor to limit. -extern void limitfd(file_pair *pair); +extern void limitpair(file_pair *pair); /// \brief Enters Capability mode, and limit basic fds. extern void capsicum_enter(void); Modified: soc2013/dpl/head/contrib/xz/src/xz/main.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/main.c Sat Sep 7 19:43:39 2013 (r257099) +++ soc2013/dpl/head/contrib/xz/src/xz/main.c Sat Sep 7 20:44:42 2013 (r257100) @@ -144,6 +144,7 @@ int forkpid, i, nfiles=0; //Filenames will be here, and get passed to io_open_files(). // If we get past of 8 elements, realloc 8 more. + // XXX check char **files = malloc( 8*sizeof(char*) ); #if defined(_WIN32) && !defined(__CYGWIN__)