s3-rpc_client: add winreg_get_printserver_secdesc.
authorGünther Deschner <gd@samba.org>
Fri, 9 Sep 2016 22:06:27 +0000 (00:06 +0200)
committerGünther Deschner <gd@samba.org>
Thu, 22 Sep 2016 10:29:27 +0000 (12:29 +0200)
Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/rpc_client/cli_winreg_spoolss.c
source3/rpc_client/cli_winreg_spoolss.h

index f1df336c895b5f38e6f1f30fed41f44d09e39e14..cbb22a3e2eddb1cd09728520a77186abaaa0a8b0 100644 (file)
@@ -1606,15 +1606,15 @@ done:
        return result;
 }
 
-WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
-                                 struct dcerpc_binding_handle *winreg_handle,
-                                 const char *sharename,
-                                 struct spoolss_security_descriptor **psecdesc)
+static WERROR winreg_get_secdesc(TALLOC_CTX *mem_ctx,
+                                struct dcerpc_binding_handle *winreg_handle,
+                                const char *path,
+                                const char *attribute,
+                                struct spoolss_security_descriptor **psecdesc)
 {
        struct spoolss_security_descriptor *secdesc;
        uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        struct policy_handle hive_hnd, key_hnd;
-       const char *path;
        TALLOC_CTX *tmp_ctx;
        NTSTATUS status;
        WERROR result;
@@ -1625,12 +1625,6 @@ WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
                return WERR_NOMEM;
        }
 
-       path = winreg_printer_data_keyname(tmp_ctx, sharename);
-       if (path == NULL) {
-               talloc_free(tmp_ctx);
-               return WERR_NOMEM;
-       }
-
        ZERO_STRUCT(hive_hnd);
        ZERO_STRUCT(key_hnd);
 
@@ -1652,7 +1646,7 @@ WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
        status = dcerpc_winreg_query_sd(tmp_ctx,
                                        winreg_handle,
                                        &key_hnd,
-                                       "Security",
+                                       attribute,
                                        &secdesc,
                                        &result);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1741,7 +1735,7 @@ create_default:
        status = dcerpc_winreg_set_sd(tmp_ctx,
                                          winreg_handle,
                                          &key_hnd,
-                                         "Security",
+                                         attribute,
                                          secdesc,
                                          &result);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1768,6 +1762,38 @@ done:
        return result;
 }
 
+WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
+                                 struct dcerpc_binding_handle *winreg_handle,
+                                 const char *sharename,
+                                 struct spoolss_security_descriptor **psecdesc)
+{
+       WERROR result;
+       char *path;
+
+       path = winreg_printer_data_keyname(mem_ctx, sharename);
+       if (path == NULL) {
+               return WERR_NOMEM;
+       }
+
+       result = winreg_get_secdesc(mem_ctx, winreg_handle,
+                                   path,
+                                   "Security",
+                                   psecdesc);
+       talloc_free(path);
+
+       return result;
+}
+
+WERROR winreg_get_printserver_secdesc(TALLOC_CTX *mem_ctx,
+                                     struct dcerpc_binding_handle *winreg_handle,
+                                     struct spoolss_security_descriptor **psecdesc)
+{
+       return winreg_get_secdesc(mem_ctx, winreg_handle,
+                                 TOP_LEVEL_CONTROL_KEY,
+                                 "ServerSecurityDescriptor",
+                                 psecdesc);
+}
+
 WERROR winreg_set_printer_secdesc(TALLOC_CTX *mem_ctx,
                                  struct dcerpc_binding_handle *winreg_handle,
                                  const char *sharename,
index aa4d98f681f8eeba4b7b482a325b788c623959b2..279e585855ae58332f121d30a8e63144fa73edc9 100644 (file)
@@ -145,6 +145,23 @@ WERROR winreg_get_printer_secdesc(TALLOC_CTX *mem_ctx,
                                  const char *sharename,
                                  struct spoolss_security_descriptor **psecdesc);
 
+/**
+ * @brief Get the security descriptor for a printserver.
+ *
+ * @param[in]  mem_ctx  The talloc memory context to use.
+ *
+ * @param[in]  b The dcerpc binding handle
+ *
+ * @param[out] psecdesc   A pointer to store the security descriptor.
+ *
+ * @return              On success WERR_OK, a corresponding DOS error is
+ *                      something went wrong.
+ */
+
+WERROR winreg_get_printserver_secdesc(TALLOC_CTX *mem_ctx,
+                                     struct dcerpc_binding_handle *winreg_handle,
+                                     struct spoolss_security_descriptor **psecdesc);
+
 /**
  * @brief Set the security descriptor for a printer.
  *