1976 |
error (1, errno, "Failed to resolve path: `%s'", path); |
error (1, errno, "Failed to resolve path: `%s'", path); |
1977 |
return hardpath; |
return hardpath; |
1978 |
} |
} |
1979 |
|
|
1980 |
|
|
1981 |
|
|
1982 |
|
/* From GNULIB's canon-host module. */ |
1983 |
|
extern char *canon_host (const char *host); |
1984 |
|
|
1985 |
|
/* Declared in main.c. */ |
1986 |
|
extern char *server_hostname; |
1987 |
|
|
1988 |
|
/* Return true if OTHERHOST resolves to this host in the DNS. |
1989 |
|
* |
1990 |
|
* GLOBALS |
1991 |
|
* server_hostname The name of this host, as determined by the call to |
1992 |
|
* xgethostname() in main(). |
1993 |
|
* |
1994 |
|
* RETURNS |
1995 |
|
* true If OTHERHOST equals or resolves to HOSTNAME. |
1996 |
|
* false Otherwise. |
1997 |
|
*/ |
1998 |
|
bool |
1999 |
|
isThisHost (const char *otherhost) |
2000 |
|
{ |
2001 |
|
char *fqdno; |
2002 |
|
char *fqdns; |
2003 |
|
bool retval; |
2004 |
|
|
2005 |
|
/* As an optimization, check the literal strings before looking up |
2006 |
|
* OTHERHOST in the DNS. |
2007 |
|
*/ |
2008 |
|
if (!strcasecmp (server_hostname, otherhost)) |
2009 |
|
return true; |
2010 |
|
|
2011 |
|
fqdno = canon_host (otherhost); |
2012 |
|
if (!fqdno) |
2013 |
|
error (1, 0, "Name lookup failed for `%s'", otherhost); |
2014 |
|
fqdns = canon_host (server_hostname); |
2015 |
|
if (!fqdns) |
2016 |
|
error (1, 0, "Name lookup failed for `%s'", server_hostname); |
2017 |
|
|
2018 |
|
retval = !strcasecmp (fqdns, fqdno); |
2019 |
|
|
2020 |
|
free (fqdno); |
2021 |
|
free (fqdns); |
2022 |
|
return retval; |
2023 |
|
} |
2024 |
|
|
2025 |
|
|
2026 |
|
|
2027 |
|
/* Return true if two paths match, resolving symlinks. |
2028 |
|
*/ |
2029 |
|
bool |
2030 |
|
isSamePath (const char *path1_in, const char *path2_in) |
2031 |
|
{ |
2032 |
|
char *p1, *p2; |
2033 |
|
bool same; |
2034 |
|
|
2035 |
|
if (!strcmp (path1_in, path2_in)) |
2036 |
|
return true; |
2037 |
|
|
2038 |
|
/* Path didn't match, but try to resolve any links that may be |
2039 |
|
* present. |
2040 |
|
*/ |
2041 |
|
if (!isdir (path1_in) || !isdir (path2_in)) |
2042 |
|
/* To be resolvable, paths must exist on this server. */ |
2043 |
|
return false; |
2044 |
|
|
2045 |
|
p1 = xcanonicalize_file_name (path1_in); |
2046 |
|
p2 = xcanonicalize_file_name (path2_in); |
2047 |
|
if (strcmp (p1, p2)) |
2048 |
|
same = false; |
2049 |
|
else |
2050 |
|
same = true; |
2051 |
|
|
2052 |
|
free (p1); |
2053 |
|
free (p2); |
2054 |
|
return same; |
2055 |
|
} |