4 * authreadkeys.c - routines to support the reading of the key file
11 #include "ntp_syslog.h"
12 #include "ntp_stdlib.h"
15 * Arbitrary long string of ASCII characters.
17 #define KEY_TYPE_MD5 4
20 static char *nexttok
P((char **));
23 * nexttok - basic internal tokenizing routine
36 * Space past white space
38 while (*cp
== ' ' || *cp
== '\t')
42 * Save this and space to end of token
45 while (*cp
!= '\0' && *cp
!= '\n' && *cp
!= ' '
46 && *cp
!= '\t' && *cp
!= '#')
50 * If token length is zero return an error, else set end of
51 * token to zero and return start.
56 if (*cp
== ' ' || *cp
== '\t')
67 * authreadkeys - (re)read keys from a file.
79 char buf
[512]; /* lots of room for line */
82 * Open file. Complain and return if it can't be opened.
84 fp
= fopen(file
, "r");
86 msyslog(LOG_ERR
, "can't open key file %s: %m", file
);
91 * Remove all existing keys
96 * Now read lines from the file, looking for key entries
98 while ((line
= fgets(buf
, sizeof buf
, fp
)) != NULL
) {
99 token
= nexttok(&line
);
104 * First is key number. See if it is okay.
109 "cannot change keyid 0, key entry `%s' ignored",
114 if (keyno
> NTP_MAXKEY
) {
116 "keyid's > %d reserved for autokey, key entry `%s' ignored",
122 * Next is keytype. See if that is all right.
124 token
= nexttok(&line
);
127 "no key type for key number %ld, entry ignored",
134 keytype
= KEY_TYPE_MD5
; break;
137 "invalid key type for key number %ld, entry ignored",
143 * Finally, get key and insert it
145 token
= nexttok(&line
);
148 "no key for number %ld entry, entry ignored",
153 if (!authusekey(keyno
, keytype
,
156 "format/parity error for MD5 key %ld, not used",