Added snsecprintf function that writes the secprintf message into the

buffer provided.
This commit is contained in:
Scott Haseley 2017-02-18 22:58:35 -05:00
parent 398e4eb90a
commit dbb57b2826
2 changed files with 32 additions and 7 deletions

View File

@ -87,6 +87,13 @@ say(const char *fmt, ...)
#ifndef SECRET_TESTING
int
snsecprintf(size_t len, char *buffer, const char *secret, const char *msg, const char *name)
{
(void)secret;
return snprintf(buffer, len, "%s: %s", name, msg);
}
int
secprintf(const char * secret, const char * msg, const char * name)
{
@ -101,8 +108,9 @@ secprintf(const char * secret, const char * msg, const char * name)
#else
int
secprintf(const char * secret, const char * msg, const char * name)
static int
secprintf_common(use_buf int, size_t len, char *buffer,
const char *secret, const char *msg, const char *name)
{
char *hash, *salt, *fullmsg;
int res;
@ -132,11 +140,15 @@ secprintf(const char * secret, const char * msg, const char * name)
goto out;
}
if (!use_buf) {
#ifdef _KERNEL
res = kprintf("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg);
#else
res = say("\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg);
#endif
} else {
res = snprintf(buffer, b_len, "\n(%s, %s, %s, %s: %s)\n", name, hash, salt, name, msg);
}
out:
// These may be NULL, but that's OK
@ -151,6 +163,18 @@ out:
return res;
}
int
snsecprintf(size_t b_len, char *buffer, const char *secret, const char *msg, const char *name)
{
return secprintf_common(1, b_len, buffer, secret, msg, name);
}
int
secprintf(const char * secret, const char * msg, const char * name)
{
return snsecprintf(0, 0, NULL, secret, msg, name);
}
#endif
#ifdef _KERNEL

View File

@ -66,6 +66,7 @@
int success(int, const char *, const char *);
int secprintf(const char *secret, const char *msg, const char *name);
int snsecprintf(size_t len, char *buffer, const char *secret, const char *msg, const char *name);
int partial_credit(const char *secret, const char *name, int scored, int total);
#ifdef _KERNEL