s3-rpc_cli: add winreg_del_driver_package()
authorGünther Deschner <gd@samba.org>
Wed, 2 Nov 2016 17:17:37 +0000 (18:17 +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 30e043e1eefeff669789e593512c8f1a7312a2f7..7a0817a176a1acb2adcf7d368e356aff80e9883e 100644 (file)
@@ -4595,3 +4595,104 @@ done:
        TALLOC_FREE(tmp_ctx);
        return result;
 }
+
+WERROR winreg_del_driver_package(TALLOC_CTX *mem_ctx,
+                                struct dcerpc_binding_handle *winreg_handle,
+                                const char *package_id,
+                                const char *architecture)
+{
+       uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       struct policy_handle hive_hnd, key_hnd;
+       TALLOC_CTX *tmp_ctx;
+       WERROR result;
+       NTSTATUS status;
+       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 */
+                                       false,
+                                       access_mask,
+                                       &hive_hnd,
+                                       &key_hnd);
+       if (!W_ERROR_IS_OK(result)) {
+               /* key doesn't exist */
+               if (W_ERROR_EQUAL(result, WERR_FILE_NOT_FOUND)) {
+                       result = WERR_OK;
+                       goto done;
+               }
+
+               DEBUG(5, ("winreg_del_driver_package: "
+                         "Could not open driver package key (%s,%s): %s\n",
+                         package_id, architecture, win_errstr(result)));
+               goto done;
+       }
+
+
+       if (is_valid_policy_hnd(&key_hnd)) {
+               dcerpc_winreg_CloseKey(winreg_handle, tmp_ctx, &key_hnd, &result);
+       }
+
+       path = talloc_asprintf(tmp_ctx, "%s\\%s\\DriverPackages\\%s",
+                                       TOP_LEVEL_PRINT_PACKAGEINSTALLATION_KEY,
+                                       architecture,
+                                       package_id);
+       if (path == NULL) {
+               result = WERR_NOT_ENOUGH_MEMORY;
+               goto done;
+       }
+
+       status = dcerpc_winreg_delete_subkeys_recursive(tmp_ctx,
+                                                       winreg_handle,
+                                                       &hive_hnd,
+                                                       access_mask,
+                                                       path,
+                                                       &result);
+       if (!NT_STATUS_IS_OK(status)) {
+               result = ntstatus_to_werror(status);
+               DEBUG(5, ("winreg_del_driver_package: "
+                         "Could not delete driver package key (%s,%s): %s\n",
+                         package_id, architecture, nt_errstr(status)));
+               goto done;
+       }
+
+       if (!W_ERROR_IS_OK(result)) {
+               DEBUG(5, ("winreg_del_driver_package: "
+                         "Could not delete driver package key (%s,%s): %s\n",
+                         package_id, architecture, win_errstr(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 a3b4ef9e6cfd6eaf369c813d052bafca1cc5f26b..1bd2746e6f4236036540d425814e8a6856cd4c4f 100644 (file)
@@ -694,4 +694,24 @@ WERROR winreg_get_driver_package(TALLOC_CTX *mem_ctx,
                                 const char **driver_store_path,
                                 const char **cab_path);
 
+/**
+ * @brief This function deletes 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.
+ *
+ * @return              On success WERR_OK, a corresponding DOS error is
+ *                      something went wrong.
+ */
+
+WERROR winreg_del_driver_package(TALLOC_CTX *mem_ctx,
+                                struct dcerpc_binding_handle *winreg_handle,
+                                const char *package_id,
+                                const char *architecture);
+
 #endif /* _RPC_CLIENT_CLI_WINREG_SPOOLSS_H_ */