From 62f6f0d13700f5a9c8ce5cb1aa3195ef7b244133 Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Fri, 12 Jan 2018 15:53:33 -0500 Subject: [PATCH] bootadm: remove C code for hsfs boot archive generation --- usr/src/cmd/boot/bootadm/Makefile | 4 +- usr/src/cmd/boot/bootadm/bootadm.c | 284 +----------------------------- usr/src/cmd/boot/bootadm/bootadm.h | 6 - usr/src/cmd/boot/bootadm/bootadm_digest.c | 92 ---------- 4 files changed, 3 insertions(+), 383 deletions(-) delete mode 100644 usr/src/cmd/boot/bootadm/bootadm_digest.c diff --git a/usr/src/cmd/boot/bootadm/Makefile b/usr/src/cmd/boot/bootadm/Makefile index cab311810e..fa26c6c518 100644 --- a/usr/src/cmd/boot/bootadm/Makefile +++ b/usr/src/cmd/boot/bootadm/Makefile @@ -30,7 +30,7 @@ PROG= bootadm SBINLINKS= $(PROG) -OBJS= bootadm.o bootadm_upgrade.o bootadm_digest.o bootadm_loader.o +OBJS= bootadm.o bootadm_upgrade.o bootadm_loader.o SRCS = $(OBJS:.o=.c) POFILES= $(OBJS:%.o=%.po) @@ -40,7 +40,7 @@ POFILE= bootadm_cmd.po .KEEP_STATE: -LDLIBS += -lficl-sys -lmd -lcryptoutil -lnvpair -lgen +LDLIBS += -lficl-sys -lnvpair -lgen LDLIBS += -lz -lbe -lzfs $(LDLIBS_$(MACH)) CPPFLAGS += -D_FILE_OFFSET_BITS=64 diff --git a/usr/src/cmd/boot/bootadm/bootadm.c b/usr/src/cmd/boot/bootadm/bootadm.c index 2a12c71b86..42366046e6 100644 --- a/usr/src/cmd/boot/bootadm/bootadm.c +++ b/usr/src/cmd/boot/bootadm/bootadm.c @@ -2559,75 +2559,6 @@ update_required(char *root) return (1); } -static int -flushfs(char *root) -{ - char cmd[PATH_MAX + 30]; - - (void) snprintf(cmd, sizeof (cmd), "%s -f \"%s\" 2>/dev/null", - LOCKFS_PATH, root); - - return (exec_cmd(cmd, NULL)); -} - -static int -do_archive_copy(char *source, char *dest) -{ - - sync(); - - /* the equivalent of mv archive-new-$pid boot_archive */ - if (rename(source, dest) != 0) { - (void) unlink(source); - return (BAM_ERROR); - } - - if (flushfs(bam_root) != 0) - sync(); - - return (BAM_SUCCESS); -} - -static int -check_cmdline(filelist_t flist) -{ - line_t *lp; - - for (lp = flist.head; lp; lp = lp->next) { - if (strstr(lp->line, "Error:") != NULL || - strstr(lp->line, "Inode number overflow") != NULL) { - (void) fprintf(stderr, "%s\n", lp->line); - return (BAM_ERROR); - } - } - - return (BAM_SUCCESS); -} - -static void -dump_errormsg(filelist_t flist) -{ - line_t *lp; - - for (lp = flist.head; lp; lp = lp->next) - (void) fprintf(stderr, "%s\n", lp->line); -} - -static int -check_archive(char *dest) -{ - struct stat sb; - - if (stat(dest, &sb) != 0 || !S_ISREG(sb.st_mode) || - sb.st_size < 10000) { - bam_error(_("archive file %s not generated correctly\n"), dest); - (void) unlink(dest); - return (BAM_ERROR); - } - - return (BAM_SUCCESS); -} - static boolean_t is_be(char *root) { @@ -2679,230 +2610,17 @@ is_be(char *root) return (be_exist); } -/* - * Returns 1 if mkiso is in the expected PATH, 0 otherwise - */ -static int -is_mkisofs() -{ - if (access(MKISOFS_PATH, X_OK) == 0) - return (1); - return (0); -} - -#define MKISO_PARAMS " -quiet -graft-points -dlrDJN -relaxed-filenames " - -static int -create_sparc_archive(char *archive, char *tempname, char *bootblk, char *list) -{ - int ret; - char cmdline[3 * PATH_MAX + 64]; - filelist_t flist = {0}; - const char *func = "create_sparc_archive()"; - - if (access(bootblk, R_OK) == 1) { - bam_error(_("unable to access bootblk file : %s\n"), bootblk); - return (BAM_ERROR); - } - - /* - * Prepare mkisofs command line and execute it - */ - (void) snprintf(cmdline, sizeof (cmdline), "%s %s -G %s -o \"%s\" " - "-path-list \"%s\" 2>&1", MKISOFS_PATH, MKISO_PARAMS, bootblk, - tempname, list); - - BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); - - ret = exec_cmd(cmdline, &flist); - if (ret != 0 || check_cmdline(flist) == BAM_ERROR) { - dump_errormsg(flist); - goto out_err; - } - - filelist_free(&flist); - - /* - * Prepare dd command line to copy the bootblk on the new archive and - * execute it - */ - (void) snprintf(cmdline, sizeof (cmdline), "%s if=\"%s\" of=\"%s\"" - " bs=1b oseek=1 count=15 conv=notrunc conv=sync 2>&1", DD_PATH_USR, - bootblk, tempname); - - BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); - - ret = exec_cmd(cmdline, &flist); - if (ret != 0 || check_cmdline(flist) == BAM_ERROR) - goto out_err; - - filelist_free(&flist); - - /* Did we get a valid archive ? */ - if (check_archive(tempname) == BAM_ERROR) - return (BAM_ERROR); - - return (do_archive_copy(tempname, archive)); - -out_err: - filelist_free(&flist); - bam_error(_("boot-archive creation FAILED, command: '%s'\n"), cmdline); - (void) unlink(tempname); - return (BAM_ERROR); -} - -/* - * creates sha1 hash of archive - */ -static int -digest_archive(const char *archive) -{ - char *archive_hash; - char *hash; - int ret; - FILE *fp; - - (void) asprintf(&archive_hash, "%s.hash", archive); - if (archive_hash == NULL) - return (BAM_ERROR); - - if ((ret = bootadm_digest(archive, &hash)) == BAM_ERROR) { - free(archive_hash); - return (ret); - } - - fp = fopen(archive_hash, "w"); - if (fp == NULL) { - free(archive_hash); - free(hash); - return (BAM_ERROR); - } - - (void) fprintf(fp, "%s\n", hash); - (void) fclose(fp); - free(hash); - free(archive_hash); - return (BAM_SUCCESS); -} - -static int -create_x86_archive(char *archive, char *tempname, char *update_dir) -{ - int ret; - char cmdline[3 * PATH_MAX + 64]; - filelist_t flist = {0}; - const char *func = "create_x86_archive()"; - - (void) snprintf(cmdline, sizeof (cmdline), "%s %s -o \"%s\" \"%s\" " - "2>&1", MKISOFS_PATH, MKISO_PARAMS, tempname, update_dir); - - BAM_DPRINTF(("%s: executing: %s\n", func, cmdline)); - - ret = exec_cmd(cmdline, &flist); - if (ret != 0 || check_cmdline(flist) == BAM_ERROR) { - bam_error(_("boot-archive creation FAILED, command: '%s'\n"), - cmdline); - dump_errormsg(flist); - filelist_free(&flist); - (void) unlink(tempname); - return (BAM_ERROR); - } - - filelist_free(&flist); - - if (check_archive(tempname) == BAM_ERROR) - return (BAM_ERROR); - - return (do_archive_copy(tempname, archive)); -} - -static int -mkisofs_archive(char *root, int what) -{ - int ret; - char temp[PATH_MAX]; - char bootblk[PATH_MAX]; - char boot_archive[PATH_MAX]; - - if (what == FILE64 && !is_flag_on(IS_SPARC_TARGET)) - ret = snprintf(temp, sizeof (temp), - "%s%s%s/amd64/archive-new-%d", root, ARCHIVE_PREFIX, - get_machine(), getpid()); - else - ret = snprintf(temp, sizeof (temp), "%s%s%s/archive-new-%d", - root, ARCHIVE_PREFIX, get_machine(), getpid()); - - if (ret >= sizeof (temp)) - goto out_path_err; - - if (what == FILE64 && !is_flag_on(IS_SPARC_TARGET)) - ret = snprintf(boot_archive, sizeof (boot_archive), - "%s%s%s/amd64%s", root, ARCHIVE_PREFIX, get_machine(), - ARCHIVE_SUFFIX); - else - ret = snprintf(boot_archive, sizeof (boot_archive), - "%s%s%s%s", root, ARCHIVE_PREFIX, get_machine(), - ARCHIVE_SUFFIX); - - if (ret >= sizeof (boot_archive)) - goto out_path_err; - - bam_print("updating %s\n", boot_archive); - - if (is_flag_on(IS_SPARC_TARGET)) { - ret = snprintf(bootblk, sizeof (bootblk), - "%s/platform/%s/lib/fs/hsfs/bootblk", root, get_machine()); - if (ret >= sizeof (bootblk)) - goto out_path_err; - - ret = create_sparc_archive(boot_archive, temp, bootblk, - get_cachedir(what)); - } else { - ret = create_x86_archive(boot_archive, temp, - get_cachedir(what)); - } - - if (digest_archive(boot_archive) == BAM_ERROR && bam_verbose) - bam_print("boot archive hashing failed\n"); - - if (ret == BAM_SUCCESS && bam_verbose) - bam_print("Successfully created %s\n", boot_archive); - - return (ret); - -out_path_err: - bam_error(_("unable to create path on mountpoint %s, path too long\n"), - root); - return (BAM_ERROR); -} - static error_t create_ramdisk(char *root) { char *cmdline, path[PATH_MAX]; size_t len; struct stat sb; - int ret, what, status = BAM_SUCCESS; - - /* If there is mkisofs, use it to create the required archives */ - if (is_mkisofs()) { - for (what = FILE32; what < CACHEDIR_NUM; what++) { - if (has_cachedir(what) && is_dir_flag_on(what, - NEED_UPDATE)) { - ret = mkisofs_archive(root, what); - if (ret != 0) - status = BAM_ERROR; - } - } - return (status); - } /* - * Else setup command args for create_ramdisk.ksh for the cpio archives + * Setup command args for create_ramdisk.ksh for the cpio archives * Note: we will not create hash here, CREATE_RAMDISK should create it. */ - if (bam_verbose) - bam_print("mkisofs not found, creating cpio archive\n"); (void) snprintf(path, sizeof (path), "%s/%s", root, CREATE_RAMDISK); if (stat(path, &sb) != 0) { diff --git a/usr/src/cmd/boot/bootadm/bootadm.h b/usr/src/cmd/boot/bootadm/bootadm.h index 5f00c54c5b..af9c1df2b7 100644 --- a/usr/src/cmd/boot/bootadm/bootadm.h +++ b/usr/src/cmd/boot/bootadm/bootadm.h @@ -148,7 +148,6 @@ extern int is_grub(const char *); extern char *s_strdup(char *); extern int is_sparc(void); extern int is_zfs(char *); -extern int bootadm_digest(const char *, char **); #define BAM_MAXLINE 8192 @@ -204,11 +203,6 @@ extern int bootadm_digest(const char *, char **); #define XEN_MENU "/boot/$ISADIR/xen.gz" #define HYPERVISOR_KERNEL "/platform/i86xpv/kernel/$ISADIR/unix" -/* Helpers */ -#define MKISOFS_PATH "/usr/bin/mkisofs" -#define DD_PATH_USR "/usr/bin/dd" -#define LOCKFS_PATH "/usr/sbin/lockfs" - /* A first guess at the number of entries in a menu */ #define BAM_ENTRY_NUM 10 diff --git a/usr/src/cmd/boot/bootadm/bootadm_digest.c b/usr/src/cmd/boot/bootadm/bootadm_digest.c deleted file mode 100644 index efcf46d473..0000000000 --- a/usr/src/cmd/boot/bootadm/bootadm_digest.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file and its contents are supplied under the terms of the - * Common Development and Distribution License ("CDDL"), version 1.0. - * You may only use this file in accordance with the terms of version - * 1.0 of the CDDL. - * - * A full copy of the text of the CDDL should have accompanied this - * source. A copy of the CDDL is also available via the Internet at - * http://www.illumos.org/license/CDDL. - */ - -/* - * Copyright 2016 Toomas Soome - * Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved. - */ - -/* - * Create sha1 hash for file. - * - * NOTE: This is hardwired for now, so use libmd's SHA1 for simplicity. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bootadm.h" - -#define BUFFERSIZE (64 * 1024) -static uint8_t buf[BUFFERSIZE]; - -int -bootadm_digest(const char *filename, char **result) -{ - int fd; - char *resultstr = NULL; - uint8_t *resultbuf; - int resultstrlen, resultlen, exitcode; - SHA1_CTX sha1_ctx; - ssize_t nread; - - /* Allocate a buffer to store result. */ - resultlen = SHA1_DIGEST_LENGTH; - if ((resultbuf = malloc(resultlen)) == NULL) { - bam_print(gettext("out of memory\n")); - exitcode = BAM_ERROR; - goto cleanup; - } - - if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) == -1) { - bam_print(gettext("can not open input file %s\n"), filename); - exitcode = BAM_ERROR; - goto cleanup; - } - - SHA1Init(&sha1_ctx); - while ((nread = read(fd, buf, sizeof (buf))) > 0) - SHA1Update(&sha1_ctx, buf, nread); - if (nread == -1) { - bam_print(gettext("error reading file: %s\n"), strerror(errno)); - exitcode = BAM_ERROR; - goto cleanup; - } - SHA1Final(resultbuf, &sha1_ctx); - - /* Allocate a buffer to store result string */ - resultstrlen = 2 * resultlen + 1; /* Two hex chars per byte. */ - if ((resultstr = malloc(resultstrlen)) == NULL) { - bam_print(gettext("out of memory\n")); - exitcode = BAM_ERROR; - goto cleanup; - } - - tohexstr(resultbuf, resultlen, resultstr, resultstrlen); - exitcode = BAM_SUCCESS; - (void) close(fd); -cleanup: - if (exitcode == BAM_ERROR) { - free(resultstr); - resultstr = NULL; - } - - free(resultbuf); - - *result = resultstr; - return (exitcode); -} -- 2.11.4.GIT