2006-11-26 11:13:41 -07:00
|
|
|
/***********************************************************
|
|
|
|
|
|
|
|
Copyright 1987, 1998 The Open Group
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
copy of this software and associated documentation files (the
|
|
|
|
"Software"), to deal in the Software without restriction, including
|
|
|
|
without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
distribute, and/or sell copies of the Software, and to permit persons
|
|
|
|
to whom the Software is furnished to do so, provided that the above
|
|
|
|
copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
the Software and that both the above copyright notice(s) and this
|
|
|
|
permission notice appear in supporting documentation.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
|
|
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
|
|
|
INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
|
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
|
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of a copyright holder
|
|
|
|
shall not be used in advertising or otherwise to promote the sale, use
|
|
|
|
or other dealings in this Software without prior written authorization
|
|
|
|
of the copyright holder.
|
|
|
|
|
|
|
|
X Window System is a trademark of The Open Group.
|
|
|
|
|
|
|
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
2006-11-26 11:13:41 -07:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
2015-09-16 13:10:19 -06:00
|
|
|
both that copyright notice and this permission notice appear in
|
2006-11-26 11:13:41 -07:00
|
|
|
supporting documentation, and that the name of Digital not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
2015-09-16 13:10:19 -06:00
|
|
|
software without specific, written prior permission.
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/*
|
2011-11-05 07:32:40 -06:00
|
|
|
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
|
2010-07-27 13:02:24 -06:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#include <X11/Xwinsock.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#define XSERV_t
|
|
|
|
#define TRANS_SERVER
|
|
|
|
#define TRANS_REOPEN
|
|
|
|
#include <X11/Xtrans/Xtrans.h>
|
|
|
|
#include <X11/Xauth.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "site.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifndef WIN32
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
#ifndef NO_LOCAL_CLIENT_CRED
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN)
|
2006-11-26 11:13:41 -07:00
|
|
|
#include <netinet/in.h>
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* TCPCONN || STREAMSCONN */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef HAVE_GETPEERUCRED
|
|
|
|
#include <ucred.h>
|
2017-12-08 08:01:59 -07:00
|
|
|
#ifdef __sun
|
2012-06-10 07:21:05 -06:00
|
|
|
#include <zone.h>
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
#if defined(SVR4) || (defined(SYSV) && defined(__i386__)) || defined(__GNU__)
|
2012-06-10 07:21:05 -06:00
|
|
|
#include <sys/utsname.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2008-11-02 08:26:08 -07:00
|
|
|
#if defined(SYSV) && defined(__i386__)
|
2012-06-10 07:21:05 -06:00
|
|
|
#include <sys/stream.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
#ifdef __GNU__
|
|
|
|
#undef SIOCGIFCONF
|
|
|
|
#include <netdb.h>
|
2012-06-10 07:21:05 -06:00
|
|
|
#else /*!__GNU__ */
|
|
|
|
#include <net/if.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif /*__GNU__ */
|
|
|
|
|
|
|
|
#ifdef SVR4
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/stropts.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
#ifdef CSRG_BASED
|
|
|
|
#include <sys/param.h>
|
|
|
|
#if (BSD >= 199103)
|
|
|
|
#define VARIABLE_IFREQ
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSD44SOCKETS
|
|
|
|
#ifndef VARIABLE_IFREQ
|
|
|
|
#define VARIABLE_IFREQ
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef HAVE_GETIFADDRS
|
2006-11-26 11:13:41 -07:00
|
|
|
#include <ifaddrs.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Solaris provides an extended interface SIOCGLIFCONF. Other systems
|
|
|
|
* may have this as well, but the code has only been tested on Solaris
|
|
|
|
* so far, so we only enable it there. Other platforms may be added as
|
|
|
|
* needed.
|
|
|
|
*
|
|
|
|
* Test for Solaris commented out -- TSI @ UQV 2003.06.13
|
|
|
|
*/
|
|
|
|
#ifdef SIOCGLIFCONF
|
2017-12-08 08:01:59 -07:00
|
|
|
/* #if defined(__sun) */
|
2006-11-26 11:13:41 -07:00
|
|
|
#define USE_SIOCGLIFCONF
|
|
|
|
/* #endif */
|
|
|
|
#endif
|
|
|
|
|
2014-05-02 13:27:46 -06:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* WIN32 */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2016-08-09 12:59:50 -06:00
|
|
|
#if !defined(WIN32) || defined(__CYGWIN__)
|
|
|
|
#include <libgen.h>
|
|
|
|
#endif
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#define X_INCLUDE_NETDB_H
|
|
|
|
#include <X11/Xos_r.h>
|
|
|
|
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "osdep.h"
|
|
|
|
|
|
|
|
#include "xace.h"
|
|
|
|
|
|
|
|
Bool defeatAccessControl = FALSE;
|
|
|
|
|
|
|
|
#define addrEqual(fam, address, length, host) \
|
|
|
|
((fam) == (host)->family &&\
|
|
|
|
(length) == (host)->len &&\
|
2012-06-10 07:21:05 -06:00
|
|
|
!memcmp (address, (host)->addr, length))
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int ConvertAddr(struct sockaddr * /*saddr */ ,
|
|
|
|
int * /*len */ ,
|
2014-09-27 11:52:59 -06:00
|
|
|
void ** /*addr */ );
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int CheckAddr(int /*family */ ,
|
|
|
|
const void * /*pAddr */ ,
|
|
|
|
unsigned /*length */ );
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool NewHost(int /*family */ ,
|
|
|
|
const void * /*addr */ ,
|
|
|
|
int /*len */ ,
|
|
|
|
int /* addingLocalHosts */ );
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* XFree86 bug #156: To keep track of which hosts were explicitly requested in
|
|
|
|
/etc/X<display>.hosts, we've added a requested field to the HOST struct,
|
|
|
|
and a LocalHostRequested variable. These default to FALSE, but are set
|
|
|
|
to TRUE in ResetHosts when reading in /etc/X<display>.hosts. They are
|
2015-09-16 13:10:19 -06:00
|
|
|
checked in DisableLocalHost(), which is called to disable the default
|
2006-11-26 11:13:41 -07:00
|
|
|
local host entries when stronger authentication is turned on. */
|
|
|
|
|
|
|
|
typedef struct _host {
|
2012-06-10 07:21:05 -06:00
|
|
|
short family;
|
|
|
|
short len;
|
|
|
|
unsigned char *addr;
|
|
|
|
struct _host *next;
|
|
|
|
int requested;
|
2006-11-26 11:13:41 -07:00
|
|
|
} HOST;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define MakeHost(h,l) (h)=malloc(sizeof *(h)+(l));\
|
2006-11-26 11:13:41 -07:00
|
|
|
if (h) { \
|
|
|
|
(h)->addr=(unsigned char *) ((h) + 1);\
|
|
|
|
(h)->requested = FALSE; \
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
#define FreeHost(h) free(h)
|
2006-11-26 11:13:41 -07:00
|
|
|
static HOST *selfhosts = NULL;
|
|
|
|
static HOST *validhosts = NULL;
|
|
|
|
static int AccessEnabled = DEFAULT_ACCESS_CONTROL;
|
|
|
|
static int LocalHostEnabled = FALSE;
|
|
|
|
static int LocalHostRequested = FALSE;
|
|
|
|
static int UsingXdmcp = FALSE;
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
static enum {
|
|
|
|
LOCAL_ACCESS_SCOPE_HOST = 0,
|
|
|
|
#ifndef NO_LOCAL_CLIENT_CRED
|
|
|
|
LOCAL_ACCESS_SCOPE_USER,
|
|
|
|
#endif
|
|
|
|
} LocalAccessScope;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* FamilyServerInterpreted implementation */
|
2014-09-27 11:52:59 -06:00
|
|
|
static Bool siAddrMatch(int family, void *addr, int len, HOST * host,
|
2012-06-10 07:21:05 -06:00
|
|
|
ClientPtr client);
|
|
|
|
static int siCheckAddr(const char *addrString, int length);
|
2006-11-26 11:13:41 -07:00
|
|
|
static void siTypesInitialize(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called when authorization is not enabled to add the
|
|
|
|
* local host to the access list
|
|
|
|
*/
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
void
|
|
|
|
EnableLocalAccess(void)
|
|
|
|
{
|
|
|
|
switch (LocalAccessScope) {
|
|
|
|
case LOCAL_ACCESS_SCOPE_HOST:
|
|
|
|
EnableLocalHost();
|
|
|
|
break;
|
|
|
|
#ifndef NO_LOCAL_CLIENT_CRED
|
|
|
|
case LOCAL_ACCESS_SCOPE_USER:
|
|
|
|
EnableLocalUser();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
EnableLocalHost(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!UsingXdmcp) {
|
|
|
|
LocalHostEnabled = TRUE;
|
|
|
|
AddLocalHosts();
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* called when authorization is enabled to keep us secure
|
|
|
|
*/
|
2015-09-16 13:10:19 -06:00
|
|
|
void
|
|
|
|
DisableLocalAccess(void)
|
|
|
|
{
|
|
|
|
switch (LocalAccessScope) {
|
|
|
|
case LOCAL_ACCESS_SCOPE_HOST:
|
|
|
|
DisableLocalHost();
|
|
|
|
break;
|
|
|
|
#ifndef NO_LOCAL_CLIENT_CRED
|
|
|
|
case LOCAL_ACCESS_SCOPE_USER:
|
|
|
|
DisableLocalUser();
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
DisableLocalHost(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
HOST *self;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!LocalHostRequested) /* Fix for XFree86 bug #156 */
|
|
|
|
LocalHostEnabled = FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (self = selfhosts; self; self = self->next) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!self->requested) /* Fix for XFree86 bug #156 */
|
|
|
|
(void) RemoveHost((ClientPtr) NULL, self->family, self->len,
|
2014-09-27 11:52:59 -06:00
|
|
|
(void *) self->addr);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
#ifndef NO_LOCAL_CLIENT_CRED
|
|
|
|
static int GetLocalUserAddr(char **addr)
|
|
|
|
{
|
|
|
|
static const char *type = "localuser";
|
|
|
|
static const char delimiter = '\0';
|
|
|
|
static const char *value;
|
|
|
|
struct passwd *pw;
|
|
|
|
int length = -1;
|
|
|
|
|
|
|
|
pw = getpwuid(getuid());
|
|
|
|
|
|
|
|
if (pw == NULL || pw->pw_name == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
value = pw->pw_name;
|
|
|
|
|
|
|
|
length = asprintf(addr, "%s%c%s", type, delimiter, value);
|
|
|
|
|
|
|
|
if (length == -1) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trailing NUL */
|
|
|
|
length++;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EnableLocalUser(void)
|
|
|
|
{
|
|
|
|
char *addr = NULL;
|
|
|
|
int length = -1;
|
|
|
|
|
|
|
|
length = GetLocalUserAddr(&addr);
|
|
|
|
|
|
|
|
if (length == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NewHost(FamilyServerInterpreted, addr, length, TRUE);
|
|
|
|
|
|
|
|
free(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DisableLocalUser(void)
|
|
|
|
{
|
|
|
|
char *addr = NULL;
|
|
|
|
int length = -1;
|
|
|
|
|
|
|
|
length = GetLocalUserAddr(&addr);
|
|
|
|
|
|
|
|
if (length == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RemoveHost(NULL, FamilyServerInterpreted, length, addr);
|
|
|
|
|
|
|
|
free(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocalAccessScopeUser(void)
|
|
|
|
{
|
|
|
|
LocalAccessScope = LOCAL_ACCESS_SCOPE_USER;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* called at init time when XDMCP will be used; xdmcp always
|
|
|
|
* adds local hosts manually when needed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
AccessUsingXdmcp(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
UsingXdmcp = TRUE;
|
|
|
|
LocalHostEnabled = FALSE;
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(SVR4) && !defined(__sun) && defined(SIOCGIFCONF) && !defined(USE_SIOCGLIFCONF)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Deal with different SIOCGIFCONF ioctl semantics on these OSs */
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ifioctl(int fd, int cmd, char *arg)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
struct strioctl ioc;
|
|
|
|
int ret;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
memset((char *) &ioc, 0, sizeof(ioc));
|
2006-11-26 11:13:41 -07:00
|
|
|
ioc.ic_cmd = cmd;
|
|
|
|
ioc.ic_timout = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (cmd == SIOCGIFCONF) {
|
|
|
|
ioc.ic_len = ((struct ifconf *) arg)->ifc_len;
|
|
|
|
ioc.ic_dp = ((struct ifconf *) arg)->ifc_buf;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
|
|
|
ioc.ic_len = sizeof(struct ifreq);
|
|
|
|
ioc.ic_dp = arg;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
ret = ioctl(fd, I_STR, (char *) &ioc);
|
|
|
|
if (ret >= 0 && cmd == SIOCGIFCONF)
|
|
|
|
#ifdef SVR4
|
2012-06-10 07:21:05 -06:00
|
|
|
((struct ifconf *) arg)->ifc_len = ioc.ic_len;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2010-12-05 08:36:02 -07:00
|
|
|
return ret;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2011-11-05 07:32:40 -06:00
|
|
|
#else
|
2006-11-26 11:13:41 -07:00
|
|
|
#define ifioctl ioctl
|
2011-11-05 07:32:40 -06:00
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DefineSelf (fd):
|
|
|
|
*
|
2015-09-16 13:10:19 -06:00
|
|
|
* Define this host for access control. Find all the hosts the OS knows about
|
2006-11-26 11:13:41 -07:00
|
|
|
* for this fd and add them to the selfhosts list.
|
|
|
|
*/
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#if !defined(SIOCGIFCONF)
|
2006-11-26 11:13:41 -07:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
DefineSelf(int fd)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2017-12-08 08:01:59 -07:00
|
|
|
#if !defined(TCPCONN) && !defined(UNIXCONN)
|
2006-11-26 11:13:41 -07:00
|
|
|
return;
|
|
|
|
#else
|
|
|
|
register int n;
|
2012-06-10 07:21:05 -06:00
|
|
|
int len;
|
|
|
|
caddr_t addr;
|
|
|
|
int family;
|
|
|
|
register HOST *host;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifndef WIN32
|
|
|
|
struct utsname name;
|
|
|
|
#else
|
|
|
|
struct {
|
2012-06-10 07:21:05 -06:00
|
|
|
char nodename[512];
|
2006-11-26 11:13:41 -07:00
|
|
|
} name;
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
register struct hostent *hp;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
union {
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in in;
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr_in6 in6;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
} saddr;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
struct sockaddr_in *inetaddr;
|
|
|
|
struct sockaddr_in6 *inet6addr;
|
2006-11-26 11:13:41 -07:00
|
|
|
struct sockaddr_in broad_addr;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
|
|
|
|
_Xgethostbynameparams hparams;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Why not use gethostname()? Well, at least on my system, I've had to
|
|
|
|
* make an ugly kernel patch to get a name longer than 8 characters, and
|
|
|
|
* uname() lets me access to the whole string (it smashes release, you
|
|
|
|
* see), whereas gethostname() kindly truncates it for me.
|
|
|
|
*/
|
|
|
|
#ifndef WIN32
|
|
|
|
uname(&name);
|
|
|
|
#else
|
|
|
|
gethostname(name.nodename, sizeof(name.nodename));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hp = _XGethostbyname(name.nodename, hparams);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (hp != NULL) {
|
|
|
|
saddr.sa.sa_family = hp->h_addrtype;
|
|
|
|
switch (hp->h_addrtype) {
|
|
|
|
case AF_INET:
|
|
|
|
inetaddr = (struct sockaddr_in *) (&(saddr.sa));
|
|
|
|
memcpy(&(inetaddr->sin_addr), hp->h_addr, hp->h_length);
|
|
|
|
len = sizeof(saddr.sa);
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
case AF_INET6:
|
|
|
|
inet6addr = (struct sockaddr_in6 *) (&(saddr.sa));
|
|
|
|
memcpy(&(inet6addr->sin6_addr), hp->h_addr, hp->h_length);
|
|
|
|
len = sizeof(saddr.in6);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
goto DefineLocalHost;
|
|
|
|
}
|
2014-09-27 11:52:59 -06:00
|
|
|
family = ConvertAddr(&(saddr.sa), &len, (void **) &addr);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family != -1 && family != FamilyLocal) {
|
|
|
|
for (host = selfhosts;
|
|
|
|
host && !addrEqual(family, addr, len, host);
|
|
|
|
host = host->next);
|
|
|
|
if (!host) {
|
|
|
|
/* add this host to the host list. */
|
|
|
|
MakeHost(host, len)
|
|
|
|
if (host) {
|
|
|
|
host->family = family;
|
|
|
|
host->len = len;
|
|
|
|
memcpy(host->addr, addr, len);
|
|
|
|
host->next = selfhosts;
|
|
|
|
selfhosts = host;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XDMCP
|
2012-06-10 07:21:05 -06:00
|
|
|
/*
|
|
|
|
* If this is an Internet Address, but not the localhost
|
|
|
|
* address (127.0.0.1), nor the bogus address (0.0.0.0),
|
|
|
|
* register it.
|
|
|
|
*/
|
|
|
|
if (family == FamilyInternet &&
|
|
|
|
!(len == 4 &&
|
|
|
|
((addr[0] == 127) ||
|
|
|
|
(addr[0] == 0 && addr[1] == 0 &&
|
|
|
|
addr[2] == 0 && addr[3] == 0)))
|
|
|
|
) {
|
|
|
|
XdmcpRegisterConnection(family, (char *) addr, len);
|
|
|
|
broad_addr = *inetaddr;
|
|
|
|
((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr =
|
|
|
|
htonl(INADDR_BROADCAST);
|
|
|
|
XdmcpRegisterBroadcastAddress((struct sockaddr_in *)
|
|
|
|
&broad_addr);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (family == FamilyInternet6 &&
|
|
|
|
!(IN6_IS_ADDR_LOOPBACK((struct in6_addr *) addr))) {
|
|
|
|
XdmcpRegisterConnection(family, (char *) addr, len);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* XDMCP */
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* now add a host of family FamilyLocalHost...
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
DefineLocalHost:
|
2006-11-26 11:13:41 -07:00
|
|
|
for (host = selfhosts;
|
2012-06-10 07:21:05 -06:00
|
|
|
host && !addrEqual(FamilyLocalHost, "", 0, host); host = host->next);
|
|
|
|
if (!host) {
|
|
|
|
MakeHost(host, 0);
|
|
|
|
if (host) {
|
|
|
|
host->family = FamilyLocalHost;
|
|
|
|
host->len = 0;
|
|
|
|
/* Nothing to store in host->addr */
|
|
|
|
host->next = selfhosts;
|
|
|
|
selfhosts = host;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* !TCPCONN && !STREAMSCONN && !UNIXCONN */
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#ifdef USE_SIOCGLIFCONF
|
|
|
|
#define ifr_type struct lifreq
|
|
|
|
#else
|
|
|
|
#define ifr_type struct ifreq
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VARIABLE_IFREQ
|
|
|
|
#define ifr_size(p) (sizeof (struct ifreq) + \
|
|
|
|
(p->ifr_addr.sa_len > sizeof (p->ifr_addr) ? \
|
|
|
|
p->ifr_addr.sa_len - sizeof (p->ifr_addr) : 0))
|
|
|
|
#define ifraddr_size(a) (a.sa_len)
|
|
|
|
#else
|
|
|
|
#define ifr_size(p) (sizeof (ifr_type))
|
|
|
|
#define ifraddr_size(a) (sizeof (a))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
static void
|
|
|
|
in6_fillscopeid(struct sockaddr_in6 *sin6)
|
|
|
|
{
|
|
|
|
#if defined(__KAME__)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
sin6->sin6_scope_id =
|
2013-06-07 11:28:45 -06:00
|
|
|
ntohs(*(u_int16_t *) &sin6->sin6_addr.s6_addr[2]);
|
2012-06-10 07:21:05 -06:00
|
|
|
sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
DefineSelf(int fd)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifndef HAVE_GETIFADDRS
|
|
|
|
char *cp, *cplim;
|
|
|
|
|
|
|
|
#ifdef USE_SIOCGLIFCONF
|
2009-09-06 13:44:18 -06:00
|
|
|
struct sockaddr_storage buf[16];
|
2012-06-10 07:21:05 -06:00
|
|
|
struct lifconf ifc;
|
2006-11-26 11:13:41 -07:00
|
|
|
register struct lifreq *ifr;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
#ifdef SIOCGLIFNUM
|
|
|
|
struct lifnum ifn;
|
|
|
|
#endif
|
|
|
|
#else /* !USE_SIOCGLIFCONF */
|
|
|
|
char buf[2048];
|
|
|
|
struct ifconf ifc;
|
2006-11-26 11:13:41 -07:00
|
|
|
register struct ifreq *ifr;
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif
|
|
|
|
void *bufptr = buf;
|
|
|
|
#else /* HAVE_GETIFADDRS */
|
|
|
|
struct ifaddrs *ifap, *ifr;
|
|
|
|
#endif
|
|
|
|
int len;
|
|
|
|
unsigned char *addr;
|
|
|
|
int family;
|
|
|
|
register HOST *host;
|
|
|
|
|
|
|
|
#ifndef HAVE_GETIFADDRS
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
len = sizeof(buf);
|
|
|
|
|
|
|
|
#ifdef USE_SIOCGLIFCONF
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef SIOCGLIFNUM
|
|
|
|
ifn.lifn_family = AF_UNSPEC;
|
|
|
|
ifn.lifn_flags = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ioctl(fd, SIOCGLIFNUM, (char *) &ifn) < 0)
|
|
|
|
ErrorF("Getting interface count: %s\n", strerror(errno));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (len < (ifn.lifn_count * sizeof(struct lifreq))) {
|
2012-06-10 07:21:05 -06:00
|
|
|
len = ifn.lifn_count * sizeof(struct lifreq);
|
|
|
|
bufptr = malloc(len);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
ifc.lifc_family = AF_UNSPEC;
|
|
|
|
ifc.lifc_flags = 0;
|
|
|
|
ifc.lifc_len = len;
|
|
|
|
ifc.lifc_buf = bufptr;
|
|
|
|
|
|
|
|
#define IFC_IOCTL_REQ SIOCGLIFCONF
|
|
|
|
#define IFC_IFC_REQ ifc.lifc_req
|
|
|
|
#define IFC_IFC_LEN ifc.lifc_len
|
|
|
|
#define IFR_IFR_ADDR ifr->lifr_addr
|
|
|
|
#define IFR_IFR_NAME ifr->lifr_name
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#else /* Use SIOCGIFCONF */
|
2006-11-26 11:13:41 -07:00
|
|
|
ifc.ifc_len = len;
|
|
|
|
ifc.ifc_buf = bufptr;
|
|
|
|
|
|
|
|
#define IFC_IOCTL_REQ SIOCGIFCONF
|
|
|
|
#define IFC_IFC_REQ ifc.ifc_req
|
|
|
|
#define IFC_IFC_LEN ifc.ifc_len
|
|
|
|
#define IFR_IFR_ADDR ifr->ifr_addr
|
|
|
|
#define IFR_IFR_NAME ifr->ifr_name
|
|
|
|
#endif
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
if (ifioctl(fd, IFC_IOCTL_REQ, (void *) &ifc) < 0)
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("Getting interface configuration (4): %s\n", strerror(errno));
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
cplim = (char *) IFC_IFC_REQ + IFC_IFC_LEN;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
for (cp = (char *) IFC_IFC_REQ; cp < cplim; cp += ifr_size(ifr)) {
|
|
|
|
ifr = (ifr_type *) cp;
|
|
|
|
len = ifraddr_size(IFR_IFR_ADDR);
|
|
|
|
family = ConvertAddr((struct sockaddr *) &IFR_IFR_ADDR,
|
2014-09-27 11:52:59 -06:00
|
|
|
&len, (void **) &addr);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (family == -1 || family == FamilyLocal)
|
2012-06-10 07:21:05 -06:00
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == FamilyInternet6)
|
|
|
|
in6_fillscopeid((struct sockaddr_in6 *) &IFR_IFR_ADDR);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
for (host = selfhosts;
|
2012-06-10 07:21:05 -06:00
|
|
|
host && !addrEqual(family, addr, len, host); host = host->next);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (host)
|
2012-06-10 07:21:05 -06:00
|
|
|
continue;
|
|
|
|
MakeHost(host, len)
|
|
|
|
if (host) {
|
|
|
|
host->family = family;
|
|
|
|
host->len = len;
|
|
|
|
memcpy(host->addr, addr, len);
|
|
|
|
host->next = selfhosts;
|
|
|
|
selfhosts = host;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XDMCP
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef USE_SIOCGLIFCONF
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr_storage broad_addr;
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr broad_addr;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/*
|
|
|
|
* If this isn't an Internet Address, don't register it.
|
|
|
|
*/
|
|
|
|
if (family != FamilyInternet
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
&& family != FamilyInternet6
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ignore 'localhost' entries as they're not useful
|
|
|
|
* on the other end of the wire
|
|
|
|
*/
|
|
|
|
if (family == FamilyInternet &&
|
|
|
|
addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1)
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (family == FamilyInternet6 &&
|
|
|
|
IN6_IS_ADDR_LOOPBACK((struct in6_addr *) addr))
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/*
|
|
|
|
* Ignore '0.0.0.0' entries as they are
|
|
|
|
* returned by some OSes for unconfigured NICs but they are
|
|
|
|
* not useful on the other end of the wire.
|
|
|
|
*/
|
|
|
|
if (len == 4 &&
|
|
|
|
addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] == 0)
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmcpRegisterConnection(family, (char *) addr, len);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
/* IPv6 doesn't support broadcasting, so we drop out here */
|
|
|
|
if (family == FamilyInternet6)
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
broad_addr = IFR_IFR_ADDR;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr =
|
|
|
|
htonl(INADDR_BROADCAST);
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(USE_SIOCGLIFCONF) && defined(SIOCGLIFBRDADDR)
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
struct lifreq broad_req;
|
|
|
|
|
|
|
|
broad_req = *ifr;
|
|
|
|
if (ioctl(fd, SIOCGLIFFLAGS, (char *) &broad_req) != -1 &&
|
|
|
|
(broad_req.lifr_flags & IFF_BROADCAST) &&
|
|
|
|
(broad_req.lifr_flags & IFF_UP)
|
|
|
|
) {
|
|
|
|
broad_req = *ifr;
|
|
|
|
if (ioctl(fd, SIOCGLIFBRDADDR, &broad_req) != -1)
|
|
|
|
broad_addr = broad_req.lifr_broadaddr;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#elif defined(SIOCGIFBRDADDR)
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
struct ifreq broad_req;
|
|
|
|
|
|
|
|
broad_req = *ifr;
|
2014-09-27 11:52:59 -06:00
|
|
|
if (ifioctl(fd, SIOCGIFFLAGS, (void *) &broad_req) != -1 &&
|
2012-06-10 07:21:05 -06:00
|
|
|
(broad_req.ifr_flags & IFF_BROADCAST) &&
|
|
|
|
(broad_req.ifr_flags & IFF_UP)
|
|
|
|
) {
|
|
|
|
broad_req = *ifr;
|
2014-09-27 11:52:59 -06:00
|
|
|
if (ifioctl(fd, SIOCGIFBRDADDR, (void *) &broad_req) != -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
broad_addr = broad_req.ifr_addr;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* SIOCGIFBRDADDR */
|
|
|
|
XdmcpRegisterBroadcastAddress((struct sockaddr_in *) &broad_addr);
|
|
|
|
}
|
|
|
|
#endif /* XDMCP */
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (bufptr != buf)
|
2012-06-10 07:21:05 -06:00
|
|
|
free(bufptr);
|
|
|
|
#else /* HAVE_GETIFADDRS */
|
2006-11-26 11:13:41 -07:00
|
|
|
if (getifaddrs(&ifap) < 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("Warning: getifaddrs returns %s\n", strerror(errno));
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
for (ifr = ifap; ifr != NULL; ifr = ifr->ifa_next) {
|
|
|
|
if (!ifr->ifa_addr)
|
|
|
|
continue;
|
2012-06-10 07:21:05 -06:00
|
|
|
len = sizeof(*(ifr->ifa_addr));
|
|
|
|
family = ConvertAddr((struct sockaddr *) ifr->ifa_addr, &len,
|
2014-09-27 11:52:59 -06:00
|
|
|
(void **) &addr);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == -1 || family == FamilyLocal)
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == FamilyInternet6)
|
|
|
|
in6_fillscopeid((struct sockaddr_in6 *) ifr->ifa_addr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (host = selfhosts;
|
|
|
|
host != NULL && !addrEqual(family, addr, len, host);
|
|
|
|
host = host->next);
|
|
|
|
if (host != NULL)
|
|
|
|
continue;
|
|
|
|
MakeHost(host, len);
|
|
|
|
if (host != NULL) {
|
|
|
|
host->family = family;
|
|
|
|
host->len = len;
|
|
|
|
memcpy(host->addr, addr, len);
|
|
|
|
host->next = selfhosts;
|
|
|
|
selfhosts = host;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XDMCP
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If this isn't an Internet Address, don't register it.
|
|
|
|
*/
|
|
|
|
if (family != FamilyInternet
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
&& family != FamilyInternet6
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
continue;
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/*
|
2012-06-10 07:21:05 -06:00
|
|
|
* ignore 'localhost' entries as they're not useful
|
|
|
|
* on the other end of the wire
|
|
|
|
*/
|
|
|
|
if (ifr->ifa_flags & IFF_LOOPBACK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (family == FamilyInternet &&
|
|
|
|
addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore '0.0.0.0' entries as they are
|
|
|
|
* returned by some OSes for unconfigured NICs but they are
|
|
|
|
* not useful on the other end of the wire.
|
|
|
|
*/
|
|
|
|
if (len == 4 &&
|
|
|
|
addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] == 0)
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (family == FamilyInternet6 &&
|
|
|
|
IN6_IS_ADDR_LOOPBACK((struct in6_addr *) addr))
|
|
|
|
continue;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmcpRegisterConnection(family, (char *) addr, len);
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == FamilyInternet6)
|
|
|
|
/* IPv6 doesn't support broadcasting, so we drop out here */
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
if ((ifr->ifa_flags & IFF_BROADCAST) &&
|
|
|
|
(ifr->ifa_flags & IFF_UP) && ifr->ifa_broadaddr)
|
|
|
|
XdmcpRegisterBroadcastAddress((struct sockaddr_in *) ifr->
|
|
|
|
ifa_broadaddr);
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* XDMCP */
|
|
|
|
|
|
|
|
} /* for */
|
2006-11-26 11:13:41 -07:00
|
|
|
freeifaddrs(ifap);
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* HAVE_GETIFADDRS */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* add something of FamilyLocalHost
|
|
|
|
*/
|
|
|
|
for (host = selfhosts;
|
2012-06-10 07:21:05 -06:00
|
|
|
host && !addrEqual(FamilyLocalHost, "", 0, host); host = host->next);
|
|
|
|
if (!host) {
|
|
|
|
MakeHost(host, 0);
|
|
|
|
if (host) {
|
|
|
|
host->family = FamilyLocalHost;
|
|
|
|
host->len = 0;
|
|
|
|
/* Nothing to store in host->addr */
|
|
|
|
host->next = selfhosts;
|
|
|
|
selfhosts = host;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* hpux && !HAVE_IFREQ */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#ifdef XDMCP
|
|
|
|
void
|
2014-09-27 11:52:59 -06:00
|
|
|
AugmentSelf(void *from, int len)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int family;
|
2014-09-27 11:52:59 -06:00
|
|
|
void *addr;
|
2006-11-26 11:13:41 -07:00
|
|
|
register HOST *host;
|
|
|
|
|
2014-09-27 11:52:59 -06:00
|
|
|
family = ConvertAddr(from, &len, (void **) &addr);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (family == -1 || family == FamilyLocal)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
|
|
|
for (host = selfhosts; host; host = host->next) {
|
|
|
|
if (addrEqual(family, addr, len, host))
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
MakeHost(host, len)
|
|
|
|
if (!host)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
host->family = family;
|
|
|
|
host->len = len;
|
2012-06-10 07:21:05 -06:00
|
|
|
memcpy(host->addr, addr, len);
|
2006-11-26 11:13:41 -07:00
|
|
|
host->next = selfhosts;
|
|
|
|
selfhosts = host;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
AddLocalHosts(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
HOST *self;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (self = selfhosts; self; self = self->next)
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Fix for XFree86 bug #156: pass addingLocal = TRUE to
|
|
|
|
* NewHost to tell that we are adding the default local
|
|
|
|
* host entries and not to flag the entries as being
|
|
|
|
* explicitely requested */
|
|
|
|
(void) NewHost(self->family, self->addr, self->len, TRUE);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset access control list to initial hosts */
|
|
|
|
void
|
2014-09-27 11:52:59 -06:00
|
|
|
ResetHosts(const char *display)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
register HOST *host;
|
|
|
|
char lhostname[120], ohostname[120];
|
|
|
|
char *hostname = ohostname;
|
|
|
|
char fname[PATH_MAX + 1];
|
|
|
|
int fnamelen;
|
|
|
|
FILE *fd;
|
|
|
|
char *ptr;
|
|
|
|
int i, hostlen;
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN) && (!defined(IPv6) || !defined(AF_INET6))
|
2006-11-26 11:13:41 -07:00
|
|
|
union {
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr sa;
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN)
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr_in in;
|
|
|
|
#endif /* TCPCONN || STREAMSCONN */
|
|
|
|
} saddr;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
int family = 0;
|
2015-09-16 13:10:19 -06:00
|
|
|
void *addr = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
int len;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
siTypesInitialize();
|
|
|
|
AccessEnabled = defeatAccessControl ? FALSE : DEFAULT_ACCESS_CONTROL;
|
|
|
|
LocalHostEnabled = FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
while ((host = validhosts) != 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
validhosts = host->next;
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeHost(host);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined WIN32 && defined __MINGW32__
|
|
|
|
#define ETC_HOST_PREFIX "X"
|
|
|
|
#else
|
|
|
|
#define ETC_HOST_PREFIX "/etc/X"
|
|
|
|
#endif
|
|
|
|
#define ETC_HOST_SUFFIX ".hosts"
|
|
|
|
fnamelen = strlen(ETC_HOST_PREFIX) + strlen(ETC_HOST_SUFFIX) +
|
2012-06-10 07:21:05 -06:00
|
|
|
strlen(display) + 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (fnamelen > sizeof(fname))
|
2012-06-10 07:21:05 -06:00
|
|
|
FatalError("Display name `%s' is too long\n", display);
|
|
|
|
snprintf(fname, sizeof(fname), ETC_HOST_PREFIX "%s" ETC_HOST_SUFFIX,
|
|
|
|
display);
|
|
|
|
|
|
|
|
if ((fd = fopen(fname, "r")) != 0) {
|
|
|
|
while (fgets(ohostname, sizeof(ohostname), fd)) {
|
|
|
|
family = FamilyWild;
|
|
|
|
if (*ohostname == '#')
|
|
|
|
continue;
|
|
|
|
if ((ptr = strchr(ohostname, '\n')) != 0)
|
|
|
|
*ptr = 0;
|
|
|
|
hostlen = strlen(ohostname) + 1;
|
|
|
|
for (i = 0; i < hostlen; i++)
|
|
|
|
lhostname[i] = tolower(ohostname[i]);
|
|
|
|
hostname = ohostname;
|
|
|
|
if (!strncmp("local:", lhostname, 6)) {
|
|
|
|
family = FamilyLocalHost;
|
|
|
|
NewHost(family, "", 0, FALSE);
|
|
|
|
LocalHostRequested = TRUE; /* Fix for XFree86 bug #156 */
|
|
|
|
}
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN)
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (!strncmp("inet:", lhostname, 5)) {
|
|
|
|
family = FamilyInternet;
|
|
|
|
hostname = ohostname + 5;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (!strncmp("inet6:", lhostname, 6)) {
|
|
|
|
family = FamilyInternet6;
|
|
|
|
hostname = ohostname + 6;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef SECURE_RPC
|
2012-06-10 07:21:05 -06:00
|
|
|
else if (!strncmp("nis:", lhostname, 4)) {
|
|
|
|
family = FamilyNetname;
|
|
|
|
hostname = ohostname + 4;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (!strncmp("si:", lhostname, 3)) {
|
|
|
|
family = FamilyServerInterpreted;
|
|
|
|
hostname = ohostname + 3;
|
|
|
|
hostlen -= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (family == FamilyServerInterpreted) {
|
|
|
|
len = siCheckAddr(hostname, hostlen);
|
|
|
|
if (len >= 0) {
|
|
|
|
NewHost(family, hostname, len, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef SECURE_RPC
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((family == FamilyNetname) || (strchr(hostname, '@'))) {
|
|
|
|
SecureRPCInit();
|
|
|
|
(void) NewHost(FamilyNetname, hostname, strlen(hostname),
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif /* SECURE_RPC */
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
if ((family == FamilyInternet) || (family == FamilyInternet6) ||
|
|
|
|
(family == FamilyWild)) {
|
|
|
|
struct addrinfo *addresses;
|
|
|
|
struct addrinfo *a;
|
|
|
|
int f;
|
|
|
|
|
|
|
|
if (getaddrinfo(hostname, NULL, NULL, &addresses) == 0) {
|
|
|
|
for (a = addresses; a != NULL; a = a->ai_next) {
|
|
|
|
len = a->ai_addrlen;
|
|
|
|
f = ConvertAddr(a->ai_addr, &len,
|
2014-09-27 11:52:59 -06:00
|
|
|
(void **) &addr);
|
2015-09-16 13:10:19 -06:00
|
|
|
if (addr && ((family == f) ||
|
|
|
|
((family == FamilyWild) && (f != -1)))) {
|
2012-06-10 07:21:05 -06:00
|
|
|
NewHost(f, addr, len, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
freeaddrinfo(addresses);
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
|
|
|
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
|
2012-06-10 07:21:05 -06:00
|
|
|
_Xgethostbynameparams hparams;
|
|
|
|
#endif
|
|
|
|
register struct hostent *hp;
|
|
|
|
|
|
|
|
/* host name */
|
|
|
|
if ((family == FamilyInternet &&
|
|
|
|
((hp = _XGethostbyname(hostname, hparams)) != 0)) ||
|
|
|
|
((hp = _XGethostbyname(hostname, hparams)) != 0)) {
|
|
|
|
saddr.sa.sa_family = hp->h_addrtype;
|
|
|
|
len = sizeof(saddr.sa);
|
|
|
|
if ((family =
|
|
|
|
ConvertAddr(&saddr.sa, &len,
|
2014-09-27 11:52:59 -06:00
|
|
|
(void **) &addr)) != -1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef h_addr /* new 4.3bsd version of gethostent */
|
|
|
|
char **list;
|
|
|
|
|
|
|
|
/* iterate over the addresses */
|
|
|
|
for (list = hp->h_addr_list; *list; list++)
|
2014-09-27 11:52:59 -06:00
|
|
|
(void) NewHost(family, (void *) *list, len, FALSE);
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
2014-09-27 11:52:59 -06:00
|
|
|
(void) NewHost(family, (void *) hp->h_addr, len,
|
2012-06-10 07:21:05 -06:00
|
|
|
FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* IPv6 */
|
|
|
|
}
|
|
|
|
#endif /* TCPCONN || STREAMSCONN */
|
|
|
|
family = FamilyWild;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
fclose(fd);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 12:59:50 -06:00
|
|
|
static Bool
|
|
|
|
xtransLocalClient(ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int alen, family, notused;
|
|
|
|
Xtransaddr *from = NULL;
|
2014-09-27 11:52:59 -06:00
|
|
|
void *addr;
|
2012-06-10 07:21:05 -06:00
|
|
|
register HOST *host;
|
|
|
|
OsCommPtr oc = (OsCommPtr) client->osPrivate;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!oc->trans_conn)
|
2010-12-05 08:36:02 -07:00
|
|
|
return FALSE;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!_XSERVTransGetPeerAddr(oc->trans_conn, ¬used, &alen, &from)) {
|
|
|
|
family = ConvertAddr((struct sockaddr *) from,
|
2014-09-27 11:52:59 -06:00
|
|
|
&alen, (void **) &addr);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == -1) {
|
|
|
|
free(from);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (family == FamilyLocal) {
|
|
|
|
free(from);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
for (host = selfhosts; host; host = host->next) {
|
|
|
|
if (addrEqual(family, addr, alen, host)) {
|
|
|
|
free(from);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(from);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-09 12:59:50 -06:00
|
|
|
/* Is client on the local host */
|
|
|
|
Bool
|
|
|
|
ComputeLocalClient(ClientPtr client)
|
|
|
|
{
|
|
|
|
const char *cmdname = GetClientCmdName(client);
|
|
|
|
|
|
|
|
if (!xtransLocalClient(client))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* If the executable name is "ssh", assume that this client connection
|
|
|
|
* is forwarded from another host via SSH
|
|
|
|
*/
|
|
|
|
if (cmdname) {
|
|
|
|
char *cmd = strdup(cmdname);
|
|
|
|
Bool ret;
|
|
|
|
|
|
|
|
/* Cut off any colon and whatever comes after it, see
|
|
|
|
* https://lists.freedesktop.org/archives/xorg-devel/2015-December/048164.html
|
|
|
|
*/
|
2018-02-18 10:16:37 -07:00
|
|
|
char *tok = strtok(cmd, ":");
|
2016-08-09 12:59:50 -06:00
|
|
|
|
|
|
|
#if !defined(WIN32) || defined(__CYGWIN__)
|
2018-02-18 10:16:37 -07:00
|
|
|
ret = strcmp(basename(tok), "ssh") != 0;
|
2016-08-09 12:59:50 -06:00
|
|
|
#else
|
2018-02-18 10:16:37 -07:00
|
|
|
ret = strcmp(tok, "ssh") != 0;
|
2016-08-09 12:59:50 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* Return the uid and all gids of a connected local client
|
2008-11-02 08:26:08 -07:00
|
|
|
* Allocates a LocalClientCredRec - caller must call FreeLocalClientCreds
|
2015-09-16 13:10:19 -06:00
|
|
|
*
|
2006-11-26 11:13:41 -07:00
|
|
|
* Used by localuser & localgroup ServerInterpreted access control forms below
|
2008-11-02 08:26:08 -07:00
|
|
|
* Used by AuthAudit to log who local connections came from
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
2008-11-02 08:26:08 -07:00
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
#if defined(HAVE_GETPEEREID) || defined(HAVE_GETPEERUCRED) || defined(SO_PEERCRED)
|
2006-11-26 11:13:41 -07:00
|
|
|
int fd;
|
|
|
|
XtransConnInfo ci;
|
2008-11-02 08:26:08 -07:00
|
|
|
LocalClientCredRec *lcc;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
#ifdef HAVE_GETPEEREID
|
2006-11-26 11:13:41 -07:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2012-06-10 07:21:05 -06:00
|
|
|
#elif defined(HAVE_GETPEERUCRED)
|
2006-11-26 11:13:41 -07:00
|
|
|
ucred_t *peercred = NULL;
|
2008-11-02 08:26:08 -07:00
|
|
|
const gid_t *gids;
|
2006-11-26 11:13:41 -07:00
|
|
|
#elif defined(SO_PEERCRED)
|
|
|
|
struct ucred peercred;
|
|
|
|
socklen_t so_len = sizeof(peercred);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (client == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return -1;
|
|
|
|
ci = ((OsCommPtr) client->osPrivate)->trans_conn;
|
2017-12-08 08:01:59 -07:00
|
|
|
#if !(defined(__sun) && defined(HAVE_GETPEERUCRED))
|
2015-09-16 13:10:19 -06:00
|
|
|
/* Most implementations can only determine peer credentials for Unix
|
|
|
|
* domain sockets - Solaris getpeerucred can work with a bit more, so
|
2006-11-26 11:13:41 -07:00
|
|
|
* we just let it tell us if the connection type is supported or not
|
|
|
|
*/
|
|
|
|
if (!_XSERVTransIsLocal(ci)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
*lccp = calloc(1, sizeof(LocalClientCredRec));
|
2008-11-02 08:26:08 -07:00
|
|
|
if (*lccp == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return -1;
|
2008-11-02 08:26:08 -07:00
|
|
|
lcc = *lccp;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
fd = _XSERVTransGetConnectionNumber(ci);
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef HAVE_GETPEEREID
|
2008-11-02 08:26:08 -07:00
|
|
|
if (getpeereid(fd, &uid, &gid) == -1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return -1;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
lcc->euid = uid;
|
|
|
|
lcc->egid = gid;
|
|
|
|
lcc->fieldsSet = LCC_UID_SET | LCC_GID_SET;
|
2006-11-26 11:13:41 -07:00
|
|
|
return 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
#elif defined(HAVE_GETPEERUCRED)
|
2008-11-02 08:26:08 -07:00
|
|
|
if (getpeerucred(fd, &peercred) < 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
lcc->euid = ucred_geteuid(peercred);
|
|
|
|
if (lcc->euid != -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
lcc->fieldsSet |= LCC_UID_SET;
|
2008-11-02 08:26:08 -07:00
|
|
|
lcc->egid = ucred_getegid(peercred);
|
|
|
|
if (lcc->egid != -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
lcc->fieldsSet |= LCC_GID_SET;
|
2008-11-02 08:26:08 -07:00
|
|
|
lcc->pid = ucred_getpid(peercred);
|
|
|
|
if (lcc->pid != -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
lcc->fieldsSet |= LCC_PID_SET;
|
2008-11-02 08:26:08 -07:00
|
|
|
#ifdef HAVE_GETZONEID
|
|
|
|
lcc->zoneid = ucred_getzoneid(peercred);
|
|
|
|
if (lcc->zoneid != -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
lcc->fieldsSet |= LCC_ZID_SET;
|
2008-11-02 08:26:08 -07:00
|
|
|
#endif
|
|
|
|
lcc->nSuppGids = ucred_getgroups(peercred, &gids);
|
|
|
|
if (lcc->nSuppGids > 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
lcc->pSuppGids = calloc(lcc->nSuppGids, sizeof(int));
|
|
|
|
if (lcc->pSuppGids == NULL) {
|
|
|
|
lcc->nSuppGids = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < lcc->nSuppGids; i++) {
|
|
|
|
(lcc->pSuppGids)[i] = (int) gids[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lcc->nSuppGids = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
ucred_free(peercred);
|
|
|
|
return 0;
|
|
|
|
#elif defined(SO_PEERCRED)
|
2008-11-02 08:26:08 -07:00
|
|
|
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peercred, &so_len) == -1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return -1;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
lcc->euid = peercred.uid;
|
|
|
|
lcc->egid = peercred.gid;
|
|
|
|
lcc->pid = peercred.pid;
|
|
|
|
lcc->fieldsSet = LCC_UID_SET | LCC_GID_SET | LCC_PID_SET;
|
2006-11-26 11:13:41 -07:00
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
/* No system call available to get the credentials of the peer */
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeLocalClientCreds(LocalClientCredRec * lcc)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
if (lcc != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (lcc->nSuppGids > 0) {
|
|
|
|
free(lcc->pSuppGids);
|
|
|
|
}
|
|
|
|
free(lcc);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-11-26 11:13:41 -07:00
|
|
|
AuthorizedClient(ClientPtr client)
|
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!client || defeatAccessControl)
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* untrusted clients can't change host access */
|
2008-11-02 08:26:08 -07:00
|
|
|
rc = XaceHook(XACE_SERVER_ACCESS, client, DixManageAccess);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2007-11-24 12:04:00 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
return client->local ? Success : BadAccess;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a host to the access control list. This is the external interface
|
|
|
|
* called from the dispatcher */
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
AddHost(ClientPtr client, int family, unsigned length, /* of bytes in pAddr */
|
|
|
|
const void *pAddr)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc, len;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
rc = AuthorizedClient(client);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
switch (family) {
|
|
|
|
case FamilyLocalHost:
|
2012-06-10 07:21:05 -06:00
|
|
|
len = length;
|
|
|
|
LocalHostEnabled = TRUE;
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef SECURE_RPC
|
|
|
|
case FamilyNetname:
|
2012-06-10 07:21:05 -06:00
|
|
|
len = length;
|
|
|
|
SecureRPCInit();
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
case FamilyInternet:
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
case FamilyInternet6:
|
|
|
|
#endif
|
|
|
|
case FamilyDECnet:
|
|
|
|
case FamilyChaos:
|
|
|
|
case FamilyServerInterpreted:
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((len = CheckAddr(family, pAddr, length)) < 0) {
|
|
|
|
client->errorValue = length;
|
|
|
|
return BadValue;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case FamilyLocal:
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
client->errorValue = family;
|
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (NewHost(family, pAddr, len, FALSE))
|
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2015-09-16 13:10:19 -06:00
|
|
|
ForEachHostInFamily(int family, Bool (*func) (unsigned char *addr,
|
|
|
|
short len,
|
|
|
|
void *closure),
|
2014-09-27 11:52:59 -06:00
|
|
|
void *closure)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
HOST *host;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
for (host = validhosts; host; host = host->next)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == host->family && func(host->addr, host->len, closure))
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/* Add a host to the access control list. This is the internal interface
|
2006-11-26 11:13:41 -07:00
|
|
|
* called when starting or resetting the server */
|
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
NewHost(int family, const void *addr, int len, int addingLocalHosts)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
register HOST *host;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (host = validhosts; host; host = host->next) {
|
|
|
|
if (addrEqual(family, addr, len, host))
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!addingLocalHosts) { /* Fix for XFree86 bug #156 */
|
|
|
|
for (host = selfhosts; host; host = host->next) {
|
|
|
|
if (addrEqual(family, addr, len, host)) {
|
|
|
|
host->requested = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
MakeHost(host, len)
|
|
|
|
if (!host)
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
host->family = family;
|
|
|
|
host->len = len;
|
2012-06-10 07:21:05 -06:00
|
|
|
memcpy(host->addr, addr, len);
|
2006-11-26 11:13:41 -07:00
|
|
|
host->next = validhosts;
|
|
|
|
validhosts = host;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove a host from the access control list */
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
RemoveHost(ClientPtr client, int family, unsigned length, /* of bytes in pAddr */
|
2014-09-27 11:52:59 -06:00
|
|
|
void *pAddr)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc, len;
|
2012-06-10 07:21:05 -06:00
|
|
|
register HOST *host, **prev;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
rc = AuthorizedClient(client);
|
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
switch (family) {
|
|
|
|
case FamilyLocalHost:
|
2012-06-10 07:21:05 -06:00
|
|
|
len = length;
|
|
|
|
LocalHostEnabled = FALSE;
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef SECURE_RPC
|
|
|
|
case FamilyNetname:
|
2012-06-10 07:21:05 -06:00
|
|
|
len = length;
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
case FamilyInternet:
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
case FamilyInternet6:
|
|
|
|
#endif
|
|
|
|
case FamilyDECnet:
|
|
|
|
case FamilyChaos:
|
|
|
|
case FamilyServerInterpreted:
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((len = CheckAddr(family, pAddr, length)) < 0) {
|
|
|
|
client->errorValue = length;
|
2010-12-05 08:36:02 -07:00
|
|
|
return BadValue;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
case FamilyLocal:
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
client->errorValue = family;
|
2010-12-05 08:36:02 -07:00
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
for (prev = &validhosts;
|
2012-06-10 07:21:05 -06:00
|
|
|
(host = *prev) && (!addrEqual(family, pAddr, len, host));
|
|
|
|
prev = &host->next);
|
|
|
|
if (host) {
|
2006-11-26 11:13:41 -07:00
|
|
|
*prev = host->next;
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeHost(host);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get all hosts in the access control list */
|
|
|
|
int
|
2014-09-27 11:52:59 -06:00
|
|
|
GetHosts(void **data, int *pnHosts, int *pLen, BOOL * pEnabled)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int len;
|
|
|
|
register int n = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
register unsigned char *ptr;
|
2012-06-10 07:21:05 -06:00
|
|
|
register HOST *host;
|
|
|
|
int nHosts = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
*pEnabled = AccessEnabled ? EnableAccess : DisableAccess;
|
2012-06-10 07:21:05 -06:00
|
|
|
for (host = validhosts; host; host = host->next) {
|
|
|
|
nHosts++;
|
|
|
|
n += pad_to_int32(host->len) + sizeof(xHostEntry);
|
2014-12-09 10:58:52 -07:00
|
|
|
/* Could check for INT_MAX, but in reality having more than 1mb of
|
|
|
|
hostnames in the access list is ridiculous */
|
|
|
|
if (n >= 1048576)
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (n) {
|
2010-12-05 08:36:02 -07:00
|
|
|
*data = ptr = malloc(n);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!ptr) {
|
|
|
|
return BadAlloc;
|
|
|
|
}
|
|
|
|
for (host = validhosts; host; host = host->next) {
|
|
|
|
len = host->len;
|
2014-12-21 04:41:44 -07:00
|
|
|
if ((ptr + sizeof(xHostEntry) + len) > ((unsigned char *) *data + n))
|
2014-12-09 10:58:52 -07:00
|
|
|
break;
|
2012-06-10 07:21:05 -06:00
|
|
|
((xHostEntry *) ptr)->family = host->family;
|
|
|
|
((xHostEntry *) ptr)->length = len;
|
|
|
|
ptr += sizeof(xHostEntry);
|
|
|
|
memcpy(ptr, host->addr, len);
|
|
|
|
ptr += pad_to_int32(len);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*data = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
*pnHosts = nHosts;
|
|
|
|
*pLen = n;
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for valid address family and length, and return address length. */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/*ARGSUSED*/ static int
|
|
|
|
CheckAddr(int family, const void *pAddr, unsigned length)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int len;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (family) {
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN)
|
2012-06-10 07:21:05 -06:00
|
|
|
case FamilyInternet:
|
|
|
|
if (length == sizeof(struct in_addr))
|
|
|
|
len = length;
|
|
|
|
else
|
|
|
|
len = -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
case FamilyInternet6:
|
|
|
|
if (length == sizeof(struct in6_addr))
|
|
|
|
len = length;
|
|
|
|
else
|
|
|
|
len = -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
break;
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif
|
|
|
|
case FamilyServerInterpreted:
|
|
|
|
len = siCheckAddr(pAddr, length);
|
|
|
|
break;
|
|
|
|
default:
|
2006-11-26 11:13:41 -07:00
|
|
|
len = -1;
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
return len;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/* Check if a host is not in the access control list.
|
2006-11-26 11:13:41 -07:00
|
|
|
* Returns 1 if host is invalid, 0 if we've found it. */
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
InvalidHost(register struct sockaddr *saddr, int len, ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int family;
|
2015-09-16 13:10:19 -06:00
|
|
|
void *addr = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
register HOST *selfhost, *host;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!AccessEnabled) /* just let them in */
|
2010-12-05 08:36:02 -07:00
|
|
|
return 0;
|
2014-09-27 11:52:59 -06:00
|
|
|
family = ConvertAddr(saddr, &len, (void **) &addr);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (family == -1)
|
|
|
|
return 1;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == FamilyLocal) {
|
|
|
|
if (!LocalHostEnabled) {
|
|
|
|
/*
|
2015-09-16 13:10:19 -06:00
|
|
|
* check to see if any local address is enabled. This
|
2012-06-10 07:21:05 -06:00
|
|
|
* implicitly enables local connections.
|
|
|
|
*/
|
|
|
|
for (selfhost = selfhosts; selfhost; selfhost = selfhost->next) {
|
|
|
|
for (host = validhosts; host; host = host->next) {
|
|
|
|
if (addrEqual(selfhost->family, selfhost->addr,
|
|
|
|
selfhost->len, host))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
for (host = validhosts; host; host = host->next) {
|
|
|
|
if (host->family == FamilyServerInterpreted) {
|
|
|
|
if (siAddrMatch(family, addr, len, host, client)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-09-16 13:10:19 -06:00
|
|
|
if (addr && addrEqual(family, addr, len, host))
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
return 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-27 11:52:59 -06:00
|
|
|
ConvertAddr(register struct sockaddr *saddr, int *len, void **addr)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
if (*len == 0)
|
2010-12-05 08:36:02 -07:00
|
|
|
return FamilyLocal;
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (saddr->sa_family) {
|
2006-11-26 11:13:41 -07:00
|
|
|
case AF_UNSPEC:
|
2007-11-24 12:04:00 -07:00
|
|
|
#if defined(UNIXCONN) || defined(LOCALCONN)
|
2006-11-26 11:13:41 -07:00
|
|
|
case AF_UNIX:
|
|
|
|
#endif
|
|
|
|
return FamilyLocal;
|
2017-12-08 08:01:59 -07:00
|
|
|
#if defined(TCPCONN)
|
2006-11-26 11:13:41 -07:00
|
|
|
case AF_INET:
|
|
|
|
#ifdef WIN32
|
2012-06-10 07:21:05 -06:00
|
|
|
if (16777343 == *(long *) &((struct sockaddr_in *) saddr)->sin_addr)
|
2006-11-26 11:13:41 -07:00
|
|
|
return FamilyLocal;
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
*len = sizeof(struct in_addr);
|
2014-09-27 11:52:59 -06:00
|
|
|
*addr = (void *) &(((struct sockaddr_in *) saddr)->sin_addr);
|
2006-11-26 11:13:41 -07:00
|
|
|
return FamilyInternet;
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
2012-06-10 07:21:05 -06:00
|
|
|
case AF_INET6:
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *) saddr;
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&(saddr6->sin6_addr))) {
|
|
|
|
*len = sizeof(struct in_addr);
|
2014-09-27 11:52:59 -06:00
|
|
|
*addr = (void *) &(saddr6->sin6_addr.s6_addr[12]);
|
2012-06-10 07:21:05 -06:00
|
|
|
return FamilyInternet;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*len = sizeof(struct in6_addr);
|
2014-09-27 11:52:59 -06:00
|
|
|
*addr = (void *) &(saddr6->sin6_addr);
|
2012-06-10 07:21:05 -06:00
|
|
|
return FamilyInternet6;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
ChangeAccessControl(ClientPtr client, int fEnabled)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
int rc = AuthorizedClient(client);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (rc != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
AccessEnabled = fEnabled;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns FALSE if xhost + in effect, else TRUE */
|
|
|
|
int
|
|
|
|
GetAccessControl(void)
|
|
|
|
{
|
|
|
|
return AccessEnabled;
|
|
|
|
}
|
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
int
|
|
|
|
GetClientFd(ClientPtr client)
|
|
|
|
{
|
|
|
|
return ((OsCommPtr) client->osPrivate)->fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
ClientIsLocal(ClientPtr client)
|
|
|
|
{
|
|
|
|
XtransConnInfo ci = ((OsCommPtr) client->osPrivate)->trans_conn;
|
|
|
|
|
|
|
|
return _XSERVTransIsLocal(ci);
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/*****************************************************************************
|
|
|
|
* FamilyServerInterpreted host entry implementation
|
|
|
|
*
|
|
|
|
* Supports an extensible system of host types which the server can interpret
|
|
|
|
* See the IPv6 extensions to the X11 protocol spec for the definition.
|
|
|
|
*
|
|
|
|
* Currently supported schemes:
|
|
|
|
*
|
|
|
|
* hostname - hostname as defined in IETF RFC 2396
|
|
|
|
* ipv6 - IPv6 literal address as defined in IETF RFC's 3513 and <TBD>
|
|
|
|
*
|
|
|
|
* See xc/doc/specs/SIAddresses for formal definitions of each type.
|
|
|
|
*/
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/* These definitions and the siTypeAdd function could be exported in the
|
2006-11-26 11:13:41 -07:00
|
|
|
* future to enable loading additional host types, but that was not done for
|
|
|
|
* the initial implementation.
|
|
|
|
*/
|
2014-09-27 11:52:59 -06:00
|
|
|
typedef Bool (*siAddrMatchFunc) (int family, void *addr, int len,
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *siAddr, int siAddrlen,
|
|
|
|
ClientPtr client, void *siTypePriv);
|
|
|
|
typedef int (*siCheckAddrFunc) (const char *addrString, int length,
|
|
|
|
void *siTypePriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
struct siType {
|
2012-06-10 07:21:05 -06:00
|
|
|
struct siType *next;
|
|
|
|
const char *typeName;
|
|
|
|
siAddrMatchFunc addrMatch;
|
|
|
|
siCheckAddrFunc checkAddr;
|
|
|
|
void *typePriv; /* Private data for type routines */
|
2006-11-26 11:13:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct siType *siTypeList;
|
|
|
|
|
|
|
|
static int
|
|
|
|
siTypeAdd(const char *typeName, siAddrMatchFunc addrMatch,
|
2012-06-10 07:21:05 -06:00
|
|
|
siCheckAddrFunc checkAddr, void *typePriv)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
struct siType *s, *p;
|
|
|
|
|
|
|
|
if ((typeName == NULL) || (addrMatch == NULL) || (checkAddr == NULL))
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
for (s = siTypeList, p = NULL; s != NULL; p = s, s = s->next) {
|
|
|
|
if (strcmp(typeName, s->typeName) == 0) {
|
|
|
|
s->addrMatch = addrMatch;
|
|
|
|
s->checkAddr = checkAddr;
|
|
|
|
s->typePriv = typePriv;
|
|
|
|
return Success;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
s = malloc(sizeof(struct siType));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (s == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadAlloc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (p == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
siTypeList = s;
|
2006-11-26 11:13:41 -07:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
p->next = s;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
s->next = NULL;
|
|
|
|
s->typeName = typeName;
|
|
|
|
s->addrMatch = addrMatch;
|
|
|
|
s->checkAddr = checkAddr;
|
|
|
|
s->typePriv = typePriv;
|
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks to see if a host matches a server-interpreted host entry */
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
siAddrMatch(int family, void *addr, int len, HOST * host, ClientPtr client)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
Bool matches = FALSE;
|
|
|
|
struct siType *s;
|
|
|
|
const char *valueString;
|
|
|
|
int addrlen;
|
|
|
|
|
|
|
|
valueString = (const char *) memchr(host->addr, '\0', host->len);
|
|
|
|
if (valueString != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
for (s = siTypeList; s != NULL; s = s->next) {
|
|
|
|
if (strcmp((char *) host->addr, s->typeName) == 0) {
|
|
|
|
addrlen = host->len - (strlen((char *) host->addr) + 1);
|
|
|
|
matches = s->addrMatch(family, addr, len,
|
|
|
|
valueString + 1, addrlen, client,
|
|
|
|
s->typePriv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef FAMILY_SI_DEBUG
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("Xserver: siAddrMatch(): type = %s, value = %*.*s -- %s\n",
|
|
|
|
host->addr, addrlen, addrlen, valueString + 1,
|
|
|
|
(matches) ? "accepted" : "rejected");
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
siCheckAddr(const char *addrString, int length)
|
|
|
|
{
|
|
|
|
const char *valueString;
|
|
|
|
int addrlen, typelen;
|
|
|
|
int len = -1;
|
|
|
|
struct siType *s;
|
|
|
|
|
|
|
|
/* Make sure there is a \0 byte inside the specified length
|
|
|
|
to separate the address type from the address value. */
|
|
|
|
valueString = (const char *) memchr(addrString, '\0', length);
|
|
|
|
if (valueString != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Make sure the first string is a recognized address type,
|
2015-09-16 13:10:19 -06:00
|
|
|
* and the second string is a valid address of that type.
|
2012-06-10 07:21:05 -06:00
|
|
|
*/
|
|
|
|
typelen = strlen(addrString) + 1;
|
|
|
|
addrlen = length - typelen;
|
|
|
|
|
|
|
|
for (s = siTypeList; s != NULL; s = s->next) {
|
|
|
|
if (strcmp(addrString, s->typeName) == 0) {
|
|
|
|
len = s->checkAddr(valueString + 1, addrlen, s->typePriv);
|
|
|
|
if (len >= 0) {
|
|
|
|
len += typelen;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef FAMILY_SI_DEBUG
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
const char *resultMsg;
|
|
|
|
|
|
|
|
if (s == NULL) {
|
|
|
|
resultMsg = "type not registered";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (len == -1)
|
|
|
|
resultMsg = "rejected";
|
|
|
|
else
|
|
|
|
resultMsg = "accepted";
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorF
|
|
|
|
("Xserver: siCheckAddr(): type = %s, value = %*.*s, len = %d -- %s\n",
|
|
|
|
addrString, addrlen, addrlen, valueString + 1, len, resultMsg);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Hostname server-interpreted host type
|
|
|
|
*
|
|
|
|
* Stored as hostname string, explicitly defined to be resolved ONLY
|
|
|
|
* at access check time, to allow for hosts with dynamic addresses
|
|
|
|
* but static hostnames, such as found in some DHCP & mobile setups.
|
|
|
|
*
|
|
|
|
* Hostname must conform to IETF RFC 2396 sec. 3.2.2, which defines it as:
|
|
|
|
* hostname = *( domainlabel "." ) toplabel [ "." ]
|
|
|
|
* domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
|
|
|
* toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef NI_MAXHOST
|
2012-06-10 07:21:05 -06:00
|
|
|
#define SI_HOSTNAME_MAXLEN NI_MAXHOST
|
|
|
|
#else
|
|
|
|
#ifdef MAXHOSTNAMELEN
|
|
|
|
#define SI_HOSTNAME_MAXLEN MAXHOSTNAMELEN
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
#define SI_HOSTNAME_MAXLEN 256
|
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
siHostnameAddrMatch(int family, void *addr, int len,
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *siAddr, int siAddrLen, ClientPtr client,
|
|
|
|
void *typePriv)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
Bool res = FALSE;
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/* Currently only supports checking against IPv4 & IPv6 connections, but
|
|
|
|
* support for other address families, such as DECnet, could be added if
|
2006-11-26 11:13:41 -07:00
|
|
|
* desired.
|
|
|
|
*/
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
if ((family == FamilyInternet) || (family == FamilyInternet6)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
char hostname[SI_HOSTNAME_MAXLEN];
|
|
|
|
struct addrinfo *addresses;
|
|
|
|
struct addrinfo *a;
|
|
|
|
int f, hostaddrlen;
|
2015-09-16 13:10:19 -06:00
|
|
|
void *hostaddr = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (siAddrLen >= sizeof(hostname))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strlcpy(hostname, siAddr, siAddrLen + 1);
|
|
|
|
|
|
|
|
if (getaddrinfo(hostname, NULL, NULL, &addresses) == 0) {
|
|
|
|
for (a = addresses; a != NULL; a = a->ai_next) {
|
|
|
|
hostaddrlen = a->ai_addrlen;
|
|
|
|
f = ConvertAddr(a->ai_addr, &hostaddrlen, &hostaddr);
|
2015-09-16 13:10:19 -06:00
|
|
|
if ((f == family) && (len == hostaddrlen) && hostaddr &&
|
2012-06-10 07:21:05 -06:00
|
|
|
(memcmp(addr, hostaddr, len) == 0)) {
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
freeaddrinfo(addresses);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
#else /* IPv6 not supported, use gethostbyname instead for IPv4 */
|
2006-11-26 11:13:41 -07:00
|
|
|
if (family == FamilyInternet) {
|
2012-06-10 07:21:05 -06:00
|
|
|
register struct hostent *hp;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
|
2012-06-10 07:21:05 -06:00
|
|
|
_Xgethostbynameparams hparams;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
char hostname[SI_HOSTNAME_MAXLEN];
|
|
|
|
int f, hostaddrlen;
|
2014-09-27 11:52:59 -06:00
|
|
|
void *hostaddr;
|
2012-06-10 07:21:05 -06:00
|
|
|
const char **addrlist;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (siAddrLen >= sizeof(hostname))
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
strlcpy(hostname, siAddr, siAddrLen + 1);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((hp = _XGethostbyname(hostname, hparams)) != NULL) {
|
|
|
|
#ifdef h_addr /* new 4.3bsd version of gethostent */
|
|
|
|
/* iterate over the addresses */
|
|
|
|
for (addrlist = hp->h_addr_list; *addrlist; addrlist++)
|
2006-11-26 11:13:41 -07:00
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
addrlist = &hp->h_addr;
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
sin.sin_family = hp->h_addrtype;
|
|
|
|
memcpy(&(sin.sin_addr), *addrlist, hp->h_length);
|
|
|
|
hostaddrlen = sizeof(sin);
|
|
|
|
f = ConvertAddr((struct sockaddr *) &sin,
|
|
|
|
&hostaddrlen, &hostaddr);
|
|
|
|
if ((f == family) && (len == hostaddrlen) &&
|
|
|
|
(memcmp(addr, hostaddr, len) == 0)) {
|
|
|
|
res = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
siHostnameCheckAddr(const char *valueString, int length, void *typePriv)
|
|
|
|
{
|
|
|
|
/* Check conformance of hostname to RFC 2396 sec. 3.2.2 definition.
|
|
|
|
* We do not use ctype functions here to avoid locale-specific
|
2015-09-16 13:10:19 -06:00
|
|
|
* character sets. Hostnames must be pure ASCII.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
|
|
|
int len = length;
|
|
|
|
int i;
|
|
|
|
Bool dotAllowed = FALSE;
|
|
|
|
Bool dashAllowed = FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if ((length <= 0) || (length >= SI_HOSTNAME_MAXLEN)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
len = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
char c = valueString[i];
|
|
|
|
|
|
|
|
if (c == 0x2E) { /* '.' */
|
|
|
|
if (dotAllowed == FALSE) {
|
|
|
|
len = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dotAllowed = FALSE;
|
|
|
|
dashAllowed = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == 0x2D) { /* '-' */
|
|
|
|
if (dashAllowed == FALSE) {
|
|
|
|
len = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dotAllowed = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (((c >= 0x30) && (c <= 0x3A)) /* 0-9 */ ||
|
|
|
|
((c >= 0x61) && (c <= 0x7A)) /* a-z */ ||
|
|
|
|
((c >= 0x41) && (c <= 0x5A)) /* A-Z */ ) {
|
|
|
|
dotAllowed = TRUE;
|
|
|
|
dashAllowed = TRUE;
|
|
|
|
}
|
|
|
|
else { /* Invalid character */
|
|
|
|
len = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
/***
|
|
|
|
* "ipv6" server interpreted type
|
|
|
|
*
|
|
|
|
* Currently supports only IPv6 literal address as specified in IETF RFC 3513
|
|
|
|
*
|
2015-09-16 13:10:19 -06:00
|
|
|
* Once draft-ietf-ipv6-scoping-arch-00.txt becomes an RFC, support will be
|
2006-11-26 11:13:41 -07:00
|
|
|
* added for the scoped address format it specifies.
|
|
|
|
*/
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/* Maximum length of an IPv6 address string - increase when adding support
|
|
|
|
* for scoped address qualifiers. Includes room for trailing NUL byte.
|
2006-11-26 11:13:41 -07:00
|
|
|
*/
|
|
|
|
#define SI_IPv6_MAXLEN INET6_ADDRSTRLEN
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
siIPv6AddrMatch(int family, void *addr, int len,
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *siAddr, int siAddrlen, ClientPtr client,
|
|
|
|
void *typePriv)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
struct in6_addr addr6;
|
|
|
|
char addrbuf[SI_IPv6_MAXLEN];
|
|
|
|
|
|
|
|
if ((family != FamilyInternet6) || (len != sizeof(addr6)))
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
memcpy(addrbuf, siAddr, siAddrlen);
|
|
|
|
addrbuf[siAddrlen] = '\0';
|
|
|
|
|
|
|
|
if (inet_pton(AF_INET6, addrbuf, &addr6) != 1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
perror("inet_pton");
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(addr, &addr6, len) == 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
siIPv6CheckAddr(const char *addrString, int length, void *typePriv)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* Minimum length is 3 (smallest legal address is "::1") */
|
|
|
|
if (length < 3) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Address is too short! */
|
|
|
|
len = -1;
|
|
|
|
}
|
|
|
|
else if (length >= SI_IPv6_MAXLEN) {
|
|
|
|
/* Address is too long! */
|
|
|
|
len = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Assume inet_pton is sufficient validation */
|
|
|
|
struct in6_addr addr6;
|
|
|
|
char addrbuf[SI_IPv6_MAXLEN];
|
|
|
|
|
|
|
|
memcpy(addrbuf, addrString, length);
|
|
|
|
addrbuf[length] = '\0';
|
|
|
|
|
|
|
|
if (inet_pton(AF_INET6, addrbuf, &addr6) != 1) {
|
|
|
|
perror("inet_pton");
|
|
|
|
len = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = length;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* IPv6 */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#if !defined(NO_LOCAL_CLIENT_CRED)
|
|
|
|
/***
|
|
|
|
* "localuser" & "localgroup" server interpreted types
|
|
|
|
*
|
|
|
|
* Allows local connections from a given local user or group
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
|
|
|
|
#define LOCAL_USER 1
|
|
|
|
#define LOCAL_GROUP 2
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int credType;
|
|
|
|
} siLocalCredPrivRec, *siLocalCredPrivPtr;
|
|
|
|
|
|
|
|
static siLocalCredPrivRec siLocalUserPriv = { LOCAL_USER };
|
|
|
|
static siLocalCredPrivRec siLocalGroupPriv = { LOCAL_GROUP };
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
siLocalCredGetId(const char *addr, int len, siLocalCredPrivPtr lcPriv, int *id)
|
|
|
|
{
|
|
|
|
Bool parsedOK = FALSE;
|
2010-12-05 08:36:02 -07:00
|
|
|
char *addrbuf = malloc(len + 1);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (addrbuf == NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(addrbuf, addr, len);
|
|
|
|
addrbuf[len] = '\0';
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (addr[0] == '#') { /* numeric id */
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
*id = strtol(addrbuf + 1, &cp, 0);
|
|
|
|
if ((errno == 0) && (cp != (addrbuf + 1))) {
|
|
|
|
parsedOK = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* non-numeric name */
|
|
|
|
if (lcPriv->credType == LOCAL_USER) {
|
|
|
|
struct passwd *pw = getpwnam(addrbuf);
|
|
|
|
|
|
|
|
if (pw != NULL) {
|
|
|
|
*id = (int) pw->pw_uid;
|
|
|
|
parsedOK = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* group */
|
|
|
|
struct group *gr = getgrnam(addrbuf);
|
|
|
|
|
|
|
|
if (gr != NULL) {
|
|
|
|
*id = (int) gr->gr_gid;
|
|
|
|
parsedOK = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(addrbuf);
|
2006-11-26 11:13:41 -07:00
|
|
|
return parsedOK;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
2014-09-27 11:52:59 -06:00
|
|
|
siLocalCredAddrMatch(int family, void *addr, int len,
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *siAddr, int siAddrlen, ClientPtr client,
|
|
|
|
void *typePriv)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2008-11-02 08:26:08 -07:00
|
|
|
int siAddrId;
|
|
|
|
LocalClientCredRec *lcc;
|
2006-11-26 11:13:41 -07:00
|
|
|
siLocalCredPrivPtr lcPriv = (siLocalCredPrivPtr) typePriv;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (GetLocalClientCreds(client, &lcc) == -1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#ifdef HAVE_GETZONEID /* Ensure process is in the same zone */
|
2008-11-02 08:26:08 -07:00
|
|
|
if ((lcc->fieldsSet & LCC_ZID_SET) && (lcc->zoneid != getzoneid())) {
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (siLocalCredGetId(siAddr, siAddrlen, lcPriv, &siAddrId) == FALSE) {
|
2012-06-10 07:21:05 -06:00
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lcPriv->credType == LOCAL_USER) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if ((lcc->fieldsSet & LCC_UID_SET) && (lcc->euid == siAddrId)) {
|
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((lcc->fieldsSet & LCC_GID_SET) && (lcc->egid == siAddrId)) {
|
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (lcc->pSuppGids != NULL) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < lcc->nSuppGids; i++) {
|
|
|
|
if (lcc->pSuppGids[i] == siAddrId) {
|
|
|
|
FreeLocalClientCreds(lcc);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2008-11-02 08:26:08 -07:00
|
|
|
FreeLocalClientCreds(lcc);
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
siLocalCredCheckAddr(const char *addrString, int length, void *typePriv)
|
|
|
|
{
|
|
|
|
int len = length;
|
|
|
|
int id;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (siLocalCredGetId(addrString, length,
|
|
|
|
(siLocalCredPrivPtr) typePriv, &id) == FALSE) {
|
|
|
|
len = -1;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* localuser */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
siTypesInitialize(void)
|
|
|
|
{
|
|
|
|
siTypeAdd("hostname", siHostnameAddrMatch, siHostnameCheckAddr, NULL);
|
|
|
|
#if defined(IPv6) && defined(AF_INET6)
|
|
|
|
siTypeAdd("ipv6", siIPv6AddrMatch, siIPv6CheckAddr, NULL);
|
|
|
|
#endif
|
|
|
|
#if !defined(NO_LOCAL_CLIENT_CRED)
|
2012-06-10 07:21:05 -06:00
|
|
|
siTypeAdd("localuser", siLocalCredAddrMatch, siLocalCredCheckAddr,
|
|
|
|
&siLocalUserPriv);
|
|
|
|
siTypeAdd("localgroup", siLocalCredAddrMatch, siLocalCredCheckAddr,
|
|
|
|
&siLocalGroupPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
}
|