示例#1
0
int send_trans_tok(BIO *bio, struct trans_tok *t)
{
	char *buf = calloc(BUFSIZ, sizeof(char));
	XDR xdr;
	xdrmem_create(&xdr, buf, BUFSIZ, XDR_ENCODE);
	if(!xdr_trans_tok(&xdr, t)) {
		perror("could not encode trans tok\n");
		return -1;
	}
	int result = send_char_buf(bio, buf, BUFSIZ);
	xdr_destroy(&xdr);
	free(buf);
	return result;
}
示例#2
0
int virNetMessageEncodePayloadEmpty(virNetMessagePtr msg)
{
    XDR xdr;
    unsigned int msglen;

    /* Re-encode the length word. */
    VIR_DEBUG("Encode length as %zu", msg->bufferOffset);
    xdrmem_create(&xdr, msg->buffer, VIR_NET_MESSAGE_HEADER_XDR_LEN, XDR_ENCODE);
    msglen = msg->bufferOffset;
    if (!xdr_u_int(&xdr, &msglen)) {
        virReportError(VIR_ERR_RPC, "%s", _("Unable to encode message length"));
        goto error;
    }
    xdr_destroy(&xdr);

    msg->bufferLength = msg->bufferOffset;
    msg->bufferOffset = 0;
    return 0;

error:
    xdr_destroy(&xdr);
    return -1;
}
示例#3
0
文件: filesnarf.c 项目: IFGHou/dsniff
void
nfs2_reply(struct xid_map *xm, struct tuple4 *addr, u_char *buf, int len)
{
	XDR xdrs;
	struct diropres dres;
	struct readres rres;
	
	switch (xm->proc) {
		
	case NFSPROC_LOOKUP:
		xdrmem_create(&xdrs, buf, len, XDR_DECODE);
		memset(&dres, 0, sizeof(dres));
		
		if (xdr_diropres(&xdrs, &dres)) {
			if (dres.status == NFS_OK)
				fh_map_add((char *)xm->data,
					   dres.diropres_u.diropres.file.data,
					   NFS_FHSIZE);
		}
		xdr_destroy(&xdrs);
		break;
		
	case NFSPROC_READ:
		xdrmem_create(&xdrs, buf, len, XDR_DECODE);
		memset(&rres, 0, sizeof(rres));
		
		if (xdr_readres(&xdrs, &rres)) {
			if (rres.status == NFS_OK) {
				nfs_save(addr, (struct myreadargs *)xm->data,
					 rres.readres_u.reply.data.data_val,
					 rres.readres_u.reply.data.data_len);
			}
		}
		xdr_destroy(&xdrs);
		break;
	}
}
示例#4
0
static int
rclose(int sock, struct LSFHeader *hdr)
{
    static char fname[] = "rclose()";
    int reqfd;
    char buf[LSRCP_MSGSIZE];
    XDR xdrs;

    xdrmem_create(&xdrs, buf, LSRCP_MSGSIZE, XDR_DECODE);
    if (readDecodeMsg_(sock, buf, hdr, SOCK_READ_FIX, &xdrs, (char *) &reqfd,
                       xdr_int, NULL)) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "readDecodeMsg_");
        xdr_destroy(&xdrs);
        closesocket(sock);
        return -1;
    }
    xdr_destroy(&xdrs);

    if (close(reqfd) == -1) {
        if (lsSendMsg_(sock, -errnoEncode_(errno), 0, NULL, buf,
                       sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL)
            < 0) {
            ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
            close(sock);
        }
        return 0;
    }

    if (lsSendMsg_(sock, 0, 0, NULL, buf,
                   sizeof(struct LSFHeader), NULL, SOCK_WRITE_FIX, NULL) < 0) {
        ls_errlog(stderr, I18N_FUNC_FAIL_MM, fname, "lsSendMsg_");
        close(sock);
        return -1;
    }

    return 0;
}
示例#5
0
void
sped_populate_npools(spe_npool *p)
{
    struct nfsspe_args	args;
    XDR			xdrs;
    char			*buf;
    size_t			len = 0;

    args.nsa_opcode = SPE_OP_NPOOL_POPULATE;
    args.nsa_did = 0xdead4ead;

    if (!p)
        return;

    args.nsa_xdr_len =
        xdr_sizeof((xdrproc_t)xdr_spe_npool, (void *)p);

    args.nsa_xdr = calloc(args.nsa_xdr_len, sizeof (char));
    if (!args.nsa_xdr)
        return;

    xdrmem_create(&xdrs, args.nsa_xdr, args.nsa_xdr_len, XDR_ENCODE);
    if (!xdr_spe_npool(&xdrs, p)) {
        free(args.nsa_xdr);
        xdr_destroy(&xdrs);
        return;
    }

#if 0
    sped_xdr_dump(args.nsa_xdr, args.nsa_xdr_len);
#endif

    (void) _nfssys(NFS_SPE, &args);

    free(args.nsa_xdr);
    xdr_destroy(&xdrs);
}
示例#6
0
文件: rmtcall.c 项目: KunX/nfs-utils
static notify_list *
recv_rply(u_long *portp)
{
	char			msgbuf[NSM_MAXMSGSIZE];
	ssize_t			msglen;
	notify_list		*lp = NULL;
	XDR			xdr;
	struct sockaddr_in	sin;
	socklen_t		alen = (socklen_t)sizeof(sin);
	uint32_t		xid;

	memset(msgbuf, 0, sizeof(msgbuf));
	msglen = recvfrom(sockfd, msgbuf, sizeof(msgbuf), 0,
				(struct sockaddr *)(char *)&sin, &alen);
	if (msglen == (ssize_t)-1) {
		xlog_warn("%s: recvfrom failed: %m", __func__);
		return NULL;
	}

	memset(&xdr, 0, sizeof(xdr));
	xdrmem_create(&xdr, msgbuf, (unsigned int)msglen, XDR_DECODE);
	xid = nsm_parse_reply(&xdr);
	if (xid == 0)
		goto done;
	if (sin.sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
		struct in_addr addr = sin.sin_addr;
		char buf[INET_ADDRSTRLEN];

		xlog_warn("%s: Unrecognized reply from %s", __func__,
				inet_ntop(AF_INET, &addr, buf,
						(socklen_t)sizeof(buf)));
		goto done;
	}

	for (lp = notify; lp != NULL; lp = lp->next) {
		/* LH - this was a bug... it should have been checking
		 * the xid from the response message from the client,
		 * not the static, internal xid */
		if (lp->xid != xid)
			continue;
		if (lp->port == 0)
			*portp = nsm_recv_getport(&xdr);
		break;
	}

done:
	xdr_destroy(&xdr);
	return lp;
}
/*
 * @msg: the outgoing message, whose header to encode
 *
 * Encodes the length word and header of the message, setting the
 * message offset ready to encode the payload. Leaves space
 * for the length field later. Upon return bufferLength will
 * refer to the total available space for message, while
 * bufferOffset will refer to current space used by header
 *
 * returns 0 if successfully encoded, -1 upon fatal error
 */
gboolean gvir_sandbox_rpcpacket_encode_header(GVirSandboxRPCPacket *msg,
                                              GError **error)
{
    XDR xdr;
    gboolean ret = FALSE;
    unsigned int len = 0;

    msg->bufferLength = sizeof(msg->buffer);
    msg->bufferOffset = 0;

    /* Format the header. */
    xdrmem_create(&xdr,
                  msg->buffer,
                  msg->bufferLength,
                  XDR_ENCODE);

    /* The real value is filled in shortly */
    if (!xdr_u_int(&xdr, &len)) {
        g_set_error(error, 0, 0,
                    "%s", "Unable to encode message length");
        goto cleanup;
    }

    if (!xdr_GVirSandboxProtocolHeader(&xdr, &msg->header)) {
        g_set_error(error, 0, 0,
                    "%s", "Unable to encode message header");
        goto cleanup;
    }

    len = xdr_getpos(&xdr);
    xdr_setpos(&xdr, 0);

    /* Fill in current length - may be re-written later
     * if a payload is added
     */
    if (!xdr_u_int(&xdr, &len)) {
        g_set_error(error, 0, 0,
                    "%s", "Unable to re-encode message length");
        goto cleanup;
    }

    msg->bufferOffset += len;

    ret = TRUE;

cleanup:
    xdr_destroy(&xdr);
    return ret;
}
示例#8
0
/*
 * @msg: the outgoing message, whose header to encode
 *
 * Encodes the length word and header of the message, setting the
 * message offset ready to encode the payload. Leaves space
 * for the length field later. Upon return bufferLength will
 * refer to the total available space for message, while
 * bufferOffset will refer to current space used by header
 *
 * returns 0 if successfully encoded, -1 upon fatal error
 */
int virNetMessageEncodeHeader(virNetMessagePtr msg)
{
    XDR xdr;
    int ret = -1;
    unsigned int len = 0;

    msg->bufferLength = VIR_NET_MESSAGE_MAX + VIR_NET_MESSAGE_LEN_MAX;
    if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) {
        virReportOOMError();
        return ret;
    }
    msg->bufferOffset = 0;

    /* Format the header. */
    xdrmem_create(&xdr,
                  msg->buffer,
                  msg->bufferLength,
                  XDR_ENCODE);

    /* The real value is filled in shortly */
    if (!xdr_u_int(&xdr, &len)) {
        virReportError(VIR_ERR_RPC, "%s", _("Unable to encode message length"));
        goto cleanup;
    }

    if (!xdr_virNetMessageHeader(&xdr, &msg->header)) {
        virReportError(VIR_ERR_RPC, "%s", _("Unable to encode message header"));
        goto cleanup;
    }

    len = xdr_getpos(&xdr);
    xdr_setpos(&xdr, 0);

    /* Fill in current length - may be re-written later
     * if a payload is added
     */
    if (!xdr_u_int(&xdr, &len)) {
        virReportError(VIR_ERR_RPC, "%s", _("Unable to re-encode message length"));
        goto cleanup;
    }

    msg->bufferOffset += len;

    ret = 0;

cleanup:
    xdr_destroy(&xdr);
    return ret;
}
示例#9
0
文件: writeinput_xdr.c 项目: kouui/rh
void writeInput(void)
{
  const char routineName[] = "writeInput";

  bool_t  result=TRUE, PRD_angle_dep, XRD, big_endian;
  FILE   *fp_out;
  XDR     xdrs;

  if (!strcmp(INPUT_DOT_OUT, "none")) return;

  if ((fp_out = fopen(INPUT_DOT_OUT, "w")) == NULL) {
    sprintf(messageStr, "Unable to open output file %s",
	    INPUT_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
    return;
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  PRD_angle_dep = (input.PRD_angle_dep != PRD_ANGLE_INDEP  &&  atmos.NPRDactive > 0);
  XRD           = (input.XRD  &&  atmos.NPRDactive > 0);

  /* --- Write various input parameters to file --     -------------- */      

  result &= xdr_bool(&xdrs, &input.magneto_optical);
  result &= xdr_bool(&xdrs, &PRD_angle_dep);
  result &= xdr_bool(&xdrs, &XRD);

  result &= xdr_enum(&xdrs, (enum_t *) &input.startJ);
  result &= xdr_enum(&xdrs, (enum_t *) &input.StokesMode);

  result &= xdr_double(&xdrs, &input.metallicity);

  result &= xdr_bool(&xdrs, &input.backgr_pol);

  /* --- Write Endianness of compute architecture so that J can be
         read properly in the analysis --              -------------- */

  big_endian = is_big_endian();
  result &= xdr_bool(&xdrs, &big_endian);


  if (!result) {
    sprintf(messageStr, "Unable to write proper amount to output file %s",
	    INPUT_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
  }
  xdr_destroy(&xdrs);
  fclose(fp_out);
}
gboolean gvir_sandbox_rpcpacket_encode_payload_empty(GVirSandboxRPCPacket *msg,
                                                     GError **error)
{
    XDR xdr;
    unsigned int msglen;

    /* Re-encode the length word. */
    xdrmem_create(&xdr, msg->buffer, GVIR_SANDBOX_PROTOCOL_LEN_MAX, XDR_ENCODE);
    msglen = msg->bufferOffset;
    if (!xdr_u_int(&xdr, &msglen)) {
        g_set_error(error, 0, 0,
                    "%s", "Unable to encode message length");
        goto error;
    }
    xdr_destroy(&xdr);

    msg->bufferLength = msg->bufferOffset;
    msg->bufferOffset = 0;
    return TRUE;

error:
    xdr_destroy(&xdr);
    return FALSE;
}
gboolean gvir_sandbox_rpcpacket_encode_payload_raw(GVirSandboxRPCPacket *msg,
                                                   const char *data,
                                                   gsize len,
                                                   GError **error)
{
    XDR xdr;
    unsigned int msglen;

    if ((msg->bufferLength - msg->bufferOffset) < len) {
        g_set_error(error, 0, 0,
                    "Raw data too long to send (%zu bytes needed, %zu bytes available)",
                    len, (msg->bufferLength - msg->bufferOffset));
        return FALSE;
    }

    memcpy(msg->buffer + msg->bufferOffset, data, len);
    msg->bufferOffset += len;

    /* Re-encode the length word. */
    xdrmem_create(&xdr, msg->buffer, GVIR_SANDBOX_PROTOCOL_LEN_MAX, XDR_ENCODE);
    msglen = msg->bufferOffset;
    if (!xdr_u_int(&xdr, &msglen)) {
        g_set_error(error, 0, 0,
                    "%s", "Unable to encode message length");
        goto error;
    }
    xdr_destroy(&xdr);

    msg->bufferLength = msg->bufferOffset;
    msg->bufferOffset = 0;
    return TRUE;

error:
    xdr_destroy(&xdr);
    return FALSE;
}
示例#12
0
static int
send_chunk (const guestfs_chunk *chunk)
{
  const size_t buf_len = GUESTFS_MAX_CHUNK_SIZE + 48;
  CLEANUP_FREE char *buf = NULL;
  char lenbuf[4];
  XDR xdr;
  uint32_t len;

  buf = malloc (buf_len);
  if (buf == NULL) {
    perror ("malloc");
    return -1;
  }

  xdrmem_create (&xdr, buf, buf_len, XDR_ENCODE);
  if (!xdr_guestfs_chunk (&xdr, (guestfs_chunk *) chunk)) {
    fprintf (stderr, "guestfsd: send_chunk: failed to encode chunk\n");
    xdr_destroy (&xdr);
    return -1;
  }

  len = xdr_getpos (&xdr);
  xdr_destroy (&xdr);

  xdrmem_create (&xdr, lenbuf, 4, XDR_ENCODE);
  xdr_u_int (&xdr, &len);
  xdr_destroy (&xdr);

  const int err = (xwrite (sock, lenbuf, 4) == 0
                   && xwrite (sock, buf, len) == 0 ? 0 : -1);
  if (err)
    error (EXIT_FAILURE, 0, "send_chunk: write failed");

  return err;
}
示例#13
0
void
do_sbdDebug(XDR * xdrs, int chfd, struct LSFHeader * reqHdr)
{
    static char       fname[] = "do_sbdDebug()";
    struct debugReq    debugReq;
    char               reply_buf[MSGSIZE / 8];
    XDR                xdrs2;
    sbdReplyType       reply;
    struct LSFHeader   replyHdr;

    if (!xdr_debugReq(xdrs, &debugReq, reqHdr)) {
        reply = LSBE_XDR;
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_debugReq");
    }
    else
        reply = ctrlSbdDebug(&debugReq);
    xdrmem_create(&xdrs2, reply_buf, MSGSIZE / 8, XDR_ENCODE);
    initLSFHeader_(&replyHdr);
    replyHdr.opCode = reply;
    if (!xdr_encodeMsg(&xdrs2, (char *) 0, &replyHdr, 0, 0, NULL)) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_encodeMsg");
        xdr_destroy(&xdrs2);
        return;
    }

    if (chanWrite_(chfd, reply_buf, XDR_GETPOS(&xdrs2)) <= 0) {
        ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5833,
                                         "%s: Sending  reply to master failed : %m"), /* catgets 5833 */
                  fname);
        xdr_destroy(&xdrs2);
        return;
    }
    xdr_destroy(&xdrs2);
    return;

}
示例#14
0
int 
rgetpidCompletionHandler_(struct lsRequest *request)
{
    struct resPid pidReply;
    XDR xdrs;
    int rc;

    
    rc = resRC2LSErr_(request->rc);
    if (rc != 0)
	return(-1);

    xdrmem_create(&xdrs, request->replyBuf, sizeof(struct resPid), XDR_DECODE);
    if (! xdr_resGetpid(&xdrs, &pidReply, NULL)) {
	lserrno = LSE_BAD_XDR;
	xdr_destroy(&xdrs);
	return(-1);
    }
    
    *((int *)request->extra) = pidReply.pid;
    xdr_destroy(&xdrs);
    return(0);

} 
示例#15
0
文件: nis_file.c 项目: jengelh/libnsl
static bool_t
write_nis_obj (const char *name, const void *obj, iofct_t writefct)
{
  FILE *out = fopen (name, "wce");
  if (out == NULL)
    return FALSE;

  XDR xdrs;
  xdrstdio_create (&xdrs, out, XDR_ENCODE);
  bool_t status = writefct (&xdrs, (void *) obj);
  xdr_destroy (&xdrs);
  fclose (out);

  return status;
}
示例#16
0
/*
 * Decode an XDR buffer into a door header structure.
 */
int
smb_doorhdr_decode(smb_doorhdr_t *hdr, uint8_t *buf, uint32_t buflen)
{
	XDR xdrs;
	int rc = 0;

	bzero(hdr, sizeof (smb_doorhdr_t));
	xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_DECODE);

	if (!smb_doorhdr_xdr(&xdrs, hdr))
		rc = -1;

	xdr_destroy(&xdrs);
	return (rc);
}
示例#17
0
int virNetMessageDecodeLength(virNetMessagePtr msg)
{
    XDR xdr;
    unsigned int len;
    int ret = -1;

    xdrmem_create(&xdr, msg->buffer,
                  msg->bufferLength, XDR_DECODE);
    if (!xdr_u_int(&xdr, &len)) {
        virReportError(VIR_ERR_RPC, "%s", _("Unable to decode message length"));
        goto cleanup;
    }
    msg->bufferOffset = xdr_getpos(&xdr);

    if (len < VIR_NET_MESSAGE_LEN_MAX) {
        virReportError(VIR_ERR_RPC,
                       _("packet %d bytes received from server too small, want %d"),
                       len, VIR_NET_MESSAGE_LEN_MAX);
        goto cleanup;
    }

    /* Length includes length word - adjust to real length to read. */
    len -= VIR_NET_MESSAGE_LEN_MAX;

    if (len > VIR_NET_MESSAGE_MAX) {
        virReportError(VIR_ERR_RPC,
                       _("packet %d bytes received from server too large, want %d"),
                       len, VIR_NET_MESSAGE_MAX);
        goto cleanup;
    }

    /* Extend our declared buffer length and carry
       on reading the header + payload */
    msg->bufferLength += len;
    if (VIR_REALLOC_N(msg->buffer, msg->bufferLength) < 0) {
        virReportOOMError();
        goto cleanup;
    }

    VIR_DEBUG("Got length, now need %zu total (%u more)",
              msg->bufferLength, len);

    ret = 0;

cleanup:
    xdr_destroy(&xdr);
    return ret;
}
示例#18
0
void
ltspfs_getattr (int sockfd, XDR *in)
{
  XDR         out;
  char        path[PATH_MAX];
  char 	      output[LTSP_MAXBUF];
  int         i;
  struct stat stbuf;

  if (get_fn(sockfd, in, path)) {
    if (debug)
      info ("get_fn failed\n");
    eacces(sockfd);
    return;
  }

  if (lstat (path, &stbuf) == -1) {
    status_return(sockfd, FAIL);
    return;
  }

  xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
  i = 0;
  xdr_int(&out, &i);	 			/* First, the dummy length */
  xdr_int(&out, &i);				/* Then the 0 status return */
  xdr_u_longlong_t(&out, &(stbuf.st_dev));	/* device */
  xdr_u_longlong_t(&out, &(stbuf.st_ino));	/* inode */
  xdr_u_int(&out, &(stbuf.st_mode));		/* protection */
  xdr_u_int(&out, &(stbuf.st_nlink));		/* number of hard links */
  xdr_u_int(&out, &(stbuf.st_uid));		/* user ID of owner */
  xdr_u_int(&out, &(stbuf.st_gid));		/* group ID of owner */
  xdr_u_longlong_t(&out, &(stbuf.st_rdev));	/* device type */
  xdr_longlong_t(&out, &(stbuf.st_size));	/* total size, in bytes */
  xdr_long(&out, &(stbuf.st_blksize));		/* blocksize for fs I/O */
  xdr_longlong_t(&out, &(stbuf.st_blocks));	/* number of blocks allocated */
  xdr_long(&out, &(stbuf.st_atime));		/* time of last access */
  xdr_long(&out, &(stbuf.st_mtime));		/* time of last modification */
  xdr_long(&out, &(stbuf.st_ctime));		/* time of last status change */
  i = xdr_getpos(&out);				/* Get our position */
  xdr_setpos(&out, 0);				/* Rewind to the beginning */
  xdr_int(&out, &i);				/* Rewrite with proper length */
  xdr_destroy(&out);

  if (debug)
    info("returning OK");

  writen(sockfd, output, i);
}
示例#19
0
int sodero_deserialize_UDP_report_v1(char *buffer, int numbytes, int *start_pos,
		const int num_max_elements, TSoderoUDPReportMsg *stored_data) {
	XDR xdr_handle;
	int result, size, num_element;
	TSoderoUDPReportMsg incoming_data;

	xdrmem_create(&xdr_handle, buffer, SEND_RECV_BUFFER_SIZE, XDR_DECODE);

	int curr_pos, prev_pos;
	prev_pos = *start_pos;
	curr_pos = prev_pos;
	num_element = 0;

	for (; curr_pos < numbytes;) {

		// printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");

		xdr_setpos(&xdr_handle, curr_pos);
		memset(&incoming_data, 0, sizeof(TSoderoUDPReportMsg));
		// result = xdr_TSoderoUDPReport(& xdr_handle, &incoming_data);
		result = xdr_TSoderoUDPReportMsg(&xdr_handle,
				&stored_data[num_element]);

		if (result != TRUE) {
			// error
			printf("Decoding error\n");
			return 0;
		}

		size = xdr_getpos(&xdr_handle);
		// printf("Decode %d bytes of encoded data\n", size - curr_pos);

		curr_pos = size;
		num_element++;

		if (num_element == num_max_elements) {
//          printf("Reach max report data elements\n");
//          printf("-------------------------------------------------------\n\n");
			break;
		}
		// printf("-------------------------------------------------------\n\n");
	}

	*start_pos = curr_pos;

	xdr_destroy(&xdr_handle);
	return num_element;
}
示例#20
0
文件: tsk.c 项目: noxdafox/libguestfs
/* Extract the information from the entry, serialize and send it out.
 * Return 0 on success, -1 on error.
 */
static int
send_dirent_info (TSK_FS_FILE *fsfile, const char *path)
{
  XDR xdr;
  int ret = 0;
  size_t len = 0;
  struct guestfs_int_tsk_dirent dirent;
  CLEANUP_FREE char *buf = NULL, *fname = NULL;

  /* Set dirent fields */
  memset (&dirent, 0, sizeof dirent);

  /* Build the full relative path of the entry */
  ret = asprintf (&fname, "%s%s", path, fsfile->name->name);
  if (ret < 0) {
    perror ("asprintf");
    return -1;
  }

  dirent.tsk_inode = fsfile->name->meta_addr;
  dirent.tsk_type = file_type (fsfile);
  dirent.tsk_name = fname;
  dirent.tsk_flags = file_flags (fsfile);

  file_metadata (fsfile->meta, &dirent);

  /* Serialize tsk_dirent struct. */
  buf = malloc (GUESTFS_MAX_CHUNK_SIZE);
  if (buf == NULL) {
    perror ("malloc");
    return -1;
  }

  xdrmem_create (&xdr, buf, GUESTFS_MAX_CHUNK_SIZE, XDR_ENCODE);

  ret = xdr_guestfs_int_tsk_dirent (&xdr, &dirent);
  if (ret == 0) {
    perror ("xdr_guestfs_int_tsk_dirent");
    return -1;
  }

  len = xdr_getpos (&xdr);

  xdr_destroy (&xdr);

  /* Send serialised tsk_dirent out. */
  return send_file_write (buf, len);
}
示例#21
0
void
ltspfs_readdir (int sockfd, XDR *in)
{
  XDR  out;
  char path[PATH_MAX];
  char output[LTSP_MAXBUF];
  DIR  *dp;
  char *nameptr;
  struct dirent *de;
  int  i;

  if (get_fn(sockfd, in, path)) {		/* Get the dir name */ 
    eacces(sockfd);
    return;
  }

  dp = opendir (path);

  if (dp == NULL) {
    status_return(sockfd, FAIL);		/* opendir failed */
    return;
  }

  while ((de = readdir (dp)) != NULL) {
    xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE);
    i = 0;
    xdr_int(&out, &i);	 			/* First, the dummy length */
    i = LTSP_STATUS_CONT;
    xdr_int(&out, &i);				/* Then the 2 status return */
    xdr_u_longlong_t(&out, &(de->d_ino));	/* Inode */
    xdr_u_char(&out, &(de->d_type));		/* type */
    nameptr = de->d_name;
    xdr_string(&out, &nameptr, PATH_MAX);	/* filename */
    i = xdr_getpos(&out);			/* Get our position */
    xdr_setpos(&out, 0);			/* Rewind to the beginning */
    xdr_int(&out, &i);				/* Rewrite with proper length */
    xdr_destroy(&out);

    if (debug)
      info("returning %s", de->d_name);

    writen(sockfd, output, i);
  }

  closedir (dp);

  status_return(sockfd, OK);
}
示例#22
0
文件: gmxfio.c 项目: yhalcyon/Gromacs
void gmx_fio_rewind(t_fileio* fio)
{
    gmx_fio_lock(fio);

    if (fio->xdr)
    {
        xdr_destroy(fio->xdr);
        frewind(fio->fp);
        xdrstdio_create(fio->xdr, fio->fp, fio->xdrmode);
    }
    else
    {
        frewind(fio->fp);
    }
    gmx_fio_unlock(fio);
}
示例#23
0
//serialise a message_client and send it over bio
int send_c_message(BIO *bio, struct message_client* m)
{
	//printf("Preparing to send message to server:\n");
	//message_print_c(m);
	char *buf = calloc(BUFSIZ, sizeof(char));
	XDR xdr;
	xdrmem_create(&xdr, buf, BUFSIZ, XDR_ENCODE);
	if(!xdr_message_client(&xdr, m)) {
		perror("could not encode message\n");
		return -1;
	}
	int result = send_char_buf(bio, buf, BUFSIZ);
	xdr_destroy(&xdr);
	free(buf);
	return result;
}
示例#24
0
文件: loop_d.c 项目: Facj/Update_sw
int save_data(void *data){
  
  container_2 *old_data;
  old_data=(container_2 *)data;
  //printf("Before serialization: %s\n",old_data->name);
  XDR xdrs;
  //Serialization
  FILE *fp;
  fp=fopen(ser_process_var,"w");
  xdrstdio_create(&xdrs,fp, XDR_ENCODE);
  if(!xdr_container(&xdrs,old_data)) {printf("Serialization error\n"); return 1;}
  //else printf("Data saved\n"); 
  xdr_destroy (&xdrs);
  fclose (fp);
  return 0;
}
示例#25
0
void mcfioC_CloseDirect(int jstr)
/*
** Close a direct access stream, Standard I/O or Memory Mapped
**
*/
{
   int i;
   mcfStream *str;
   nTuDDL *ddl;
      
   str =  McfStreamPtrList[jstr];
   if (str->row == MCFIO_WRITE) {
       /*
       **  Flush the event header, and the last table header. 
       */
       if (str->status == MCFIO_RUNNING) { 
         str->table->numevts++;
         str->ehead->evtnum++;
         if (mcfioC_WrtEvt(str, FLUSH) == FALSE) return;
         str->table->nextLocator = -2;
         str->table->numevts--; /* Decrement, the table is incomplete at 
         				this point */
         if (mcfioC_Wrttable(str, FLUSH) == FALSE) return;
         if (mcfioC_Wrtfhead(str, FLUSH) == FALSE) return;
       }
     }
     xdr_destroy(str->xdr);
     if (str->dos == MCFIO_DIRECT) { 
         fclose(str->filePtr);
     } else {
         /*
         ** Memory mapped I/O, one has to unmapped.. 
         */
         munmap((caddr_t) str->fileAddr, str->fileLen);
         close(str->fileDescr);
     }
     /*
     ** One must declare the Ntuples obsolete for this stream. 
     ** Do not release the memory, just flag these Ntuple with an obsolete 
     ** stream
     */
     for (i=0; i<NumOfNTuples; i++) {
         ddl = mcf_GetNTuByPtrID((i+1));
         if ((ddl != NULL) && (ddl->streamId == (jstr+1)))
               ddl->streamId = -1;
    }
}
示例#26
0
/*
 * Encode an smb_netfileinfo_t into a buffer.
 */
int
smb_netfileinfo_encode(smb_netfileinfo_t *info, uint8_t *buf,
    uint32_t buflen, uint_t *nbytes)
{
	XDR xdrs;
	int rc = 0;

	xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_ENCODE);

	if (!smb_netfileinfo_xdr(&xdrs, info))
		rc = -1;

	if (nbytes != NULL)
		*nbytes = xdr_getpos(&xdrs);
	xdr_destroy(&xdrs);
	return (rc);
}
示例#27
0
/**
 * Receive a chunk of file data.
 *
 * Returns C<-1> = error, C<0> = EOF, C<E<gt>0> = more data
 */
static ssize_t
receive_file_data (guestfs_h *g, void **buf_r)
{
  int r;
  CLEANUP_FREE void *buf = NULL;
  uint32_t len;
  XDR xdr;
  guestfs_chunk chunk;

  r = guestfs_int_recv_from_daemon (g, &len, &buf);
  if (r == -1)
    return -1;

  if (len == GUESTFS_LAUNCH_FLAG || len == GUESTFS_CANCEL_FLAG) {
    error (g, _("receive_file_data: unexpected flag received when reading file chunks"));
    return -1;
  }

  memset (&chunk, 0, sizeof chunk);

  xdrmem_create (&xdr, buf, len, XDR_DECODE);
  if (!xdr_guestfs_chunk (&xdr, &chunk)) {
    error (g, _("failed to parse file chunk"));
    return -1;
  }
  xdr_destroy (&xdr);

  if (chunk.cancel) {
    if (g->user_cancel)
      guestfs_int_error_errno (g, EINTR, _("operation cancelled by user"));
    else
      error (g, _("file receive cancelled by daemon"));
    free (chunk.data.data_val);
    return -1;
  }

  if (chunk.data.data_len == 0) { /* end of transfer */
    free (chunk.data.data_val);
    return 0;
  }

  if (buf_r) *buf_r = chunk.data.data_val;
  else free (chunk.data.data_val); /* else caller frees */

  return chunk.data.data_len;
}
示例#28
0
文件: testNfs.c 项目: mnv104/xdrTests
int main()
{
   XDR xdr;
   char buffer[512];
   FSINFO3args args;
   FSINFO3res  res;
   memset(&args, 0, sizeof args);
   memset(&res, 0, sizeof res);
   char rootHandle[28];
   args.fsroot.data.data_val = (char*) rootHandle;
   args.fsroot.data.data_len = sizeof(rootHandle);
   xdrmem_create(&xdr, buffer, sizeof(buffer), XDR_ENCODE);
   xdr_FSINFO3args(&xdr, &args);
   printf("%d\n", xdr_getpos(&xdr));
   xdr_destroy(&xdr);
   return 0;
}
示例#29
0
文件: cmds.c 项目: jeffpc/nx01
static bool send_response(XDR *xdr, int fd, int err)
{
	struct rpc_header_res cmd;

	xdr_destroy(xdr);
	xdrfd_create(xdr, fd, XDR_ENCODE);

	cmd.err = errno_to_nerr(err);

	if (!xdr_rpc_header_res(xdr, &cmd))
		return false; /* failed to send */

	if (cmd.err != NERR_SUCCESS)
		return true; /* RPC failed */

	return true; /* all good */
}
示例#30
0
/*
 * Decode an XDR buffer into an smb_netconnectinfo_t.
 */
int
smb_netconnectinfo_decode(smb_netconnectinfo_t *info, uint8_t *buf,
    uint32_t buflen, uint_t *nbytes)
{
	XDR xdrs;
	int rc = 0;

	xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_DECODE);

	bzero(info, sizeof (smb_netconnectinfo_t));
	if (!smb_netconnectinfo_xdr(&xdrs, info))
		rc = -1;

	if (nbytes != NULL)
		*nbytes = xdr_getpos(&xdrs);
	xdr_destroy(&xdrs);
	return (rc);
}