/* * Clear existing diagnostic results for the specified diagnostic * and optionally for the specified device. */ void diag_clear_results(const enum diagnostic_test type, const NVM_BOOL clear_specific_device, const NVM_GUID device_guid) { int event_count; PersistentStore *p_store = get_lib_store(); if (p_store) { db_get_event_count_by_event_type_type(p_store, type, &event_count); struct db_event events[event_count]; db_get_events_by_event_type_type(p_store, type, events, event_count); for (int i = 0; i < event_count; i++) { NVM_BOOL matched = 1; // check for a matching guid is requested if (clear_specific_device) { COMMON_GUID guid; str_to_guid(events[i].guid, guid); if (guid_cmp(guid, device_guid) != 1) { matched = 0; } } if (matched) { db_delete_event_by_id(p_store, events[i].id); } } } }
std::list<NVM_UINT16> wbem::logic::PostLayoutAddressDecoderLimitCheck::getListOfSocketsInLayout( const struct MemoryAllocationLayout &layout) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); std::list<NVM_UINT16> socketList; for (std::map<std::string, struct config_goal>::const_iterator iter = layout.goals.begin(); iter != layout.goals.end(); iter++) { NVM_GUID guid; str_to_guid((*iter).first.c_str(), guid); NVM_UINT16 socketId = getSocketIdForDimm(guid); socketList.push_back(socketId); } socketList.sort(); socketList.unique(); return socketList; }
std::vector<struct config_goal> wbem::logic::PostLayoutAddressDecoderLimitCheck::getConfigGoalsForSocket( const struct MemoryAllocationLayout &layout, const NVM_UINT16 socketId) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); std::vector<struct config_goal> configGoalList; for (std::map<std::string, struct config_goal>::const_iterator iter = layout.goals.begin(); iter != layout.goals.end(); iter++) { NVM_GUID guid; str_to_guid((*iter).first.c_str(), guid); NVM_UINT16 dimmSocketId = getSocketIdForDimm(guid); if (dimmSocketId == socketId) { configGoalList.push_back((*iter).second); } } return configGoalList; }
int main(int argc, char *argv[]) { char *certfile, *efifile; const char *progname = argv[0]; int rsasig; EFI_GUID owner = { 0 }; while (argc > 1) { if (strcmp("--version", argv[1]) == 0) { version(progname); exit(0); } else if (strcmp("--help", argv[1]) == 0) { help(progname); exit(0); } else if (strcmp("-g", argv[1]) == 0) { str_to_guid(argv[2], &owner); argv += 2; argc -= 2; } else if (strcmp("-r", argv[1]) == 0) { rsasig = 1; argv += 1; argc += 1; } else { break; } } if (argc != 3) { exit(1); } certfile = argv[1]; efifile = argv[2]; ERR_load_crypto_strings(); OpenSSL_add_all_digests(); OpenSSL_add_all_ciphers(); BIO *cert_bio = BIO_new_file(certfile, "r"); X509 *cert = PEM_read_bio_X509(cert_bio, NULL, NULL, NULL); int PkCertLen = i2d_X509(cert, NULL); PkCertLen += sizeof(EFI_SIGNATURE_LIST) + OFFSET_OF(EFI_SIGNATURE_DATA, SignatureData); EFI_SIGNATURE_LIST *PkCert = malloc (PkCertLen); if (!PkCert) { fprintf(stderr, "failed to malloc cert\n"); exit(1); } unsigned char *tmp = (unsigned char *)PkCert + sizeof(EFI_SIGNATURE_LIST) + OFFSET_OF(EFI_SIGNATURE_DATA, SignatureData); i2d_X509(cert, &tmp); PkCert->SignatureListSize = PkCertLen; PkCert->SignatureSize = (UINT32) (PkCertLen - sizeof(EFI_SIGNATURE_LIST)); PkCert->SignatureHeaderSize = 0; PkCert->SignatureType = EFI_CERT_X509_GUID; EFI_SIGNATURE_DATA *PkCertData = (void *)PkCert + sizeof(EFI_SIGNATURE_LIST); PkCertData->SignatureOwner = owner; FILE *f = fopen(efifile, "w"); if (!f) { fprintf(stderr, "failed to open efi file %s: ", efifile); perror(""); exit(1); } if (fwrite(PkCert, 1, PkCertLen, f) != PkCertLen) { perror("Did not write enough bytes to efi file"); exit(1); } return 0; }
int main(int argc, char *argv[]) { char *progname = argv[0], *buf, *vardata, *timestampstr = NULL; uint32_t attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; int flashfile, varfile, i, offset, varlen, varfilesize, listvars = 0; const int chunk = 8; wchar_t var[128]; struct stat st; EFI_GUID *owner = NULL, guid; EFI_TIME timestamp; while (argc > 1 && argv[1][0] == '-') { if (strcmp("--version", argv[1]) == 0) { version(progname); exit(0); } else if (strcmp("--help", argv[1]) == 0) { help(progname); exit(0); } else if (strcmp(argv[1], "-g") == 0) { if (str_to_guid(argv[2], &guid)) { fprintf(stderr, "Invalid GUID %s\n", argv[2]); exit(1); } owner = &guid; argv += 2; argc -= 2; } else if (strcmp("-t", argv[1]) == 0) { timestampstr = argv[2]; argv += 2; argc -= 2; } else if (strcmp("-l", argv[1]) == 0) { listvars = 1; argv += 1; argc -= 1; } else { /* unrecognised option */ break; } } if ((argc != 4 && !listvars) || (argc != 2 && listvars)) { usage(progname); exit(1); } /* copy to wchar16_t including trailing zero */ for (i = 0; i < strlen(argv[2]) + 1; i++) var[i] = argv[2][i]; varlen = i*2; /* size of storage including zero */ if (!owner) owner = get_owner_guid(argv[2]); if (!owner) { fprintf(stderr, "variable %s has no defined guid, one must be specified\n", argv[2]); exit(1); } memset(×tamp, 0, sizeof(timestamp)); time_t t; struct tm *tm, tms; memset(&tms, 0, sizeof(tms)); if (timestampstr) { strptime(timestampstr, "%Y-%m-%d %H:%M:%S", &tms); tm = &tms; } else { time(&t); tm = localtime(&t); } /* timestamp.Year is from 0 not 1900 as tm year is */ timestamp.Year = tm->tm_year + 1900; /* timestamp Month is 1-12 not 0-11 as tm_mon is */ timestamp.Month = tm->tm_mon + 1; timestamp.Day = tm->tm_mday; timestamp.Hour = tm->tm_hour; timestamp.Minute = tm->tm_min; timestamp.Second = tm->tm_sec; printf("Timestamp is %d-%d-%d %02d:%02d:%02d\n", timestamp.Year, timestamp.Month, timestamp.Day, timestamp.Hour, timestamp.Minute, timestamp.Second); flashfile = open(argv[1], O_RDWR); if (flashfile < 0) { fprintf(stderr, "Failed to read file %s:", argv[1]); perror(""); } varfile = open(argv[3], O_RDONLY); if (varfile < 0) { fprintf(stderr, "Failed to read file %s:", argv[1]); perror(""); } fstat(varfile, &st); varfilesize = st.st_size; vardata = malloc(varfilesize); if (read(varfile, vardata, varfilesize) != varfilesize) { perror("Failed to read variable file"); exit(1); } close(varfile); buf = malloc(sizeof(EFI_GUID)); for (i = 0; ; i += chunk) { lseek(flashfile, i, SEEK_SET); if (read(flashfile, buf, sizeof(EFI_GUID)) != sizeof(EFI_GUID)) goto eof; if (memcmp(buf, &SECURE_VARIABLE_GUID, sizeof(EFI_GUID)) == 0) break; } offset = i; printf("Variable header found at offset 0x%x\n", offset); lseek(flashfile, offset, SEEK_SET); free(buf); buf = malloc(sizeof(VARIABLE_STORE_HEADER)); read(flashfile, buf, sizeof(VARIABLE_STORE_HEADER)); VARIABLE_STORE_HEADER *vsh = (VARIABLE_STORE_HEADER *)buf; if (vsh->Format != VARIABLE_STORE_FORMATTED && vsh->State != VARIABLE_STORE_HEALTHY) { fprintf(stderr, "Variable store header is corrupt\n"); exit(1); } UINT32 size = vsh->Size; free(buf); buf = malloc(size); lseek(flashfile, offset, SEEK_SET); read(flashfile, buf, size); vsh = (VARIABLE_STORE_HEADER *)buf; printf("Variable Store Size = 0x%x\n", vsh->Size); VARIABLE_HEADER *vh = (void *)HEADER_ALIGN(vsh + 1); printf("variables begin at 0x%x\n", (int)((char *)vh - (char *)vsh)); for (i = 0; IsValidVariableHeader(vh); i++) { vh = (void *)HEADER_ALIGN((char *)(vh + 1) + vh->NameSize + vh->DataSize); } printf("Found %d variables, now at offset %ld\n", i, (long)((char *)vh - (char *)vsh)); memset(vh, 0, sizeof(*vh)); vh->StartId = VARIABLE_DATA; vh->State = VAR_ADDED; vh->Attributes = attributes; vh->NameSize = varlen; vh->DataSize = varfilesize; vh->TimeStamp = timestamp; vh->VendorGuid = *owner; buf = (void *)(vh + 1); memcpy (buf, var, varlen); buf += varlen; memcpy (buf, vardata, varfilesize); lseek(flashfile, offset, SEEK_SET); write(flashfile, vsh, vsh->Size); close(flashfile); exit(0); eof: printf("No variables found in file at offset 0x%x\n", i); exit(2); }
int find_dp(struct part_iter **_iter) { struct part_iter *iter = NULL; struct disk_info diskinfo; struct guid gpt_guid; uint64_t fs_lba; int drive, hd, partition; const union syslinux_derivative_info *sdi; sdi = syslinux_derivative_info(); if (!strncmp(opt.drivename, "mbr", 3)) { if (find_by_sig(strtoul(opt.drivename + 4, NULL, 0), &iter) < 0) { error("Unable to find requested MBR signature."); goto bail; } } else if (!strncmp(opt.drivename, "guid", 4)) { if (str_to_guid(opt.drivename + 5, &gpt_guid)) goto bail; if (find_by_guid(&gpt_guid, &iter) < 0) { error("Unable to find requested GPT disk or partition by guid."); goto bail; } } else if (!strncmp(opt.drivename, "label", 5)) { if (!opt.drivename[6]) { error("No label specified."); goto bail; } if (find_by_label(opt.drivename + 6, &iter) < 0) { error("Unable to find requested GPT partition by label."); goto bail; } } else if ((opt.drivename[0] == 'h' || opt.drivename[0] == 'f') && opt.drivename[1] == 'd') { hd = opt.drivename[0] == 'h' ? 0x80 : 0; opt.drivename += 2; drive = hd | strtol(opt.drivename, NULL, 0); if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over FDD, possibly raw */ if (!(iter = pi_begin(&diskinfo, opt.piflags))) goto bail; } else if (!strcmp(opt.drivename, "boot") || !strcmp(opt.drivename, "fs")) { if (!is_phys(sdi->c.filesystem)) { error("When syslinux is not booted from physical disk (or its emulation),\n" "'boot' and 'fs' are meaningless."); goto bail; } /* offsets match, but in case it changes in the future */ if (sdi->c.filesystem == SYSLINUX_FS_ISOLINUX) { drive = sdi->iso.drive_number; fs_lba = *sdi->iso.partoffset; } else { drive = sdi->disk.drive_number; fs_lba = *sdi->disk.partoffset; } if (disk_get_params(drive, &diskinfo)) goto bail; /* this will start iteration over disk emulation, possibly raw */ if (!(iter = pi_begin(&diskinfo, opt.piflags))) goto bail; /* 'fs' => we should lookup the syslinux partition number and use it */ if (!strcmp(opt.drivename, "fs")) { do { if (iter->abs_lba == fs_lba) break; } while (!pi_next(iter)); /* broken part structure or other problems */ if (iter->status) { error("Unable to find partition with syslinux (fs)."); goto bail; } } } else { error("Unparsable drive specification."); goto bail; } /* main options done - only thing left is explicit partition specification, * if we're still at the disk stage with the iterator AND user supplied * partition number (including disk pseudo-partition). */ if (!iter->index && opt.partition) { partition = strtol(opt.partition, NULL, 0); /* search for matching part#, including disk */ do { if (iter->index == partition) break; } while (!pi_next(iter)); if (iter->status) { error("Unable to find requested disk / partition combination."); goto bail; } } if (!(iter->di.disk & 0x80) && iter->index) { warn("Partitions on floppy devices may not work."); } *_iter = iter; return 0; bail: pi_del(&iter); return -1; }
/* * Retrieve a specific instance given an object path */ wbem::framework::Instance* wbem::support::NVDIMMSensorViewFactory::getInstance( framework::ObjectPath &path, framework::attribute_names_t &attributes) throw (wbem::framework::Exception) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); framework::Instance *pInstance = new framework::Instance(path); try { // Get the sensorViewAttributes checkAttributes(attributes); framework::Attribute attribute = path.getKeyValue(DEVICEID_KEY); std::string guidStr; enum sensor_type type; if(!NVDIMMSensorFactory::splitDeviceIdAttribute(attribute, guidStr, (int &)type)) { throw framework::ExceptionBadParameter(DEVICEID_KEY.c_str()); } NVM_GUID guid; str_to_guid(guidStr.c_str(), guid); struct sensor sensor; int rc = NVM_SUCCESS; if ((rc = nvm_get_sensor(guid, type, &sensor)) != NVM_SUCCESS) { throw exception::NvmExceptionLibError(rc); } // DimmID = handle or guid depending on user selection if (containsAttribute(DIMMID_KEY, attributes)) { framework::Attribute attrDimmId = physical_asset::NVDIMMFactory::guidToDimmIdAttribute(guidStr); pInstance->setAttribute(DIMMID_KEY, attrDimmId, attributes); } // DimmGUID if (containsAttribute(DIMMGUID_KEY, attributes)) { framework::Attribute attrDimmHandle(guidStr, false); pInstance->setAttribute(DIMMGUID_KEY, attrDimmHandle, attributes); } // DimmHandle = NFIT Handle if (containsAttribute(DIMMHANDLE_KEY, attributes)) { NVM_UINT32 handle; physical_asset::NVDIMMFactory::guidToHandle(guidStr, handle); framework::Attribute attrDimmHandle(handle, false); pInstance->setAttribute(DIMMHANDLE_KEY, attrDimmHandle, attributes); } if (containsAttribute(TYPE_KEY, attributes)) { framework::Attribute a(getSensorNameStr(type), false); pInstance->setAttribute(TYPE_KEY, a, attributes); } if (containsAttribute(CURRENTVALUE_KEY, attributes)) { std::stringstream currentValue; if (sensor.units == UNIT_SECONDS) { // convert to HH:MM:SS, note HH can grow beyond 2 digits which is fine. NVM_UINT64 hours, minutes, seconds, remainder = 0; // 60 seconds in a minute, 60 minutes in an hour hours = sensor.reading / (60*60); remainder = sensor.reading % (60*60); minutes = remainder / 60; seconds = remainder % 60; currentValue << std::setfill('0') << std::setw(2) << hours << ":"; currentValue << std::setfill('0') << std::setw(2) << minutes << ":"; currentValue << std::setfill('0') << std::setw(2) << seconds; } else if (sensor.type == SENSOR_MEDIA_TEMPERATURE || sensor.type == SENSOR_CONTROLLER_TEMPERATURE) { float celsius = nvm_decode_temperature(sensor.reading); currentValue << celsius << baseUnitToString(sensor.units); } else { NVM_INT32 scaled = 0; NVM_INT32 scaler = 0; NVDIMMSensorFactory::scaleNumberBaseTen(sensor.reading, &scaled, &scaler); currentValue << scaled << baseUnitToString(sensor.units); if (scaler > 0) { currentValue << "* 10 ^" << scaler; } } framework::Attribute a(currentValue.str(), false); pInstance->setAttribute(CURRENTVALUE_KEY, a, attributes); } if (containsAttribute(ENABLEDSTATE_KEY, attributes)) { std::string enabledState; if ((sensor.type == SENSOR_MEDIA_TEMPERATURE) || (sensor.type == SENSOR_SPARECAPACITY) || (sensor.type == SENSOR_CONTROLLER_TEMPERATURE)) { enabledState = getEnabledStateStr( sensor.settings.enabled ? SENSOR_ENABLEDSTATE_ENABLED : SENSOR_ENABLEDSTATE_DISABLED); } else { enabledState = getEnabledStateStr(SENSOR_ENABLEDSTATE_NA); } framework::Attribute a(enabledState, false); pInstance->setAttribute(ENABLEDSTATE_KEY, a, attributes); } if (containsAttribute(LOWERTHRESHOLDCRITICAL_KEY, attributes)) { framework::Attribute a(sensor.settings.lower_critical_threshold, false); pInstance->setAttribute(LOWERTHRESHOLDCRITICAL_KEY, a, attributes); } if (containsAttribute(UPPERTHRESHOLDCRITICAL_KEY, attributes)) { if (sensor.type == SENSOR_MEDIA_TEMPERATURE || sensor.type == SENSOR_CONTROLLER_TEMPERATURE) { float celsius = nvm_decode_temperature(sensor.settings.upper_critical_threshold); pInstance->setAttribute(UPPERTHRESHOLDCRITICAL_KEY, framework::Attribute (celsius, false), attributes); } else { pInstance->setAttribute(UPPERTHRESHOLDCRITICAL_KEY, framework::Attribute (sensor.settings.upper_critical_threshold, false), attributes); } } if (containsAttribute(CURRENTSTATE_KEY, attributes)) { framework::Attribute a(NVDIMMSensorFactory::getSensorStateStr(sensor.current_state), false); pInstance->setAttribute(CURRENTSTATE_KEY, a, attributes); } if (containsAttribute(SUPPORTEDTHRESHOLDS_KEY, attributes)) { framework::STR_LIST supportedThresholds; if (sensor.lower_critical_support) { supportedThresholds.push_back(getThresholdTypeStr(SENSOR_LOWER_CRITICAL_THRESHOLD)); } if (sensor.upper_critical_support) { supportedThresholds.push_back(getThresholdTypeStr(SENSOR_UPPER_CRITICAL_THRESHOLD)); } framework::Attribute a(supportedThresholds, false); pInstance->setAttribute(SUPPORTEDTHRESHOLDS_KEY, a, attributes); } if (containsAttribute(SETTABLETHRESHOLDS_KEY, attributes)) { framework::STR_LIST settableThresholds; if (sensor.lower_critical_settable) { settableThresholds.push_back(getThresholdTypeStr(SENSOR_LOWER_CRITICAL_THRESHOLD)); } if (sensor.upper_critical_settable) { settableThresholds.push_back(getThresholdTypeStr(SENSOR_UPPER_CRITICAL_THRESHOLD)); } framework::Attribute a(settableThresholds, false); pInstance->setAttribute(SETTABLETHRESHOLDS_KEY, a, attributes); } } catch (framework::Exception &) // clean up and re-throw { if (pInstance != NULL) { delete pInstance; } throw; } return pInstance; }