Blame AuGetAddr.c

Packit 56e0ee
/*
Packit 56e0ee
Packit 56e0ee
Copyright 1988, 1998  The Open Group
Packit 56e0ee
Packit 56e0ee
Permission to use, copy, modify, distribute, and sell this software and its
Packit 56e0ee
documentation for any purpose is hereby granted without fee, provided that
Packit 56e0ee
the above copyright notice appear in all copies and that both that
Packit 56e0ee
copyright notice and this permission notice appear in supporting
Packit 56e0ee
documentation.
Packit 56e0ee
Packit 56e0ee
The above copyright notice and this permission notice shall be included in
Packit 56e0ee
all copies or substantial portions of the Software.
Packit 56e0ee
Packit 56e0ee
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit 56e0ee
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit 56e0ee
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit 56e0ee
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit 56e0ee
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 56e0ee
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit 56e0ee
Packit 56e0ee
Except as contained in this notice, the name of The Open Group shall not be
Packit 56e0ee
used in advertising or otherwise to promote the sale, use or other dealings
Packit 56e0ee
in this Software without prior written authorization from The Open Group.
Packit 56e0ee
Packit 56e0ee
*/
Packit 56e0ee
Packit 56e0ee
#ifdef HAVE_CONFIG_H
Packit 56e0ee
#include <config.h>
Packit 56e0ee
#endif
Packit 56e0ee
#include <X11/Xauth.h>
Packit 56e0ee
#include <X11/Xos.h>
Packit 56e0ee
Packit 56e0ee
#define binaryEqual(a, b, len) (memcmp(a, b, len) == 0)
Packit 56e0ee
Packit 56e0ee
Xauth *
Packit 56e0ee
XauGetAuthByAddr (
Packit 56e0ee
#if NeedWidePrototypes
Packit 56e0ee
unsigned int	family,
Packit 56e0ee
unsigned int	address_length,
Packit 56e0ee
#else
Packit 56e0ee
unsigned short	family,
Packit 56e0ee
unsigned short	address_length,
Packit 56e0ee
#endif
Packit 56e0ee
_Xconst char*	address,
Packit 56e0ee
#if NeedWidePrototypes
Packit 56e0ee
unsigned int	number_length,
Packit 56e0ee
#else
Packit 56e0ee
unsigned short	number_length,
Packit 56e0ee
#endif
Packit 56e0ee
_Xconst char*	number,
Packit 56e0ee
#if NeedWidePrototypes
Packit 56e0ee
unsigned int	name_length,
Packit 56e0ee
#else
Packit 56e0ee
unsigned short	name_length,
Packit 56e0ee
#endif
Packit 56e0ee
_Xconst char*	name)
Packit 56e0ee
{
Packit 56e0ee
    FILE    *auth_file;
Packit 56e0ee
    char    *auth_name;
Packit 56e0ee
    Xauth   *entry;
Packit 56e0ee
Packit 56e0ee
    auth_name = XauFileName ();
Packit 56e0ee
    if (!auth_name)
Packit 56e0ee
	return NULL;
Packit 56e0ee
    if (access (auth_name, R_OK) != 0)		/* checks REAL id */
Packit 56e0ee
	return NULL;
Packit 56e0ee
    auth_file = fopen (auth_name, "rb");
Packit 56e0ee
    if (!auth_file)
Packit 56e0ee
	return NULL;
Packit 56e0ee
    for (;;) {
Packit 56e0ee
	entry = XauReadAuth (auth_file);
Packit 56e0ee
	if (!entry)
Packit 56e0ee
	    break;
Packit 56e0ee
	/*
Packit 56e0ee
	 * Match when:
Packit 56e0ee
	 *   either family or entry->family are FamilyWild or
Packit 56e0ee
	 *    family and entry->family are the same and
Packit 56e0ee
	 *     address and entry->address are the same
Packit 56e0ee
	 *  and
Packit 56e0ee
	 *   either number or entry->number are empty or
Packit 56e0ee
	 *    number and entry->number are the same
Packit 56e0ee
	 *  and
Packit 56e0ee
	 *   either name or entry->name are empty or
Packit 56e0ee
	 *    name and entry->name are the same
Packit 56e0ee
	 */
Packit 56e0ee
Packit 56e0ee
	if ((family == FamilyWild || entry->family == FamilyWild ||
Packit 56e0ee
	     (entry->family == family &&
Packit 56e0ee
	      address_length == entry->address_length &&
Packit 56e0ee
	      binaryEqual (entry->address, address, address_length))) &&
Packit 56e0ee
	    (number_length == 0 || entry->number_length == 0 ||
Packit 56e0ee
	     (number_length == entry->number_length &&
Packit 56e0ee
	      binaryEqual (entry->number, number, number_length))) &&
Packit 56e0ee
	    (name_length == 0 || entry->name_length == 0 ||
Packit 56e0ee
	     (entry->name_length == name_length &&
Packit 56e0ee
	      binaryEqual (entry->name, name, name_length))))
Packit 56e0ee
	    break;
Packit 56e0ee
	XauDisposeAuth (entry);
Packit 56e0ee
    }
Packit 56e0ee
    (void) fclose (auth_file);
Packit 56e0ee
    return entry;
Packit 56e0ee
}