/* ================================================== */
-void
+NSR_Status
NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, SourceParameters *params)
{
struct UnresolvedSource *us;
struct SourcePool *sp;
NTP_Remote_Address remote_addr;
+ int i;
/* If the name is an IP address, don't bother with full resolving now
or later when trying to replace the source */
if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
remote_addr.port = port;
- NSR_AddSource(&remote_addr, type, params);
- return;
+ return NSR_AddSource(&remote_addr, type, params);
+ }
+
+ /* Make sure the name is at least printable and has no spaces */
+ for (i = 0; name[i] != '\0'; i++) {
+ if (!isgraph(name[i]))
+ return NSR_InvalidName;
}
us = MallocNew(struct UnresolvedSource);
}
append_unresolved_source(us);
+
+ return NSR_UnresolvedName;
}
/* ================================================== */
NSR_NoSuchSource, /* Remove - attempt to remove a source that is not known */
NSR_AlreadyInUse, /* AddSource - attempt to add a source that is already known */
NSR_TooManySources, /* AddSource - too many sources already present */
- NSR_InvalidAF /* AddSource - attempt to add a source with invalid address family */
+ NSR_InvalidAF, /* AddSource - attempt to add a source with invalid address family */
+ NSR_InvalidName, /* AddSourceByName - attempt to add a source with invalid name */
+ NSR_UnresolvedName, /* AddSourceByName - name will be resolved later */
} NSR_Status;
/* Procedure to add a new server or peer source. */
/* Procedure to add a new server, peer source, or pool of servers specified by
name instead of address. The name is resolved in exponentially increasing
- intervals until it succeeds or fails with a non-temporary error. */
-extern void NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type, SourceParameters *params);
+ intervals until it succeeds or fails with a non-temporary error. If the
+ name is an address, it is equivalent to NSR_AddSource(). */
+extern NSR_Status NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
+ SourceParameters *params);
/* Function type for handlers to be called back when an attempt
* (possibly unsuccessful) to resolve unresolved sources ends */