From owner-freebsd-arch@FreeBSD.ORG Wed Jan 14 12:42:49 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 65A6F16A4CE; Wed, 14 Jan 2004 12:42:49 -0800 (PST) Received: from kientzle.com (h-66-166-149-50.SNVACAID.covad.net [66.166.149.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id F247A43D1D; Wed, 14 Jan 2004 12:42:29 -0800 (PST) (envelope-from kientzle@acm.org) Received: from acm.org ([66.166.149.54]) by kientzle.com (8.12.9/8.12.9) with ESMTP id i0EKgHkX074721; Wed, 14 Jan 2004 12:42:18 -0800 (PST) (envelope-from kientzle@acm.org) Message-ID: <4005A9A9.6090503@acm.org> Date: Wed, 14 Jan 2004 12:42:17 -0800 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.4) Gecko/20031006 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "M. Warner Losh" References: <4004D445.7020205@acm.org> <20040114.131705.93652359.imp@bsdimp.com> In-Reply-To: <20040114.131705.93652359.imp@bsdimp.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: rwatson@freebsd.org cc: freebsd-arch@freebsd.org Subject: Re: Request for Comments: libarchive, bsdtar X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: kientzle@acm.org List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Jan 2004 20:42:49 -0000 M. Warner Losh wrote: > In message: > Robert Watson writes: > : I know NetBSD has a neat tool to create file systems from userspace > : without privilege, but my understanding is that it has to pull in a lot of > : code from the kernel in fairly messy ways. Since tar files are a well > : supported portable format... :-) > > The problem then reduces to needing to be able to create the tar file > with ownership/permissions different than is in the unpriv'd build > tree. Generation of this list, as well as getting tar/whatever to > honor it are interesting problems. Not all that interesting, really. ;-) For example, the following simple C program uses libarchive to read an archive from stdin, and write a new ustar/gzip archive to stdout with all entries owned by 'root'. You just create the archive as usual and then feed it through this filter to create a new archive with the proper ownership/permissions. The same technique can be used add entries to an archive, remove entries from an archive, rename archive entries, convert archive formats, etc. struct archive *in; struct archive *out; struct archive_entry *entry; /* Read an archive from stdin: format/compression will be auto-detected. */ in = archive_read_new(); archive_read_support_format_all(in); archive_read_support_compression_all(in); archive_read_open_file(in, NULL); /* NULL == stdin */ /* Write a ustar/gzip archive to stdout. */ out = archive_write_new(); archive_write_set_compression_gzip(out); archive_write_set_format_ustar(out); archive_write_open_file(out, NULL); /* NULL == stdout */ /* Copy entries over, doing any necessary editing */ while (archive_read_next_header(in, &entry) == ARCHIVE_READ_OK) { /* Edit the entry as appropriate */ archive_entry_set_uid(entry, 0); archive_entry_set_uname(entry, "root"); /* Write a header to the output archive */ archive_write_header(out, entry); /* TODO: XXX Copy data to output archive XXX */ } /* All done */ archive_write_finish(out); archive_read_finish(in);