1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/utils/antispoof.c
Simon Tatham cc6d3591ad Marshalling macros put_dataz and put_datalit.
When I wanted to append an ordinary C string to a BinarySink, without
any prefix length field or suffix terminator, I was using the idiom

  put_datapl(bs, ptrlen_from_asciz(string));

but I've finally decided that's too cumbersome, and it deserves a
shorter name. put_dataz(bs, string) now does the same thing - in fact
it's a macro expanding to exactly the above.

While I'm at it, I've also added put_datalit(), which is the same
except that it expects a C string literal (and will enforce that at
compile time, via PTRLEN_LITERAL which it calls in turn). You can use
that where possible to avoid the run-time cost of the strlen.
2021-11-19 15:09:17 +00:00

29 lines
887 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_dataz(sb, 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);
}