summaryrefslogtreecommitdiff
path: root/source3/rpc_server
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2011-02-01 14:28:39 +0100
committerGünther Deschner <gd@samba.org>2011-02-07 12:32:01 +0100
commit8238732330d3dde73b23750d9b5646bfe3d4a39a (patch)
treedda26874cac7de1c6ac15148c7263f57135b4785 /source3/rpc_server
parentc6255adc6f027cafeca7247ce58bbeae0733d45a (diff)
downloadsamba-8238732330d3dde73b23750d9b5646bfe3d4a39a.tar.gz
samba-8238732330d3dde73b23750d9b5646bfe3d4a39a.tar.bz2
samba-8238732330d3dde73b23750d9b5646bfe3d4a39a.zip
s3-rpc_server: Migrated spoolss to dcerpc_winreg_enum_keys.
Signed-off-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'source3/rpc_server')
-rw-r--r--source3/rpc_server/srv_spoolss_util.c184
1 files changed, 21 insertions, 163 deletions
diff --git a/source3/rpc_server/srv_spoolss_util.c b/source3/rpc_server/srv_spoolss_util.c
index 70601c862d..4fe94e4f73 100644
--- a/source3/rpc_server/srv_spoolss_util.c
+++ b/source3/rpc_server/srv_spoolss_util.c
@@ -29,6 +29,7 @@
#include "secrets.h"
#include "rpc_server/rpc_ncacn_np.h"
#include "../libcli/security/security.h"
+#include "rpc_client/cli_winreg.h"
#define TOP_LEVEL_PRINT_KEY "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print"
#define TOP_LEVEL_PRINT_PRINTERS_KEY TOP_LEVEL_PRINT_KEY "\\Printers"
@@ -544,163 +545,6 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx,
/**
* @internal
*
- * @brief Enumerate subkeys of an opened key handle and get the names.
- *
- * @param[in] mem_ctx The memory context to use.
- *
- * @param[in] winreg_handle The binding handle for the rpc connection.
- *
- * @param[in] key_hnd The opened key handle.
- *
- * @param[in] pnum_subkeys A pointer to store the number of found subkeys.
- *
- * @param[in] psubkeys A pointer to an array to store the found names of
- * subkeys.
- *
- * @return WERR_OK on success, the corresponding DOS error
- * code if something gone wrong.
- */
-static WERROR winreg_printer_enumkeys(TALLOC_CTX *mem_ctx,
- struct dcerpc_binding_handle *winreg_handle,
- struct policy_handle *key_hnd,
- uint32_t *pnum_subkeys,
- const char ***psubkeys)
-{
- TALLOC_CTX *tmp_ctx;
- const char **subkeys;
- uint32_t num_subkeys, max_subkeylen, max_classlen;
- uint32_t num_values, max_valnamelen, max_valbufsize;
- uint32_t i;
- NTTIME last_changed_time;
- uint32_t secdescsize;
- struct winreg_String classname;
- WERROR result = WERR_OK;
- NTSTATUS status;
-
- tmp_ctx = talloc_stackframe();
- if (tmp_ctx == NULL) {
- return WERR_NOMEM;
- }
-
- ZERO_STRUCT(classname);
-
- status = dcerpc_winreg_QueryInfoKey(winreg_handle,
- tmp_ctx,
- key_hnd,
- &classname,
- &num_subkeys,
- &max_subkeylen,
- &max_classlen,
- &num_values,
- &max_valnamelen,
- &max_valbufsize,
- &secdescsize,
- &last_changed_time,
- &result);
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
- nt_errstr(status)));
- result = ntstatus_to_werror(status);
- goto error;
- }
- if (!W_ERROR_IS_OK(result)) {
- DEBUG(0, ("winreg_printer_enumkeys: Could not query info: %s\n",
- win_errstr(result)));
- goto error;
- }
-
- subkeys = talloc_zero_array(tmp_ctx, const char *, num_subkeys + 2);
- if (subkeys == NULL) {
- result = WERR_NOMEM;
- goto error;
- }
-
- if (num_subkeys == 0) {
- subkeys[0] = talloc_strdup(subkeys, "");
- if (subkeys[0] == NULL) {
- result = WERR_NOMEM;
- goto error;
- }
- *pnum_subkeys = 0;
- if (psubkeys) {
- *psubkeys = talloc_move(mem_ctx, &subkeys);
- }
-
- TALLOC_FREE(tmp_ctx);
- return WERR_OK;
- }
-
- for (i = 0; i < num_subkeys; i++) {
- char c = '\0';
- char n = '\0';
- char *name = NULL;
- struct winreg_StringBuf class_buf;
- struct winreg_StringBuf name_buf;
- NTTIME modtime;
-
- class_buf.name = &c;
- class_buf.size = max_classlen + 2;
- class_buf.length = 0;
-
- name_buf.name = &n;
- name_buf.size = max_subkeylen + 2;
- name_buf.length = 0;
-
- ZERO_STRUCT(modtime);
-
- status = dcerpc_winreg_EnumKey(winreg_handle,
- tmp_ctx,
- key_hnd,
- i,
- &name_buf,
- &class_buf,
- &modtime,
- &result);
- if (W_ERROR_EQUAL(result, WERR_NO_MORE_ITEMS) ) {
- result = WERR_OK;
- status = NT_STATUS_OK;
- break;
- }
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
- nt_errstr(status)));
- result = ntstatus_to_werror(status);
- goto error;
- }
- if (!W_ERROR_IS_OK(result)) {
- DEBUG(0, ("winreg_printer_enumkeys: Could not enumerate keys: %s\n",
- win_errstr(result)));
- goto error;
- }
-
- if (name_buf.name == NULL) {
- result = WERR_INVALID_PARAMETER;
- goto error;
- }
-
- name = talloc_strdup(subkeys, name_buf.name);
- if (name == NULL) {
- result = WERR_NOMEM;
- goto error;
- }
-
- subkeys[i] = name;
- }
-
- *pnum_subkeys = num_subkeys;
- if (psubkeys) {
- *psubkeys = talloc_move(mem_ctx, &subkeys);
- }
-
- error:
- TALLOC_FREE(tmp_ctx);
- return result;
-}
-
-/**
- * @internal
- *
* @brief A function to delete a key and its subkeys recurively.
*
* @param[in] mem_ctx The memory context to use.
@@ -754,11 +598,15 @@ static WERROR winreg_printer_delete_subkeys(TALLOC_CTX *mem_ctx,
return result;
}
- result = winreg_printer_enumkeys(mem_ctx,
+ status = dcerpc_winreg_enum_keys(mem_ctx,
winreg_handle,
&key_hnd,
&num_subkeys,
- &subkeys);
+ &subkeys,
+ &result);
+ if (!NT_STATUS_IS_OK(status)) {
+ result = ntstatus_to_werror(status);
+ }
if (!W_ERROR_IS_OK(result)) {
goto done;
}
@@ -2937,6 +2785,7 @@ WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
uint32_t num_subkeys = -1;
WERROR result = WERR_OK;
+ NTSTATUS status;
TALLOC_CTX *tmp_ctx;
@@ -2970,11 +2819,15 @@ WERROR winreg_enum_printer_key(TALLOC_CTX *mem_ctx,
goto done;
}
- result = winreg_printer_enumkeys(tmp_ctx,
+ status = dcerpc_winreg_enum_keys(tmp_ctx,
winreg_handle,
&key_hnd,
&num_subkeys,
- &subkeys);
+ &subkeys,
+ &result);
+ if (!NT_STATUS_IS_OK(status)) {
+ result = ntstatus_to_werror(status);
+ }
if (!W_ERROR_IS_OK(result)) {
DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n",
key, win_errstr(result)));
@@ -4387,6 +4240,7 @@ WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
const char **drivers;
TALLOC_CTX *tmp_ctx;
WERROR result;
+ NTSTATUS status;
*num_drivers = 0;
*drivers_p = NULL;
@@ -4419,11 +4273,15 @@ WERROR winreg_get_driver_list(TALLOC_CTX *mem_ctx,
goto done;
}
- result = winreg_printer_enumkeys(tmp_ctx,
+ status = dcerpc_winreg_enum_keys(tmp_ctx,
winreg_handle,
&key_hnd,
num_drivers,
- &drivers);
+ &drivers,
+ &result);
+ if (!NT_STATUS_IS_OK(status)) {
+ result = ntstatus_to_werror(status);
+ }
if (!W_ERROR_IS_OK(result)) {
DEBUG(0, ("winreg_get_driver_list: "
"Could not enumerate drivers for (%s,%u): %s\n",