From e7d674282191152f29d0fe812af9c5afcba084b9 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 15 Apr 2010 21:51:16 +0200 Subject: s3-spoolss: Added a function to get the ChangeID from a printer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Günther Deschner --- source3/rpc_server/srv_spoolss_util.c | 71 +++++++++++++++++++++++++++++++++++ source3/rpc_server/srv_spoolss_util.h | 19 ++++++++++ 2 files changed, 90 insertions(+) (limited to 'source3/rpc_server') diff --git a/source3/rpc_server/srv_spoolss_util.c b/source3/rpc_server/srv_spoolss_util.c index 3e35eb98ff..95f292a5a3 100644 --- a/source3/rpc_server/srv_spoolss_util.c +++ b/source3/rpc_server/srv_spoolss_util.c @@ -1450,6 +1450,77 @@ done: return result; } +WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx, + struct auth_serversupplied_info *server_info, + const char *printer, + uint32_t *pchangeid) +{ + uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + struct rpc_pipe_client *winreg_pipe = NULL; + struct policy_handle hive_hnd, key_hnd; + uint32_t changeid = 0; + char *path; + WERROR result; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(mem_ctx); + if (tmp_ctx == NULL) { + return WERR_NOMEM; + } + + path = winreg_printer_data_keyname(tmp_ctx, printer); + if (path == NULL) { + TALLOC_FREE(tmp_ctx); + return WERR_NOMEM; + } + + ZERO_STRUCT(hive_hnd); + ZERO_STRUCT(key_hnd); + + result = winreg_printer_openkey(tmp_ctx, + server_info, + &winreg_pipe, + path, + "", + false, + access_mask, + &hive_hnd, + &key_hnd); + if (!W_ERROR_IS_OK(result)) { + DEBUG(0, ("winreg_printer_get_changeid: Could not open key %s: %s\n", + path, win_errstr(result))); + goto done; + } + + DEBUG(0, ("winreg_printer_get_changeid: get changeid from %s\n", path)); + result = winreg_printer_query_dword(tmp_ctx, + winreg_pipe, + &key_hnd, + "ChangeID", + &changeid); + if (!W_ERROR_IS_OK(result)) { + goto done; + } + + if (pchangeid) { + *pchangeid = changeid; + } + + result = WERR_OK; +done: + if (winreg_pipe != NULL) { + if (is_valid_policy_hnd(&key_hnd)) { + rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &key_hnd, NULL); + } + if (is_valid_policy_hnd(&hive_hnd)) { + rpccli_winreg_CloseKey(winreg_pipe, tmp_ctx, &hive_hnd, NULL); + } + } + + TALLOC_FREE(tmp_ctx); + return result; +} + /* * The special behaviour of the spoolss forms is documented at the website: * diff --git a/source3/rpc_server/srv_spoolss_util.h b/source3/rpc_server/srv_spoolss_util.h index e8cea01495..a4b5c88271 100644 --- a/source3/rpc_server/srv_spoolss_util.h +++ b/source3/rpc_server/srv_spoolss_util.h @@ -210,6 +210,25 @@ WERROR winreg_printer_update_changeid(TALLOC_CTX *mem_ctx, struct auth_serversupplied_info *server_info, const char *printer); +/** + * @brief Get the ChangeID of the given printer. + * + * @param[in] mem_ctx The talloc memory context to use. + * + * @param[in] server_info The server supplied session info. + * + * @param[in] printer The printer name. + * + * @param[in] changeid A pointer to store the changeid. + * + * @return On success WERR_OK, a corresponding DOS error is + * something went wrong. + */ +WERROR winreg_printer_get_changeid(TALLOC_CTX *mem_ctx, + struct auth_serversupplied_info *server_info, + const char *printer, + uint32_t *pchangeid); + /** * @internal * -- cgit