s3-spoolss: Added a function to get the ChangeID from a printer.
authorAndreas Schneider <asn@samba.org>
Thu, 15 Apr 2010 19:51:16 +0000 (21:51 +0200)
committerGünther Deschner <gd@samba.org>
Fri, 23 Apr 2010 14:23:40 +0000 (16:23 +0200)
Signed-off-by: Günther Deschner <gd@samba.org>
source3/rpc_server/srv_spoolss_util.c
source3/rpc_server/srv_spoolss_util.h

index 3e35eb98ff70166020de7d4046b417cae02143e4..95f292a5a37da44d7fe57bde30f9c7b35b7843fc 100644 (file)
@@ -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:
  *
index e8cea014953efa0fa20e30eb7476f63a1c6ad189..a4b5c88271451983a66cfb1bcafbb362ef869b83 100644 (file)
@@ -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
  *