@cryptotaxi247 / netdata-1 / commits / cd0104a07

users and group names are filtered for invalid characters #261

Costa Tsaousis (ktsaou) committed Apr 19, 2016 at 01:41 UTC cd0104a07ba594b9d299b3ff728c547a29a122c2
3 files changed +272 -1
src/apps_plugin.c
+4 -1
@@ -211,7 +211,6 @@ char *strdup_debug(const char *file, int line, const char *function, const char
211
212 #endif /* NETDATA_INTERNAL_CHECKS */
213
214 -
214 // ----------------------------------------------------------------------------
215 // system functions
216 // to retrieve settings of the system
@@ -411,6 +410,8 @@ struct target *get_users_target(uid_t uid)
410 else
411 snprintf(w->name, MAX_NAME, "%s", pw->pw_name);
412
413 + netdata_fix_id(w->name);
414 +
415 w->uid = uid;
416
417 w->next = users_root_target;
@@ -447,6 +448,8 @@ struct target *get_groups_target(gid_t gid)
448 else
449 snprintf(w->name, MAX_NAME, "%s", gr->gr_name);
450
451 + netdata_fix_id(w->name);
452 +
453 w->gid = gid;
454
455 w->next = groups_root_target;
src/common.c
+266
@@ -15,10 +15,276 @@
15 #include "log.h"
16 #include "common.h"
17 #include "appconfig.h"
18 +#include "../config.h"
19
20 char *global_host_prefix = "";
21 int enable_ksm = 1;
22
23 +unsigned char netdata_keys_map[256] = {
24 + [0] = '\0', //
25 + [1] = '_', //
26 + [2] = '_', //
27 + [3] = '_', //
28 + [4] = '_', //
29 + [5] = '_', //
30 + [6] = '_', //
31 + [7] = '_', //
32 + [8] = '_', //
33 + [9] = '_', //
34 + [10] = '_', //
35 + [11] = '_', //
36 + [12] = '_', //
37 + [13] = '_', //
38 + [14] = '_', //
39 + [15] = '_', //
40 + [16] = '_', //
41 + [17] = '_', //
42 + [18] = '_', //
43 + [19] = '_', //
44 + [20] = '_', //
45 + [21] = '_', //
46 + [22] = '_', //
47 + [23] = '_', //
48 + [24] = '_', //
49 + [25] = '_', //
50 + [26] = '_', //
51 + [27] = '_', //
52 + [28] = '_', //
53 + [29] = '_', //
54 + [30] = '_', //
55 + [31] = '_', //
56 + [32] = '_', //
57 + [33] = '_', // !
58 + [34] = '_', // "
59 + [35] = '_', // #
60 + [36] = '_', // $
61 + [37] = '_', // %
62 + [38] = '_', // &
63 + [39] = '_', // '
64 + [40] = '_', // (
65 + [41] = '_', // )
66 + [42] = '_', // *
67 + [43] = '_', // +
68 + [44] = '.', // ,
69 + [45] = '-', // -
70 + [46] = '.', // .
71 + [47] = '/', // /
72 + [48] = '0', // 0
73 + [49] = '1', // 1
74 + [50] = '2', // 2
75 + [51] = '3', // 3
76 + [52] = '4', // 4
77 + [53] = '5', // 5
78 + [54] = '6', // 6
79 + [55] = '7', // 7
80 + [56] = '8', // 8
81 + [57] = '9', // 9
82 + [58] = '_', // :
83 + [59] = '_', // ;
84 + [60] = '_', // <
85 + [61] = '_', // =
86 + [62] = '_', // >
87 + [63] = '_', // ?
88 + [64] = '_', // @
89 + [65] = 'a', // A
90 + [66] = 'b', // B
91 + [67] = 'c', // C
92 + [68] = 'd', // D
93 + [69] = 'e', // E
94 + [70] = 'f', // F
95 + [71] = 'g', // G
96 + [72] = 'h', // H
97 + [73] = 'i', // I
98 + [74] = 'j', // J
99 + [75] = 'k', // K
100 + [76] = 'l', // L
101 + [77] = 'm', // M
102 + [78] = 'n', // N
103 + [79] = 'o', // O
104 + [80] = 'p', // P
105 + [81] = 'q', // Q
106 + [82] = 'r', // R
107 + [83] = 's', // S
108 + [84] = 't', // T
109 + [85] = 'u', // U
110 + [86] = 'v', // V
111 + [87] = 'w', // W
112 + [88] = 'x', // X
113 + [89] = 'y', // Y
114 + [90] = 'z', // Z
115 + [91] = '_', // [
116 + [92] = '/', // backslash
117 + [93] = '_', // ]
118 + [94] = '_', // ^
119 + [95] = '_', // _
120 + [96] = '_', // `
121 + [97] = 'a', // a
122 + [98] = 'b', // b
123 + [99] = 'c', // c
124 + [100] = 'd', // d
125 + [101] = 'e', // e
126 + [102] = 'f', // f
127 + [103] = 'g', // g
128 + [104] = 'h', // h
129 + [105] = 'i', // i
130 + [106] = 'j', // j
131 + [107] = 'k', // k
132 + [108] = 'l', // l
133 + [109] = 'm', // m
134 + [110] = 'n', // n
135 + [111] = 'o', // o
136 + [112] = 'p', // p
137 + [113] = 'q', // q
138 + [114] = 'r', // r
139 + [115] = 's', // s
140 + [116] = 't', // t
141 + [117] = 'u', // u
142 + [118] = 'v', // v
143 + [119] = 'w', // w
144 + [120] = 'x', // x
145 + [121] = 'y', // y
146 + [122] = 'z', // z
147 + [123] = '_', // {
148 + [124] = '_', // |
149 + [125] = '_', // }
150 + [126] = '_', // ~
151 + [127] = '_', //
152 + [128] = '_', //
153 + [129] = '_', //
154 + [130] = '_', //
155 + [131] = '_', //
156 + [132] = '_', //
157 + [133] = '_', //
158 + [134] = '_', //
159 + [135] = '_', //
160 + [136] = '_', //
161 + [137] = '_', //
162 + [138] = '_', //
163 + [139] = '_', //
164 + [140] = '_', //
165 + [141] = '_', //
166 + [142] = '_', //
167 + [143] = '_', //
168 + [144] = '_', //
169 + [145] = '_', //
170 + [146] = '_', //
171 + [147] = '_', //
172 + [148] = '_', //
173 + [149] = '_', //
174 + [150] = '_', //
175 + [151] = '_', //
176 + [152] = '_', //
177 + [153] = '_', //
178 + [154] = '_', //
179 + [155] = '_', //
180 + [156] = '_', //
181 + [157] = '_', //
182 + [158] = '_', //
183 + [159] = '_', //
184 + [160] = '_', //
185 + [161] = '_', //
186 + [162] = '_', //
187 + [163] = '_', //
188 + [164] = '_', //
189 + [165] = '_', //
190 + [166] = '_', //
191 + [167] = '_', //
192 + [168] = '_', //
193 + [169] = '_', //
194 + [170] = '_', //
195 + [171] = '_', //
196 + [172] = '_', //
197 + [173] = '_', //
198 + [174] = '_', //
199 + [175] = '_', //
200 + [176] = '_', //
201 + [177] = '_', //
202 + [178] = '_', //
203 + [179] = '_', //
204 + [180] = '_', //
205 + [181] = '_', //
206 + [182] = '_', //
207 + [183] = '_', //
208 + [184] = '_', //
209 + [185] = '_', //
210 + [186] = '_', //
211 + [187] = '_', //
212 + [188] = '_', //
213 + [189] = '_', //
214 + [190] = '_', //
215 + [191] = '_', //
216 + [192] = '_', //
217 + [193] = '_', //
218 + [194] = '_', //
219 + [195] = '_', //
220 + [196] = '_', //
221 + [197] = '_', //
222 + [198] = '_', //
223 + [199] = '_', //
224 + [200] = '_', //
225 + [201] = '_', //
226 + [202] = '_', //
227 + [203] = '_', //
228 + [204] = '_', //
229 + [205] = '_', //
230 + [206] = '_', //
231 + [207] = '_', //
232 + [208] = '_', //
233 + [209] = '_', //
234 + [210] = '_', //
235 + [211] = '_', //
236 + [212] = '_', //
237 + [213] = '_', //
238 + [214] = '_', //
239 + [215] = '_', //
240 + [216] = '_', //
241 + [217] = '_', //
242 + [218] = '_', //
243 + [219] = '_', //
244 + [220] = '_', //
245 + [221] = '_', //
246 + [222] = '_', //
247 + [223] = '_', //
248 + [224] = '_', //
249 + [225] = '_', //
250 + [226] = '_', //
251 + [227] = '_', //
252 + [228] = '_', //
253 + [229] = '_', //
254 + [230] = '_', //
255 + [231] = '_', //
256 + [232] = '_', //
257 + [233] = '_', //
258 + [234] = '_', //
259 + [235] = '_', //
260 + [236] = '_', //
261 + [237] = '_', //
262 + [238] = '_', //
263 + [239] = '_', //
264 + [240] = '_', //
265 + [241] = '_', //
266 + [242] = '_', //
267 + [243] = '_', //
268 + [244] = '_', //
269 + [245] = '_', //
270 + [246] = '_', //
271 + [247] = '_', //
272 + [248] = '_', //
273 + [249] = '_', //
274 + [250] = '_', //
275 + [251] = '_', //
276 + [252] = '_', //
277 + [253] = '_', //
278 + [254] = '_', //
279 + [255] = '_' //
280 +};
281 +
282 +// make sure the supplied string
283 +// is good for a netdata chart/dimension ID/NAME
284 +void netdata_fix_id(char *s) {
285 + while((*s = netdata_keys_map[(unsigned char)*s])) s++;
286 +}
287 +
288 /*
289 // http://stackoverflow.com/questions/7666509/hash-function-for-string
290 uint32_t simple_hash(const char *name)
src/common.h
+2
@@ -15,6 +15,8 @@
15 #define abs(x) ((x < 0)? -x : x)
16 #define usecdiff(now, last) (((((now)->tv_sec * 1000000ULL) + (now)->tv_usec) - (((last)->tv_sec * 1000000ULL) + (last)->tv_usec)))
17
18 +extern void netdata_fix_id(char *s);
19 +
20 extern uint32_t simple_hash(const char *name);
21 extern void strreverse(char* begin, char* end);
22 extern char *mystrsep(char **ptr, char *s);