Index: usr.sbin/efivar/efivar.c =================================================================== --- usr.sbin/efivar/efivar.c +++ usr.sbin/efivar/efivar.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,8 @@ static int aflag, Aflag, bflag, dflag, Dflag, Hflag, Nflag, lflag, Lflag, Rflag, wflag, pflag; static char *varname; -static u_long attrib = 0x7; +static char *from = NULL; +static uint32_t attrib = 0; static void usage(void) @@ -92,14 +94,22 @@ get_value(char *val, size_t *datalen) { static char buffer[16*1024]; + int fd = 0; if (val != NULL) { *datalen = strlen(val); return ((uint8_t *)val); } /* Read from stdin */ + if (from != NULL) { + fd = open(from, O_RDONLY, 0); + if (fd < 0) + return NULL; + } *datalen = sizeof(buffer); - *datalen = read(0, buffer, *datalen); + *datalen = read(fd, buffer, *datalen); + if (fd != 0) + close(fd); return ((uint8_t *)buffer); } @@ -110,9 +120,15 @@ efi_guid_t guid; size_t datalen; uint8_t *data; + uint32_t old_attrib = 0; breakdown_name(name, &guid, &vname); + if (efi_get_variable(guid, vname, NULL, &datalen, &old_attrib) < 0) + err(1, "efi_get_variable"); + if (attrib == 0) + attrib = old_attrib; data = get_value(val, &datalen); + attrib |= EFI_VARIABLE_APPEND_WRITE; if (efi_append_variable(guid, vname, data, datalen, attrib) < 0) err(1, "efi_append_variable"); } @@ -135,8 +151,13 @@ efi_guid_t guid; size_t datalen; uint8_t *data; + uint32_t old_attrib = 0; breakdown_name(name, &guid, &vname); + if (efi_get_variable(guid, vname, NULL, &datalen, &old_attrib) < 0) + err(1, "efi_get_variable"); + if (attrib == 0) + attrib = old_attrib; data = get_value(val, &datalen); if (efi_set_variable(guid, vname, data, datalen, attrib, 0) < 0) err(1, "efi_set_variable"); @@ -297,8 +318,12 @@ case 'w': wflag++; break; - case 'f': case 't': + attrib = strtoul(optarg, NULL, 0); + break; + case 'f': + from = optarg; + break; case 0: errx(1, "unknown or unimplemented option\n"); break;