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