| 1 | /*
|
|---|
| 2 | * Samba Unix/Linux SMB client library
|
|---|
| 3 | * Distributed SMB/CIFS Server Management Utility
|
|---|
| 4 | * registry utility functions
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (C) Michael Adam 2008
|
|---|
| 7 | *
|
|---|
| 8 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | * it under the terms of the GNU General Public License as published by
|
|---|
| 10 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | * (at your option) any later version.
|
|---|
| 12 | *
|
|---|
| 13 | * This program is distributed in the hope that it will be useful,
|
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | * GNU General Public License for more details.
|
|---|
| 17 | *
|
|---|
| 18 | * You should have received a copy of the GNU General Public License
|
|---|
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 | #include "utils/net_registry_util.h"
|
|---|
| 24 |
|
|---|
| 25 | void print_registry_key(const char *keyname, NTTIME *modtime)
|
|---|
| 26 | {
|
|---|
| 27 | d_printf("Keyname = %s\n", keyname);
|
|---|
| 28 | d_printf("Modtime = %s\n",
|
|---|
| 29 | modtime
|
|---|
| 30 | ? http_timestring(nt_time_to_unix(*modtime))
|
|---|
| 31 | : "None");
|
|---|
| 32 | d_printf("\n");
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | void print_registry_value(const struct registry_value *valvalue, bool raw)
|
|---|
| 36 | {
|
|---|
| 37 | if (!raw) {
|
|---|
| 38 | d_printf("Type = %s\n",
|
|---|
| 39 | reg_type_lookup(valvalue->type));
|
|---|
| 40 | }
|
|---|
| 41 | switch(valvalue->type) {
|
|---|
| 42 | case REG_DWORD:
|
|---|
| 43 | if (!raw) {
|
|---|
| 44 | d_printf("Value = ");
|
|---|
| 45 | }
|
|---|
| 46 | d_printf("%d\n", valvalue->v.dword);
|
|---|
| 47 | break;
|
|---|
| 48 | case REG_SZ:
|
|---|
| 49 | case REG_EXPAND_SZ:
|
|---|
| 50 | if (!raw) {
|
|---|
| 51 | d_printf("Value = \"");
|
|---|
| 52 | }
|
|---|
| 53 | d_printf("%s", valvalue->v.sz.str);
|
|---|
| 54 | if (!raw) {
|
|---|
| 55 | d_printf("\"");
|
|---|
| 56 | }
|
|---|
| 57 | d_printf("\n");
|
|---|
| 58 | break;
|
|---|
| 59 | case REG_MULTI_SZ: {
|
|---|
| 60 | uint32 j;
|
|---|
| 61 | for (j = 0; j < valvalue->v.multi_sz.num_strings; j++) {
|
|---|
| 62 | if (!raw) {
|
|---|
| 63 | d_printf("Value[%3.3d] = \"", j);
|
|---|
| 64 | }
|
|---|
| 65 | d_printf("%s", valvalue->v.multi_sz.strings[j]);
|
|---|
| 66 | if (!raw) {
|
|---|
| 67 | d_printf("\"");
|
|---|
| 68 | }
|
|---|
| 69 | d_printf("\n");
|
|---|
| 70 | }
|
|---|
| 71 | break;
|
|---|
| 72 | }
|
|---|
| 73 | case REG_BINARY:
|
|---|
| 74 | if (!raw) {
|
|---|
| 75 | d_printf("Value = ");
|
|---|
| 76 | }
|
|---|
| 77 | d_printf("%d bytes\n", (int)valvalue->v.binary.length);
|
|---|
| 78 | break;
|
|---|
| 79 | default:
|
|---|
| 80 | if (!raw) {
|
|---|
| 81 | d_printf("Value = ");
|
|---|
| 82 | }
|
|---|
| 83 | d_printf("<unprintable>\n");
|
|---|
| 84 | break;
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void print_registry_value_with_name(const char *valname,
|
|---|
| 89 | const struct registry_value *valvalue)
|
|---|
| 90 | {
|
|---|
| 91 | d_printf("Valuename = %s\n", valname);
|
|---|
| 92 | print_registry_value(valvalue, false);
|
|---|
| 93 | d_printf("\n");
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /**
|
|---|
| 97 | * Split path into hive name and subkeyname
|
|---|
| 98 | * normalizations performed:
|
|---|
| 99 | * - convert '/' to '\\'
|
|---|
| 100 | * - strip trailing '\\' chars
|
|---|
| 101 | */
|
|---|
| 102 | WERROR split_hive_key(TALLOC_CTX *ctx, const char *path, char **hivename,
|
|---|
| 103 | char **subkeyname)
|
|---|
| 104 | {
|
|---|
| 105 | char *p;
|
|---|
| 106 | const char *tmp_subkeyname;
|
|---|
| 107 |
|
|---|
| 108 | if ((path == NULL) || (hivename == NULL) || (subkeyname == NULL)) {
|
|---|
| 109 | return WERR_INVALID_PARAM;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | if (strlen(path) == 0) {
|
|---|
| 113 | return WERR_INVALID_PARAM;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | *hivename = talloc_string_sub(ctx, path, "/", "\\");
|
|---|
| 117 | if (*hivename == NULL) {
|
|---|
| 118 | return WERR_NOMEM;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /* strip trailing '\\' chars */
|
|---|
| 122 | p = strrchr(*hivename, '\\');
|
|---|
| 123 | while ((p != NULL) && (p[1] == '\0')) {
|
|---|
| 124 | *p = '\0';
|
|---|
| 125 | p = strrchr(*hivename, '\\');
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | p = strchr(*hivename, '\\');
|
|---|
| 129 |
|
|---|
| 130 | if ((p == NULL) || (*p == '\0')) {
|
|---|
| 131 | /* just the hive - no subkey given */
|
|---|
| 132 | tmp_subkeyname = "";
|
|---|
| 133 | } else {
|
|---|
| 134 | *p = '\0';
|
|---|
| 135 | tmp_subkeyname = p+1;
|
|---|
| 136 | }
|
|---|
| 137 | *subkeyname = talloc_strdup(ctx, tmp_subkeyname);
|
|---|
| 138 | if (*subkeyname == NULL) {
|
|---|
| 139 | return WERR_NOMEM;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | return WERR_OK;
|
|---|
| 143 | }
|
|---|