s3-rpc_cli: add winreg_add_core_driver()
authorGünther Deschner <gd@samba.org>
Mon, 31 Oct 2016 17:07:33 +0000 (18:07 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 9 May 2017 14:43:13 +0000 (16:43 +0200)
Guenther

Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/include/registry.h
source3/registry/reg_backend_db.c
source3/registry/reg_init_full.c
source3/rpc_client/cli_winreg_spoolss.c
source3/rpc_client/cli_winreg_spoolss.h

index 0de392f15d96a8fb1d6ca6f25c28f4f903f7b096..7d2aad9d64d817cd3645b19a015e62d626264999 100644 (file)
@@ -103,6 +103,7 @@ struct registry_key {
 #define KEY_TCPIP_PARAMS       "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
 #define KEY_PROD_OPTIONS       "HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions"
 #define KEY_PRINTING           "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print"
+#define KEY_PCC                        "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\PackageInstallation"
 #define KEY_PRINTING_2K                "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers"
 #define KEY_PRINTING_PORTS     "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ports"
 #define KEY_CURRENT_VERSION    "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
index 9d511b4f2ac51a0292fc4a16b15a7f83d9e85fa6..928572e8a5a1644e8e25581365058700b8bd05de 100644 (file)
@@ -121,6 +121,7 @@ static WERROR regdb_trans_do(struct db_context *db,
 
 static const char *builtin_registry_paths[] = {
        KEY_PRINTING_2K,
+       KEY_PCC,
        KEY_PRINTING_PORTS,
        KEY_PRINTING,
        KEY_PRINTING "\\Forms",
index e47b3f6ab56412a8cf77c74219fc3967175cc90b..ca78370b5ef13277aa46e4896d1cd88f25efe3dd 100644 (file)
@@ -55,6 +55,7 @@ struct registry_hook reg_hooks[] = {
   { KEY_PRINTING "\\Printers", &printing_ops },
   { KEY_PRINTING_2K,           &regdb_ops },
   { KEY_PRINTING_PORTS,        &regdb_ops },
+  { KEY_PCC,                   &regdb_ops },
   { KEY_SHARES,                &shares_reg_ops },
   { KEY_SMBCONF,               &smbconf_reg_ops },
   { KEY_NETLOGON_PARAMS,       &netlogon_params_reg_ops },
index 1823168685d71b847e97d9b679bb80344445eab2..4ce25baed8f7dd4ec07da382b717494217b0502c 100644 (file)
@@ -316,6 +316,165 @@ static WERROR winreg_printer_openkey(TALLOC_CTX *mem_ctx,
        return WERR_OK;
 }
 
+static WERROR winreg_printer_open_core_driver(TALLOC_CTX *mem_ctx,
+                                             struct dcerpc_binding_handle *binding_handle,
+                                             const char *architecture,
+                                             const char *key,
+                                             uint32_t access_mask,
+                                             struct policy_handle *hive_handle,
+                                             struct policy_handle *key_handle)
+{
+       struct winreg_String wkey, wkeyclass;
+       NTSTATUS status;
+       WERROR result = WERR_OK;
+       WERROR ignore;
+       enum winreg_CreateAction action = REG_ACTION_NONE;
+       const char *path;
+
+       status = dcerpc_winreg_OpenHKLM(binding_handle,
+                                       mem_ctx,
+                                       NULL,
+                                       access_mask,
+                                       hive_handle,
+                                       &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("winreg_printer_open_core_driver: Could not open HKLM hive: %s\n",
+                         nt_errstr(status)));
+               return ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0,("winreg_printer_open_core_driver: Could not open HKLM hive: %s\n",
+                         win_errstr(result)));
+               return result;
+       }
+
+       ZERO_STRUCT(wkey);
+       wkey.name = TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY;
+
+       ZERO_STRUCT(wkeyclass);
+       wkeyclass.name = "";
+
+       status = dcerpc_winreg_CreateKey(binding_handle,
+                                        mem_ctx,
+                                        hive_handle,
+                                        wkey,
+                                        wkeyclass,
+                                        0,
+                                        access_mask,
+                                        NULL,
+                                        key_handle,
+                                        &action,
+                                        &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       dcerpc_winreg_CloseKey(binding_handle, mem_ctx, key_handle, &ignore);
+
+       path = talloc_asprintf(mem_ctx, "%s\\%s",
+                                       TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
+                                       architecture);
+       if (path == NULL) {
+               result = WERR_NOT_ENOUGH_MEMORY;
+               goto done;
+       }
+
+       wkey.name = path;
+
+       status = dcerpc_winreg_CreateKey(binding_handle,
+                                        mem_ctx,
+                                        hive_handle,
+                                        wkey,
+                                        wkeyclass,
+                                        0,
+                                        access_mask,
+                                        NULL,
+                                        key_handle,
+                                        &action,
+                                        &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       dcerpc_winreg_CloseKey(binding_handle, mem_ctx, key_handle, &ignore);
+
+       path = talloc_asprintf(mem_ctx, "%s\\%s\\CorePrinterDrivers",
+                                       TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
+                                       architecture);
+       if (path == NULL) {
+               result = WERR_NOT_ENOUGH_MEMORY;
+               goto done;
+       }
+
+       wkey.name = path;
+
+       status = dcerpc_winreg_CreateKey(binding_handle,
+                                        mem_ctx,
+                                        hive_handle,
+                                        wkey,
+                                        wkeyclass,
+                                        0,
+                                        access_mask,
+                                        NULL,
+                                        key_handle,
+                                        &action,
+                                        &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       dcerpc_winreg_CloseKey(binding_handle, mem_ctx, key_handle, &ignore);
+
+       path = talloc_asprintf(mem_ctx, "%s\\%s\\CorePrinterDrivers\\%s",
+                                       TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
+                                       architecture,
+                                       key);
+       if (path == NULL) {
+               result = WERR_NOT_ENOUGH_MEMORY;
+               goto done;
+       }
+
+       wkey.name = path;
+
+       status = dcerpc_winreg_CreateKey(binding_handle,
+                                        mem_ctx,
+                                        hive_handle,
+                                        wkey,
+                                        wkeyclass,
+                                        0,
+                                        access_mask,
+                                        NULL,
+                                        key_handle,
+                                        &action,
+                                        &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+ done:
+       if (is_valid_policy_hnd(hive_handle)) {
+               dcerpc_winreg_CloseKey(binding_handle,
+                                      mem_ctx,
+                                      hive_handle,
+                                      &ignore);
+       }
+       ZERO_STRUCTP(hive_handle);
+
+       return result;
+}
+
 /**
  * @brief Create the registry keyname for the given printer.
  *
@@ -4131,3 +4290,88 @@ done:
        TALLOC_FREE(tmp_ctx);
        return result;
 }
+
+WERROR winreg_add_core_driver(TALLOC_CTX *mem_ctx,
+                             struct dcerpc_binding_handle *winreg_handle,
+                             const char *architecture,
+                             const struct spoolss_CorePrinterDriver *r)
+{
+       uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       struct policy_handle hive_hnd, key_hnd;
+       TALLOC_CTX *tmp_ctx = NULL;
+       NTSTATUS status;
+       WERROR result;
+       const char *guid_str;
+
+       ZERO_STRUCT(hive_hnd);
+       ZERO_STRUCT(key_hnd);
+
+       tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return WERR_NOT_ENOUGH_MEMORY;
+       }
+
+       guid_str = GUID_string2(tmp_ctx, &r->core_driver_guid);
+       if (guid_str == NULL) {
+               result = WERR_NOT_ENOUGH_MEMORY;
+               goto done;
+       }
+
+       result = winreg_printer_open_core_driver(tmp_ctx,
+                                                winreg_handle,
+                                                architecture,
+                                                guid_str,
+                                                access_mask,
+                                                &hive_hnd,
+                                                &key_hnd);
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_add_core_driver: "
+                         "Could not open core driver key (%s,%s): %s\n",
+                         guid_str, architecture, win_errstr(result)));
+               goto done;
+       }
+
+       result = winreg_printer_write_date(tmp_ctx, winreg_handle,
+                                          &key_hnd, "DriverDate",
+                                          r->driver_date);
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       result = winreg_printer_write_ver(tmp_ctx, winreg_handle,
+                                         &key_hnd, "DriverVersion",
+                                         r->driver_version);
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       status = dcerpc_winreg_set_sz(tmp_ctx,
+                                     winreg_handle,
+                                     &key_hnd,
+                                     "InfPath",
+                                     r->szPackageID,
+                                     &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       result = WERR_OK;
+done:
+       if (winreg_handle != NULL) {
+               WERROR ignore;
+
+               if (is_valid_policy_hnd(&key_hnd)) {
+                       dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &ignore);
+               }
+               if (is_valid_policy_hnd(&hive_hnd)) {
+                       dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &hive_hnd, &ignore);
+               }
+       }
+
+       TALLOC_FREE(tmp_ctx);
+       return result;
+}
+
index 90ff7315e82d148372d82ae0adc2002d52556e41..7acba9a25702f08ff66a895d4940f16ac848886b 100644 (file)
@@ -622,4 +622,24 @@ WERROR winreg_get_core_driver(TALLOC_CTX *mem_ctx,
                              const struct GUID *core_driver_guid,
                              struct spoolss_CorePrinterDriver **_core_printer_driver);
 
+/**
+ * @brief This function adds a core printer driver
+ *
+ * @param[in]  mem_ctx        A talloc memory context.
+ *
+ * @param[in]  b The dcerpc binding handle
+ *
+ * @param[in]  architecture    The architecture type.
+ *
+ * @param[in]  core_driver_driver The core driver.
+ *
+ * @return              On success WERR_OK, a corresponding DOS error is
+ *                      something went wrong.
+ */
+
+WERROR winreg_add_core_driver(TALLOC_CTX *mem_ctx,
+                             struct dcerpc_binding_handle *winreg_handle,
+                             const char *architecture,
+                             const struct spoolss_CorePrinterDriver *r);
+
 #endif /* _RPC_CLIENT_CLI_WINREG_SPOOLSS_H_ */