/* Returns TRUE when the given tokeninfo contains the subset of features we * support. */ static krb5_boolean is_tokeninfo_supported(krb5_otp_tokeninfo *ti) { krb5_flags supported_flags = KRB5_OTP_FLAG_COLLECT_PIN | KRB5_OTP_FLAG_NO_COLLECT_PIN | KRB5_OTP_FLAG_SEPARATE_PIN; /* Flags we don't support... */ if (ti->flags & ~supported_flags) return FALSE; /* We don't currently support hashing. */ if (ti->supported_hash_alg != NULL || ti->iteration_count >= 0) return FALSE; /* Remove tokeninfos with invalid vendor strings. */ if (!is_printable_string(&ti->vendor)) return FALSE; /* Remove tokeninfos with non-printable challenges. */ if (!is_printable_string(&ti->challenge)) return FALSE; /* We don't currently support base64. */ if (ti->format == KRB5_OTP_FORMAT_BASE64) return FALSE; return TRUE; }
static void print_data(const void *data, int len) { int j; const u8 *s; /* no data, don't print */ if (len == 0) return; /* * It is a string, but it may have multiple strings (embedded '\0's). */ if (is_printable_string(data, len)) { puts("\""); j = 0; while (j < len) { if (j > 0) puts("\", \""); puts(data); j += strlen(data) + 1; data += strlen(data) + 1; } puts("\""); return; } switch (len) { case 1: /* byte */ printf("<%02x>", (*(u8 *) data) & 0xff); break; case 2: /* half-word */ printf("<%04x>", be16_to_cpu(*(u16 *) data) & 0xffff); break; case 4: /* word */ printf("<%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU); break; case 8: /* double-word */ #if __WORDSIZE == 64 printf("<%016llx>", be64_to_cpu(*(uint64_t *) data)); #else printf("<%08x ", be32_to_cpu(*(u32 *) data) & 0xffffffffU); data += 4; printf("%08x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU); #endif break; default: /* anything else... hexdump */ printf("["); for (j = 0, s = data; j < len; j++) printf("%02x%s", s[j], j < len - 1 ? " " : ""); printf("]"); break; } }
static int print_data(char * page, const void *data, int len) { int j, plen = 0; /* no data, don't print */ if (len == 0) return plen; /* * It is a string, but it may have multiple strings (embedded '\0's). */ if (is_printable_string(data, len)) { plen += sprintf(page + plen, "\""); j = 0; while (j < len) { if (j > 0) plen += sprintf(page + plen, "\", \""); plen += sprintf(page + plen, "%s", (char *)data); j += strlen(data) + 1; data += strlen(data) + 1; } plen += sprintf(page + plen, "\""); return plen; } if ((len %4) == 0) { const u32 *p; plen += sprintf(page + plen, "<"); for (j = 0, p = data; j < len/4; j ++) plen += sprintf(page + plen, "0x%x%s", fdt32_to_cpu(p[j]), j < (len/4 - 1) ? " " : ""); plen += sprintf(page + plen, ">"); } else { /* anything else... hexdump */ const u8 *s; plen += sprintf(page + plen, "["); for (j = 0, s = data; j < len; j++) plen += sprintf(page + plen, "%02x%s", s[j], j < len - 1 ? " " : ""); plen += sprintf(page + plen, "]"); } return plen; }
/* * Get a value from the fdt and format it to be set in the environment */ static int fdt_value_setenv(const void *nodep, int len, const char *var) { if (is_printable_string(nodep, len)) setenv(var, (void *)nodep); else if (len == 4) { char buf[11]; sprintf(buf, "0x%08X", *(uint32_t *)nodep); setenv(var, buf); } else if (len%4 == 0 && len <= 20) { /* Needed to print things like sha1 hashes. */ char buf[41]; int i; for (i = 0; i < len; i += sizeof(unsigned int)) sprintf(buf + (i * 2), "%08x", *(unsigned int *)(nodep + i)); setenv(var, buf); } else { printf("error: unprintable value\n"); return 1; } return 0; }