RIP BOOL. Convert BOOL -> bool. I found a few interesting
[amitay/samba.git] / source3 / 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 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_REGISTRY
24
25 extern REGISTRY_OPS smbconf_reg_ops;
26
27 const char *reg_type_lookup(enum winreg_Type type)
28 {
29         const char *result;
30
31         switch(type) {
32         case REG_NONE:
33                 result = "REG_NONE";
34                 break;
35         case REG_SZ:
36                 result = "REG_SZ";
37                 break;
38         case REG_EXPAND_SZ:
39                 result = "REG_EXPAND_SZ";
40                 break;
41         case REG_BINARY:
42                 result = "REG_BINARY";
43                 break;
44         case REG_DWORD:
45                 result = "REG_DWORD";
46                 break;
47         case REG_DWORD_BIG_ENDIAN:
48                 result = "REG_DWORD_BIG_ENDIAN";
49                 break;
50         case REG_LINK:
51                 result = "REG_LINK";
52                 break;
53         case REG_MULTI_SZ:
54                 result = "REG_MULTI_SZ";
55                 break;
56         case REG_RESOURCE_LIST:
57                 result = "REG_RESOURCE_LIST";
58                 break;
59         case REG_FULL_RESOURCE_DESCRIPTOR:
60                 result = "REG_FULL_RESOURCE_DESCRIPTOR";
61                 break;
62         case REG_RESOURCE_REQUIREMENTS_LIST:
63                 result = "REG_RESOURCE_REQUIREMENTS_LIST";
64                 break;
65         case REG_QWORD:
66                 result = "REG_QWORD";
67                 break;
68         default:
69                 result = "REG TYPE IS UNKNOWN";
70                 break;
71         }
72         return result;
73 }
74
75 WERROR reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
76                          uint32 *num_values, char ***values)
77 {
78         const smb_ucs2_t *p = (const smb_ucs2_t *)buf;
79         *num_values = 0;
80
81         /*
82          * Make sure that a talloc context for the strings retrieved exists
83          */
84
85         if (!(*values = TALLOC_ARRAY(mem_ctx, char *, 1))) {
86                 return WERR_NOMEM;
87         }
88
89         len /= 2;               /* buf is a set of UCS2 strings */
90
91         while (len > 0) {
92                 char *val;
93                 size_t dstlen, thislen;
94
95                 thislen = strnlen_w(p, len) + 1;
96                 dstlen = convert_string_allocate(*values, CH_UTF16LE, CH_UNIX,
97                                                  p, thislen*2, (void *)&val,
98                                                  True);
99                 if (dstlen == (size_t)-1) {
100                         TALLOC_FREE(*values);
101                         return WERR_NOMEM;
102                 }
103
104                 ADD_TO_ARRAY(*values, char *, val, values, num_values);
105                 if (*values == NULL) {
106                         return WERR_NOMEM;
107                 }
108
109                 p += thislen;
110                 len -= thislen;
111         }
112
113         return WERR_OK;
114 }
115
116 void normalize_dbkey(char *key)
117 {
118         size_t len = strlen(key);
119         string_sub(key, "\\", "/", len+1);
120         strupper_m(key);
121 }
122
123 /*
124  * check whether a given value name is forbidden in registry (smbconf)
125  */
126 bool registry_smbconf_valname_forbidden(const char *valname)
127 {
128         /* hard code the list of forbidden names here for now */
129         const char *forbidden_valnames[] = {
130                 "include",
131                 "lock directory",
132                 "lock dir",
133                 NULL
134         };
135         const char **forbidden = NULL;
136
137         for (forbidden = forbidden_valnames; *forbidden != NULL; forbidden++) {
138                 if (strwicmp(valname, *forbidden) == 0) {
139                         return True;
140                 }
141         }
142         return False;
143 }