summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2009-02-24 12:19:01 +0100
committerGünther Deschner <gd@samba.org>2009-02-24 12:41:21 +0100
commite1749a1f7815dae4f0721a62a0ea5d3a88aaf320 (patch)
tree6e48e8a7477c3f6cdf2a72b13d4aa51bce291f7f
parentf21ae452a008370a4846c8955ac1a8fe1a0acb3c (diff)
downloadsamba-e1749a1f7815dae4f0721a62a0ea5d3a88aaf320.tar.gz
samba-e1749a1f7815dae4f0721a62a0ea5d3a88aaf320.tar.bz2
samba-e1749a1f7815dae4f0721a62a0ea5d3a88aaf320.zip
s3-spoolss: use marshall/unmarshall_sec_desc_buf in nt_printing_setsec/getsec.
Guenther
-rw-r--r--source3/printing/nt_printing.c80
1 files changed, 35 insertions, 45 deletions
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index ad3a95826a..bbe8ebc2bc 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -5408,11 +5408,12 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
{
SEC_DESC_BUF *new_secdesc_ctr = NULL;
SEC_DESC_BUF *old_secdesc_ctr = NULL;
- prs_struct ps;
- bool prs_init_done = false;
TALLOC_CTX *mem_ctx = NULL;
TDB_DATA kbuf;
+ TDB_DATA dbuf;
+ DATA_BLOB blob;
WERROR status;
+ NTSTATUS nt_status;
mem_ctx = talloc_init("nt_printing_setsec");
if (mem_ctx == NULL)
@@ -5474,26 +5475,19 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
/* Store the security descriptor in a tdb */
- if (!prs_init(&ps,
- (uint32_t)ndr_size_security_descriptor(new_secdesc_ctr->sd,
- NULL, 0)
- + sizeof(SEC_DESC_BUF), mem_ctx, MARSHALL) ) {
- status = WERR_NOMEM;
- goto out;
- }
-
-
- prs_init_done = true;
-
- if (!sec_io_desc_buf("nt_printing_setsec", &new_secdesc_ctr,
- &ps, 1)) {
- status = WERR_BADFUNC;
+ nt_status = marshall_sec_desc_buf(mem_ctx, new_secdesc_ctr,
+ &blob.data, &blob.length);
+ if (!NT_STATUS_IS_OK(nt_status)) {
+ status = ntstatus_to_werror(nt_status);
goto out;
}
kbuf = make_printers_secdesc_tdbkey(mem_ctx, sharename );
- if (tdb_prs_store(tdb_printers, kbuf, &ps)==0) {
+ dbuf.dptr = (unsigned char *)blob.data;
+ dbuf.dsize = blob.length;
+
+ if (tdb_trans_store(tdb_printers, kbuf, dbuf, TDB_REPLACE)==0) {
status = WERR_OK;
} else {
DEBUG(1,("Failed to store secdesc for %s\n", sharename));
@@ -5501,12 +5495,10 @@ WERROR nt_printing_setsec(const char *sharename, SEC_DESC_BUF *secdesc_ctr)
}
/* Free malloc'ed memory */
+ talloc_free(blob.data);
out:
- if (prs_init_done) {
- prs_mem_free(&ps);
- }
if (mem_ctx)
talloc_destroy(mem_ctx);
return status;
@@ -5602,47 +5594,45 @@ static SEC_DESC_BUF *construct_default_printer_sdb(TALLOC_CTX *ctx)
bool nt_printing_getsec(TALLOC_CTX *ctx, const char *sharename, SEC_DESC_BUF **secdesc_ctr)
{
- prs_struct ps;
TDB_DATA kbuf;
+ TDB_DATA dbuf;
+ DATA_BLOB blob;
char *temp;
+ NTSTATUS status;
if (strlen(sharename) > 2 && (temp = strchr(sharename + 2, '\\'))) {
sharename = temp + 1;
}
- ZERO_STRUCT(ps);
-
/* Fetch security descriptor from tdb */
- kbuf = make_printers_secdesc_tdbkey(ctx, sharename );
-
- if (tdb_prs_fetch(tdb_printers, kbuf, &ps, ctx)!=0 ||
- !sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
-
- prs_mem_free(&ps);
-
- DEBUG(4,("using default secdesc for %s\n", sharename));
+ kbuf = make_printers_secdesc_tdbkey(ctx, sharename);
- if (!(*secdesc_ctr = construct_default_printer_sdb(ctx))) {
- return False;
- }
-
- /* Save default security descriptor for later */
+ dbuf = tdb_fetch(tdb_printers, kbuf);
+ if (dbuf.dptr) {
- if (!prs_init(&ps, (uint32_t)ndr_size_security_descriptor((*secdesc_ctr)->sd, NULL, 0) +
- sizeof(SEC_DESC_BUF), ctx, MARSHALL))
- return False;
+ status = unmarshall_sec_desc_buf(ctx, dbuf.dptr, dbuf.dsize,
+ secdesc_ctr);
+ SAFE_FREE(dbuf.dptr);
- if (sec_io_desc_buf("nt_printing_getsec", secdesc_ctr, &ps, 1)) {
- tdb_prs_store(tdb_printers, kbuf, &ps);
+ if (NT_STATUS_IS_OK(status)) {
+ return true;
}
+ }
- prs_mem_free(&ps);
-
- return True;
+ *secdesc_ctr = construct_default_printer_sdb(ctx);
+ if (!*secdesc_ctr) {
+ return false;
}
- prs_mem_free(&ps);
+ status = marshall_sec_desc_buf(ctx, *secdesc_ctr,
+ &blob.data, &blob.length);
+ if (NT_STATUS_IS_OK(status)) {
+ dbuf.dptr = (unsigned char *)blob.data;
+ dbuf.dsize = blob.length;
+ tdb_trans_store(tdb_printers, kbuf, dbuf, TDB_REPLACE);
+ talloc_free(blob.data);
+ }
/* If security descriptor is owned by S-1-1-0 and winbindd is up,
this security descriptor has been created when winbindd was