Skip to content
Snippets Groups Projects
Commit c5584fee authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Clean up and improve 6e516aed

The first entry I tried adding was "Example..." which was not a
valid hostname, but was copied into the address and looked silly.

Now only copies into address if it's a valid, usable hostname.

Also, add a convenience macro to check if a connection type uses
the network or not.

New functions in netwrap:
bool isValidHostname(const char *str);
bool isValidAddressString(const char *str);
bool isResolvableHostname(const char *str);

We ust the last one (which calls the other two) for this feature now.
parent f4a2249b
No related branches found
No related tags found
No related merge requests found
Pipeline #6640 failed
...@@ -15,19 +15,19 @@ If you need help with SyncTERM, the best places are: ...@@ -15,19 +15,19 @@ If you need help with SyncTERM, the best places are:
Connect to irc.synchro.net and find Deuce in #Synchronet. Ask your Connect to irc.synchro.net and find Deuce in #Synchronet. Ask your
question, then idle. I can take hours to respond. Do not give up, question, then idle. I can take hours to respond. Do not give up,
this is the quickest way to get a response. this is the quickest way to get a response.
2) E-Mail: 2) SourceForge:
The official SyncTERM project page at
http://www.sf.net/projects/syncterm has a bug tracker and other
features that will email me and provide tracking for issues that
are filed.
3) E-Mail:
I am usually fairly responsive to emails sent to me at I am usually fairly responsive to emails sent to me at
shurd@sasktel.net. Please describe your issue as clearly as possible. shurd@sasktel.net. Please describe your issue as clearly as possible.
3) Dove-Net: 4) Dove-Net:
I usually read Dove-Net regularly, and many other users can often I usually read Dove-Net regularly, and many other users can often
help with support issues. Ask questions in the Hardware/Software Help help with support issues. Ask questions in the Hardware/Software Help
sub. If your local BBS does not carry Dove-Net, you can telnet to sub. If your local BBS does not carry Dove-Net, you can telnet to
vert.synchro.net and leave messages there. vert.synchro.net and leave messages there.
4) SourceForge:
The official SyncTERM project page at
http://www.sf.net/projects/syncterm has a bug tracker and other
features that will email me and provide tracking for issues that
are filed.
Throughout this document, I will mention things which are not supported. Throughout this document, I will mention things which are not supported.
These are things which I don't normally test, and are unlikely to work These are things which I don't normally test, and are unlikely to work
...@@ -69,7 +69,7 @@ build system is used. There are a number of optional dependencies, and ...@@ -69,7 +69,7 @@ build system is used. There are a number of optional dependencies, and
a large number of supported compile flags (many of which are shared with a large number of supported compile flags (many of which are shared with
Synchronet). Synchronet).
The biggest optional dependency is SDL 1.2 (from http://libsdl.org). The biggest optional dependency is SDL 2 (from http://libsdl.org).
SyncTERM can use SDL for both graphics and sound. X11 can also be used SyncTERM can use SDL for both graphics and sound. X11 can also be used
for graphics, and OSS, ALSA, or Portaudio can also provide sound. These for graphics, and OSS, ALSA, or Portaudio can also provide sound. These
use run-time linking, so at compile time, only the headers are needed. use run-time linking, so at compile time, only the headers are needed.
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <dirwrap.h> #include <dirwrap.h>
#include <ini_file.h> #include <ini_file.h>
#include <netwrap.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -2956,16 +2957,9 @@ show_bbslist(char *current, int connected) ...@@ -2956,16 +2957,9 @@ show_bbslist(char *current, int connected)
&(list[listcount - 1]->conn_type), NULL, "Connection Type", &(list[listcount - 1]->conn_type), NULL, "Connection Type",
&(conn_types[1])) >= 0) { &(conn_types[1])) >= 0) {
list[listcount - 1]->conn_type++; list[listcount - 1]->conn_type++;
if ((list[listcount - 1]->conn_type != CONN_TYPE_MODEM) if (IS_NETWORK_CONN(list[listcount - 1]->conn_type)) {
&& (list[listcount - 1]->conn_type
!= CONN_TYPE_SERIAL)
&& (list[listcount - 1]->conn_type
!= CONN_TYPE_SERIAL_NORTS)
&& (list[listcount - 1]->conn_type
!= CONN_TYPE_SHELL)) {
/* Default address to name, if appears to be address */ /* Default address to name, if appears to be address */
if (strchr(list[listcount - 1]->name, ' ') == NULL if (isResolvableHostname(list[listcount - 1]->name))
&& strchr(list[listcount - 1]->name, '.') != NULL)
SAFECOPY(list[listcount - 1]->addr, list[listcount - 1]->name); SAFECOPY(list[listcount - 1]->addr, list[listcount - 1]->name);
/* Set the port too */ /* Set the port too */
j = conn_ports[list[listcount - 1]->conn_type]; j = conn_ports[list[listcount - 1]->conn_type];
......
...@@ -45,6 +45,16 @@ enum { ...@@ -45,6 +45,16 @@ enum {
CONN_TYPE_TERMINATOR CONN_TYPE_TERMINATOR
}; };
#define IS_NETWORK_CONN(x) ( \
((x) == CONN_TYPE_RLOGIN) || \
((x) == CONN_TYPE_RLOGIN_REVERSED) || \
((x) == CONN_TYPE_TELNET) || \
((x) == CONN_TYPE_RAW) || \
((x) == CONN_TYPE_SSH) || \
((x) == CONN_TYPE_SSHNA) || \
((x) == CONN_TYPE_MBBS_GHOST) || \
((x) == CONN_TYPE_TELNETS))
struct conn_api { struct conn_api {
int (*connect)(struct bbslist *bbs); int (*connect)(struct bbslist *bbs);
int (*close)(void); int (*close)(void);
......
...@@ -172,6 +172,125 @@ const char* IPv4AddressToStr(uint32_t addr, char* dest, size_t size) ...@@ -172,6 +172,125 @@ const char* IPv4AddressToStr(uint32_t addr, char* dest, size_t size)
#endif #endif
} }
/*
* While RFC-952 limits a name to 24 characters, this is never enforced.
* RFC-952 also doesn't allow beginning or ending with a hyphen.
* RFC-952 also bans starting with a digit.
* RFC-1123 explicitly overrode the restriction against starting with a digit.
* RFC-1123 implicitly overrode the length restriction.
*
* The limit of 63 characters for a name comes from DNS, as does the 253
* (254 with trailing dot) overall limit. If DNS isn't used, it's chaos.
*/
static bool
isValidHostnameString(const char *str)
{
size_t pos;
size_t seglen = 0;
size_t totallen = 0;
size_t segcount = 0;
bool last_was_hyphen = false;
while (*str) {
if ((*str >= 'a' && *str <= 'z')
|| (*str >= 'A' && *str <= 'Z')
|| (*str >= '0' && *str <= '9')
|| (*str == '-')
|| (*str == '.')) {
if (*str == '.') {
if (last_was_hyphen) {
return false;
}
if (seglen == 0) {
return false;
}
seglen = 0;
}
else {
if (seglen == 0) {
if (*str == '-') {
return false;
}
segcount++;
}
seglen++;
if (seglen > 63) {
return false;
}
}
totallen++;
if (totallen > 253) {
// Allow a trailing dot
if (totallen != 254 || *str != '.') {
return false;
}
}
last_was_hyphen = (*str == '-');
}
else {
return false;
}
str++;
}
return true;
}
bool
isValidAddressString(const char *str)
{
struct sockaddr_in in;
struct sockaddr_in6 in6;
/*
* Per RFC-1123, we need to check for valid IP address first
*/
if (xp_inet_pton(AF_INET, str, &in) != -1)
return true;
if (xp_inet_pton(AF_INET6, str, &in6) != -1)
return true;
return false;
}
bool
isValidHostname(const char *str)
{
/*
* Per RFC-1123, we need to check for valid IP address first
*/
if (isValidAddressString(str))
return true;
return isValidHostnameString(str);
}
bool
isResolvableHostname(const char *str)
{
if (!isValidHostname(str)) {
return false;
}
struct addrinfo hints = {0};
struct addrinfo *res = NULL;
const char portnum[2] = "1";
hints.ai_flags = PF_UNSPEC;
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_NUMERICSERV;
#ifdef AI_ADDRCONFIG
hints.ai_flags |= AI_ADDRCONFIG;
#endif
if (getaddrinfo(str, portnum, &hints, &res) != 0) {
return false;
}
freeaddrinfo(res);
return true;
}
#if NETWRAP_TEST #if NETWRAP_TEST
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
......
...@@ -45,6 +45,9 @@ DLLEXPORT void freeNameServerList(str_list_t); ...@@ -45,6 +45,9 @@ DLLEXPORT void freeNameServerList(str_list_t);
DLLEXPORT const char* IPv4AddressToStr(uint32_t, char* dest, size_t size); DLLEXPORT const char* IPv4AddressToStr(uint32_t, char* dest, size_t size);
DLLEXPORT uint32_t parseIPv4Address(const char*); DLLEXPORT uint32_t parseIPv4Address(const char*);
DLLEXPORT struct in6_addr parseIPv6Address(const char*); DLLEXPORT struct in6_addr parseIPv6Address(const char*);
DLLEXPORT bool isValidHostname(const char *str);
DLLEXPORT bool isValidAddressString(const char *str);
DLLEXPORT bool isResolvableHostname(const char *str);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment