From d8dda3014aca5b3d3c4d5165d052ca2e9b0de706 Mon Sep 17 00:00:00 2001 From: Alexandra Ellwood Date: Fri, 27 Jun 2008 19:46:33 +0000 Subject: [PATCH] Big endian stash file support Added support for stash files with a consistent endianness (big endian) so that one can migrate a KDC from a machine with one endianess to a machine with the other endianess. Used by Kerberos for Macintosh. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20489 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/kdb_default.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/kdb/kdb_default.c b/src/lib/kdb/kdb_default.c index fd95c8379..093bbc4bc 100644 --- a/src/lib/kdb/kdb_default.c +++ b/src/lib/kdb/kdb_default.c @@ -30,6 +30,7 @@ #include #include #include +#include /* @@ -142,6 +143,7 @@ krb5_def_store_mkey(context, keyfile, mname, key, master_pwd) FILE *kf; krb5_error_code retval = 0; krb5_ui_2 enctype; + unsigned long keylength; char defkeyfile[MAXPATHLEN+1]; krb5_data *realm = krb5_princ_realm(context, mname); #if HAVE_UMASK @@ -176,11 +178,17 @@ krb5_def_store_mkey(context, keyfile, mname, key, master_pwd) return e; } set_cloexec_file(kf); +#if BIG_ENDIAN_MASTER_KEY + enctype = htons(key->enctype); + keylength = htonl(key->length); +#else enctype = key->enctype; + keylength = key->length; +#endif if ((fwrite((krb5_pointer) &enctype, 2, 1, kf) != 1) || - (fwrite((krb5_pointer) &key->length, - sizeof(key->length), 1, kf) != 1) || + (fwrite((krb5_pointer) &keylength, + sizeof(keylength), 1, kf) != 1) || (fwrite((krb5_pointer) key->contents, sizeof(key->contents[0]), (unsigned) key->length, kf) != key->length)) { @@ -229,6 +237,10 @@ krb5_db_def_fetch_mkey( krb5_context context, goto errout; } +#if BIG_ENDIAN_MASTER_KEY + enctype = ntohs(enctype); +#endif + if (key->enctype == ENCTYPE_UNKNOWN) key->enctype = enctype; else if (enctype != key->enctype) { @@ -242,6 +254,10 @@ krb5_db_def_fetch_mkey( krb5_context context, goto errout; } +#if BIG_ENDIAN_MASTER_KEY + key->length = ntohl(key->length); +#endif + if (!key->length || ((int) key->length) < 0) { retval = KRB5_KDB_BADSTORED_MKEY; goto errout; -- 2.26.2