r23801: The FSF has moved around a lot. This fixes their Mass Ave address.
[metze/samba/wip.git] / source / lib / util_reg.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * Registry helper routines
4  * Copyright (C) Volker Lendecke 2006
5  * 
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; either version 3 of the License, or (at your option)
9  * any later version.
10  * 
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include "includes.h"
21
22 extern REGISTRY_OPS smbconf_reg_ops;
23
24 const char *reg_type_lookup(enum winreg_Type type)
25 {
26         const char *result;
27
28         switch(type) {
29         case REG_NONE:
30                 result = "REG_NONE";
31                 break;
32         case REG_SZ:
33                 result = "REG_SZ";
34                 break;
35         case REG_EXPAND_SZ:
36                 result = "REG_EXPAND_SZ";
37                 break;
38         case REG_BINARY:
39                 result = "REG_BINARY";
40                 break;
41         case REG_DWORD:
42                 result = "REG_DWORD";
43                 break;
44         case REG_DWORD_BIG_ENDIAN:
45                 result = "REG_DWORD_BIG_ENDIAN";
46                 break;
47         case REG_LINK:
48                 result = "REG_LINK";
49                 break;
50         case REG_MULTI_SZ:
51                 result = "REG_MULTI_SZ";
52                 break;
53         case REG_RESOURCE_LIST:
54                 result = "REG_RESOURCE_LIST";
55                 break;
56         case REG_FULL_RESOURCE_DESCRIPTOR:
57                 result = "REG_FULL_RESOURCE_DESCRIPTOR";
58                 break;
59         case REG_RESOURCE_REQUIREMENTS_LIST:
60                 result = "REG_RESOURCE_REQUIREMENTS_LIST";
61                 break;
62         case REG_QWORD:
63                 result = "REG_QWORD";
64                 break;
65         default:
66                 result = "REG TYPE IS UNKNOWN";
67                 break;
68         }
69         return result;
70 }
71
72 WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
73                          uint32 *num_values, char ***values)
74 {
75         const smb_ucs2_t *p = (const smb_ucs2_t *)buf;
76         *num_values = 0;
77
78         /*
79          * Make sure that a talloc context for the strings retrieved exists
80          */
81
82         if (!(*values = TALLOC_ARRAY(mem_ctx, char *, 1))) {
83                 return WERR_NOMEM;
84         }
85
86         len /= 2;               /* buf is a set of UCS2 strings */
87
88         while (len > 0) {
89                 char *val;
90                 size_t dstlen, thislen;
91
92                 thislen = strnlen_w(p, len) + 1;
93                 dstlen = convert_string_allocate(*values, CH_UTF16LE, CH_UNIX,
94                                                  p, thislen*2, (void *)&val,
95                                                  True);
96                 if (dstlen == (size_t)-1) {
97                         TALLOC_FREE(*values);
98                         return WERR_NOMEM;
99                 }
100
101                 ADD_TO_ARRAY(*values, char *, val, values, num_values);
102                 if (*values == NULL) {
103                         return WERR_NOMEM;
104                 }
105
106                 p += thislen;
107                 len -= thislen;
108         }
109
110         return WERR_OK;
111 }
112
113 void normalize_dbkey(char *key)
114 {
115         size_t len = strlen(key);
116         string_sub(key, "\\", "/", len+1);
117         strupper_m(key);
118 }
119
120 /*
121  * check whether a given value name is forbidden in registry (smbconf)
122  */
123 BOOL registry_smbconf_valname_forbidden(const char *valname)
124 {
125         /* hard code the list of forbidden names here for now */
126         const char *forbidden_valnames[] = {
127                 "include",
128                 "lock directory",
129                 "lock dir",
130                 NULL
131         };
132         const char **forbidden = NULL;
133
134         for (forbidden = forbidden_valnames; *forbidden != NULL; forbidden++) {
135                 if (strwicmp(valname, *forbidden) == 0) {
136                         return True;
137                 }
138         }
139         return False;
140 }