s3-lib: add marshall_sec_desc_buf and unmarshall_sec_desc_buf helpers.
authorGünther Deschner <gd@samba.org>
Tue, 24 Feb 2009 10:34:57 +0000 (11:34 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 24 Feb 2009 11:41:20 +0000 (12:41 +0100)
Guenther

source3/include/proto.h
source3/lib/secdesc.c

index 14241d5ce37091ed99bfc32981e3881a645e4376..3ca94b9192bfa479643d008c590ac2bbb16c69e7 100644 (file)
@@ -695,8 +695,13 @@ SEC_DESC *dup_sec_desc(TALLOC_CTX *ctx, const SEC_DESC *src);
 NTSTATUS marshall_sec_desc(TALLOC_CTX *mem_ctx,
                           struct security_descriptor *secdesc,
                           uint8 **data, size_t *len);
+NTSTATUS marshall_sec_desc_buf(TALLOC_CTX *mem_ctx,
+                              struct sec_desc_buf *secdesc_buf,
+                              uint8_t **data, size_t *len);
 NTSTATUS unmarshall_sec_desc(TALLOC_CTX *mem_ctx, uint8 *data, size_t len,
                             struct security_descriptor **psecdesc);
+NTSTATUS unmarshall_sec_desc_buf(TALLOC_CTX *mem_ctx, uint8_t *data, size_t len,
+                                struct sec_desc_buf **psecdesc_buf);
 SEC_DESC *make_standard_sec_desc(TALLOC_CTX *ctx, const DOM_SID *owner_sid, const DOM_SID *grp_sid,
                                 SEC_ACL *dacl, size_t *sd_size);
 SEC_DESC_BUF *make_sec_desc_buf(TALLOC_CTX *ctx, size_t len, SEC_DESC *sec_desc);
index 232bbca43c876d4b62766de73beef013bfb3fc64..a81c4ae82a2e3ba8150527af896ffa8e382d4ac9 100644 (file)
@@ -290,6 +290,32 @@ NTSTATUS marshall_sec_desc(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
+/*******************************************************************
+ Convert a secdesc_buf into a byte stream
+********************************************************************/
+
+NTSTATUS marshall_sec_desc_buf(TALLOC_CTX *mem_ctx,
+                              struct sec_desc_buf *secdesc_buf,
+                              uint8_t **data, size_t *len)
+{
+       DATA_BLOB blob;
+       enum ndr_err_code ndr_err;
+
+       ndr_err = ndr_push_struct_blob(
+               &blob, mem_ctx, NULL, secdesc_buf,
+               (ndr_push_flags_fn_t)ndr_push_sec_desc_buf);
+
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DEBUG(0, ("ndr_push_sec_desc_buf failed: %s\n",
+                         ndr_errstr(ndr_err)));
+               return ndr_map_error2ntstatus(ndr_err);;
+       }
+
+       *data = blob.data;
+       *len = blob.length;
+       return NT_STATUS_OK;
+}
+
 /*******************************************************************
  Parse a byte stream into a secdesc
 ********************************************************************/
@@ -326,6 +352,43 @@ NTSTATUS unmarshall_sec_desc(TALLOC_CTX *mem_ctx, uint8 *data, size_t len,
        return NT_STATUS_OK;
 }
 
+/*******************************************************************
+ Parse a byte stream into a sec_desc_buf
+********************************************************************/
+
+NTSTATUS unmarshall_sec_desc_buf(TALLOC_CTX *mem_ctx, uint8_t *data, size_t len,
+                                struct sec_desc_buf **psecdesc_buf)
+{
+       DATA_BLOB blob;
+       enum ndr_err_code ndr_err;
+       struct sec_desc_buf *result;
+
+       if ((data == NULL) || (len == 0)) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       result = TALLOC_ZERO_P(mem_ctx, struct sec_desc_buf);
+       if (result == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       blob = data_blob_const(data, len);
+
+       ndr_err = ndr_pull_struct_blob(
+               &blob, result, NULL, result,
+               (ndr_pull_flags_fn_t)ndr_pull_sec_desc_buf);
+
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DEBUG(0, ("ndr_pull_sec_desc_buf failed: %s\n",
+                         ndr_errstr(ndr_err)));
+               TALLOC_FREE(result);
+               return ndr_map_error2ntstatus(ndr_err);;
+       }
+
+       *psecdesc_buf = result;
+       return NT_STATUS_OK;
+}
+
 /*******************************************************************
  Creates a SEC_DESC structure with typical defaults.
 ********************************************************************/