From 724c6fa337bb535e1b97d0452c2489f58339a3bf Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 27 Mar 2007 11:15:59 +0000 Subject: [PATCH] r21987: split tdb_prs_*() functions in version which take a keystr and a TDB_DATA key metze --- source/lib/sharesec.c | 4 ++-- source/printing/nt_printing.c | 6 +++--- source/rpc_parse/parse_prs.c | 26 +++++++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/source/lib/sharesec.c b/source/lib/sharesec.c index 7a6a4255590..c4704dfc125 100644 --- a/source/lib/sharesec.c +++ b/source/lib/sharesec.c @@ -125,7 +125,7 @@ SEC_DESC *get_share_security( TALLOC_CTX *ctx, const char *servicename, slprintf(key, sizeof(key)-1, "SECDESC/%s", servicename); - if (tdb_prs_fetch(share_tdb, key, &ps, ctx)!=0 || + if (tdb_prs_fetch_bystring(share_tdb, key, &ps, ctx)!=0 || !sec_io_desc("get_share_security", &psd, &ps, 1)) { DEBUG(4, ("get_share_security: using default secdesc for %s\n", @@ -167,7 +167,7 @@ BOOL set_share_security(const char *share_name, SEC_DESC *psd) slprintf(key, sizeof(key)-1, "SECDESC/%s", share_name); - if (tdb_prs_store(share_tdb, key, &ps)==0) { + if (tdb_prs_store_bystring(share_tdb, key, &ps)==0) { ret = True; DEBUG(5,("set_share_security: stored secdesc for %s\n", share_name )); } else { diff --git a/source/printing/nt_printing.c b/source/printing/nt_printing.c index 78ba9862148..967ea883a93 100644 --- a/source/printing/nt_printing.c +++ b/source/printing/nt_printing.c @@ -5159,7 +5159,7 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr) key = make_printers_secdesc_tdbkey( sharename ); - if (tdb_prs_store(tdb_printers, key, &ps)==0) { + if (tdb_prs_store_bystring(tdb_printers, key, &ps)==0) { status = WERR_OK; } else { DEBUG(1,("Failed to store secdesc for %s\n", sharename)); @@ -5280,7 +5280,7 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s key = make_printers_secdesc_tdbkey( sharename ); - if (tdb_prs_fetch(tdb_printers, key, &ps, ctx)!=0 || + if (tdb_prs_fetch_bystring(tdb_printers, key, &ps, ctx)!=0 || !sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) { prs_mem_free(&ps); @@ -5297,7 +5297,7 @@ BOOL nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **s sizeof(SEC_DESC_BUF), ctx, MARSHALL); if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) { - tdb_prs_store(tdb_printers, key, &ps); + tdb_prs_store_bystring(tdb_printers, key, &ps); } prs_mem_free(&ps); diff --git a/source/rpc_parse/parse_prs.c b/source/rpc_parse/parse_prs.c index 54bbe3adf6c..ca46807932d 100644 --- a/source/rpc_parse/parse_prs.c +++ b/source/rpc_parse/parse_prs.c @@ -1454,22 +1454,24 @@ BOOL prs_uint32_post(const char *name, prs_struct *ps, int depth, uint32 *data32 } /* useful function to store a structure in rpc wire format */ -int tdb_prs_store(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps) +int tdb_prs_store(TDB_CONTEXT *tdb, TDB_DATA kbuf, prs_struct *ps) { - TDB_DATA kbuf, dbuf; - kbuf.dptr = keystr; - kbuf.dsize = strlen(keystr)+1; + TDB_DATA dbuf; dbuf.dptr = 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, char *keystr, prs_struct *ps, TALLOC_CTX *mem_ctx) +int tdb_prs_store_bystring(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps) { - TDB_DATA kbuf, dbuf; - kbuf.dptr = keystr; - kbuf.dsize = strlen(keystr)+1; + TDB_DATA kbuf = string_term_tdb_data(keystr); + return tdb_prs_store(tdb, kbuf, ps); +} + +/* 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(ps, 0, mem_ctx, UNMARSHALL); @@ -1482,6 +1484,12 @@ int tdb_prs_fetch(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps, TALLOC_CTX *me return 0; } +int tdb_prs_fetch_bystring(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps, TALLOC_CTX *mem_ctx) +{ + TDB_DATA kbuf = string_term_tdb_data(keystr); + return tdb_prs_fetch(tdb, kbuf, ps, mem_ctx); +} + /******************************************************************* hash a stream. ********************************************************************/