s3-rpc_cli: add winreg_add_driver_package()
authorGünther Deschner <gd@samba.org>
Wed, 2 Nov 2016 12:40:00 +0000 (13:40 +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/rpc_client/cli_winreg_spoolss.c
source3/rpc_client/cli_winreg_spoolss.h

index 4ce25baed8f7dd4ec07da382b717494217b0502c..8556d5c008800164513b8995576ed7bb32076cfa 100644 (file)
@@ -4375,3 +4375,92 @@ done:
        return result;
 }
 
+WERROR winreg_add_driver_package(TALLOC_CTX *mem_ctx,
+                                struct dcerpc_binding_handle *winreg_handle,
+                                const char *package_id,
+                                const char *architecture,
+                                const char *driver_store_path,
+                                const char *cab_path)
+{
+       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 *path;
+
+       ZERO_STRUCT(hive_hnd);
+       ZERO_STRUCT(key_hnd);
+
+       tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return WERR_NOT_ENOUGH_MEMORY;
+       }
+
+       path = talloc_asprintf(tmp_ctx, "%s\\%s\\DriverPackages",
+                                       TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
+                                       architecture);
+       if (path == NULL) {
+               result = WERR_NOT_ENOUGH_MEMORY;
+               goto done;
+       }
+
+       result = winreg_printer_openkey(tmp_ctx,
+                                       winreg_handle,
+                                       path,
+                                       package_id, /* key */
+                                       true,
+                                       access_mask,
+                                       &hive_hnd,
+                                       &key_hnd);
+
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(0, ("winreg_add_driver_package: "
+                         "Could not open driver package key (%s,%s): %s\n",
+                         package_id, architecture, win_errstr(result)));
+               goto done;
+       }
+
+       status = dcerpc_winreg_set_sz(tmp_ctx,
+                                     winreg_handle,
+                                     &key_hnd,
+                                     "CabPath",
+                                     cab_path,
+                                     &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+       }
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       status = dcerpc_winreg_set_sz(tmp_ctx,
+                                     winreg_handle,
+                                     &key_hnd,
+                                     "DriverStorePath",
+                                     driver_store_path,
+                                     &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 7acba9a25702f08ff66a895d4940f16ac848886b..7e3f735b58753d949e201b268c7a25bc0349d306 100644 (file)
@@ -642,4 +642,30 @@ WERROR winreg_add_core_driver(TALLOC_CTX *mem_ctx,
                              const char *architecture,
                              const struct spoolss_CorePrinterDriver *r);
 
+/**
+ * @brief This function adds a driver package
+ *
+ * @param[in]  mem_ctx        A talloc memory context.
+ *
+ * @param[in]  b The dcerpc binding handle
+ *
+ * @param[in]  package_id    The package ID.
+ *
+ * @param[in]  architecture    The architecture type.
+ *
+ * @param[in]  driver_store_path The local DriverStorePath
+ *
+ * @param[in]  cab_path The local CabFile path
+ *
+ * @return              On success WERR_OK, a corresponding DOS error is
+ *                      something went wrong.
+ */
+
+WERROR winreg_add_driver_package(TALLOC_CTX *mem_ctx,
+                                struct dcerpc_binding_handle *winreg_handle,
+                                const char *package_id,
+                                const char *architecture,
+                                const char *driver_store_path,
+                                const char *cab_path);
+
 #endif /* _RPC_CLIENT_CLI_WINREG_SPOOLSS_H_ */