}
if (retbool == FALSE ){
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, _("Error: not found -> "));
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, _("Error: not found -> "));
for(j= 0; j < i; j ++)
- krb5int_buf_add_fmt(&buf, " %s ", fcmd_arr[j]);
- krb5int_buf_add(&buf, "\n");
- *err_out = krb5int_buf_data(&buf);
+ k5_buf_add_fmt(&buf, " %s ", fcmd_arr[j]);
+ k5_buf_add(&buf, "\n");
+ *err_out = k5_buf_data(&buf);
if (*err_out == NULL) {
perror(prog_name);
exit(1);
size_t xx_len;
};
-/** Initialize a k5buf using a fixed-sized, existing buffer. SPACE must be
+/* Initialize a k5buf using a fixed-sized, existing buffer. SPACE must be
* more than zero, or an assertion failure will result. */
-void krb5int_buf_init_fixed(struct k5buf *buf, char *data, size_t space);
+void k5_buf_init_fixed(struct k5buf *buf, char *data, size_t space);
-/** Initialize a k5buf using an internally allocated dynamic buffer. The
- * buffer contents must be freed with krb5int_free_buf. */
-void krb5int_buf_init_dynamic(struct k5buf *buf);
+/* Initialize a k5buf using an internally allocated dynamic buffer. The
+ * buffer contents must be freed with k5_free_buf. */
+void k5_buf_init_dynamic(struct k5buf *buf);
-/** Add a C string to BUF. */
-void krb5int_buf_add(struct k5buf *buf, const char *data);
+/* Add a C string to BUF. */
+void k5_buf_add(struct k5buf *buf, const char *data);
-/**
+/*
* Add a counted set of bytes to BUF. It is okay for DATA[0..LEN-1]
* to contain null bytes if you are prepared to deal with that in the
- * output (use krb5int_buf_len to retrieve the length of the output).
+ * output (use k5_buf_len to retrieve the length of the output).
*/
-void krb5int_buf_add_len(struct k5buf *buf, const char *data, size_t len);
+void k5_buf_add_len(struct k5buf *buf, const char *data, size_t len);
-/** Add sprintf-style formatted data to BUF. */
-void krb5int_buf_add_fmt(struct k5buf *buf, const char *fmt, ...)
+/* Add sprintf-style formatted data to BUF. */
+void k5_buf_add_fmt(struct k5buf *buf, const char *fmt, ...)
#if !defined(__cplusplus) && (__GNUC__ > 2)
__attribute__((__format__(__printf__, 2, 3)))
#endif
;
-/** Truncate BUF. LEN must be between 0 and the existing buffer
+/* Truncate BUF. LEN must be between 0 and the existing buffer
* length, or an assertion failure will result. */
-void krb5int_buf_truncate(struct k5buf *buf, size_t len);
+void k5_buf_truncate(struct k5buf *buf, size_t len);
-/**
+/*
* Retrieve the byte array value of BUF, or NULL if there has been an
* allocation failure or the fixed buffer ran out of room.
-
+ *
* The byte array will be a C string unless binary data was added with
- * krb5int_buf_add_len; it will be null-terminated regardless.
- * Modifying the byte array does not invalidate the buffer, as long as
- * its length is not changed.
-
- * For a fixed buffer, the return value will always be equal to the
- * passed-in value of DATA at initialization time if it is not NULL.
-
+ * k5_buf_add_len; it will be null-terminated regardless. Modifying the byte
+ * array does not invalidate the buffer, as long as its length is not changed.
+ *
+ * For a fixed buffer, the return value will always be equal to the passed-in
+ * value of DATA at initialization time if it is not NULL.
+ *
* For a dynamic buffer, any buffer modification operation except
- * krb5int_buf_truncate may invalidate the byte array address.
+ * k5_buf_truncate may invalidate the byte array address.
*/
-char *krb5int_buf_data(struct k5buf *buf);
+char *k5_buf_data(struct k5buf *buf);
-/**
- * Retrieve the length of BUF, or -1 if there has been an allocation
- * failure or the fixed buffer ran out of room. The length is equal
- * to strlen(krb5int_buf_data(buf)) unless binary data was added with
- * krb5int_buf_add_len.
+/*
+ * Retrieve the length of BUF, or -1 if there has been an allocation failure or
+ * the fixed buffer ran out of room. The length is equal to
+ * strlen(k5_buf_data(buf)) unless binary data was added with k5_buf_add_len.
*/
-ssize_t krb5int_buf_len(struct k5buf *buf);
+ssize_t k5_buf_len(struct k5buf *buf);
-/**
- * Free the storage used in the dynamic buffer BUF. The caller may
- * choose to take responsibility for freeing the return value of
- * krb5int_buf_data instead of using this function. If BUF is a fixed
- * buffer, an assertion failure will result. It is unnecessary
- * (though harmless) to free a buffer after an error is detected; the
- * storage will already have been freed in that case.
+/*
+ * Free the storage used in the dynamic buffer BUF. The caller may choose to
+ * take responsibility for freeing the return value of k5_buf_data instead of
+ * using this function. If BUF is a fixed buffer, an assertion failure will
+ * result. It is unnecessary (though harmless) to free a buffer after an error
+ * is detected; the storage will already have been freed in that case.
*/
-void krb5int_free_buf(struct k5buf *buf);
+void k5_free_buf(struct k5buf *buf);
#endif /* K5_BUF_H */
exit(1);
}
- krb5int_buf_init_fixed(&buf, stroutbuf, sizeof(stroutbuf));
- krb5int_buf_add(&buf, "0x");
+ k5_buf_init_fixed(&buf, stroutbuf, sizeof(stroutbuf));
+ k5_buf_add(&buf, "0x");
for (j = 0; j < out.length; j++)
- krb5int_buf_add_fmt(&buf, "%02x", 0xff & outbuf[j]);
- if (krb5int_buf_data(&buf) == NULL)
+ k5_buf_add_fmt(&buf, "%02x", 0xff & outbuf[j]);
+ if (k5_buf_data(&buf) == NULL)
abort();
if (strcmp(stroutbuf, md5tests[i].hexdigest)) {
printf("*** CHECK FAILED!\n"
char *buffer = NULL;
struct k5buf prf_inbuf;
- krb5int_buf_init_dynamic(&prf_inbuf);
- krb5int_buf_add_len(&prf_inbuf, "\001", 1);
- krb5int_buf_add(&prf_inbuf, pepper);
+ k5_buf_init_dynamic(&prf_inbuf);
+ k5_buf_add_len(&prf_inbuf, "\001", 1);
+ k5_buf_add(&prf_inbuf, pepper);
retval = krb5_c_prf_length( context, k->enctype, &prflen);
if (retval)
goto cleanup;
buffer = k5alloc(iterations * prflen, &retval);
if (retval)
goto cleanup;
- if (krb5int_buf_len(&prf_inbuf) == -1) {
+ if (k5_buf_len(&prf_inbuf) == -1) {
retval = ENOMEM;
goto cleanup;
}
- in_data.length = (krb5_int32) krb5int_buf_len(&prf_inbuf);
- in_data.data = krb5int_buf_data(&prf_inbuf);
+ in_data.length = (krb5_int32)k5_buf_len(&prf_inbuf);
+ in_data.data = k5_buf_data(&prf_inbuf);
out_data.length = prflen;
out_data.data = buffer;
cleanup:
free(buffer);
- krb5int_free_buf(&prf_inbuf);
+ k5_free_buf(&prf_inbuf);
return retval;
}
gss_buffer_t output_buffer)
{
OM_uint32 status = GSS_S_COMPLETE;
- char *bp = krb5int_buf_data(input_k5buf);
- output_buffer->length = krb5int_buf_len(input_k5buf);
+ char *bp = k5_buf_data(input_k5buf);
+ output_buffer->length = k5_buf_len(input_k5buf);
#if defined(_WIN32) || defined(DEBUG_GSSALLOC)
if (output_buffer->length > 0) {
output_buffer->value = gssalloc_malloc(output_buffer->length);
} else {
output_buffer->value = NULL;
}
- krb5int_free_buf(input_k5buf);
+ k5_free_buf(input_k5buf);
#else
output_buffer->value = bp;
/*
cp = (unsigned char *) oid->elements;
number = (unsigned long) cp[0];
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, "{ ");
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, "{ ");
number = 0;
cp = (unsigned char *) oid->elements;
first = 1;
if ((cp[i] & 0x80) == 0) {
if (first) {
n = (number < 40) ? 0 : (number < 80) ? 1 : 2;
- krb5int_buf_add_fmt(&buf, "%lu %lu ", n, number - (n * 40));
+ k5_buf_add_fmt(&buf, "%lu %lu ", n, number - (n * 40));
first = 0;
} else {
- krb5int_buf_add_fmt(&buf, "%lu ", number);
+ k5_buf_add_fmt(&buf, "%lu ", number);
}
number = 0;
}
}
- krb5int_buf_add_len(&buf, "}\0", 2);
- if (krb5int_buf_data(&buf) == NULL) {
+ k5_buf_add_len(&buf, "}\0", 2);
+ if (k5_buf_data(&buf) == NULL) {
*minor_status = ENOMEM;
return(GSS_S_FAILURE);
}
if (status != GSS_S_COMPLETE)
return status;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
cred = (gss_union_cred_t) cred_handle;
for (i = 0; i < cred->count; i++) {
/* Append the mech OID and token to buf. */
store_32_be(public_oid->length, lenbuf);
- krb5int_buf_add_len(&buf, lenbuf, 4);
- krb5int_buf_add_len(&buf, public_oid->elements, public_oid->length);
+ k5_buf_add_len(&buf, lenbuf, 4);
+ k5_buf_add_len(&buf, public_oid->elements, public_oid->length);
store_32_be(mech_token.length, lenbuf);
- krb5int_buf_add_len(&buf, lenbuf, 4);
- krb5int_buf_add_len(&buf, mech_token.value, mech_token.length);
+ k5_buf_add_len(&buf, lenbuf, 4);
+ k5_buf_add_len(&buf, mech_token.value, mech_token.length);
gss_release_buffer(&tmpmin, &mech_token);
}
- if (krb5int_buf_data(&buf) == NULL) {
+ if (k5_buf_data(&buf) == NULL) {
*minor_status = ENOMEM;
return GSS_S_FAILURE;
}
return k5buf_to_gss(minor_status, &buf, token);
error:
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return status;
}
return ret;
if (envname == NULL || (kdc_config = getenv(envname)) == NULL)
kdc_config = fname;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
if (kdc_config)
- krb5int_buf_add(&buf, kdc_config);
+ k5_buf_add(&buf, kdc_config);
for (i = 0; filenames[i] != NULL; i++) {
- if (krb5int_buf_len(&buf) > 0)
- krb5int_buf_add(&buf, ":");
- krb5int_buf_add(&buf, filenames[i]);
+ if (k5_buf_len(&buf) > 0)
+ k5_buf_add(&buf, ":");
+ k5_buf_add(&buf, filenames[i]);
}
krb5_free_config_files(filenames);
- profile_path = krb5int_buf_data(&buf);
+ profile_path = k5_buf_data(&buf);
if (profile_path == NULL)
return ENOMEM;
profile = (profile_t) NULL;
pflags = 0;
sepstring = (sep) ? sep : flags_default_sep;
- krb5int_buf_init_fixed(&buf, buffer, buflen);
+ k5_buf_init_fixed(&buf, buffer, buflen);
/* Blast through the table matching all we can */
for (i=0; i<flags_table_nents; i++) {
if (flags & flags_table[i].fl_flags) {
- if (krb5int_buf_len(&buf) > 0)
- krb5int_buf_add(&buf, sepstring);
- krb5int_buf_add(&buf, _(flags_table[i].fl_output));
+ if (k5_buf_len(&buf) > 0)
+ k5_buf_add(&buf, sepstring);
+ k5_buf_add(&buf, _(flags_table[i].fl_output));
/* Keep track of what we matched */
pflags |= flags_table[i].fl_flags;
}
}
- if (krb5int_buf_data(&buf) == NULL)
+ if (k5_buf_data(&buf) == NULL)
return(ENOMEM);
/* See if there's any leftovers */
code = begin_attrs(context, entry, &pos, &end);
if (code)
return code;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
while (next_attr(&pos, end, &mapkey, &mapval)) {
if (strcmp(mapkey, key) == 0) {
if (value != NULL) {
- krb5int_buf_add_len(&buf, mapkey, strlen(mapkey) + 1);
- krb5int_buf_add_len(&buf, value, strlen(value) + 1);
+ k5_buf_add_len(&buf, mapkey, strlen(mapkey) + 1);
+ k5_buf_add_len(&buf, value, strlen(value) + 1);
}
found = TRUE;
} else {
- krb5int_buf_add_len(&buf, mapkey, strlen(mapkey) + 1);
- krb5int_buf_add_len(&buf, mapval, strlen(mapval) + 1);
+ k5_buf_add_len(&buf, mapkey, strlen(mapkey) + 1);
+ k5_buf_add_len(&buf, mapval, strlen(mapval) + 1);
}
}
/* If key wasn't found in the map, add a new entry for it. */
if (!found && value != NULL) {
- krb5int_buf_add_len(&buf, key, strlen(key) + 1);
- krb5int_buf_add_len(&buf, value, strlen(value) + 1);
+ k5_buf_add_len(&buf, key, strlen(key) + 1);
+ k5_buf_add_len(&buf, value, strlen(value) + 1);
}
- len = krb5int_buf_len(&buf);
+ len = k5_buf_len(&buf);
if (len == -1)
return ENOMEM;
if (len > 65535)
return KRB5_KDB_STRINGS_TOOLONG;
tl_data.tl_data_type = KRB5_TL_STRING_ATTRS;
- tl_data.tl_data_contents = (krb5_octet *)krb5int_buf_data(&buf);
+ tl_data.tl_data_contents = (krb5_octet *)k5_buf_data(&buf);
tl_data.tl_data_length = len;
code = krb5_dbe_update_tl_data(context, entry, &tl_data);
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return code;
}
static void
add_spaces(struct k5buf *buf)
{
- if (krb5int_buf_len(buf) > 0)
- krb5int_buf_add(buf, " ");
+ if (k5_buf_len(buf) > 0)
+ k5_buf_add(buf, " ");
}
static krb5_error_code
/* Check that we processed exactly the expected number of bytes. */
assert(p == data->data + AD_POLICY_INFO_LENGTH);
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
/*
* Update src/tests/misc/test_chpw_message.c if changing these strings!
*/
if (policy.password_properties & AD_POLICY_COMPLEX) {
- krb5int_buf_add(&buf,
- _("The password must include numbers or symbols. "
- "Don't include any part of your name in the "
- "password."));
+ k5_buf_add(&buf, _("The password must include numbers or symbols. "
+ "Don't include any part of your name in the "
+ "password."));
}
if (policy.min_length_password > 0) {
add_spaces(&buf);
- krb5int_buf_add_fmt(&buf,
- ngettext("The password must contain at least %d "
- "character.",
- "The password must contain at least %d "
- "characters.",
- policy.min_length_password),
- policy.min_length_password);
+ k5_buf_add_fmt(&buf, ngettext("The password must contain at least %d "
+ "character.",
+ "The password must contain at least %d "
+ "characters.",
+ policy.min_length_password),
+ policy.min_length_password);
}
if (policy.password_history) {
add_spaces(&buf);
- krb5int_buf_add_fmt(&buf,
- ngettext("The password must be different from the "
- "previous password.",
- "The password must be different from the "
- "previous %d passwords.",
- policy.password_history),
- policy.password_history);
+ k5_buf_add_fmt(&buf, ngettext("The password must be different from "
+ "the previous password.",
+ "The password must be different from "
+ "the previous %d passwords.",
+ policy.password_history),
+ policy.password_history);
}
if (policy.min_passwordage) {
password_days = policy.min_passwordage / AD_POLICY_TIME_TO_DAYS;
if (password_days == 0)
password_days = 1;
add_spaces(&buf);
- krb5int_buf_add_fmt(&buf,
- ngettext("The password can only be changed once a "
- "day.",
- "The password can only be changed every "
- "%d days.", (int)password_days),
- (int)password_days);
+ k5_buf_add_fmt(&buf, ngettext("The password can only be changed once "
+ "a day.",
+ "The password can only be changed every "
+ "%d days.", (int)password_days),
+ (int)password_days);
}
- msg = krb5int_buf_data(&buf);
+ msg = k5_buf_data(&buf);
if (msg == NULL)
return ENOMEM;
struct k5buf buf;
char *cc_name;
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, krb5_cc_get_type(context, ccache));
- krb5int_buf_add(&buf, ":");
- krb5int_buf_add(&buf, krb5_cc_get_name(context, ccache));
- cc_name = krb5int_buf_data(&buf);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, krb5_cc_get_type(context, ccache));
+ k5_buf_add(&buf, ":");
+ k5_buf_add(&buf, krb5_cc_get_name(context, ccache));
+ cc_name = k5_buf_data(&buf);
if (cc_name)
retval = krb5_get_init_creds_opt_set_fast_ccache_name(context, opt,
cc_name);
else
retval = ENOMEM;
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return retval;
}
cachetype = krb5_rc_default_type(context);
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, cachetype);
- krb5int_buf_add(&buf, ":");
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, cachetype);
+ k5_buf_add(&buf, ":");
for (i = 0; i < piece->length; i++) {
if (piece->data[i] == '-')
- krb5int_buf_add(&buf, "--");
+ k5_buf_add(&buf, "--");
else if (!isvalidrcname((int) piece->data[i]))
- krb5int_buf_add_fmt(&buf, "-%03o", piece->data[i]);
+ k5_buf_add_fmt(&buf, "-%03o", piece->data[i]);
else
- krb5int_buf_add_len(&buf, &piece->data[i], 1);
+ k5_buf_add_len(&buf, &piece->data[i], 1);
}
#ifdef HAVE_GETEUID
- krb5int_buf_add_fmt(&buf, "_%lu", uid);
+ k5_buf_add_fmt(&buf, "_%lu", uid);
#endif
- cachename = krb5int_buf_data(&buf);
+ cachename = k5_buf_data(&buf);
if (cachename == NULL)
return ENOMEM;
return KRB5_LNAME_NOTRANS;
current++;
- krb5int_buf_init_dynamic(&selstring);
+ k5_buf_init_dynamic(&selstring);
while (1) {
/* Copy in literal characters up to the next $ or ]. */
nlit = strcspn(current, "$]");
- krb5int_buf_add_len(&selstring, current, nlit);
+ k5_buf_add_len(&selstring, current, nlit);
current += nlit;
if (*current != '$')
break;
: krb5_princ_realm(context, aname);
if (!datap)
break;
- krb5int_buf_add_len(&selstring, datap->data, datap->length);
+ k5_buf_add_len(&selstring, datap->data, datap->length);
}
/* Check that we hit a ']' and not the end of the string. */
if (*current != ']') {
- krb5int_free_buf(&selstring);
+ k5_free_buf(&selstring);
return KRB5_CONFIG_BADFORMAT;
}
- str = krb5int_buf_data(&selstring);
+ str = k5_buf_data(&selstring);
if (str == NULL)
return ENOMEM;
* Form our query, and send it via DNS
*/
- krb5int_buf_init_fixed(&buf, host, sizeof(host));
+ k5_buf_init_fixed(&buf, host, sizeof(host));
if (name == NULL || name[0] == '\0') {
- krb5int_buf_add(&buf, prefix);
+ k5_buf_add(&buf, prefix);
} else {
- krb5int_buf_add_fmt(&buf, "%s.%s", prefix, name);
+ k5_buf_add_fmt(&buf, "%s.%s", prefix, name);
/* Realm names don't (normally) end with ".", but if the query
doesn't end with "." and doesn't get an answer as is, the
the local domain or domain search lists to be expanded.
*/
- len = krb5int_buf_len(&buf);
+ len = k5_buf_len(&buf);
if (len > 0 && host[len - 1] != '.')
- krb5int_buf_add(&buf, ".");
+ k5_buf_add(&buf, ".");
}
- if (krb5int_buf_data(&buf) == NULL)
+ if (k5_buf_data(&buf) == NULL)
return KRB5_ERR_HOST_REALM_UNKNOWN;
ret = krb5int_dns_init(&ds, host, C_IN, T_TXT);
if (ret < 0)
if (memchr(realm->data, 0, realm->length))
return 0;
- krb5int_buf_init_fixed(&buf, host, sizeof(host));
- krb5int_buf_add_fmt(&buf, "%s.%s.", service, protocol);
- krb5int_buf_add_len(&buf, realm->data, realm->length);
+ k5_buf_init_fixed(&buf, host, sizeof(host));
+ k5_buf_add_fmt(&buf, "%s.%s.", service, protocol);
+ k5_buf_add_len(&buf, realm->data, realm->length);
/* Realm names don't (normally) end with ".", but if the query
doesn't end with "." and doesn't get an answer as is, the
a search on the prefix alone then the intention is to allow
the local domain or domain search lists to be expanded. */
- len = krb5int_buf_len(&buf);
+ len = k5_buf_len(&buf);
if (len > 0 && host[len - 1] != '.')
- krb5int_buf_add(&buf, ".");
+ k5_buf_add(&buf, ".");
- if (krb5int_buf_data(&buf) == NULL)
+ if (k5_buf_data(&buf) == NULL)
return 0;
#ifdef TEST
*path_out = NULL;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
/* Count extra tokens. */
va_start(ap, path_out);
* If there are no more tokens, we can finish up. */
tok_begin = strstr(path_left, "%{");
if (tok_begin == NULL) {
- krb5int_buf_add(&buf, path_left);
+ k5_buf_add(&buf, path_left);
break;
}
- krb5int_buf_add_len(&buf, path_left, tok_begin - path_left);
+ k5_buf_add_len(&buf, path_left, tok_begin - path_left);
/* Find the end of this token. */
tok_end = strchr(tok_begin, '}');
&tok_val);
if (ret)
goto cleanup;
- krb5int_buf_add(&buf, tok_val);
+ k5_buf_add(&buf, tok_val);
free(tok_val);
path_left = tok_end + 1;
}
- path = krb5int_buf_data(&buf);
+ path = k5_buf_data(&buf);
if (path == NULL) {
ret = ENOMEM;
goto cleanup;
cleanup:
if (*path_out == NULL)
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
free_extra_tokens(extra_tokens);
return 0;
}
case 'A':
/* %A => addrinfo */
ai = va_arg(args, struct addrinfo *);
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
if (ai->ai_socktype == SOCK_DGRAM)
- krb5int_buf_add(&buf, "dgram");
+ k5_buf_add(&buf, "dgram");
else if (ai->ai_socktype == SOCK_STREAM)
- krb5int_buf_add(&buf, "stream");
+ k5_buf_add(&buf, "stream");
else
- krb5int_buf_add_fmt(&buf, "socktype%d", ai->ai_socktype);
+ k5_buf_add_fmt(&buf, "socktype%d", ai->ai_socktype);
if (0 != getnameinfo (ai->ai_addr, ai->ai_addrlen,
addrbuf, sizeof (addrbuf),
portbuf, sizeof (portbuf),
NI_NUMERICHOST | NI_NUMERICSERV)) {
if (ai->ai_addr->sa_family == AF_UNSPEC)
- krb5int_buf_add(&buf, " AF_UNSPEC");
+ k5_buf_add(&buf, " AF_UNSPEC");
else
- krb5int_buf_add_fmt(&buf, " af%d", ai->ai_addr->sa_family);
+ k5_buf_add_fmt(&buf, " af%d", ai->ai_addr->sa_family);
} else
- krb5int_buf_add_fmt(&buf, " %s.%s", addrbuf, portbuf);
- if (krb5int_buf_data(&buf))
- putstr(krb5int_buf_data(&buf));
- krb5int_free_buf(&buf);
+ k5_buf_add_fmt(&buf, " %s.%s", addrbuf, portbuf);
+ if (k5_buf_data(&buf))
+ putstr(k5_buf_data(&buf));
+ k5_free_buf(&buf);
break;
case 'D':
/* %D => krb5_data * */
size_t i;
if (buf_is_printable(p, len)) {
- krb5int_buf_add_len(buf, p, len);
+ k5_buf_add_len(buf, p, len);
} else {
for (i = 0; i < len; i++) {
if (buf_is_printable(p + i, 1)) {
- krb5int_buf_add_len(buf, p + i, 1);
+ k5_buf_add_len(buf, p + i, 1);
} else {
snprintf(text, sizeof(text), "\\x%02x",
(unsigned)(p[i] & 0xff));
- krb5int_buf_add_len(buf, text, 4);
+ k5_buf_add_len(buf, text, 4);
}
}
}
krb5_creds *creds;
krb5_enctype *etypes, etype;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
while (TRUE) {
/* Advance to the next word in braces. */
len = strcspn(fmt, "{");
- krb5int_buf_add_len(&buf, fmt, len);
+ k5_buf_add_len(&buf, fmt, len);
if (fmt[len] == '\0')
break;
fmt += len + 1;
/* Process the format word. */
if (strcmp(tmpbuf, "int") == 0) {
- krb5int_buf_add_fmt(&buf, "%d", va_arg(ap, int));
+ k5_buf_add_fmt(&buf, "%d", va_arg(ap, int));
} else if (strcmp(tmpbuf, "long") == 0) {
- krb5int_buf_add_fmt(&buf, "%ld", va_arg(ap, long));
+ k5_buf_add_fmt(&buf, "%ld", va_arg(ap, long));
} else if (strcmp(tmpbuf, "str") == 0) {
p = va_arg(ap, const char *);
buf_add_printable(&buf, (p == NULL) ? "(null)" : p);
len = va_arg(ap, size_t);
p = va_arg(ap, const char *);
if (p == NULL && len != 0)
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else
buf_add_printable_len(&buf, p, len);
} else if (strcmp(tmpbuf, "hexlenstr") == 0) {
len = va_arg(ap, size_t);
p = va_arg(ap, const char *);
if (p == NULL && len != 0)
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else {
for (i = 0; i < len; i++)
- krb5int_buf_add_fmt(&buf, "%02X", (unsigned char) p[i]);
+ k5_buf_add_fmt(&buf, "%02X", (unsigned char)p[i]);
}
} else if (strcmp(tmpbuf, "hashlenstr") == 0) {
len = va_arg(ap, size_t);
p = va_arg(ap, const char *);
if (p == NULL && len != 0)
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else {
str = hash_bytes(context, p, len);
if (str != NULL)
- krb5int_buf_add(&buf, str);
+ k5_buf_add(&buf, str);
free(str);
}
} else if (strcmp(tmpbuf, "connstate") == 0) {
cs = va_arg(ap, struct conn_state *);
if (cs->socktype == SOCK_DGRAM)
- krb5int_buf_add(&buf, "dgram");
+ k5_buf_add(&buf, "dgram");
else if (cs->socktype == SOCK_STREAM)
- krb5int_buf_add(&buf, "stream");
+ k5_buf_add(&buf, "stream");
else
- krb5int_buf_add_fmt(&buf, "socktype%d", cs->socktype);
+ k5_buf_add_fmt(&buf, "socktype%d", cs->socktype);
if (getnameinfo((struct sockaddr *)&cs->addr, cs->addrlen,
addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf),
NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
if (cs->family == AF_UNSPEC)
- krb5int_buf_add(&buf, " AF_UNSPEC");
+ k5_buf_add(&buf, " AF_UNSPEC");
else
- krb5int_buf_add_fmt(&buf, " af%d", cs->family);
+ k5_buf_add_fmt(&buf, " af%d", cs->family);
} else
- krb5int_buf_add_fmt(&buf, " %s:%s", addrbuf, portbuf);
+ k5_buf_add_fmt(&buf, " %s:%s", addrbuf, portbuf);
} else if (strcmp(tmpbuf, "data") == 0) {
d = va_arg(ap, krb5_data *);
if (d == NULL || (d->length != 0 && d->data == NULL))
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else
buf_add_printable_len(&buf, d->data, d->length);
} else if (strcmp(tmpbuf, "hexdata") == 0) {
d = va_arg(ap, krb5_data *);
if (d == NULL)
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else
subfmt(context, &buf, "{hexlenstr}", d->length, d->data);
} else if (strcmp(tmpbuf, "errno") == 0) {
#endif
if (p == NULL)
p = strerror(err);
- krb5int_buf_add_fmt(&buf, "%d/%s", err, p);
+ k5_buf_add_fmt(&buf, "%d/%s", err, p);
} else if (strcmp(tmpbuf, "kerr") == 0) {
kerr = va_arg(ap, krb5_error_code);
p = krb5_get_error_message(context, kerr);
- krb5int_buf_add_fmt(&buf, "%ld/%s", (long) kerr,
- kerr ? p : "Success");
+ k5_buf_add_fmt(&buf, "%ld/%s", (long)kerr, kerr ? p : "Success");
krb5_free_error_message(context, p);
} else if (strcmp(tmpbuf, "keyblock") == 0) {
keyblock = va_arg(ap, const krb5_keyblock *);
if (keyblock == NULL)
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else {
subfmt(context, &buf, "{etype}/{hashlenstr}",
keyblock->enctype, keyblock->length,
} else if (strcmp(tmpbuf, "key") == 0) {
key = va_arg(ap, krb5_key);
if (key == NULL)
- krb5int_buf_add(&buf, "(null)");
+ k5_buf_add(&buf, "(null)");
else
subfmt(context, &buf, "{keyblock}", &key->keyblock);
} else if (strcmp(tmpbuf, "cksum") == 0) {
} else if (strcmp(tmpbuf, "princ") == 0) {
princ = va_arg(ap, krb5_principal);
if (krb5_unparse_name(context, princ, &str) == 0) {
- krb5int_buf_add(&buf, str);
+ k5_buf_add(&buf, str);
krb5_free_unparsed_name(context, str);
}
} else if (strcmp(tmpbuf, "ptype") == 0) {
p = principal_type_string(va_arg(ap, krb5_int32));
- krb5int_buf_add(&buf, p);
+ k5_buf_add(&buf, p);
} else if (strcmp(tmpbuf, "patypes") == 0) {
padata = va_arg(ap, krb5_pa_data **);
if (padata == NULL || *padata == NULL)
- krb5int_buf_add(&buf, "(empty)");
+ k5_buf_add(&buf, "(empty)");
for (; padata != NULL && *padata != NULL; padata++) {
- krb5int_buf_add_fmt(&buf, "%d", (int) (*padata)->pa_type);
+ k5_buf_add_fmt(&buf, "%d", (int)(*padata)->pa_type);
if (*(padata + 1) != NULL)
- krb5int_buf_add(&buf, ", ");
+ k5_buf_add(&buf, ", ");
}
} else if (strcmp(tmpbuf, "etype") == 0) {
etype = va_arg(ap, krb5_enctype);
if (krb5_enctype_to_name(etype, TRUE, tmpbuf, sizeof(tmpbuf)) == 0)
- krb5int_buf_add(&buf, tmpbuf);
+ k5_buf_add(&buf, tmpbuf);
else
- krb5int_buf_add_fmt(&buf, "%d", (int) etype);
+ k5_buf_add_fmt(&buf, "%d", (int)etype);
} else if (strcmp(tmpbuf, "etypes") == 0) {
etypes = va_arg(ap, krb5_enctype *);
if (etypes == NULL || *etypes == 0)
- krb5int_buf_add(&buf, "(empty)");
+ k5_buf_add(&buf, "(empty)");
for (; etypes != NULL && *etypes != 0; etypes++) {
subfmt(context, &buf, "{etype}", *etypes);
if (*(etypes + 1) != 0)
- krb5int_buf_add(&buf, ", ");
+ k5_buf_add(&buf, ", ");
}
} else if (strcmp(tmpbuf, "ccache") == 0) {
ccache = va_arg(ap, krb5_ccache);
- krb5int_buf_add(&buf, krb5_cc_get_type(context, ccache));
- krb5int_buf_add(&buf, ":");
- krb5int_buf_add(&buf, krb5_cc_get_name(context, ccache));
+ k5_buf_add(&buf, krb5_cc_get_type(context, ccache));
+ k5_buf_add(&buf, ":");
+ k5_buf_add(&buf, krb5_cc_get_name(context, ccache));
} else if (strcmp(tmpbuf, "keytab") == 0) {
keytab = va_arg(ap, krb5_keytab);
if (krb5_kt_get_name(context, keytab, tmpbuf, sizeof(tmpbuf)) == 0)
- krb5int_buf_add(&buf, tmpbuf);
+ k5_buf_add(&buf, tmpbuf);
} else if (strcmp(tmpbuf, "creds") == 0) {
creds = va_arg(ap, krb5_creds *);
subfmt(context, &buf, "{princ} -> {princ}",
creds->client, creds->server);
}
}
- return krb5int_buf_data(&buf);
+ return k5_buf_data(&buf);
}
/* Allows trace_format formatters to be represented in terms of other
va_start(ap, fmt);
str = trace_format(context, fmt, ap);
if (str != NULL)
- krb5int_buf_add(buf, str);
+ k5_buf_add(buf, str);
free(str);
va_end(ap);
}
*/
/* Format the extension value so we know its length. */
- krb5int_buf_init_dynamic(&extbuf);
- krb5int_buf_add_fmt(&extbuf, "HASH:%s %lu:%s %lu:%s", rep->msghash,
- (unsigned long) clientlen, rep->client,
- (unsigned long) serverlen, rep->server);
- extstr = krb5int_buf_data(&extbuf);
+ k5_buf_init_dynamic(&extbuf);
+ k5_buf_add_fmt(&extbuf, "HASH:%s %lu:%s %lu:%s", rep->msghash,
+ (unsigned long)clientlen, rep->client,
+ (unsigned long)serverlen, rep->server);
+ extstr = k5_buf_data(&extbuf);
if (!extstr)
return KRB5_RC_MALLOC;
* Put the extension value into the server field of a
* regular-format record, with an empty client field.
*/
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
len = 1;
- krb5int_buf_add_len(&buf, (char *) &len, sizeof(len));
- krb5int_buf_add_len(&buf, "", 1);
+ k5_buf_add_len(&buf, (char *)&len, sizeof(len));
+ k5_buf_add_len(&buf, "", 1);
len = strlen(extstr) + 1;
- krb5int_buf_add_len(&buf, (char *) &len, sizeof(len));
- krb5int_buf_add_len(&buf, extstr, len);
- krb5int_buf_add_len(&buf, (char *) &rep->cusec, sizeof(rep->cusec));
- krb5int_buf_add_len(&buf, (char *) &rep->ctime, sizeof(rep->ctime));
+ k5_buf_add_len(&buf, (char *)&len, sizeof(len));
+ k5_buf_add_len(&buf, extstr, len);
+ k5_buf_add_len(&buf, (char *)&rep->cusec, sizeof(rep->cusec));
+ k5_buf_add_len(&buf, (char *)&rep->ctime, sizeof(rep->ctime));
free(extstr);
} else /* No extension record needed. */
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
len = clientlen + 1;
- krb5int_buf_add_len(&buf, (char *) &len, sizeof(len));
- krb5int_buf_add_len(&buf, rep->client, len);
+ k5_buf_add_len(&buf, (char *)&len, sizeof(len));
+ k5_buf_add_len(&buf, rep->client, len);
len = serverlen + 1;
- krb5int_buf_add_len(&buf, (char *) &len, sizeof(len));
- krb5int_buf_add_len(&buf, rep->server, len);
- krb5int_buf_add_len(&buf, (char *) &rep->cusec, sizeof(rep->cusec));
- krb5int_buf_add_len(&buf, (char *) &rep->ctime, sizeof(rep->ctime));
+ k5_buf_add_len(&buf, (char *)&len, sizeof(len));
+ k5_buf_add_len(&buf, rep->server, len);
+ k5_buf_add_len(&buf, (char *)&rep->cusec, sizeof(rep->cusec));
+ k5_buf_add_len(&buf, (char *)&rep->ctime, sizeof(rep->ctime));
- bufptr = krb5int_buf_data(&buf);
- buflen = krb5int_buf_len(&buf);
+ bufptr = k5_buf_data(&buf);
+ buflen = k5_buf_len(&buf);
if (bufptr == NULL || buflen < 0)
return KRB5_RC_MALLOC;
ret = krb5_rc_io_write(context, &t->d, bufptr, buflen);
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return ret;
}
if (!o_princ_name)
return ENOMEM;
} else {
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
for (p = i_princ_name; p < at_rlm_name; p++) {
if (*p == '@')
- krb5int_buf_add(&buf, "\\");
- krb5int_buf_add_len(&buf, p, 1);
+ k5_buf_add(&buf, "\\");
+ k5_buf_add_len(&buf, p, 1);
}
- krb5int_buf_add(&buf, at_rlm_name);
- *o_princ_name = krb5int_buf_data(&buf);
+ k5_buf_add(&buf, at_rlm_name);
+ *o_princ_name = k5_buf_data(&buf);
if (!*o_princ_name)
return ENOMEM;
}
const char special[] = "*()\\ #\"+,;<>";
struct k5buf buf;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
while (TRUE) {
count = strcspn(in, special);
- krb5int_buf_add_len(&buf, in, count);
+ k5_buf_add_len(&buf, in, count);
in += count;
if (*in == '\0')
break;
- krb5int_buf_add_fmt(&buf, "\\%2x", (unsigned char)*in++);
+ k5_buf_add_fmt(&buf, "\\%2x", (unsigned char)*in++);
}
- return krb5int_buf_data(&buf);
+ return k5_buf_data(&buf);
}
static int
int n = 0;
char *ret;
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, "PKCS11:");
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, "PKCS11:");
n = 0;
if (idopts->p11_module_name != NULL) {
- krb5int_buf_add_fmt(&buf, "%smodule_name=%s",
- n++ ? "," : "",
- idopts->p11_module_name);
+ k5_buf_add_fmt(&buf, "%smodule_name=%s", n++ ? "," : "",
+ idopts->p11_module_name);
}
if (idopts->token_label != NULL) {
- krb5int_buf_add_fmt(&buf, "%stoken=%s",
- n++ ? "," : "",
- idopts->token_label);
+ k5_buf_add_fmt(&buf, "%stoken=%s", n++ ? "," : "",
+ idopts->token_label);
}
if (idopts->cert_label != NULL) {
- krb5int_buf_add_fmt(&buf, "%scertlabel=%s",
- n++ ? "," : "",
- idopts->cert_label);
+ k5_buf_add_fmt(&buf, "%scertlabel=%s", n++ ? "," : "",
+ idopts->cert_label);
}
if (idopts->cert_id_string != NULL) {
- krb5int_buf_add_fmt(&buf, "%scertid=%s",
- n++ ? "," : "",
- idopts->cert_id_string);
+ k5_buf_add_fmt(&buf, "%scertid=%s", n++ ? "," : "",
+ idopts->cert_id_string);
}
if (idopts->slotid != PK_NOSLOT) {
- krb5int_buf_add_fmt(&buf, "%sslotid=%ld",
- n++ ? "," : "",
- (long)idopts->slotid);
+ k5_buf_add_fmt(&buf, "%sslotid=%ld", n++ ? "," : "",
+ (long)idopts->slotid);
}
- if (krb5int_buf_len(&buf) >= 0)
- ret = PORT_ArenaStrdup(pool, krb5int_buf_data(&buf));
+ if (k5_buf_len(&buf) >= 0)
+ ret = PORT_ArenaStrdup(pool, k5_buf_data(&buf));
else
ret = NULL;
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return ret;
}
int n = 0;
char *ret;
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, "PKCS11:");
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, "PKCS11:");
n = 0;
if (idopts->p11_module_name != NULL) {
- krb5int_buf_add_fmt(&buf, "%smodule_name=%s",
- n++ ? "," : "",
- idopts->p11_module_name);
+ k5_buf_add_fmt(&buf, "%smodule_name=%s", n++ ? "," : "",
+ idopts->p11_module_name);
}
if (idopts->token_label != NULL) {
- krb5int_buf_add_fmt(&buf, "%stoken=%s",
- n++ ? "," : "",
- idopts->token_label);
+ k5_buf_add_fmt(&buf, "%stoken=%s", n++ ? "," : "",
+ idopts->token_label);
}
if (idopts->cert_label != NULL) {
- krb5int_buf_add_fmt(&buf, "%scertlabel=%s",
- n++ ? "," : "",
- idopts->cert_label);
+ k5_buf_add_fmt(&buf, "%scertlabel=%s", n++ ? "," : "",
+ idopts->cert_label);
}
if (idopts->cert_id_string != NULL) {
- krb5int_buf_add_fmt(&buf, "%scertid=%s",
- n++ ? "," : "",
- idopts->cert_id_string);
+ k5_buf_add_fmt(&buf, "%scertid=%s", n++ ? "," : "",
+ idopts->cert_id_string);
}
if (idopts->slotid != PK_NOSLOT) {
- krb5int_buf_add_fmt(&buf, "%sslotid=%ld",
- n++ ? "," : "",
- (long)idopts->slotid);
+ k5_buf_add_fmt(&buf, "%sslotid=%ld", n++ ? "," : "",
+ (long)idopts->slotid);
}
- if (krb5int_buf_len(&buf) >= 0)
- ret = strdup(krb5int_buf_data(&buf));
+ if (k5_buf_len(&buf) >= 0)
+ ret = strdup(k5_buf_data(&buf));
else
ret = NULL;
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return ret;
}
*pid_out = pid;
}
-#define WRITE(b, d) krb5int_buf_add_len(b, (char *)&d, sizeof(d))
+#define WRITE(b, d) k5_buf_add_len(b, (char *)&d, sizeof(d))
/* Add the fields of lkey to bufp. */
static void
{
WRITE(bufp, lkey->type);
WRITE(bufp, lkey->length);
- krb5int_buf_add_len(bufp, lkey->data, lkey->length);
+ k5_buf_add_len(bufp, lkey->data, lkey->length);
}
/* Using a machine-dependent format, marshal the fields of lctx into an
{
struct k5buf buf;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
WRITE(&buf, lctx->version);
WRITE(&buf, lctx->initiate);
WRITE(&buf, lctx->endtime);
add_lucid_key(&buf, &lctx->cfx_kd.acceptor_subkey);
} else
abort();
- assert(krb5int_buf_data(&buf) != NULL);
- *data_out = (unsigned char *)krb5int_buf_data(&buf);
- *len_out = krb5int_buf_len(&buf);
+ assert(k5_buf_data(&buf) != NULL);
+ *data_out = (unsigned char *)k5_buf_data(&buf);
+ *len_out = k5_buf_len(&buf);
}
/* Export ctx as a lucid context, marshal it, and write it to fd. */
size_t n;
const char *p;
- krb5int_buf_add(buf, "\"");
+ k5_buf_add(buf, "\"");
while (*str != '\0') {
n = strcspn(str, needs_quote);
- krb5int_buf_add_len(buf, str, n);
+ k5_buf_add_len(buf, str, n);
str += n;
if (*str == '\0')
break;
- krb5int_buf_add(buf, "\\");
+ k5_buf_add(buf, "\\");
p = strchr(quotemap_c, *str);
if (p != NULL)
- krb5int_buf_add_len(buf, quotemap_json + (p - quotemap_c), 1);
+ k5_buf_add_len(buf, quotemap_json + (p - quotemap_c), 1);
else
- krb5int_buf_add_fmt(buf, "u00%02X", (unsigned int)*str);
+ k5_buf_add_fmt(buf, "u00%02X", (unsigned int)*str);
str++;
}
- krb5int_buf_add(buf, "\"");
+ k5_buf_add(buf, "\"");
}
struct obj_ctx {
if (j->first)
j->first = 0;
else
- krb5int_buf_add(j->buf, ",");
+ k5_buf_add(j->buf, ",");
encode_string(j->buf, key);
- krb5int_buf_add(j->buf, ":");
+ k5_buf_add(j->buf, ":");
j->ret = encode_value(j->buf, value);
}
type = k5_json_get_tid(val);
switch (type) {
case K5_JSON_TID_ARRAY:
- krb5int_buf_add(buf, "[");
+ k5_buf_add(buf, "[");
len = k5_json_array_length(val);
for (i = 0; i < len; i++) {
if (i != 0)
- krb5int_buf_add(buf, ",");
+ k5_buf_add(buf, ",");
ret = encode_value(buf, k5_json_array_get(val, i));
if (ret)
return ret;
}
- krb5int_buf_add(buf, "]");
+ k5_buf_add(buf, "]");
return 0;
case K5_JSON_TID_OBJECT:
- krb5int_buf_add(buf, "{");
+ k5_buf_add(buf, "{");
ctx.buf = buf;
ctx.ret = 0;
ctx.first = 1;
k5_json_object_iterate(val, encode_obj_entry, &ctx);
- krb5int_buf_add(buf, "}");
+ k5_buf_add(buf, "}");
return ctx.ret;
case K5_JSON_TID_STRING:
return 0;
case K5_JSON_TID_NUMBER:
- krb5int_buf_add_fmt(buf, "%lld", k5_json_number_value(val));
+ k5_buf_add_fmt(buf, "%lld", k5_json_number_value(val));
return 0;
case K5_JSON_TID_NULL:
- krb5int_buf_add(buf, "null");
+ k5_buf_add(buf, "null");
return 0;
case K5_JSON_TID_BOOL:
- krb5int_buf_add(buf, k5_json_bool_value(val) ? "true" : "false");
+ k5_buf_add(buf, k5_json_bool_value(val) ? "true" : "false");
return 0;
default:
int ret;
*json_out = NULL;
- krb5int_buf_init_dynamic(&buf);
+ k5_buf_init_dynamic(&buf);
ret = encode_value(&buf, val);
if (ret) {
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
return ret;
}
- *json_out = krb5int_buf_data(&buf);
+ *json_out = k5_buf_data(&buf);
return (*json_out == NULL) ? ENOMEM : 0;
}
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* util/support/k5buf-int.h */
+/* util/support/k5buf-int.h - Internal declarations for string buffers */
/*
* Copyright 2008 Massachusetts Institute of Technology.
* All Rights Reserved.
* or implied warranty.
*/
-/* Internal declarations for the k5buf string buffer module */
-
#ifndef K5BUF_INT_H
#define K5BUF_INT_H
#include "k5-platform.h"
#include "k5-buf.h"
-/* The k5buf structure has funny field names to discourage callers
- from violating the abstraction barrier. Define less funny names
- for them here. */
+/*
+ * The k5buf structure has funny field names to discourage callers from
+ * violating the abstraction barrier. Define less funny names for them here.
+ */
#define buftype xx_buftype
#define data xx_data
#define space xx_space
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* util/support/k5buf.c */
+/* util/support/k5buf.c - string buffer functions */
+
/*
* Copyright 2008 Massachusetts Institute of Technology.
* All Rights Reserved.
* or implied warranty.
*/
-/* Implement the k5buf string buffer module. */
-
-/* Can't include krb5.h here, or k5-int.h which includes it, because
- krb5.h needs to be generated with error tables, after util/et,
- which builds after this directory. */
+/*
+ * Can't include krb5.h here, or k5-int.h which includes it, because krb5.h
+ * needs to be generated with error tables, after util/et, which builds after
+ * this directory.
+ */
#include "k5buf-int.h"
#include <assert.h>
* data[len] = '\0'
*/
-/* Make sure there is room for LEN more characters in BUF, in addition
- to the null terminator and what's already in there. Return true on
- success. On failure, set the error flag and return false. */
-static int ensure_space(struct k5buf *buf, size_t len)
+/*
+ * Make sure there is room for LEN more characters in BUF, in addition to the
+ * null terminator and what's already in there. Return true on success. On
+ * failure, set the error flag and return false.
+ */
+static int
+ensure_space(struct k5buf *buf, size_t len)
{
size_t new_space;
char *new_data;
return 0;
}
-void krb5int_buf_init_fixed(struct k5buf *buf, char *data, size_t space)
+void
+k5_buf_init_fixed(struct k5buf *buf, char *data, size_t space)
{
assert(space > 0);
buf->buftype = BUFTYPE_FIXED;
buf->data[0] = '\0';
}
-void krb5int_buf_init_dynamic(struct k5buf *buf)
+void
+k5_buf_init_dynamic(struct k5buf *buf)
{
buf->buftype = BUFTYPE_DYNAMIC;
buf->space = DYNAMIC_INITIAL_SIZE;
buf->data[0] = '\0';
}
-void krb5int_buf_add(struct k5buf *buf, const char *data)
+void
+k5_buf_add(struct k5buf *buf, const char *data)
{
- krb5int_buf_add_len(buf, data, strlen(data));
+ k5_buf_add_len(buf, data, strlen(data));
}
-void krb5int_buf_add_len(struct k5buf *buf, const char *data, size_t len)
+void
+k5_buf_add_len(struct k5buf *buf, const char *data, size_t len)
{
if (!ensure_space(buf, len))
return;
buf->data[buf->len] = '\0';
}
-void krb5int_buf_add_fmt(struct k5buf *buf, const char *fmt, ...)
+void
+k5_buf_add_fmt(struct k5buf *buf, const char *fmt, ...)
{
va_list ap;
int r;
return;
}
- /* It's a pre-C99 snprintf implementation, or something else went
- wrong. Fall back to asprintf. */
+ /* It's a pre-C99 snprintf implementation, or something else went wrong.
+ * Fall back to asprintf. */
va_start(ap, fmt);
r = vasprintf(&tmp, fmt, ap);
va_end(ap);
free(tmp);
}
-void krb5int_buf_truncate(struct k5buf *buf, size_t len)
+void
+k5_buf_truncate(struct k5buf *buf, size_t len)
{
if (buf->buftype == BUFTYPE_ERROR)
return;
}
-char *krb5int_buf_data(struct k5buf *buf)
+char *
+k5_buf_data(struct k5buf *buf)
{
return (buf->buftype == BUFTYPE_ERROR) ? NULL : buf->data;
}
-ssize_t krb5int_buf_len(struct k5buf *buf)
+ssize_t
+k5_buf_len(struct k5buf *buf)
{
return (buf->buftype == BUFTYPE_ERROR) ? -1 : (ssize_t) buf->len;
}
-void krb5int_free_buf(struct k5buf *buf)
+void
+k5_free_buf(struct k5buf *buf)
{
if (buf->buftype == BUFTYPE_ERROR)
return;
+k5_buf_init_fixed
+k5_buf_init_dynamic
+k5_buf_add
+k5_buf_add_len
+k5_buf_add_fmt
+k5_buf_truncate
+k5_buf_data
+k5_buf_len
+k5_free_buf
k5_set_error
k5_vset_error
k5_set_error_fl
krb5int_mutex_lock
krb5int_mutex_unlock
krb5int_gmt_mktime
-krb5int_buf_init_fixed
-krb5int_buf_init_dynamic
-krb5int_buf_add
-krb5int_buf_add_len
-krb5int_buf_add_fmt
-krb5int_buf_truncate
-krb5int_buf_data
-krb5int_buf_len
-krb5int_free_buf
krb5int_utf8cs_to_ucs2les
krb5int_utf8s_to_ucs2les
krb5int_ucs2lecs_to_utf8s
#include <stdio.h>
#include <stdlib.h>
-static void fail_if(int condition, const char *name)
+static void
+fail_if(int condition, const char *name)
{
if (condition) {
fprintf(stderr, "%s failed\n", name);
}
/* Test the invariants of a buffer. */
-static void check_buf(struct k5buf *buf, const char *name)
+static void
+check_buf(struct k5buf *buf, const char *name)
{
fail_if(buf->buftype != BUFTYPE_FIXED && buf->buftype != BUFTYPE_DYNAMIC
&& buf->buftype != BUFTYPE_ERROR, name);
fail_if(buf->data[buf->len] != 0, name);
}
-static void test_basic()
+static void
+test_basic()
{
struct k5buf buf;
char storage[1024], *s;
ssize_t len;
- krb5int_buf_init_fixed(&buf, storage, sizeof(storage));
- krb5int_buf_add(&buf, "Hello ");
- krb5int_buf_add_len(&buf, "world", 5);
+ k5_buf_init_fixed(&buf, storage, sizeof(storage));
+ k5_buf_add(&buf, "Hello ");
+ k5_buf_add_len(&buf, "world", 5);
check_buf(&buf, "basic fixed");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || strcmp(s, "Hello world") != 0 || len != 11, "basic fixed");
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, "Hello", 5);
- krb5int_buf_add(&buf, " world");
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, "Hello", 5);
+ k5_buf_add(&buf, " world");
check_buf(&buf, "basic dynamic");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || strcmp(s, "Hello world") != 0 || len != 11, "basic dynamic");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
}
-static void test_realloc()
+static void
+test_realloc()
{
struct k5buf buf;
char data[1024], *s;
data[i] = 'a';
/* Cause the buffer size to double from 128 to 256 bytes. */
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, data, 10);
- krb5int_buf_add_len(&buf, data, 128);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, data, 10);
+ k5_buf_add_len(&buf, data, 128);
fail_if(buf.space != 256, "realloc 1");
check_buf(&buf, "realloc 1");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 138 || memcmp(s, data, len) != 0, "realloc 1");
/* Cause the same buffer to double in size to 512 bytes. */
- krb5int_buf_add_len(&buf, data, 128);
+ k5_buf_add_len(&buf, data, 128);
fail_if(buf.space != 512, "realloc 2");
check_buf(&buf, "realloc 2");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 266 || memcmp(s, data, len) != 0, "realloc 2");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
/* Cause a buffer to increase from 128 to 512 bytes directly. */
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, data, 10);
- krb5int_buf_add_len(&buf, data, 256);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, data, 10);
+ k5_buf_add_len(&buf, data, 256);
fail_if(buf.space != 512, "realloc 3");
check_buf(&buf, "realloc 3");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 266 || memcmp(s, data, len) != 0, "realloc 3");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
/* Cause a buffer to increase from 128 to 1024 bytes directly. */
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, data, 10);
- krb5int_buf_add_len(&buf, data, 512);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, data, 10);
+ k5_buf_add_len(&buf, data, 512);
fail_if(buf.space != 1024, "realloc 4");
check_buf(&buf, "realloc 4");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 522 || memcmp(s, data, len) != 0, "realloc 4");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
/* Cause a reallocation to fail by exceeding SPACE_MAX. */
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, data, 10);
- krb5int_buf_add_len(&buf, NULL, SPACE_MAX);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, data, 10);
+ k5_buf_add_len(&buf, NULL, SPACE_MAX);
check_buf(&buf, "realloc 5");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1,
"realloc 5");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
/* Cause a reallocation to fail by integer overflow. */
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, data, 100);
- krb5int_buf_add_len(&buf, NULL, SPACE_MAX * 2);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, data, 100);
+ k5_buf_add_len(&buf, NULL, SPACE_MAX * 2);
check_buf(&buf, "realloc 6");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1,
"realloc 6");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
}
-static void test_overflow()
+static void
+test_overflow()
{
struct k5buf buf;
char storage[10], *s;
ssize_t len;
/* Cause a fixed-sized buffer overflow. */
- krb5int_buf_init_fixed(&buf, storage, sizeof(storage));
- krb5int_buf_add(&buf, "12345");
- krb5int_buf_add(&buf, "12345");
+ k5_buf_init_fixed(&buf, storage, sizeof(storage));
+ k5_buf_add(&buf, "12345");
+ k5_buf_add(&buf, "12345");
check_buf(&buf, "overflow 1");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1,
"overflow 1");
/* Cause a fixed-sized buffer overflow with integer overflow. */
- krb5int_buf_init_fixed(&buf, storage, sizeof(storage));
- krb5int_buf_add(&buf, "12345");
- krb5int_buf_add_len(&buf, NULL, SPACE_MAX * 2);
+ k5_buf_init_fixed(&buf, storage, sizeof(storage));
+ k5_buf_add(&buf, "12345");
+ k5_buf_add_len(&buf, NULL, SPACE_MAX * 2);
check_buf(&buf, "overflow 2");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1,
"overflow 2");
}
-static void test_error()
+static void
+test_error()
{
struct k5buf buf;
char storage[1];
/* Cause an overflow and then perform actions afterwards. */
- krb5int_buf_init_fixed(&buf, storage, sizeof(storage));
- krb5int_buf_add(&buf, "1");
+ k5_buf_init_fixed(&buf, storage, sizeof(storage));
+ k5_buf_add(&buf, "1");
fail_if(buf.buftype != BUFTYPE_ERROR, "error");
check_buf(&buf, "error");
- krb5int_buf_add(&buf, "test");
+ k5_buf_add(&buf, "test");
check_buf(&buf, "error");
- krb5int_buf_add_len(&buf, "test", 4);
+ k5_buf_add_len(&buf, "test", 4);
check_buf(&buf, "error");
- krb5int_buf_truncate(&buf, 3);
+ k5_buf_truncate(&buf, 3);
check_buf(&buf, "error");
fail_if(buf.buftype != BUFTYPE_ERROR, "error");
}
-static void test_truncate()
+static void
+test_truncate()
{
struct k5buf buf;
char *s;
ssize_t len;
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, "abcde");
- krb5int_buf_add(&buf, "fghij");
- krb5int_buf_truncate(&buf, 7);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, "abcde");
+ k5_buf_add(&buf, "fghij");
+ k5_buf_truncate(&buf, 7);
check_buf(&buf, "truncate");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 7 || strcmp(s, "abcdefg") != 0, "truncate");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
}
-static void test_binary()
+static void
+test_binary()
{
struct k5buf buf;
char *s, data[] = { 'a', 0, 'b' };
ssize_t len;
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add_len(&buf, data, 3);
- krb5int_buf_add_len(&buf, data, 3);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add_len(&buf, data, 3);
+ k5_buf_add_len(&buf, data, 3);
check_buf(&buf, "binary");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 6, "binary");
fail_if(s[0] != 'a' || s[1] != 0 || s[2] != 'b', "binary");
fail_if(s[3] != 'a' || s[4] != 0 || s[5] != 'b', "binary");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
}
-static void test_fmt()
+static void
+test_fmt()
{
struct k5buf buf;
char *s, storage[10], data[1024];
data[i] = '\0';
/* Format some text into a non-empty fixed buffer. */
- krb5int_buf_init_fixed(&buf, storage, sizeof(storage));
- krb5int_buf_add(&buf, "foo");
- krb5int_buf_add_fmt(&buf, " %d ", 3);
+ k5_buf_init_fixed(&buf, storage, sizeof(storage));
+ k5_buf_add(&buf, "foo");
+ k5_buf_add_fmt(&buf, " %d ", 3);
check_buf(&buf, "fmt 1");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 6 || strcmp(s, "foo 3 ") != 0, "fmt 1");
/* Overflow the same buffer with formatted text. */
- krb5int_buf_add_fmt(&buf, "%d%d%d%d", 1, 2, 3, 4);
+ k5_buf_add_fmt(&buf, "%d%d%d%d", 1, 2, 3, 4);
check_buf(&buf, "fmt 2");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(buf.buftype != BUFTYPE_ERROR || s != NULL || len != -1, "fmt 2");
/* Format some text into a non-empty dynamic buffer. */
- krb5int_buf_init_dynamic(&buf);
- krb5int_buf_add(&buf, "foo");
- krb5int_buf_add_fmt(&buf, " %d ", 3);
+ k5_buf_init_dynamic(&buf);
+ k5_buf_add(&buf, "foo");
+ k5_buf_add_fmt(&buf, " %d ", 3);
check_buf(&buf, "fmt 3");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 6 || strcmp(s, "foo 3 ") != 0, "fmt 3");
/* Format more text into the same buffer, causing a big resize. */
- krb5int_buf_add_fmt(&buf, "%s", data);
+ k5_buf_add_fmt(&buf, "%s", data);
check_buf(&buf, "fmt 4");
fail_if(buf.space != 2048, "fmt 4");
- s = krb5int_buf_data(&buf);
- len = krb5int_buf_len(&buf);
+ s = k5_buf_data(&buf);
+ len = k5_buf_len(&buf);
fail_if(!s || len != 1029 || strcmp(s + 6, data) != 0, "fmt 4");
- krb5int_free_buf(&buf);
+ k5_free_buf(&buf);
}
-int main()
+int
+main()
{
test_basic();
test_realloc();