summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2010-04-01 11:51:59 +0200
committerGünther Deschner <gd@samba.org>2010-04-07 15:16:53 +0200
commitc7fb84a58fd3597431c0bbe131e51a95eaff8a70 (patch)
treeb72f2ec52ea386fa41f6f4d02e74144d3a2c0a92 /source3
parent0d46ab0f3eb9662d7ee3eaf8f680632486878d46 (diff)
downloadsamba-c7fb84a58fd3597431c0bbe131e51a95eaff8a70.tar.gz
samba-c7fb84a58fd3597431c0bbe131e51a95eaff8a70.tar.bz2
samba-c7fb84a58fd3597431c0bbe131e51a95eaff8a70.zip
s3-spoolss: Added a winreg_setform1 function.
Signed-off-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/rpc_server/srv_spoolss_util.c100
-rw-r--r--source3/rpc_server/srv_spoolss_util.h20
2 files changed, 120 insertions, 0 deletions
diff --git a/source3/rpc_server/srv_spoolss_util.c b/source3/rpc_server/srv_spoolss_util.c
index f5d4b56011..74cc5fb65a 100644
--- a/source3/rpc_server/srv_spoolss_util.c
+++ b/source3/rpc_server/srv_spoolss_util.c
@@ -1535,3 +1535,103 @@ done:
TALLOC_FREE(tmp_ctx);
return result;
}
+
+WERROR winreg_printer_setform1(struct pipes_struct *p,
+ const char *form_name,
+ struct spoolss_AddFormInfo1 *form)
+{
+ uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+ struct rpc_pipe_client *winreg_pipe = NULL;
+ struct policy_handle hive_hnd, key_hnd;
+ struct winreg_String wvalue;
+ DATA_BLOB blob;
+ uint32_t num_builtin = ARRAY_SIZE(builtin_forms1);
+ uint32_t i;
+ WERROR result;
+ NTSTATUS status;
+ TALLOC_CTX *tmp_ctx;
+
+ for (i = 0; i < num_builtin; i++) {
+ if (strequal(builtin_forms1[i].form_name, form->form_name)) {
+ result = WERR_INVALID_PARAM;
+ goto done;
+ }
+ }
+
+ tmp_ctx = talloc_new(p->mem_ctx);
+ if (tmp_ctx == NULL) {
+ return WERR_NOMEM;
+ }
+
+ ZERO_STRUCT(hive_hnd);
+ ZERO_STRUCT(key_hnd);
+
+ result = winreg_printer_openkey(tmp_ctx,
+ p->server_info,
+ &winreg_pipe,
+ TOP_LEVEL_CONTROL_FORMS_KEY,
+ "",
+ true,
+ access_mask,
+ &hive_hnd,
+ &key_hnd);
+ if (!W_ERROR_IS_OK(result)) {
+ DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
+ TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
+ goto done;
+ }
+
+ /* If form_name != form->form_name then we renamed the form */
+ if (strequal(form_name, form->form_name)) {
+ result = winreg_printer_deleteform1(p, form_name);
+ if (!W_ERROR_IS_OK(result)) {
+ DEBUG(0, ("winreg_printer_setform1: Could not open key %s: %s\n",
+ TOP_LEVEL_CONTROL_FORMS_KEY, win_errstr(result)));
+ goto done;
+ }
+ }
+
+ wvalue.name = form->form_name;
+
+ blob = data_blob_talloc(tmp_ctx, NULL, 32);
+ SIVAL(blob.data, 0, form->size.width);
+ SIVAL(blob.data, 4, form->size.height);
+ SIVAL(blob.data, 8, form->area.left);
+ SIVAL(blob.data, 12, form->area.top);
+ SIVAL(blob.data, 16, form->area.right);
+ SIVAL(blob.data, 20, form->area.bottom);
+ SIVAL(blob.data, 24, 42);
+ SIVAL(blob.data, 28, form->flags);
+
+ status = rpccli_winreg_SetValue(winreg_pipe,
+ tmp_ctx,
+ &key_hnd,
+ wvalue,
+ REG_BINARY,
+ blob.data,
+ blob.length,
+ &result);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0, ("winreg_printer_setform1: Could not set value %s: %s\n",
+ wvalue.name, nt_errstr(status)));
+ if (!W_ERROR_IS_OK(result)) {
+ goto done;
+ }
+ result = ntstatus_to_werror(status);
+ goto done;
+ }
+
+ 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;
+}
diff --git a/source3/rpc_server/srv_spoolss_util.h b/source3/rpc_server/srv_spoolss_util.h
index e99de5fb63..1fcc3244ba 100644
--- a/source3/rpc_server/srv_spoolss_util.h
+++ b/source3/rpc_server/srv_spoolss_util.h
@@ -218,4 +218,24 @@ WERROR winreg_printer_enumforms1(struct pipes_struct *p,
WERROR winreg_printer_deleteform1(struct pipes_struct *p,
const char *form_name);
+/**
+ * @brief This function sets the form information for the specified printer.
+ *
+ * If one provides both the name in the API call and inside the FormInfo
+ * structure, then the form gets renamed.
+ *
+ * @param[in] p The pipes structure to be able to open a new pipe.
+ *
+ * @param[in] form_name The name of the form to set or rename.
+ *
+ * @param[in] form The FormInfo structure to save.
+ *
+ * @return WERR_OK on success.
+ * WERR_INVALID_PARAM if the form is a builtin form.
+ * A corresponding DOS error is something went wrong.
+ */
+WERROR winreg_printer_setform1(struct pipes_struct *p,
+ const char *form_name,
+ struct spoolss_AddFormInfo1 *form);
+
#endif /* _SRV_SPOOLSS_UITL_H */