diff options
author | Günther Deschner <gd@samba.org> | 2016-10-31 18:07:33 +0100 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2017-05-09 16:43:13 +0200 |
commit | f22c5f1b9aaac39fea7b58817f67654595f74658 (patch) | |
tree | 3a4dc5175e3450d141619e2545c54a6e455b6cde /source3/rpc_client | |
parent | 5eeb178fe8942b0a4c41dee4ed1195ffa4ab524e (diff) | |
download | samba-f22c5f1b9aaac39fea7b58817f67654595f74658.tar.gz |
s3-rpc_cli: add winreg_add_core_driver()
Guenther
Signed-off-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'source3/rpc_client')
-rw-r--r-- | source3/rpc_client/cli_winreg_spoolss.c | 244 | ||||
-rw-r--r-- | source3/rpc_client/cli_winreg_spoolss.h | 20 |
2 files changed, 264 insertions, 0 deletions
diff --git a/source3/rpc_client/cli_winreg_spoolss.c b/source3/rpc_client/cli_winreg_spoolss.c index 1823168685d..4ce25baed8f 100644 --- a/source3/rpc_client/cli_winreg_spoolss.c +++ b/source3/rpc_client/cli_winreg_spoolss.c @@ -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; +} + diff --git a/source3/rpc_client/cli_winreg_spoolss.h b/source3/rpc_client/cli_winreg_spoolss.h index 90ff7315e82..7acba9a2570 100644 --- a/source3/rpc_client/cli_winreg_spoolss.h +++ b/source3/rpc_client/cli_winreg_spoolss.h @@ -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_ */ |