diff options
author | Andreas Schneider <asn@redhat.com> | 2010-03-17 15:59:10 +0100 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2010-04-07 15:16:52 +0200 |
commit | f0054d8361b90acc3b4d39b0c283f9d54467e61d (patch) | |
tree | 9fcd7f5862a50625c9a7d999a641e634178027e4 | |
parent | 77d1b73a3e31f67dce28055603c34bd78e927616 (diff) | |
download | samba-f0054d8361b90acc3b4d39b0c283f9d54467e61d.tar.gz samba-f0054d8361b90acc3b4d39b0c283f9d54467e61d.tar.bz2 samba-f0054d8361b90acc3b4d39b0c283f9d54467e61d.zip |
s3-spoolss: Added a enum_printer_key function using the winreg pipe.
Signed-off-by: Günther Deschner <gd@samba.org>
-rw-r--r-- | source3/rpc_server/srv_spoolss_util.c | 225 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_util.h | 25 |
2 files changed, 250 insertions, 0 deletions
diff --git a/source3/rpc_server/srv_spoolss_util.c b/source3/rpc_server/srv_spoolss_util.c index 4837c1c3db..2f13cf49f8 100644 --- a/source3/rpc_server/srv_spoolss_util.c +++ b/source3/rpc_server/srv_spoolss_util.c @@ -330,6 +330,159 @@ static WERROR winreg_printer_enumvalues(TALLOC_CTX *mem_ctx, return result; } +/** + * @internal + * + * @brief Enumerate subkeys of an opened key handle and get the names. + * + * @param[in] mem_ctx The memory context to use. + * + * @param[in] pipe_handle The pipe 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 rpc_pipe_client *pipe_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_new(mem_ctx); + if (tmp_ctx == NULL) { + return WERR_NOMEM; + } + + ZERO_STRUCT(classname); + + status = rpccli_winreg_QueryInfoKey(pipe_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))); + if (!W_ERROR_IS_OK(result)) { + goto error; + } + result = ntstatus_to_werror(status); + 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 = rpccli_winreg_EnumKey(pipe_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))); + if (!W_ERROR_IS_OK(result)) { + goto error; + } + result = ntstatus_to_werror(status); + 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; +} + /******************************************************************** Public winreg function for spoolss ********************************************************************/ @@ -663,3 +816,75 @@ done: TALLOC_FREE(tmp_ctx); return result; } + +/* Enumerate on the subkeys of a given key and provide the data. */ +WERROR winreg_enum_printer_key(struct pipes_struct *p, + const char *printer, + const char *key, + uint32_t *pnum_subkeys, + const char ***psubkeys) +{ + uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + struct rpc_pipe_client *winreg_pipe = NULL; + struct policy_handle hive_hnd, key_hnd; + + const char **subkeys = NULL; + uint32_t num_subkeys = -1; + + WERROR result = WERR_OK; + + TALLOC_CTX *tmp_ctx; + + 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, + printer, + key, + false, + access_mask, + &hive_hnd, + &key_hnd); + if (!W_ERROR_IS_OK(result)) { + DEBUG(0, ("winreg_enum_printer_key: Could not open key %s: %s\n", + key, win_errstr(result))); + goto done; + } + + result = winreg_printer_enumkeys(tmp_ctx, + winreg_pipe, + &key_hnd, + &num_subkeys, + &subkeys); + if (!W_ERROR_IS_OK(result)) { + DEBUG(0, ("winreg_enum_printer_key: Could not enumerate subkeys in %s: %s\n", + key, win_errstr(result))); + goto done; + } + + *pnum_subkeys = num_subkeys; + if (psubkeys) { + *psubkeys = talloc_move(p->mem_ctx, &subkeys); + } + + 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 2e6aa903f0..21e3d3581b 100644 --- a/source3/rpc_server/srv_spoolss_util.h +++ b/source3/rpc_server/srv_spoolss_util.h @@ -127,4 +127,29 @@ WERROR winreg_delete_printer_dataex(struct pipes_struct *p, const char *key, const char *value); +/** + * @internal + * + * @brief Enumerate on the subkeys of a given key and provide the data. + * + * @param[in] p The pipes structure to be able to open a new pipe. + * + * @param[in] printer The printer name. + * + * @param[in] key The key of the printer data to get the value. + * + * @param[out] pnum_subkeys A pointer to store the number of subkeys found. + * + * @param[in] psubkeys A pointer to an array to store the names of the subkeys + * found. + * + * @return WERR_OK on success, the corresponding DOS error + * code if something gone wrong. + */ +WERROR winreg_enum_printer_key(struct pipes_struct *p, + const char *printer, + const char *key, + uint32_t *pnum_subkeys, + const char ***psubkeys); + #endif /* _SRV_SPOOLSS_UITL_H */ |