freebsd-src/contrib/ntp/libntp/authusekey.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
668 B
C
Raw Normal View History

1999-12-09 13:01:21 +00:00
/*
* authusekey - decode a key from ascii and use it
*/
#include <config.h>
1999-12-09 13:01:21 +00:00
#include <stdio.h>
#include <ctype.h>
#include "ntp_types.h"
#include "ntp_string.h"
#include "ntp_stdlib.h"
/*
* Only used by ntp{q,dc} to set the key/algo/secret triple to use.
* Uses the same decoding scheme ntpd uses for keys in the key file.
1999-12-09 13:01:21 +00:00
*/
int
authusekey(
2001-08-29 14:35:15 +00:00
keyid_t keyno,
1999-12-09 13:01:21 +00:00
int keytype,
const u_char *str
)
{
2016-01-08 08:06:14 +00:00
size_t len;
u_char buf[AUTHPWD_MAXSECLEN];
1999-12-09 13:01:21 +00:00
len = authdecodepw(buf, sizeof(buf), (const char*)str,
AUTHPWD_UNSPEC);
if (len < 1 || len > sizeof(buf))
1999-12-09 13:01:21 +00:00
return 0;
MD5auth_setkey(keyno, keytype, buf, len, NULL);
memset(buf, 0, sizeof(buf));
1999-12-09 13:01:21 +00:00
return 1;
}