-bool prs_string_alloc(const char *name, prs_struct *ps, int depth, const char **str)
-{
- size_t len;
- char *tmp_str;
-
- if (UNMARSHALLING(ps)) {
- len = strlen(&ps->data_p[ps->data_offset]);
- } else {
- len = strlen(*str);
- }
-
- tmp_str = PRS_ALLOC_MEM(ps, char, len+1);
-
- if (tmp_str == NULL) {
- return False;
- }
-
- if (MARSHALLING(ps)) {
- strncpy(tmp_str, *str, len);
- }
-
- if (!prs_string(name, ps, depth, tmp_str, len+1)) {
- return False;
- }
-
- *str = tmp_str;
- return True;
-}
-
-/*******************************************************************
- prs_uint16 wrapper. Call this and it sets up a pointer to where the
- uint16 should be stored, or gets the size if reading.
- ********************************************************************/
-
-bool prs_uint16_pre(const char *name, prs_struct *ps, int depth, uint16 *data16, uint32 *offset)
-{
- *offset = ps->data_offset;
- if (UNMARSHALLING(ps)) {
- /* reading. */
- return prs_uint16(name, ps, depth, data16);
- } else {
- char *q = prs_mem_get(ps, sizeof(uint16));
- if(q ==NULL)
- return False;
- ps->data_offset += sizeof(uint16);
- }
- return True;
-}
-
-/*******************************************************************
- prs_uint16 wrapper. call this and it retrospectively stores the size.
- does nothing on reading, as that is already handled by ...._pre()
- ********************************************************************/
-
-bool prs_uint16_post(const char *name, prs_struct *ps, int depth, uint16 *data16,
- uint32 ptr_uint16, uint32 start_offset)
-{
- if (MARSHALLING(ps)) {
- /*
- * Writing - temporarily move the offset pointer.
- */
- uint16 data_size = ps->data_offset - start_offset;
- uint32 old_offset = ps->data_offset;
-
- ps->data_offset = ptr_uint16;
- if(!prs_uint16(name, ps, depth, &data_size)) {
- ps->data_offset = old_offset;
- return False;
- }
- ps->data_offset = old_offset;
- } else {
- ps->data_offset = start_offset + (uint32)(*data16);
- }
- return True;
-}
-
-/*******************************************************************
- prs_uint32 wrapper. Call this and it sets up a pointer to where the
- uint32 should be stored, or gets the size if reading.
- ********************************************************************/
-
-bool prs_uint32_pre(const char *name, prs_struct *ps, int depth, uint32 *data32, uint32 *offset)
-{
- *offset = ps->data_offset;
- if (UNMARSHALLING(ps) && (data32 != NULL)) {
- /* reading. */
- return prs_uint32(name, ps, depth, data32);
- } else {
- ps->data_offset += sizeof(uint32);
- }
- return True;
-}
-
-/*******************************************************************
- prs_uint32 wrapper. call this and it retrospectively stores the size.
- does nothing on reading, as that is already handled by ...._pre()
- ********************************************************************/
-
-bool prs_uint32_post(const char *name, prs_struct *ps, int depth, uint32 *data32,
- uint32 ptr_uint32, uint32 data_size)
-{
- if (MARSHALLING(ps)) {
- /*
- * Writing - temporarily move the offset pointer.
- */
- uint32 old_offset = ps->data_offset;
- ps->data_offset = ptr_uint32;
- if(!prs_uint32(name, ps, depth, &data_size)) {
- ps->data_offset = old_offset;
- return False;
- }
- ps->data_offset = old_offset;
- }
- return True;
-}
-
-/* useful function to store a structure in rpc wire format */
-int tdb_prs_store(TDB_CONTEXT *tdb, TDB_DATA kbuf, prs_struct *ps)
-{
- TDB_DATA dbuf;
- dbuf.dptr = (uint8 *)ps->data_p;
- dbuf.dsize = prs_offset(ps);
- return tdb_trans_store(tdb, kbuf, dbuf, TDB_REPLACE);
-}
-
-/* useful function to fetch a structure into rpc wire format */
-int tdb_prs_fetch(TDB_CONTEXT *tdb, TDB_DATA kbuf, prs_struct *ps, TALLOC_CTX *mem_ctx)
-{
- TDB_DATA dbuf;
-
- prs_init_empty(ps, mem_ctx, UNMARSHALL);
-
- dbuf = tdb_fetch(tdb, kbuf);
- if (!dbuf.dptr)
- return -1;
-
- prs_give_memory(ps, (char *)dbuf.dptr, dbuf.dsize, True);
-
- return 0;
-}
-
-/*******************************************************************
- hash a stream.
- ********************************************************************/
-
-bool prs_hash1(prs_struct *ps, uint32 offset, int len)
-{
- char *q;
-
- q = ps->data_p;
- q = &q[offset];
-
-#ifdef DEBUG_PASSWORD
- DEBUG(100, ("prs_hash1\n"));
- dump_data(100, (uint8 *)ps->sess_key, 16);
- dump_data(100, (uint8 *)q, len);
-#endif
- arcfour_crypt((uchar *) q, (const unsigned char *)ps->sess_key, len);
-
-#ifdef DEBUG_PASSWORD
- dump_data(100, (uint8 *)q, len);
-#endif
-
- return True;
-}
-