mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
be8d3974ff
marshal.h now provides a macro put_fmt() which allows you to write arbitrary printf-formatted data to an arbitrary BinarySink. We already had this facility for strbufs in particular, in the form of strbuf_catf(). That was able to take advantage of knowing the inner structure of a strbuf to minimise memory allocation (it would snprintf directly into the strbuf's existing buffer if possible). For a general black-box BinarySink we can't do that, so instead we dupvprintf into a temporary buffer. For consistency, I've removed strbuf_catf, and converted all uses of it into the new put_fmt - and I've also added an extra vtable method in the BinarySink API, so that put_fmt can still use strbuf_catf's more efficient memory management when talking to a strbuf, and fall back to the simpler strategy when that's not available.
29 lines
907 B
C
29 lines
907 B
C
#include "putty.h"
|
|
#include "misc.h"
|
|
|
|
void seat_antispoof_msg(InteractionReadySeat iseat, const char *msg)
|
|
{
|
|
strbuf *sb = strbuf_new();
|
|
seat_set_trust_status(iseat.seat, true);
|
|
if (seat_can_set_trust_status(iseat.seat)) {
|
|
/*
|
|
* If the seat can directly indicate that this message is
|
|
* generated by the client, then we can just use the message
|
|
* unmodified as an unspoofable header.
|
|
*/
|
|
put_datapl(sb, ptrlen_from_asciz(msg));
|
|
} else if (*msg) {
|
|
/*
|
|
* Otherwise, add enough padding around it that the server
|
|
* wouldn't be able to mimic it within our line-length
|
|
* constraint.
|
|
*/
|
|
put_fmt(sb, "-- %s ", msg);
|
|
while (sb->len < 78)
|
|
put_byte(sb, '-');
|
|
}
|
|
put_datapl(sb, PTRLEN_LITERAL("\r\n"));
|
|
seat_banner_pl(iseat, ptrlen_from_strbuf(sb));
|
|
strbuf_free(sb);
|
|
}
|