Exemple #1
0
static bool  /* must manage buffers, fragments, and records */
xdr_inrec_getbytes(XDR *xdrs, char *addr, u_int len)
{
    RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
    int current;

    while (len > 0) {
        current = (int)rstrm->fbtbc;
        if (current == 0) {
            if (rstrm->last_frag)
                return (FALSE);
            if (! set_input_fragment(rstrm, INT_MAX))
                return (FALSE);
            continue;
        }
        current = (len < current) ? len : current;
        if (! get_input_bytes(rstrm, addr, current, INT_MAX))
            return (FALSE);
        addr += current;
        rstrm->fbtbc -= current;
        len -= current;
        /* handle checksumming if requested */
        if (xdrs->x_flags & XDR_FLAG_CKSUM) {
            if (rstrm->cklen) {
                if (! (rstrm->cksum)) {
                    if (rstrm->offset >= rstrm->cklen) {
                        compute_buffer_cksum(rstrm);
                    }
                }
            }
        }
    }
    return (TRUE);
}
Exemple #2
0
static bool_t  /* must manage buffers, fragments, and records */
xdrrec_getbytes(
	XDR *xdrs,
	void *baddr,
	uint_t len)
{
	char *addr = baddr;
	RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
	int current;

	while (len > 0) {
		current = rstrm->fbtbc;
		if (current == 0) {
			if (rstrm->last_frag)
				return (FALSE);
			if (! set_input_fragment(rstrm))
				return (FALSE);
			continue;
		}
		current = (len < current) ? len : current;
		if (! get_input_bytes(rstrm, addr, current))
			return (FALSE);
		addr += current; 
		rstrm->fbtbc -= current;
		len -= current;
	}
	return (TRUE);
}
static bool_t  /* next two bytes of the input stream are treated as a header */
set_input_fragment(RECSTREAM *rstrm)
{
	uint32_t header;

	if (rstrm->nonblock)
		return FALSE;
	if (! get_input_bytes(rstrm, (char *)(void *)&header,
	    (u_int)sizeof(header)))
		return (FALSE);
	header = ntohl(header);
	rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
	/*
	 * Sanity check. Try not to accept wildly incorrect
	 * record sizes. Unfortunately, the only record size
	 * we can positively identify as being 'wildly incorrect'
	 * is zero. Ridiculously large record sizes may look wrong,
	 * but we don't have any way to be certain that they aren't
	 * what the client actually intended to send us.
	 */
	if (header == 0)
		return(FALSE);
	rstrm->fbtbc = header & (~LAST_FRAG);
	return (TRUE);
}
Exemple #4
0
/*
 * This is just like the ops vector x_getbytes(), except that
 * instead of returning success or failure on getting a certain number
 * of bytes, it behaves much more like the read() system call against a
 * pipe -- it returns up to the number of bytes requested and a return of
 * zero indicates end-of-record.  A -1 means something very bad happened.
 */
XDR_API u_int /* must manage buffers, fragments, and records */
xdrrec_readbytes(XDR *xdrs, caddr_t addr, u_int l)
{
	/* LINTED pointer cast */
	RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
	int current, len;

	len = l;
	while (len > 0) {
		current = rstrm->fbtbc;
		if (current == 0) {
			if (rstrm->last_frag)
				return (l - len);
			if (!set_input_fragment(rstrm))
				return ((u_int)-1);
			continue;
		}
		current = (len < current) ? len : current;
		if (!get_input_bytes(rstrm, addr, current, FALSE))
			return ((u_int)-1);
		addr += current;
		rstrm->fbtbc -= current;
		len -= current;
	}
	return (l - len);
}
Exemple #5
0
static bool_t  /* must manage buffers, fragments, and records */
xdrrec_getbytes(
	XDR *xdrs,
	register char* addr,
	register unsigned len)
{
	register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
	register int current;

	while (len != 0) {
		current = (int)rstrm->fbtbc;
		if (current == 0) {
			if (rstrm->last_frag)
				return (FALSE);
			if (! set_input_fragment(rstrm))
				return (FALSE);
			continue;
		}
		current = (len < current) ? (int)len : current;
		if (! get_input_bytes(rstrm, addr, current))
			return (FALSE);
		addr += current; 
		rstrm->fbtbc -= current;
		len -= current;
	}
	return (TRUE);
}
Exemple #6
0
static bool_t  /* next two bytes of the input stream are treated as a header */
set_input_fragment(
	RECSTREAM *rstrm)
{
	uint32_t header;

	if (! get_input_bytes(rstrm, (void *)&header, sizeof(header)))
		return (FALSE);
	header = (int32_t)ntohl(header);
	rstrm->last_frag = ((header & (uint32_t)LAST_FRAG) == 0) ? FALSE : TRUE;
	rstrm->fbtbc = header & (~LAST_FRAG);
	return (TRUE);
}
Exemple #7
0
static bool_t  /* next 32-bits of the input stream are treated as a header */
set_input_fragment(
	register RECSTREAM *rstrm)
{
	uint32_t header;

	if (! get_input_bytes(rstrm, (char*)&header, sizeof(header)))
		return (FALSE);
	header = ntohl(header);
	rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
	rstrm->fbtbc = header & (~LAST_FRAG);
	return (TRUE);
}
Exemple #8
0
static bool_t  /* next four bytes of the input stream are treated as a header */
set_input_fragment(RECSTREAM *rstrm)
{
	uint32_t header;

	if (! get_input_bytes(rstrm, (caddr_t)&header, 0, sizeof (header)))
		return (FALSE);
	header = (uint32_t)ntohl(header);
	rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
	rstrm->fbtbc = header & (~LAST_FRAG);
#ifdef DEBUG
	printf("set_input_fragment: frag_len = %d, last frag = %s\n",
		rstrm->fbtbc, rstrm->last_frag ? "TRUE" : "FALSE");
#endif
	return (TRUE);
}
Exemple #9
0
/* next four bytes of the input stream are treated as a header */
static bool_t
set_input_fragment(RECSTREAM *rstrm)
{
	uint32_t header;

	if (rstrm->in_nonblock) {
		/*
		 * In the non-blocking case, the fragment headers should
		 * already have been consumed, so we should never get
		 * here. Might as well return failure right away.
		 */
		return (FALSE);
	}
	if (!get_input_bytes(rstrm, (caddr_t)&header, (int)sizeof (header),
							rstrm->last_frag))
		return (FALSE);
	header = (uint32_t)xdr_ntoh32(header);
	rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
	rstrm->fbtbc = header & (~LAST_FRAG);
	return (TRUE);
}
Exemple #10
0
static bool /* must manage buffers, fragments, and records */
xdrrec_getbytes(XDR *xdrs, char *addr, u_int len)
{
	RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
	int current;

	while (len > 0) {
		current = (int)rstrm->fbtbc;
		if (current == 0) {
			if (rstrm->last_frag)
				return (false);
			if (!set_input_fragment(rstrm))
				return (false);
			continue;
		}
		current = (len < current) ? len : current;
		if (!get_input_bytes(rstrm, addr, current))
			return (false);
		addr += current;
		rstrm->fbtbc -= current;
		len -= current;
	}
	return (true);
}