5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* libadm.a */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern char *devattr(char *device, char *attribute);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern int fpkginfo(struct pkginfo *info, char *pkginst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern int getvol(char *device, char *label, int options, char *prompt);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern int _getvol(char *device, char *label, int options, char *prompt,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define CMDSIZE 512 /* command block size */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define BLK_SIZE 512 /* size of logical block */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ENTRY_MAX 256 /* max size of entry for cpio cmd or header */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define MAP_STAT_SIZE 60 /* 1st line of pkgmap (3 numbers & a : */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void cleanup(void);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int rd_map_size(FILE *fp, int *npts, int *maxpsz, int *cmpsize);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int cat_and_count(struct dm_buf *, char *);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int ckoverwrite(char *dir, char *inst, int options);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int pkgxfer(char *srcinst, int options);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int wdsheader(struct dm_buf *, char *src, char *device,
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amorestatic struct dm_buf *genheader(char *, char **);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int dump_hdr_and_pkgs(BIO *, struct dm_buf *, char **);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern int ds_fd; /* open file descriptor for data stream WHERE? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandchar **xpkg; /* array of transferred packages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland else if ((device[0] == '/') && !isdir(device)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if ((pt = devattr(device, "pathname")) != NULL && !isdir(pt)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* check for datastream */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = pkgtrans(device, (char *)0, allpkg, PT_SILENT|PT_INFO_ONLY,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* pkgtrans has set pkgdir */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) strncpy(buf, pinput, strlen(pinput));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Here we construct the package size summaries for the headers. The
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * pkgmap file associated with fp must be rewound to the beginning of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file. Note that we read three values from pkgmap first line in order
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to get the *actual* size if this package is compressed.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This returns
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 2 : not a compressed package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * 3 : compressed package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and sets has_comp_size to indicate whether or not this is a compressed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandrd_map_size(FILE *fp, int *npts, int *maxpsz, int *cmpsize)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* First read the null terminated first line */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (fgets(line_buffer, MAP_STAT_SIZE, fp) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = sscanf(line_buffer, ": %d %d %d", npts, maxpsz, cmpsize);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 3) /* A valid compressed package entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland else if (n == 2) /* A valid standard package entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland else { /* invalid entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* will return 0, 1, 3, or 99 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland_pkgtrans(char *device1, char *device2, char **pkg, int options,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland keystore_handle_t keystore, char *keystore_alias)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland making_sig = (keystore != NULL) ? B_TRUE : B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* new error object */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* find matching cert and key */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland keystore_alias, &privkey, &pubcert) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get CA certificates */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (find_ca_certs(err, keystore, &cacerts) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get CL (aka "chain") certificates */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (find_cl_certs(err, keystore, &clcerts) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initialize PKCS7 object to be filled in later */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) PKCS7_set_type(sec_pkcs7, NID_pkcs7_signed);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland sec_signerinfo = PKCS7_add_signature(sec_pkcs7,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* add signer cert into signature */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) PKCS7_add_certificate(sec_pkcs7, pubcert);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* attempt to resolve cert chain starting at the signer cert */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (get_cert_chain(err, pubcert, clcerts, cacerts,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * add the verification chain of certs into the signature.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The first cert is the user cert, which we don't need,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * since it's baked in already, so skip it
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 1; i < sk_X509_num(sec_chain); i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* transfer spool to appropriate device */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* check for datastream */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = _getvol(srcdev.bdevice, NULL, NULL,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pkg_gt("Insert %v into %p."), srcdev.norewind)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = pkgmount(&srcdev, NULL, 1, 0, 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strcmp(srcdev.cdevice, dstdev.cdevice) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dstdev.cdevice && !dstdev.bdevice || dstdev.pathname)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!((ods_name = dstdev.cdevice) != NULL ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * output device isn't a stream. If we're making a signed
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * package, then fail, since we can't make signed,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * non-stream pkgs
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strcmp(srcdev.dirname, dstdev.dirname) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((srcdev.pathname && dstdev.pathname) &&
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland strcmp(srcdev.pathname, dstdev.pathname) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (n = _getvol(srcdev.cdevice, NULL, NULL, NULL,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland tmpdir = srcdev.dirname = strdup(srcdev.dirname);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((srcdev.dirname == NULL) || mkdir(srcdev.dirname, 0755) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(pkg_gt(MSG_NOTEMP), srcdev.dirname);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ds_init(ids_name, pkg, srcdev.norewind)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = pkgmount(&srcdev, NULL, 1, 0, 0)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (n = _getvol(ods_name, NULL, DM_FORMAT, NULL,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start up signature data stream */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) PKCS7_content_new(sec_pkcs7, NID_pkcs7_data);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Here we generate all the data that will go into
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the package, and send it through the signature
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * generator, essentially calculating the signature
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of the entire package so we can place it in the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * header. Otherwise we'd have to place it at the end
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of the pkg, which would break the ABI
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stderr, pkg_gt(MSG_SIGNING),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dump_hdr_and_pkgs(p7_bio, hdr, pkg) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * now generate PKCS7 signature
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out header to stream, which includes signature */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (wdsheader(hdr, src, ods_name, pkg, sec_pkcs7)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* nuke in-memory signature for safety */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ds_volno = 1; /* number of volumes in datastream */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* skip past first line in header */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; pkg[i]; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(options & PT_ODTSTREAM) && dstdev.mount) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = pkgmount(&dstdev, NULL, 0, 0, 1)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((options & PT_ODTSTREAM) || (errflg != 2))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * No cleanup of temporary directories created in this
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * function is done here. The calling function must do
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the cleanup.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandpkgtrans(char *device1, char *device2, char **pkg, int options,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland keystore_handle_t keystore, char *keystore_alias)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * setup signal handlers for SIGINT and SIGHUP and release hold
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* hold SIGINT/SIGHUP interrupts */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* hook SIGINT to sigtrap */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* hook SIGHUP to sigtrap */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset signal received count */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* release hold on signals */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * perform the package translation
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland r = _pkgtrans(device1, device2, pkg, options, keystore, keystore_alias);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * reset signal handlers
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* hold SIGINT/SIGHUP interrupts */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset SIGINT */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) sigaction(SIGINT, &nact, (struct sigaction *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reset SIGHUP */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) sigaction(SIGHUP, &nact, (struct sigaction *)NULL);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* if signal received and pkgtrans returned error, call cleanup */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* release hold on signals */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This function concatenates append to the text described in the buf_ctrl
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * structure. This code modifies data in this structure and handles all
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * allocation issues. It returns '0' if everything was successful and '1'
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcat_and_count(struct dm_buf *buf_ctrl, char *append)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* keep allocating until we have enough room to hold string */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((buf_ctrl->offset + (int)strlen(append))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* reallocate (and maybe move) text buffer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland buf_ctrl->allocation + BLK_SIZE)) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* clear the new memory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* adjust total allocation */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* append new string to end of buffer */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland *(buf_ctrl->text_buffer + buf_ctrl->offset) = *append++;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic struct dm_buf *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland char path[MAXPATHLEN], tmp_entry[ENTRY_MAX];
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((hdrbuf.text_buffer = (char *)malloc(BLK_SIZE)) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* clear the new memory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) memset(hdrbuf.text_buffer, '\0', BLK_SIZE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* set up the buffer control structure for the header */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; pkg[i]; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(path, MAXPATHLEN, "%s/%s/%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * totsize contains number of blocks used by the pkginfo files
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dstdev.capacity && totsize > dstdev.capacity) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(pkg_gt(MSG_NOSPACE), totsize, dstdev.capacity);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; pkg[i]; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(path, MAXPATHLEN, "%s/%s/%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Evaluate the first entry in pkgmap */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = rd_map_size(fp, &nparts, &maxpsize, &compressedsize);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n == 3) /* It's a compressed package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* The header needs the *real* size */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland else if (n == 0) /* pkgmap is corrupt */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dstdev.capacity && maxpsize > dstdev.capacity) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* add pkg name, number of parts and the max part size */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (snprintf(tmp_entry, ENTRY_MAX, "%s %d %d",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (dstdev.capacity && dstdev.capacity < totsize) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* partcnt == 0 means skip to next volume */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* first parts/volume number does not count */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandwdsheader(struct dm_buf *hdr, char *src, char *device, char **pkg, PKCS7 *sig)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland making_sig = (sig != NULL) ? B_TRUE : B_FALSE;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The loop below assures compatibility with tapes that don't
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * have a block size (e.g.: Exabyte) by forcing EOR at the end
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of each 512 bytes.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (block_cnt = 0; block_cnt < hdr->allocation;
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) write(ds_fd, (hdr->text_buffer + block_cnt), BLK_SIZE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * write the first cpio() archive to the datastream
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * which should contain the pkginfo & pkgmap files
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for all packages
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) tmpnam(tmp_file); /* temporary file name */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore if ((list_fd = open(tmp_file, O_RDWR | O_CREAT, 0644)) == -1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Create a cpio-compatible list of the requisite files in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the temporary file.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; pkg[i]; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copy pkginfo and pkgmap filenames into the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * temporary string allowing for the first line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * as a special case.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (i == 0) ? "%s/%s\n%s/%s" : "\n%s/%s\n%s/%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * if we're making a signature, we must make a
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * temporary area full of symlinks to the requisite
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * files, plus an extra entry for the signature, so
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * that cpio will put all files and signature in the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * same archive in a single invocation of cpio.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* generate the signature */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (((len = snprintf(path, PATH_MAX, "%s/%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland tmpsymdir, SIGNATURE_FILENAME)) >= PATH_MAX) ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; pkg[i]; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(pkg_gt(MSG_SYMLINK), path, srcpath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(pkg_gt(MSG_SYMLINK), path, srcpath);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copy pkginfo and pkgmap filenames into the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * temporary string allowing for the first line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * as a special case.
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore entry_size = snprintf(tmp_entry, sizeof (tmp_entry),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (i == 0) ? "%s/%s\n%s/%s" : "\n%s/%s\n%s/%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* add signature to list of files */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore entry_size = snprintf(tmp_entry, sizeof (tmp_entry), "\n%s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (write(list_fd, tmp_entry, entry_size) != entry_size) {
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) snprintf(tmp_entry, sizeof (tmp_entry),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * when making a signature, we must make sure to follow
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * symlinks during the cpio so that we don't archive
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the links themselves
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) snprintf(tmp_entry, sizeof (tmp_entry),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save cwd and change to symlink dir for cpio invocation */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = esystem(tmp_entry, list_fd, ds_fd)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* change to back to src dir for subsequent operations */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandckoverwrite(char *dir, char *inst, int options)
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) snprintf(path, sizeof (path), "%s/%s", dir, inst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int i, n, part, nparts, maxpartsize, curpartcnt, iscomp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info.pkginst = NULL; /* required initialization */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * when this routine is entered, the first part of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the package to transfer is already available in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the directory indicated by 'src' --- unless the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * source device is a datstream, in which case only
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the pkginfo and pkgmap files are available in 'src'
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stderr, pkg_gt(MSG_TRANSFER), srcinst);
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) strlcpy(dstinst, srcinst, sizeof (dstinst));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* destination is a (possibly mounted) directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * need to check destination directory to assure
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * that we will not be duplicating a package which
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * already resides there (though we are allowed to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * overwrite the same version)
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) strlcpy(temp, srcinst, sizeof (temp));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (pt = fpkginst(temp, info.arch, info.version)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the same instance already exists, although
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * its pkgid might be different
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) strlcpy(dstinst, pt, sizeof (dstinst));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * find next available instance by appending numbers
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to the package abbreviation until the instance
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * does not exist in the destination directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 2; (access(dstdir, 0) == 0); i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we're allowed to overwrite, but there seems
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to be no valid package to overwrite, and we are
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * not allowed to rename the destination, so act
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * as if we weren't given permission to overwrite
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * --- this keeps us from removing a destination
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance which is named the same as the source
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * instance, but really reflects a different pkg!
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (isdir(dstdir) && mkdir(dstdir, 0755)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (chmod(dstdir, (srcstat.st_mode & S_IAMB)) == -1) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(options & PT_SILENT) && strcmp(dstinst, srcinst))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(stderr, pkg_gt(MSG_RENAME), dstinst);
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) snprintf(srcdir, sizeof (srcdir), "%s/%s", src, srcinst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ids_name) { /* unpack the datatstream into a directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * transfer pkginfo & pkgmap first
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) fprintf(pp, "%s\n%s\n", PKGINFO, PKGMAP);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* don't transfer objects */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * for each part of the package, use cpio() to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * unpack the archive into the destination directory
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland nparts = ds_findpkg(srcdev.cdevice, srcinst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (part = 1; part <= nparts; /* void */) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (ds_getpkg(srcdev.cdevice, part, dstdir)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * since volume is removable, each part
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * must contain a duplicate of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * pkginfo file to properly identify the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (r != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!rd_map_size(fp, &nparts, &maxpartsize, &compressedsize))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write each part of this package */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore /* LINTED E_SEC_SCANF_UNBOUNDED_COPY */
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore if (sscanf(line, "%s %d %d %[ 0-9]", pkgname, &nparts,
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) strlcpy(volnos, tmpvol, sizeof (volnos));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (part = 1; part <= nparts; /* void */) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (curpartcnt == 0 && (options & PT_ODTSTREAM)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n = getvol(ods_name, NULL, DM_FORMAT, prompt))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((ds_fd = open(dstdev.cdevice, O_WRONLY)) < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) sscanf(volnos, "%d %[ 0-9]", &index, tmpvol);
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) strlcpy(volnos, tmpvol, sizeof (volnos));
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) snprintf(cmd, sizeof (cmd), "find %s", PKGINFO);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (iscpio(temp, &iscomp) || isdir(temp) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (iscpio(temp, &iscomp) || isdir(temp) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -print | %s -ocD -C %d",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland logerr(pkg_gt(MSG_STATVFS), dstdir, errno);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland free_blocks = (((long)svfsb.f_frsize > 0) ?
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland howmany(svfsb.f_bsize, DEV_BSIZE)) * svfsb.f_bavail;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((has_comp_size ? compressedsize : maxpartsize) >
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore " -print | %s -pdum %s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = esystem(cmd, -1, (options & PT_ODTSTREAM) ? ds_fd : -1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* unmount current source volume */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* loop until volume is mounted successfully */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* read only */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = pkgmount(&srcdev, NULL, part, nparts, 1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!(options & PT_ODTSTREAM) && dstdev.mount) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* unmount current volume */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* loop until next volume is mounted successfully */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* writable */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland n = pkgmount(&dstdev, NULL, part, nparts, 1);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (isdir(dstdir) && mkdir(dstdir, 0755)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((options & PT_ODTSTREAM) && part <= nparts) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (curpartcnt >= 0 && part > curpartcnt) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((ds_fd = open(dstdev.cdevice, 1)) < 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) sscanf(volnos, "%d %[ 0-9]", &index,
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) strlcpy(volnos, tmpvol, sizeof (volnos));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: pkgdump
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Dump a cpio archive of a package's contents to a BIO.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: srcinst - Name of package, which resides on the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * device pointed to by the static 'srcdev' variable,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * bio - BIO object to dump data to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns : 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * nonzero - failure. errors printed to screen.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland int i, n, part, nparts, maxpartsize, iscomp;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * when this routine is entered, the entire package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is already available at 'src' - including the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * pkginfo/pkgmap files and the objects as well.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* read the pkgmap to get it's size information */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!rd_map_size(fp, &nparts, &maxpartsize, &compressedsize))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* make sure the first volume is available */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(srcdir, MAXPATHLEN, "%s/%s", src, srcinst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * form cpio command that will output the contents of all of
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * this package's parts
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (part = 1; part <= nparts; /* void */) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(cmd, CMDSIZE, "find %s %s",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(cmd, CMDSIZE, "find %s", PKGINFO);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(temp, MAXPATHLEN, "%s.%d", RELOC, part);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (iscpio(temp, &iscomp) || isdir(temp) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(temp, MAXPATHLEN, "%s.%d", ROOT, part);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (iscpio(temp, &iscomp) || isdir(temp) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -print | %s -ocD -C %d",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * execute the command, dumping all standard output
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to the BIO.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (n != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remove any previous tmppath stuff */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* remove temp symbolic links made for signed pkg */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: dump_hdr_and_pkgs
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Dumps datastream header and each package's contents
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to the supplied BIO
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: bio - BIO object to dump data to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * hdr - Header for the datastream being dumped
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * pkglist - NULL-terminated list of packages
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * to dump. The location of the packages are stored
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * in the static 'srcdev' variable.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns : 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * nonzero - failure. errors printed to screen.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlanddump_hdr_and_pkgs(BIO *bio, struct dm_buf *hdr, char **pkglist)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* write out the header to the signature stream */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (block_cnt = 0; block_cnt < hdr->allocation;
4656d4747c8743290bfbe910c64cd75eb4e4af8dGarrett D'Amore (void) BIO_write(bio, (hdr->text_buffer + block_cnt), BLK_SIZE);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* save current directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* now write out each package's contents */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; pkglist[i]; i++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * change to the source dir, so we can find and dump
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the package(s) bits into the BIO
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* change to the package source directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) snprintf(srcdir, MAXPATHLEN, "%s/%s", src, pkglist[i]);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* change back to directory we were in upon entering this routine */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Name: BIO_dump_cmd
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Description: Dump the output of invoking a command
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Arguments: cmd - Command to invoke
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * bio - BIO to dump output of command to
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * only 'stdout' is dumped.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Returns : 0 - success
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * nonzero - failure. errors printed to screen.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* start up the process */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* read output in chunks, transfer to BIO */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (BIO_write(bio, buf, BLK_SIZE) != BLK_SIZE) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* done with stream, make sure no errors were encountered */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* done, close stream, report any errors */