Blame AuGetAddr.c

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