Treat 127.0.0.1, [::1], and hostname as localhost
This commit is contained in:
@@ -1573,6 +1573,16 @@ expandName(char *name)
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
is_localhost(const char *host)
|
||||
{
|
||||
if (!host ||
|
||||
!strcasecmp(host, "localhost") || !strcmp(host, "127.0.0.1") ||
|
||||
(HostName && !strcasecmp(host, HostName)) || !strcmp(host, "[::1]"))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
char *
|
||||
file_to_url(char *file)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -135,6 +136,10 @@ void bzero(void *, int);
|
||||
#define DICTBUFFERNAME "*dictionary*"
|
||||
#endif /* USE_DICT */
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
#define HOST_NAME_MAX 255
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Line Property
|
||||
*/
|
||||
@@ -837,6 +842,7 @@ global char PreserveTimestamp init(TRUE);
|
||||
global char ArgvIsURL init(TRUE);
|
||||
global char MetaRefresh init(FALSE);
|
||||
global char LocalhostOnly init(FALSE);
|
||||
global char* HostName init(NULL);
|
||||
|
||||
global char fmInitialized init(FALSE);
|
||||
global char QuietMessage init(FALSE);
|
||||
|
||||
@@ -51,13 +51,10 @@ writeLocalCookie()
|
||||
Str
|
||||
localCookie()
|
||||
{
|
||||
char hostname[256];
|
||||
|
||||
if (Local_cookie)
|
||||
return Local_cookie;
|
||||
gethostname(hostname, 256);
|
||||
srand48((long)New(char) + (long)time(NULL));
|
||||
Local_cookie = Sprintf("%ld@%s", lrand48(), hostname);
|
||||
Local_cookie = Sprintf("%ld@%s", lrand48(), HostName ? HostName : "localhost");
|
||||
return Local_cookie;
|
||||
}
|
||||
|
||||
|
||||
@@ -455,6 +455,18 @@ main(int argc, char **argv, char **envp)
|
||||
BookmarkFile = NULL;
|
||||
config_file = NULL;
|
||||
|
||||
{
|
||||
char hostname[HOST_NAME_MAX + 2];
|
||||
if (gethostname(hostname, HOST_NAME_MAX + 2) == 0) {
|
||||
size_t hostname_len;
|
||||
/* Don't use hostname if it is truncated. */
|
||||
hostname[HOST_NAME_MAX + 1] = '\0';
|
||||
hostname_len = strlen(hostname);
|
||||
if (hostname_len <= HOST_NAME_MAX && hostname_len <= INT_MAX)
|
||||
HostName = allocStr(hostname, (int)hostname_len);
|
||||
}
|
||||
}
|
||||
|
||||
/* argument search 1 */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (*argv[i] == '-') {
|
||||
|
||||
@@ -672,6 +672,7 @@ extern void myExec(char *command);
|
||||
extern void mySystem(char *command, int background);
|
||||
extern Str myExtCommand(char *cmd, char *arg, int redirect);
|
||||
extern Str myEditor(char *cmd, char *file, int line);
|
||||
extern int is_localhost(const char *host);
|
||||
extern char *file_to_url(char *file);
|
||||
#ifdef USE_M17N
|
||||
extern char *url_unquote_conv(char *url, wc_ces charset);
|
||||
|
||||
@@ -41,10 +41,6 @@
|
||||
#define close(fd) closesocket(fd)
|
||||
#endif
|
||||
|
||||
#ifndef HOST_NAME_MAX
|
||||
#define HOST_NAME_MAX 64
|
||||
#endif
|
||||
|
||||
#ifdef INET6
|
||||
/* see rc.c, "dns_order" and dnsorders[] */
|
||||
int ai_family_order_table[7][3] = {
|
||||
@@ -781,34 +777,13 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current)
|
||||
copyParsedURL(p_url, current);
|
||||
goto do_label;
|
||||
}
|
||||
if (!strncasecmp(url, "file://", 7)) {
|
||||
#if defined( __EMX__ ) || defined( __CYGWIN__ )
|
||||
if (!strncasecmp(url + 7, "localhost/", 10)) {
|
||||
p_url->scheme = SCM_LOCAL;
|
||||
p += 7 + 10 - 1;
|
||||
url += 7 + 10 - 1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* Recognize the machine's host name. This is necessary for URLs
|
||||
* produced by 'ls --hyperlink' or similar. */
|
||||
char hostname[HOST_NAME_MAX + 2];
|
||||
if (gethostname (hostname, HOST_NAME_MAX + 2) == 0) {
|
||||
size_t hostname_len;
|
||||
/* Don't use hostname if it is truncated. */
|
||||
hostname[HOST_NAME_MAX + 1] = '\0';
|
||||
hostname_len = strlen (hostname);
|
||||
if (hostname_len <= HOST_NAME_MAX) {
|
||||
if (!strncasecmp(url + 7, hostname, hostname_len)
|
||||
&& *(url + 7 + hostname_len) == '/') {
|
||||
p_url->scheme = SCM_LOCAL;
|
||||
p += 7 + hostname_len;
|
||||
url += 7 + hostname_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strncasecmp(url, "file://localhost/", 17)) {
|
||||
p_url->scheme = SCM_LOCAL;
|
||||
p += 17 - 1;
|
||||
url += 17 - 1;
|
||||
}
|
||||
#endif
|
||||
#ifdef SUPPORT_DOS_DRIVE_PREFIX
|
||||
if (IS_ALPHA(*p) && (p[1] == ':' || p[1] == '|')) {
|
||||
p_url->scheme = SCM_LOCAL;
|
||||
@@ -951,7 +926,7 @@ parseURL(char *url, ParsedURL *p_url, ParsedURL *current)
|
||||
#ifndef SUPPORT_NETBIOS_SHARE
|
||||
if (p_url->scheme == SCM_LOCAL && p_url->user == NULL &&
|
||||
p_url->host != NULL && *p_url->host != '\0' &&
|
||||
strcmp(p_url->host, "localhost")) {
|
||||
!is_localhost(p_url->host)) {
|
||||
/*
|
||||
* In the environments other than CYGWIN, a URL like
|
||||
* file://host/file is regarded as ftp://host/file.
|
||||
@@ -1262,7 +1237,7 @@ parseURL2(char *url, ParsedURL *pu, ParsedURL *current)
|
||||
}
|
||||
if (pu->scheme == SCM_LOCAL) {
|
||||
#ifdef SUPPORT_NETBIOS_SHARE
|
||||
if (pu->host && strcmp(pu->host, "localhost") != 0) {
|
||||
if (pu->host && !is_localhost(pu->host)) {
|
||||
Str tmp = Strnew_charp("//");
|
||||
Strcat_m_charp(tmp, pu->host,
|
||||
cleanupName(file_unquote(pu->file)), NULL);
|
||||
@@ -1696,8 +1671,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current,
|
||||
}
|
||||
}
|
||||
|
||||
if (LocalhostOnly && pu->host &&
|
||||
strcasecmp(pu->host, "localhost") && strcasecmp(pu->host, "127.0.0.1"))
|
||||
if (LocalhostOnly && pu->host && !is_localhost(pu->host))
|
||||
pu->host = NULL;
|
||||
|
||||
uf.scheme = pu->scheme;
|
||||
|
||||
Reference in New Issue
Block a user