Blame AuRead.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 <stdlib.h>
Packit Service f89583
Packit Service f89583
static int
Packit Service f89583
read_short (unsigned short *shortp, FILE *file)
Packit Service f89583
{
Packit Service f89583
    unsigned char   file_short[2];
Packit Service f89583
Packit Service f89583
    if (fread ((char *) file_short, sizeof (file_short), 1, file) != 1)
Packit Service f89583
	return 0;
Packit Service f89583
    *shortp = file_short[0] * 256 + file_short[1];
Packit Service f89583
    return 1;
Packit Service f89583
}
Packit Service f89583
Packit Service f89583
static int
Packit Service f89583
read_counted_string (unsigned short *countp, char **stringp, FILE *file)
Packit Service f89583
{
Packit Service f89583
    unsigned short  len;
Packit Service f89583
    char	    *data;
Packit Service f89583
Packit Service f89583
    if (read_short (&len, file) == 0)
Packit Service f89583
	return 0;
Packit Service f89583
    if (len == 0) {
Packit Service f89583
	data = NULL;
Packit Service f89583
    } else {
Packit Service f89583
    	data = malloc ((unsigned) len);
Packit Service f89583
    	if (!data)
Packit Service f89583
	    return 0;
Packit Service f89583
	if (fread (data, sizeof (char), len, file) != len) {
Packit Service f89583
	    bzero (data, len);
Packit Service f89583
	    free (data);
Packit Service f89583
	    return 0;
Packit Service f89583
    	}
Packit Service f89583
    }
Packit Service f89583
    *stringp = data;
Packit Service f89583
    *countp = len;
Packit Service f89583
    return 1;
Packit Service f89583
}
Packit Service f89583
Packit Service f89583
Xauth *
Packit Service f89583
XauReadAuth (FILE *auth_file)
Packit Service f89583
{
Packit Service f89583
    Xauth   local;
Packit Service f89583
    Xauth   *ret;
Packit Service f89583
Packit Service f89583
    if (read_short (&local.family, auth_file) == 0)
Packit Service f89583
	return NULL;
Packit Service f89583
    if (read_counted_string (&local.address_length, &local.address, auth_file) == 0)
Packit Service f89583
	return NULL;
Packit Service f89583
    if (read_counted_string (&local.number_length, &local.number, auth_file) == 0) {
Packit Service f89583
	free (local.address);
Packit Service f89583
	return NULL;
Packit Service f89583
    }
Packit Service f89583
    if (read_counted_string (&local.name_length, &local.name, auth_file) == 0) {
Packit Service f89583
	free (local.address);
Packit Service f89583
	free (local.number);
Packit Service f89583
	return NULL;
Packit Service f89583
    }
Packit Service f89583
    if (read_counted_string (&local.data_length, &local.data, auth_file) == 0) {
Packit Service f89583
	free (local.address);
Packit Service f89583
	free (local.number);
Packit Service f89583
	free (local.name);
Packit Service f89583
	return NULL;
Packit Service f89583
    }
Packit Service f89583
    ret = (Xauth *) malloc (sizeof (Xauth));
Packit Service f89583
    if (!ret) {
Packit Service f89583
	free (local.address);
Packit Service f89583
	free (local.number);
Packit Service f89583
	free (local.name);
Packit Service f89583
	if (local.data) {
Packit Service f89583
	    bzero (local.data, local.data_length);
Packit Service f89583
	    free (local.data);
Packit Service f89583
	}
Packit Service f89583
	return NULL;
Packit Service f89583
    }
Packit Service f89583
    *ret = local;
Packit Service f89583
    return ret;
Packit Service f89583
}