blob: 3c8da1d3c7c7da54ca8a50edbed21820cfbf2a24 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/*
* authusekey - decode a key from ascii and use it
*/
#include <config.h>
#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.
*/
int
authusekey(
keyid_t keyno,
int keytype,
const u_char *str
)
{
size_t len;
u_char buf[AUTHPWD_MAXSECLEN];
len = authdecodepw(buf, sizeof(buf), (const char*)str,
AUTHPWD_UNSPEC);
if (len < 1 || len > sizeof(buf))
return 0;
MD5auth_setkey(keyno, keytype, buf, len, NULL);
memset(buf, 0, sizeof(buf));
return 1;
}
|