]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Use k5-buf.h integer helpers where appropriate 1000/head
authorGreg Hudson <ghudson@mit.edu>
Wed, 13 Nov 2019 05:53:56 +0000 (00:53 -0500)
committerGreg Hudson <ghudson@mit.edu>
Wed, 13 Nov 2019 22:56:12 +0000 (17:56 -0500)
src/lib/gssapi/mechglue/g_export_cred.c
src/lib/krb5/ccache/cc_file.c
src/lib/krb5/ccache/cc_kcm.c
src/plugins/kdb/lmdb/marshal.c
src/plugins/preauth/spake/spake_kdc.c
src/util/support/utf8_conv.c

index 0c273bf14ed9cbcee60eefb7ef23763f2a23caf4..9678c6de0a38e3e3b89da151823a8853a375fd93 100644 (file)
@@ -66,7 +66,6 @@ gss_export_cred(OM_uint32 * minor_status, gss_cred_id_t cred_handle,
     gss_mechanism mech;
     gss_buffer_desc mech_token;
     struct k5buf buf;
-    char lenbuf[4];
     int i;
 
     status = val_exp_cred_args(minor_status, cred_handle, token);
@@ -97,11 +96,9 @@ gss_export_cred(OM_uint32 * minor_status, gss_cred_id_t cred_handle,
         }
 
         /* Append the mech OID and token to buf. */
-        store_32_be(public_oid->length, lenbuf);
-        k5_buf_add_len(&buf, lenbuf, 4);
+        k5_buf_add_uint32_be(&buf, public_oid->length);
         k5_buf_add_len(&buf, public_oid->elements, public_oid->length);
-        store_32_be(mech_token.length, lenbuf);
-        k5_buf_add_len(&buf, lenbuf, 4);
+        k5_buf_add_uint32_be(&buf, mech_token.length);
         k5_buf_add_len(&buf, mech_token.value, mech_token.length);
         gss_release_buffer(&tmpmin, &mech_token);
     }
index e78ac3a7fa61d21e67b88d159e7def43d26ed524..9a9b45a6e2304425151bba79a24b4b68c343e007 100644 (file)
@@ -446,7 +446,6 @@ fcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ)
     krb5_error_code ret;
     krb5_os_context os_ctx = &context->os_context;
     fcc_data *data = id->data;
-    char i16buf[2], i32buf[4];
     uint16_t fields_len;
     ssize_t nwritten;
     int st, flags, version, fd = -1;
@@ -484,25 +483,19 @@ fcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ)
     /* Prepare the header and principal in buf. */
     k5_buf_init_dynamic(&buf);
     version = context->fcc_default_format - FVNO_BASE;
-    store_16_be(FVNO_BASE + version, i16buf);
-    k5_buf_add_len(&buf, i16buf, 2);
+    k5_buf_add_uint16_be(&buf, FVNO_BASE + version);
     if (version >= 4) {
         /* Add tagged header fields. */
         fields_len = 0;
         if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID)
             fields_len += 12;
-        store_16_be(fields_len, i16buf);
-        k5_buf_add_len(&buf, i16buf, 2);
+        k5_buf_add_uint16_be(&buf, fields_len);
         if (os_ctx->os_flags & KRB5_OS_TOFFSET_VALID) {
             /* Add time offset tag. */
-            store_16_be(FCC_TAG_DELTATIME, i16buf);
-            k5_buf_add_len(&buf, i16buf, 2);
-            store_16_be(8, i16buf);
-            k5_buf_add_len(&buf, i16buf, 2);
-            store_32_be(os_ctx->time_offset, i32buf);
-            k5_buf_add_len(&buf, i32buf, 4);
-            store_32_be(os_ctx->usec_offset, i32buf);
-            k5_buf_add_len(&buf, i32buf, 4);
+            k5_buf_add_uint16_be(&buf, FCC_TAG_DELTATIME);
+            k5_buf_add_uint16_be(&buf, 8);
+            k5_buf_add_uint32_be(&buf, os_ctx->time_offset);
+            k5_buf_add_uint32_be(&buf, os_ctx->usec_offset);
         }
     }
     k5_marshal_princ(&buf, version, princ);
index 1f5d6c834560a9e0c9a42da5227ae1bd84ed0381..a76a285d91863a571b362497c9b4ccaa97199e30 100644 (file)
@@ -121,16 +121,6 @@ kcmreq_init(struct kcmreq *req, kcm_opcode opcode, krb5_ccache cache)
     }
 }
 
-/* Add a 32-bit value to the request in big-endian byte order. */
-static void
-kcmreq_put32(struct kcmreq *req, uint32_t val)
-{
-    unsigned char bytes[4];
-
-    store_32_be(val, bytes);
-    k5_buf_add_len(&req->reqbuf, bytes, 4);
-}
-
 #ifdef __APPLE__
 
 /* The maximum length of an in-band request or reply as defined by the RPC
@@ -596,7 +586,7 @@ set_kdc_offset(krb5_context context, krb5_ccache cache)
 
     if (context->os_context.os_flags & KRB5_OS_TOFFSET_VALID) {
         kcmreq_init(&req, KCM_OP_SET_KDC_OFFSET, cache);
-        kcmreq_put32(&req, context->os_context.time_offset);
+        k5_buf_add_uint32_be(&req.reqbuf, context->os_context.time_offset);
         (void)cache_call(context, cache, &req);
         kcmreq_free(&req);
     }
@@ -824,7 +814,7 @@ kcm_remove_cred(krb5_context context, krb5_ccache cache, krb5_flags flags,
     struct kcmreq req;
 
     kcmreq_init(&req, KCM_OP_REMOVE_CRED, cache);
-    kcmreq_put32(&req, flags);
+    k5_buf_add_uint32_be(&req.reqbuf, flags);
     k5_marshal_mcred(&req.reqbuf, mcred);
     ret = cache_call(context, cache, &req);
     kcmreq_free(&req);
index f49a2cbd99bbf8088c74789b18916bc272491e09..433bb816db1ed23df93c0299cc4ab31c3ceb6324 100644 (file)
 #include <kdb.h>
 #include "klmdb-int.h"
 
-static void
-put16(struct k5buf *buf, uint16_t num)
-{
-    uint8_t n[2];
-
-    store_16_le(num, n);
-    k5_buf_add_len(buf, n, 2);
-}
-
-static void
-put32(struct k5buf *buf, uint32_t num)
-{
-    uint8_t n[4];
-
-    store_32_le(num, n);
-    k5_buf_add_len(buf, n, 4);
-}
-
 static void
 put_tl_data(struct k5buf *buf, const krb5_tl_data *tl)
 {
     for (; tl != NULL; tl = tl->tl_data_next) {
-        put16(buf, tl->tl_data_type);
-        put16(buf, tl->tl_data_length);
+        k5_buf_add_uint16_le(buf, tl->tl_data_type);
+        k5_buf_add_uint16_le(buf, tl->tl_data_length);
         k5_buf_add_len(buf, tl->tl_data_contents, tl->tl_data_length);
     }
 }
@@ -76,21 +58,21 @@ klmdb_encode_princ(krb5_context context, const krb5_db_entry *entry,
 
     k5_buf_init_dynamic(&buf);
 
-    put32(&buf, entry->attributes);
-    put32(&buf, entry->max_life);
-    put32(&buf, entry->max_renewable_life);
-    put32(&buf, entry->expiration);
-    put32(&buf, entry->pw_expiration);
-    put16(&buf, entry->n_tl_data);
-    put16(&buf, entry->n_key_data);
+    k5_buf_add_uint32_le(&buf, entry->attributes);
+    k5_buf_add_uint32_le(&buf, entry->max_life);
+    k5_buf_add_uint32_le(&buf, entry->max_renewable_life);
+    k5_buf_add_uint32_le(&buf, entry->expiration);
+    k5_buf_add_uint32_le(&buf, entry->pw_expiration);
+    k5_buf_add_uint16_le(&buf, entry->n_tl_data);
+    k5_buf_add_uint16_le(&buf, entry->n_key_data);
     put_tl_data(&buf, entry->tl_data);
     for (i = 0; i < entry->n_key_data; i++) {
         kd = &entry->key_data[i];
-        put16(&buf, kd->key_data_ver);
-        put16(&buf, kd->key_data_kvno);
+        k5_buf_add_uint16_le(&buf, kd->key_data_ver);
+        k5_buf_add_uint16_le(&buf, kd->key_data_kvno);
         for (j = 0; j < kd->key_data_ver; j++) {
-            put16(&buf, kd->key_data_type[j]);
-            put16(&buf, kd->key_data_length[j]);
+            k5_buf_add_uint16_le(&buf, kd->key_data_type[j]);
+            k5_buf_add_uint16_le(&buf, kd->key_data_length[j]);
             if (kd->key_data_length[j] > 0) {
                 k5_buf_add_len(&buf, kd->key_data_contents[j],
                                kd->key_data_length[j]);
@@ -125,26 +107,26 @@ klmdb_encode_policy(krb5_context context, const osa_policy_ent_rec *pol,
     *len_out = 0;
 
     k5_buf_init_dynamic(&buf);
-    put32(&buf, pol->pw_min_life);
-    put32(&buf, pol->pw_max_life);
-    put32(&buf, pol->pw_min_length);
-    put32(&buf, pol->pw_min_classes);
-    put32(&buf, pol->pw_history_num);
-    put32(&buf, pol->pw_max_fail);
-    put32(&buf, pol->pw_failcnt_interval);
-    put32(&buf, pol->pw_lockout_duration);
-    put32(&buf, pol->attributes);
-    put32(&buf, pol->max_life);
-    put32(&buf, pol->max_renewable_life);
+    k5_buf_add_uint32_le(&buf, pol->pw_min_life);
+    k5_buf_add_uint32_le(&buf, pol->pw_max_life);
+    k5_buf_add_uint32_le(&buf, pol->pw_min_length);
+    k5_buf_add_uint32_le(&buf, pol->pw_min_classes);
+    k5_buf_add_uint32_le(&buf, pol->pw_history_num);
+    k5_buf_add_uint32_le(&buf, pol->pw_max_fail);
+    k5_buf_add_uint32_le(&buf, pol->pw_failcnt_interval);
+    k5_buf_add_uint32_le(&buf, pol->pw_lockout_duration);
+    k5_buf_add_uint32_le(&buf, pol->attributes);
+    k5_buf_add_uint32_le(&buf, pol->max_life);
+    k5_buf_add_uint32_le(&buf, pol->max_renewable_life);
 
     if (pol->allowed_keysalts == NULL) {
-        put32(&buf, 0);
+        k5_buf_add_uint32_le(&buf, 0);
     } else {
-        put32(&buf, strlen(pol->allowed_keysalts));
+        k5_buf_add_uint32_le(&buf, strlen(pol->allowed_keysalts));
         k5_buf_add(&buf, pol->allowed_keysalts);
     }
 
-    put16(&buf, pol->n_tl_data);
+    k5_buf_add_uint16_le(&buf, pol->n_tl_data);
     put_tl_data(&buf, pol->tl_data);
 
     if (k5_buf_status(&buf) != 0)
index 59e88409ed949d31f91304d6402633ccc3e21a18..88c964ce1dad581543bdc602e825173a8ef7f382 100644 (file)
@@ -120,10 +120,7 @@ parse_cookie(const krb5_data *cookie, int *stage_out, int32_t *group_out,
 static void
 marshal_data(struct k5buf *buf, const krb5_data *data)
 {
-    uint8_t lenbuf[4];
-
-    store_32_be(data->length, lenbuf);
-    k5_buf_add_len(buf, lenbuf, 4);
+    k5_buf_add_uint32_be(buf, data->length);
     k5_buf_add_len(buf, data->data, data->length);
 }
 
@@ -133,18 +130,14 @@ make_cookie(int stage, int32_t group, const krb5_data *spake,
             const krb5_data *thash, krb5_data *cookie_out)
 {
     struct k5buf buf;
-    uint8_t intbuf[4];
 
     *cookie_out = empty_data();
     k5_buf_init_dynamic_zap(&buf);
 
     /* Marshal the version, stage, and group. */
-    store_16_be(1, intbuf);
-    k5_buf_add_len(&buf, intbuf, 2);
-    store_16_be(stage, intbuf);
-    k5_buf_add_len(&buf, intbuf, 2);
-    store_32_be(group, intbuf);
-    k5_buf_add_len(&buf, intbuf, 4);
+    k5_buf_add_uint16_be(&buf, 1);
+    k5_buf_add_uint16_be(&buf, stage);
+    k5_buf_add_uint32_be(&buf, group);
 
     /* Marshal the data fields. */
     marshal_data(&buf, spake);
index 5bfb03a9c74c37731cb0c26284a951e82d5e1975..5ddaa2d939098d2db613c420c876e9a58d2fa7ff 100644 (file)
@@ -94,7 +94,6 @@ k5_utf8_to_utf16le(const char *utf8, uint8_t **utf16_out, size_t *nbytes_out)
     struct k5buf buf;
     krb5_ucs4 ch;
     size_t chlen, i;
-    uint8_t *p;
 
     *utf16_out = NULL;
     *nbytes_out = 0;
@@ -127,16 +126,13 @@ k5_utf8_to_utf16le(const char *utf8, uint8_t **utf16_out, size_t *nbytes_out)
 
         /* Characters in the basic multilingual plane are encoded using two
          * bytes; other characters are encoded using four bytes. */
-        p = k5_buf_get_space(&buf, IS_BMP(ch) ? 2 : 4);
-        if (p == NULL)
-            return ENOMEM;
         if (IS_BMP(ch)) {
-            store_16_le(ch, p);
+            k5_buf_add_uint16_le(&buf, ch);
         } else {
             /* 0x10000 is subtracted from ch; then the high ten bits plus
              * 0xD800 and the low ten bits plus 0xDC00 are the surrogates. */
-            store_16_le(HIGH_SURROGATE(ch), p);
-            store_16_le(LOW_SURROGATE(ch), p + 2);
+            k5_buf_add_uint16_le(&buf, HIGH_SURROGATE(ch));
+            k5_buf_add_uint16_le(&buf, LOW_SURROGATE(ch));
         }
 
         /* Move to next UTF-8 character. */