/** * Send performance data to a file. * * Sends performance data to the current "send-to" file previously specified by * CBTF_SetSendToFile(). Any header generation and data encoding is performed * by the caller. Here the data is treated purely as a buffer of bytes to be * sent. * * @param size Size of the data to be sent (in bytes). * @param data Pointer to the data to be sent. * @return Integer "1" if succeeded or "0" if failed. * * @ingroup RuntimeAPI */ int CBTF_SendToFile(const unsigned size, const void* data) { unsigned encoded_size; char buffer[8]; /* Large enough to encode one 32-bit unsigned integer */ XDR xdrs; int fd; /* Access our thread-local storage */ #ifdef USE_EXPLICIT_TLS TLS* tls = CBTF_GetTLS(TLSKey); #else TLS* tls = &the_tls; #endif Assert(tls != NULL); /* Create an XDR stream using the encoding buffer */ xdrmem_create(&xdrs, buffer, sizeof(buffer), XDR_ENCODE); /* Encode the size of the data to be sent */ Assert(xdr_u_int(&xdrs, (void*)&size) == TRUE); /* Get the encoded size */ encoded_size = xdr_getpos(&xdrs); /* Close the XDR stream */ xdr_destroy(&xdrs); /* Open the file for writing */ Assert((fd = open(tls->path, O_WRONLY | O_APPEND)) >= 0); /* Write the size of the data to be sent */ Assert(write(fd, buffer, encoded_size) == encoded_size); /* Write the data */ Assert(write(fd, data, size) == size); /* fsync call taken out due to slow processing time reported at LLNL */ /* via Matt Legendre for a LLNL user. */ #if 0 /* Flush the data to disk. We could also test for fsyncdata * and use that as our fsync vi a #define. */ Assert(fsync(fd) == 0); #endif /* Close the file */ Assert(close(fd) == 0); /* Indicate success to the caller */ return 1; }
int make_rpc_packet(char *buf, int buflen, u_long proc, struct rpc_msg *mp, voidp arg, XDRPROC_T_TYPE arg_xdr, AUTH *auth) { XDR msg_xdr; int len; /* * Never cast pointers between different integer types, it breaks badly * on big-endian platforms if those types have different sizes. * * Cast to a local variable instead, and use that variable's address. */ enum_t local_proc = (enum_t) proc; xdrmem_create(&msg_xdr, buf, buflen, XDR_ENCODE); /* * Basic protocol header */ if (!xdr_callhdr(&msg_xdr, mp)) return -EIO; /* * Called procedure number */ if (!xdr_enum(&msg_xdr, &local_proc)) return -EIO; /* * Authorization */ if (!AUTH_MARSHALL(auth, &msg_xdr)) return -EIO; /* * Arguments */ if (!(*arg_xdr) (&msg_xdr, arg)) return -EIO; /* * Determine length */ len = xdr_getpos(&msg_xdr); /* * Throw away xdr */ xdr_destroy(&msg_xdr); return len; }
/* Counting records actually requires walking the xdr packet so it is not necessarily cheap*/ size_t ocrecordcount(OCstate* state, OCcontent* content) { int stat = OC_NOERR; size_t count; OCnode* node = content->node; XDR* xdrs; char tmp[BYTES_PER_XDR_UNIT]; OCASSERT((node != NULL)); OCASSERT((node->octype == OC_Sequence)); OCASSERT((content->mode == Recordmode)); /* If we are using memdata; then use that value */ if(content->memdata != NULL) { return content->memdata->count; } xdrs = content->tree->data.xdrs; OCASSERT((xdrs != NULL)); /* checkpoint the beginning of this instance*/ if(!content->xdrpos.valid) { content->xdrpos.offset = xdr_getpos(xdrs); content->xdrpos.valid = 1; } /* move to checkpoint position*/ if(!xdr_setpos(xdrs,content->xdrpos.offset)) return 0; for(count=0;;count++) { /* pick up the sequence record begin marker*/ /* extract the tag byte*/ if(!xdr_opaque(xdrs,tmp,sizeof(tmp))) return 0; if(tmp[0] == StartOfoclist) { /* skip instance*/ stat = ocskipinstance(content->node,xdrs); if(stat != OC_NOERR) return 0; } else if(tmp[0] == EndOfoclist) { break; /* done with the count*/ } else { oc_log(LOGERR,"missing/invalid begin/end record marker\n"); return 0; } } /* move back to checkpoint position*/ if(!xdr_setpos(xdrs,content->xdrpos.offset)) return 0; return count; }
void reply (xdrproc_t xdrp, char *ret) { XDR xdr; CLEANUP_FREE char *buf = NULL; char lenbuf[4]; struct guestfs_message_header hdr; uint32_t len; buf = malloc (GUESTFS_MESSAGE_MAX); if (!buf) error (EXIT_FAILURE, errno, "malloc"); xdrmem_create (&xdr, buf, GUESTFS_MESSAGE_MAX, XDR_ENCODE); memset (&hdr, 0, sizeof hdr); hdr.prog = GUESTFS_PROGRAM; hdr.vers = GUESTFS_PROTOCOL_VERSION; hdr.direction = GUESTFS_DIRECTION_REPLY; hdr.status = GUESTFS_STATUS_OK; hdr.proc = proc_nr; hdr.serial = serial; if (!xdr_guestfs_message_header (&xdr, &hdr)) error (EXIT_FAILURE, 0, "failed to encode reply header"); if (xdrp) { /* This can fail if the reply body is too large, for example * if it exceeds the maximum message size. In that case * we want to return an error message instead. (RHBZ#509597). */ if (!(*xdrp) (&xdr, ret)) { reply_with_error ("guestfsd: failed to encode reply body\n(maybe the reply exceeds the maximum message size in the protocol?)"); xdr_destroy (&xdr); return; } } len = xdr_getpos (&xdr); xdr_destroy (&xdr); xdrmem_create (&xdr, lenbuf, 4, XDR_ENCODE); xdr_u_int (&xdr, &len); xdr_destroy (&xdr); if (xwrite (sock, lenbuf, 4) == -1) error (EXIT_FAILURE, 0, "xwrite failed"); if (xwrite (sock, buf, (size_t) len) == -1) error (EXIT_FAILURE, 0, "xwrite failed"); }
/* * @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; }
/* * @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; }
static int request_meta_data (const char *host, const char *name) /* {{{ */ { Ganglia_metadata_msg msg; char buffer[BUFF_SIZE]; unsigned int buffer_size; XDR xdr; size_t i; memset (&msg, 0, sizeof (msg)); msg.id = gmetadata_request; msg.Ganglia_metadata_msg_u.grequest.metric_id.host = strdup (host); msg.Ganglia_metadata_msg_u.grequest.metric_id.name = strdup (name); if ((msg.Ganglia_metadata_msg_u.grequest.metric_id.host == NULL) || (msg.Ganglia_metadata_msg_u.grequest.metric_id.name == NULL)) { sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host); sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.name); return (-1); } memset (buffer, 0, sizeof (buffer)); xdrmem_create (&xdr, buffer, sizeof (buffer), XDR_ENCODE); if (!xdr_Ganglia_metadata_msg (&xdr, &msg)) { sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host); sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.name); return (-1); } buffer_size = xdr_getpos (&xdr); DEBUG ("gmond plugin: Requesting meta data for %s/%s.", host, name); pthread_mutex_lock (&mc_send_sockets_lock); for (i = 0; i < mc_send_sockets_num; i++) sendto (mc_send_sockets[i].fd, buffer, (size_t) buffer_size, /* flags = */ 0, (struct sockaddr *) &mc_send_sockets[i].addr, mc_send_sockets[i].addrlen); pthread_mutex_unlock (&mc_send_sockets_lock); sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.host); sfree (msg.Ganglia_metadata_msg_u.grequest.metric_id.name); return (0); } /* }}} int request_meta_data */
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); }
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; }
/* 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); }
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; }
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); }
static bool_t apply_buf(bool_t (*fn)(), caddr_t in, u_int size) { bool_t result; char out[BUFSIZ]; XDR xin, xout; xdrbuf_create(&xin, 0, XDR_ENCODE); /* Inline to force grow. */ if (!fn(&xin, in) || !xdr_inline(&xin, 2 * BUFSIZ)) { xdr_destroy(&xin); return FALSE; } xdrmem_create(&xout, xin.x_base, xdr_getpos(&xin), XDR_DECODE); result = fn(&xout, out) && 0 == memcmp(in, out, size); xdr_destroy(&xin); return result; }
/* * 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); }
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; }
/* * 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); }
static int gp_rpc_return_buffer(XDR *xdr_reply_ctx, char *reply_buffer, uint8_t **outbuf, size_t *outlen) { unsigned int length; uint8_t *buffer; length = xdr_getpos(xdr_reply_ctx); buffer = malloc(length); if (!buffer) { return ENOMEM; } memcpy(buffer, reply_buffer, length); *outbuf = buffer; *outlen = length; return 0; }
int make_rpc_packet(char *buf, int buflen, u_long proc, struct rpc_msg *mp, voidp arg, XDRPROC_T_TYPE arg_xdr, AUTH *auth) { XDR msg_xdr; int len; xdrmem_create(&msg_xdr, buf, buflen, XDR_ENCODE); /* * Basic protocol header */ if (!xdr_callhdr(&msg_xdr, mp)) return -EIO; /* * Called procedure number */ if (!xdr_enum(&msg_xdr, (enum_t *) & proc)) return -EIO; /* * Authorization */ if (!AUTH_MARSHALL(auth, &msg_xdr)) return -EIO; /* * Arguments */ if (!(*arg_xdr) (&msg_xdr, arg)) return -EIO; /* * Determine length */ len = xdr_getpos(&msg_xdr); /* * Throw away xdr */ xdr_destroy(&msg_xdr); return len; }
/* * Function: kdb_put_entry * * Purpose: Stores the osa_princ_ent_t and krb5_db_entry into to * database. * * Arguments: * * handle (r) the server_handle * kdb (r/w) the krb5_db_entry to store * adb (r) the osa_princ_db_ent to store * * Effects: * * The last modifier field of the kdb is set to the caller at now. * adb is encoded with xdr_osa_princ_ent_ret and stored in kbd as * KRB5_TL_KADM_DATA. kdb is then written to the database. */ krb5_error_code kdb_put_entry(kadm5_server_handle_t handle, krb5_db_entry *kdb, osa_princ_ent_rec *adb) { krb5_error_code ret; krb5_int32 now; XDR xdrs; krb5_tl_data tl_data; int one; ret = krb5_timeofday(handle->context, &now); if (ret) return(ret); ret = krb5_dbe_update_mod_princ_data(handle->context, kdb, now, handle->current_caller); if (ret) return(ret); xdralloc_create(&xdrs, XDR_ENCODE); if(! xdr_osa_princ_ent_rec(&xdrs, adb)) { xdr_destroy(&xdrs); return(KADM5_XDR_FAILURE); } tl_data.tl_data_type = KRB5_TL_KADM_DATA; tl_data.tl_data_length = xdr_getpos(&xdrs); /* Solaris Kerberos */ tl_data.tl_data_contents = (unsigned char *) xdralloc_getdata(&xdrs); ret = krb5_dbe_update_tl_data(handle->context, kdb, &tl_data); xdr_destroy(&xdrs); if (ret) return(ret); one = 1; ret = krb5_db_put_principal(handle->context, kdb, &one); if (ret) return(ret); return(0); }
/* * Function: kdb_put_entry * * Purpose: Stores the osa_princ_ent_t and krb5_db_entry into to * database. * * Arguments: * * handle (r) the server_handle * kdb (r/w) the krb5_db_entry to store * adb (r) the osa_princ_db_ent to store * * Effects: * * The last modifier field of the kdb is set to the caller at now. * adb is encoded with xdr_osa_princ_ent_ret and stored in kbd as * KRB5_TL_KADM_DATA. kdb is then written to the database. */ krb5_error_code kdb_put_entry(kadm5_server_handle_t handle, krb5_db_entry *kdb, osa_princ_ent_rec *adb) { krb5_error_code ret; krb5_int32 now; XDR xdrs; krb5_tl_data tl_data; ret = krb5_timeofday(handle->context, &now); if (ret) return(ret); ret = krb5_dbe_update_mod_princ_data(handle->context, kdb, now, handle->current_caller); if (ret) return(ret); xdralloc_create(&xdrs, XDR_ENCODE); if(! xdr_osa_princ_ent_rec(&xdrs, adb)) { xdr_destroy(&xdrs); return(KADM5_XDR_FAILURE); } tl_data.tl_data_type = KRB5_TL_KADM_DATA; tl_data.tl_data_length = xdr_getpos(&xdrs); tl_data.tl_data_contents = (krb5_octet *)xdralloc_getdata(&xdrs); ret = krb5_dbe_update_tl_data(handle->context, kdb, &tl_data); xdr_destroy(&xdrs); if (ret) return(ret); /* we are always updating TL data */ kdb->mask |= KADM5_TL_DATA; ret = krb5_db_put_principal(handle->context, kdb); if (ret) return(ret); return(0); }
gboolean gvir_sandbox_rpcpacket_decode_length(GVirSandboxRPCPacket *msg, GError **error) { XDR xdr; unsigned int len; gboolean ret = FALSE; xdrmem_create(&xdr, msg->buffer, msg->bufferLength, XDR_DECODE); if (!xdr_u_int(&xdr, &len)) { g_set_error(error, 0, 0, "%s", "Unable to decode message length"); goto cleanup; } msg->bufferOffset = xdr_getpos(&xdr); if (len < GVIR_SANDBOX_PROTOCOL_LEN_MAX) { g_set_error(error, 0, 0, "packet %u bytes received from server too small, want %u", len, GVIR_SANDBOX_PROTOCOL_LEN_MAX); goto cleanup; } /* Length includes length word - adjust to real length to read. */ len -= GVIR_SANDBOX_PROTOCOL_LEN_MAX; if (len > GVIR_SANDBOX_PROTOCOL_PACKET_MAX) { g_set_error(error, 0, 0, "packet %u bytes received from server too large, want %d", len, GVIR_SANDBOX_PROTOCOL_PACKET_MAX); goto cleanup; } /* Extend our declared buffer length and carry on reading the header + payload */ msg->bufferLength += len; ret = TRUE; cleanup: xdr_destroy(&xdr); return ret; }
int Rast3d_copy_from_xdr(int nofNum, void *dst) { int i; if (useXdr == RASTER3D_NO_XDR) { Rast3d_copy_values(xdrTmp, 0, type, dst, 0, dstType, nofNum); xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * Rast3d_extern_length(type)); return 1; } for (i = 0; i < nofNum; i++, dst = G_incr_void_ptr(dst, eltLength)) { if (Rast3d_is_xdr_null_num(xdrTmp, isFloat)) { Rast3d_set_null_value(dst, 1, dstType); if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) { Rast3d_error("Rast3d_copy_from_xdr: positioning xdr failed"); return 0; } } else { if (type == dstType) { if (xdrFun(xdrs, dst) < 0) { Rast3d_error("Rast3d_copy_from_xdr: reading xdr failed"); return 0; } } else { if (xdrFun(xdrs, tmp) < 0) { Rast3d_error("Rast3d_copy_from_xdr: reading xdr failed"); return 0; } if (type == FCELL_TYPE) *((double *)dst) = (double)*((float *)tmp); else *((float *)dst) = (float)*((double *)tmp); } } xdrTmp = G_incr_void_ptr(xdrTmp, externLength); } return 1; }
int Rast3d_copy_to_xdr(const void *src, int nofNum) { int i; if (useXdr == RASTER3D_NO_XDR) { Rast3d_copy_values(src, 0, srcType, xdrTmp, 0, type, nofNum); xdrTmp = G_incr_void_ptr(xdrTmp, nofNum * Rast3d_extern_length(type)); return 1; } for (i = 0; i < nofNum; i++, src = G_incr_void_ptr(src, eltLength)) { if (Rast3d_is_null_value_num(src, srcType)) { Rast3d_set_xdr_null_num(xdrTmp, isFloat); if (!xdr_setpos(xdrs, xdr_getpos(xdrs) + externLength)) { Rast3d_error("Rast3d_copy_to_xdr: positioning xdr failed"); return 0; } } else { if (type == srcType) { if (xdrFun(xdrs, src) < 0) { Rast3d_error("Rast3d_copy_to_xdr: writing xdr failed"); return 0; } } else { if (type == FCELL_TYPE) *((float *)tmp) = (float)*((double *)src); else *((double *)tmp) = (double)*((float *)src); if (xdrFun(xdrs, tmp) < 0) { Rast3d_error("Rast3d_copy_to_xdr: writing xdr failed"); return 0; } } } xdrTmp = G_incr_void_ptr(xdrTmp, externLength); } return 1; }
void notify_progress_no_ratelimit (uint64_t position, uint64_t total, const struct timeval *now_t) { XDR xdr; char buf[128]; uint32_t i; size_t len; guestfs_progress message; count_progress++; last_progress_t = *now_t; /* Send the header word. */ i = GUESTFS_PROGRESS_FLAG; xdrmem_create (&xdr, buf, 4, XDR_ENCODE); xdr_u_int (&xdr, &i); xdr_destroy (&xdr); if (xwrite (sock, buf, 4) == -1) { fprintf (stderr, "guestfsd: xwrite failed\n"); exit (EXIT_FAILURE); } message.proc = proc_nr; message.serial = serial; message.position = position; message.total = total; xdrmem_create (&xdr, buf, sizeof buf, XDR_ENCODE); if (!xdr_guestfs_progress (&xdr, &message)) { fprintf (stderr, "guestfsd: xdr_guestfs_progress: failed to encode message\n"); xdr_destroy (&xdr); return; } len = xdr_getpos (&xdr); xdr_destroy (&xdr); if (xwrite (sock, buf, len) == -1) { fprintf (stderr, "guestfsd: xwrite failed\n"); exit (EXIT_FAILURE); } }
void ltspfs_statfs (int sockfd, XDR *in) { XDR out; char path[PATH_MAX]; char output[LTSP_MAXBUF]; struct statfs stbuf; int i; if (get_fn(sockfd, in, path)) { /* Get the path */ eacces(sockfd); return; } if (statfs (path, &stbuf) == -1) { status_return(sockfd, FAIL); return; } xdrmem_create(&out, output, LTSP_MAXBUF, XDR_ENCODE); i = 0; xdr_int(&out, &i); /* dummy length */ i = LTSP_STATUS_OK; /* OK status */ xdr_int(&out, &i); xdr_int(&out, &stbuf.f_type); /* type of fs */ xdr_int(&out, &stbuf.f_bsize); /* optimal transfer block sz */ xdr_u_longlong_t(&out, &stbuf.f_blocks); /* total data blocks in fs */ xdr_u_longlong_t(&out, &stbuf.f_bfree); /* free blks in fs */ xdr_u_longlong_t(&out, &stbuf.f_bavail); /* free blks avail to non-su */ xdr_u_longlong_t(&out, &stbuf.f_files); /* total file nodes in fs */ xdr_u_longlong_t(&out, &stbuf.f_ffree); /* free file nodes in fs */ xdr_int(&out, &stbuf.f_namelen); /* max length of filenames */ i = xdr_getpos(&out); /* Get current position */ xdr_setpos(&out, 0); /* rewind to the beginning */ xdr_int(&out, &i); /* re-write proper length */ xdr_destroy(&out); /* Clean up the XDR structs */ if (debug) info("returning OK"); writen(sockfd, output, i); }
gboolean gvir_sandbox_rpcpacket_encode_payload_msg(GVirSandboxRPCPacket *msg, xdrproc_t filter, void *data, GError **error) { XDR xdr; unsigned int msglen; /* Serialise payload of the message. This assumes that * GVirSandboxRPCPacketEncodeHeader has already been run, so * just appends to that data */ xdrmem_create(&xdr, msg->buffer + msg->bufferOffset, msg->bufferLength - msg->bufferOffset, XDR_ENCODE); if (!(*filter)(&xdr, data)) { g_set_error(error, 0, 0, "%s", "Unable to encode message payload"); goto error; } /* Get the length stored in buffer. */ msg->bufferOffset += xdr_getpos(&xdr); xdr_destroy(&xdr); /* 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; }
krb5_error_code krb5_update_tl_kadm_data(krb5_context context, krb5_db_entry *entry, osa_princ_ent_rec *princ_entry) { XDR xdrs; krb5_tl_data tl_data; krb5_error_code retval; xdralloc_create(&xdrs, XDR_ENCODE); if (! ldap_xdr_osa_princ_ent_rec(&xdrs, princ_entry)) { xdr_destroy(&xdrs); return KADM5_XDR_FAILURE; } tl_data.tl_data_type = KRB5_TL_KADM_DATA; tl_data.tl_data_length = xdr_getpos(&xdrs); tl_data.tl_data_contents = (krb5_octet *)xdralloc_getdata(&xdrs); retval = krb5_dbe_update_tl_data(context, entry, &tl_data); xdr_destroy(&xdrs); return retval; }
int32_t msg_xdr_extdecode(xdrproc_t xdrproc, const struct msg *m, void *out, const void **extra) { size_t cl; uint32_t xl; XDR xdrs; xl = unpack_from_be32(&m->len) - sizeof(struct msg); if (xl > 0x7fffffff) return -EINVAL; xdrmem_create(&xdrs, (void*)&m->data, xl, XDR_DECODE); if (!xdrproc(&xdrs, out)) { xdr_destroy(&xdrs); return -EINVAL; } cl = xdr_getpos(&xdrs); xdr_destroy(&xdrs); *extra = ((char*)out) + cl; return xl - cl; }
/* * Function: marshall_new_creds * * Purpose: (pre-)serialize auth_msg and client_handle fields of * auth_gssapi_creds into auth->cred_buf * * Arguments: * * auth (r/w) the AUTH structure to modify * auth_msg (r) the auth_msg field to serialize * client_handle (r) the client_handle field to serialize, or * NULL * * Returns: TRUE if successful, FALSE if not * * Requires: auth must point to a valid GSS-API auth structure, auth_msg * must be TRUE or FALSE, client_handle must be a gss_buffer_t with a valid * value and length field or NULL. * * Effects: auth->ah_cred is set to the serialized auth_gssapi_creds * version 2 structure (stored in the cred_buf field of private data) * containing version, auth_msg and client_handle. * auth->ah_cred.oa_flavor is set to AUTH_GSSAPI. If cliend_handle is * NULL, it is treated as if it had a length of 0 and a value of NULL. * * Modifies: auth */ static bool_t marshall_new_creds( AUTH *auth, bool_t auth_msg, gss_buffer_t client_handle) { auth_gssapi_creds creds; XDR xdrs; PRINTF(("marshall_new_creds: starting\n")); creds.version = 2; creds.auth_msg = auth_msg; if (client_handle) GSS_COPY_BUFFER(creds.client_handle, *client_handle) else { creds.client_handle.length = 0; creds.client_handle.value = NULL; } xdrmem_create(&xdrs, (caddr_t) AUTH_PRIVATE(auth)->cred_buf, MAX_AUTH_BYTES, XDR_ENCODE); if (! xdr_authgssapi_creds(&xdrs, &creds)) { PRINTF(("marshall_new_creds: failed encoding auth_gssapi_creds\n")); XDR_DESTROY(&xdrs); return FALSE; } AUTH_PRIVATE(auth)->cred_len = xdr_getpos(&xdrs); XDR_DESTROY(&xdrs); PRINTF(("marshall_new_creds: auth_gssapi_creds is %d bytes\n", AUTH_PRIVATE(auth)->cred_len)); auth->ah_cred.oa_flavor = AUTH_GSSAPI; auth->ah_cred.oa_base = (char *) AUTH_PRIVATE(auth)->cred_buf; auth->ah_cred.oa_length = AUTH_PRIVATE(auth)->cred_len; PRINTF(("marshall_new_creds: succeeding\n")); return TRUE; }
void ltspfs_readlink (int sockfd, XDR *in) { XDR out; char path[PATH_MAX]; char buf[PATH_MAX]; /* linkname */ char output[LTSP_MAXBUF]; char *bufptr = buf; int i; /* readlink doesn't terminate with a null */ memset (buf, 0, PATH_MAX); if (get_fn(sockfd, in, path)) { /* Get the link source */ eacces(sockfd); return; } if (readlink (path, buf, PATH_MAX) == -1) { status_return(sockfd, FAIL); return; } if (!strncmp(buf, mountpoint, strlen(mountpoint))) /* adjust link target */ bufptr += strlen(mountpoint); 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_string(&out, &bufptr, PATH_MAX); /* Link target */ 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", output); writen(sockfd, output, i); }