1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* authusekey - decode a key from ascii and use it
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
#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"
|
|
|
|
|
|
|
|
/*
|
2023-05-11 18:17:53 +00:00
|
|
|
* 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;
|
2023-05-11 18:17:53 +00:00
|
|
|
u_char buf[AUTHPWD_MAXSECLEN];
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2023-05-11 18:17:53 +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;
|
|
|
|
|
2023-05-11 18:17:53 +00:00
|
|
|
MD5auth_setkey(keyno, keytype, buf, len, NULL);
|
|
|
|
memset(buf, 0, sizeof(buf));
|
1999-12-09 13:01:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|