void ee_verifychecksums(void) { struct keytabent kt; u_char checkme[EE_SIZE - EE_HWUPDATE_LOC]; u_char checksum, ochecksum[3]; u_short owritecount[3]; /* * Verify that the EEPROM's write counts match, and update the * global copy for use later. */ kt.kt_keyword = "eeprom writecount"; kt.kt_offset = EE_WC_LOC; kt.kt_handler = ee_notsupp; if (doio(&kt, (u_char *)&owritecount, sizeof(owritecount), IO_READ)) { cksumfail = 1; FAILEDREAD(&kt); } if (owritecount[0] != owritecount[1] || owritecount[0] != owritecount[2]) { warnx("eeprom writecount mismatch %s", ignore_checksum ? "(ignoring)" : (fix_checksum ? "(fixing)" : "")); if (!ignore_checksum && !fix_checksum) { cksumfail = 1; return; } writecount = MAXIMUM(owritecount[0], owritecount[1]); writecount = MAXIMUM(writecount, owritecount[2]); } else writecount = owritecount[0]; /* * Verify that the EEPROM's checksums match and are correct. */ kt.kt_keyword = "eeprom checksum"; kt.kt_offset = EE_CKSUM_LOC; if (doio(&kt, ochecksum, sizeof(ochecksum), IO_READ)) { cksumfail = 1; FAILEDREAD(&kt); } if (ochecksum[0] != ochecksum[1] || ochecksum[0] != ochecksum[2]) { warnx("eeprom checksum mismatch %s", ignore_checksum ? "(ignoring)" : (fix_checksum ? "(fixing)" : "")); if (!ignore_checksum && !fix_checksum) { cksumfail = 1; return; } } kt.kt_keyword = "eeprom contents"; kt.kt_offset = EE_HWUPDATE_LOC; if (doio(&kt, checkme, sizeof(checkme), IO_READ)) { cksumfail = 1; FAILEDREAD(&kt); } checksum = ee_checksum(checkme, sizeof(checkme)); if (ochecksum[0] != checksum) { warnx("eeprom checksum incorrect %s", ignore_checksum ? "(ignoring)" : (fix_checksum ? "(fixing)" : "")); if (!ignore_checksum && !fix_checksum) { cksumfail = 1; return; } } if (fix_checksum) ee_updatechecksums(); }
int main(int argc, char *argv[]) { int ch, do_stdin = 0; char *cp, line[BUFSIZE]; char *optstring = "cf:ipvN:-"; while ((ch = getopt(argc, argv, optstring)) != -1) switch (ch) { case '-': do_stdin = 1; break; case 'c': fix_checksum = 1; break; case 'f': path_eeprom = path_openprom = optarg; break; case 'i': ignore_checksum = 1; break; case 'p': print_tree = 1; break; case 'v': verbose = 1; break; #if defined(__sparc__) && !defined(__sparc64__) case 'N': nlistf = optarg; break; #endif /* __sparc__ && !__sparc64__ */ case '?': default: usage(); } argc -= optind; argv += optind; #if defined(__sparc__) && !defined(__sparc64__) if (getcputype() != CPU_SUN4) #endif /* __sparc__ && !__sparc64__ */ use_openprom = 1; if (print_tree && use_openprom) { op_tree(); exit(0); } #if defined(__sparc__) && !defined(__sparc64__) if (use_openprom == 0) { ee_verifychecksums(); if (fix_checksum || cksumfail) exit(cksumfail); } #endif /* __sparc__ && !__sparc64__ */ if (do_stdin) { while (fgets(line, BUFSIZE, stdin) != NULL) { if (line[0] == '\n') continue; if ((cp = strrchr(line, '\n')) != NULL) *cp = '\0'; action(line); } if (ferror(stdin)) err(++eval, "stdin"); } else { if (argc == 0) { dump_prom(); exit(eval + cksumfail); } while (argc) { action(*argv); ++argv; --argc; } } #if defined(__sparc__) && !defined(__sparc64__) if (use_openprom == 0) if (update_checksums) { ++writecount; ee_updatechecksums(); } #endif /* __sparc__ && !__sparc64__ */ exit(eval + cksumfail); }