summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2016-11-02 14:36:45 +0100
committerGünther Deschner <gd@samba.org>2017-05-09 16:43:13 +0200
commit7ced1c30fcadfcab239a8796292f736a74a4357a (patch)
tree92d5640b545e8cf3f22f3dd9147d1edb18a366b4 /source3
parent5a3b99b7ce6a7342a8a427b941268a6a302ee158 (diff)
downloadsamba-7ced1c30fcadfcab239a8796292f736a74a4357a.tar.gz
s3-rpc_cli: add winreg_get_driver_package()
Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/rpc_client/cli_winreg_spoolss.c131
-rw-r--r--source3/rpc_client/cli_winreg_spoolss.h26
2 files changed, 157 insertions, 0 deletions
diff --git a/source3/rpc_client/cli_winreg_spoolss.c b/source3/rpc_client/cli_winreg_spoolss.c
index 8556d5c0088..30e043e1eef 100644
--- a/source3/rpc_client/cli_winreg_spoolss.c
+++ b/source3/rpc_client/cli_winreg_spoolss.c
@@ -4464,3 +4464,134 @@ done:
return result;
}
+WERROR winreg_get_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;
+ struct spoolss_PrinterEnumValues *enum_values = NULL;
+ struct spoolss_PrinterEnumValues *v;
+ uint32_t num_values = 0;
+ TALLOC_CTX *tmp_ctx;
+ WERROR result;
+ NTSTATUS status;
+ const char *path;
+ uint32_t i;
+ const char **enum_names = NULL;
+ enum winreg_Type *enum_types = NULL;
+ DATA_BLOB *enum_data_blobs = NULL;
+
+ 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)) {
+ DEBUG(5, ("winreg_get_driver_package: "
+ "Could not open driver package key (%s,%s): %s\n",
+ package_id, architecture, win_errstr(result)));
+ goto done;
+ }
+
+ status = dcerpc_winreg_enumvals(tmp_ctx,
+ winreg_handle,
+ &key_hnd,
+ &num_values,
+ &enum_names,
+ &enum_types,
+ &enum_data_blobs,
+ &result);
+ if (!NT_STATUS_IS_OK(status)){
+ result = ntstatus_to_werror(status);
+ }
+
+ if (!W_ERROR_IS_OK(result)) {
+ DEBUG(0, ("winreg_get_driver_package: "
+ "Could not enumerate values for (%s,%s): %s\n",
+ package_id, architecture, win_errstr(result)));
+ goto done;
+ }
+
+ enum_values = talloc_zero_array(tmp_ctx,
+ struct spoolss_PrinterEnumValues,
+ num_values);
+ if (enum_values == NULL){
+ result = WERR_NOT_ENOUGH_MEMORY;
+ goto done;
+ }
+
+ for (i = 0; i < num_values; i++){
+ enum_values[i].value_name = enum_names[i];
+ enum_values[i].value_name_len = strlen_m_term(enum_names[i]) * 2;
+ enum_values[i].type = enum_types[i];
+ enum_values[i].data_length = enum_data_blobs[i].length;
+ enum_values[i].data = NULL;
+ if (enum_values[i].data_length != 0){
+ enum_values[i].data = &enum_data_blobs[i];
+ }
+ }
+
+ result = WERR_OK;
+
+ for (i = 0; i < num_values; i++) {
+
+ v = &enum_values[i];
+
+ result = winreg_enumval_to_sz(mem_ctx, v,
+ "CabPath",
+ cab_path);
+ CHECK_ERROR(result);
+
+ result = winreg_enumval_to_sz(mem_ctx, v,
+ "DriverStorePath",
+ driver_store_path);
+ CHECK_ERROR(result);
+ }
+
+ if (!W_ERROR_IS_OK(result)) {
+ DEBUG(0, ("winreg_enumval_to_TYPE() failed "
+ "for %s: %s\n", v->value_name,
+ 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;
+}
diff --git a/source3/rpc_client/cli_winreg_spoolss.h b/source3/rpc_client/cli_winreg_spoolss.h
index 7e3f735b587..a3b4ef9e6cf 100644
--- a/source3/rpc_client/cli_winreg_spoolss.h
+++ b/source3/rpc_client/cli_winreg_spoolss.h
@@ -668,4 +668,30 @@ WERROR winreg_add_driver_package(TALLOC_CTX *mem_ctx,
const char *driver_store_path,
const char *cab_path);
+/**
+ * @brief This function gets 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 pointer to a local DriverStorePath
+ *
+ * @param[in] cab_path The pointer to a local CabFile path
+ *
+ * @return On success WERR_OK, a corresponding DOS error is
+ * something went wrong.
+ */
+
+WERROR winreg_get_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_ */