From owner-svn-soc-all@FreeBSD.ORG Tue Jul 9 07:15:59 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 71AFD755 for ; Tue, 9 Jul 2013 07:15:59 +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 49BAB1C9E for ; Tue, 9 Jul 2013 07:15:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r697FxNB030321 for ; Tue, 9 Jul 2013 07:15:59 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r697FxxE030319 for svn-soc-all@FreeBSD.org; Tue, 9 Jul 2013 07:15:59 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 9 Jul 2013 07:15:59 GMT Message-Id: <201307090715.r697FxxE030319@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: r254452 - 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: Tue, 09 Jul 2013 07:15:59 -0000 Author: dpl Date: Tue Jul 9 07:15:59 2013 New Revision: 254452 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254452 Log: Added functions to enter capability mode, and limitfds. Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c Modified: soc2013/dpl/head/contrib/xz/src/xz/file_io.c ============================================================================== --- soc2013/dpl/head/contrib/xz/src/xz/file_io.c Tue Jul 9 07:13:20 2013 (r254451) +++ soc2013/dpl/head/contrib/xz/src/xz/file_io.c Tue Jul 9 07:15:59 2013 (r254452) @@ -604,6 +604,7 @@ free(pair->dest_name); return true; } + limitfd(pair); } // If this really fails... well, we have a safe fallback. @@ -956,14 +957,49 @@ return io_write_buf(pair, buf->u8, size); } -#if CAPSICUM +#if defined(CAPSICUM) extern void -limitfd(struct file_pair *pair) +limitfd(file_pair *pair) { cap_rights_t rights = 0; - + rights |= CAP_READ; + if (cap_rights_limit(pair->src_fd, rights) < 0 && errno != ENOSYS){ + message_error("%s: %s", pair->src_name, strerror(errno)); + exit(E_ERROR); + } + rights |= CAP_WRITE|CAP_FSTAT|CAP_FCHOWN; + rights |= 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; } -#endif \ No newline at end of file + +extern void +cap_init(void) +{ + if (cap_rights_limit(STDIN_FILENO, CAP_READ) < 0 && errno != ENOSYS){ + message_error("%d: %s", STDIN_FILENO, strerror(errno)); + exit(E_ERROR); + } + + 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); + } + + if (cap_enter() < 0 && errno != ENOSYS){ + message_error("cap_enter: %s", strerror(errno)); + exit(E_ERROR); + } + return; +} +#endif