]> git.pld-linux.org Git - packages/openchange.git/blob - samba-4.4.patch
- release 15
[packages/openchange.git] / samba-4.4.patch
1 diff -up openchange-openchange-2.3-VULCAN/configure.ac.samba44 openchange-openchange-2.3-VULCAN/configure.ac
2 --- openchange-openchange-2.3-VULCAN/configure.ac.samba44       2016-02-09 11:51:31.089982153 +0100
3 +++ openchange-openchange-2.3-VULCAN/configure.ac       2016-02-09 12:04:55.985948047 +0100
4 @@ -657,10 +657,11 @@ AC_CHECK_LIB([popt], [poptFreeContext],
5                enable_libpopt="no"
6               ])
7  
8 +mapitest=0
9  if test x"$enable_libpopt" = x"yes"; then
10         if test x"$enable_libmapiadmin" = x"yes"; then
11            openchangepfadmin=1
12 -          mapitest=1
13 +          mapitest=0
14         fi
15  
16         if test x"$enable_libocpf" = x"yes"; then
17 @@ -692,7 +693,7 @@ OC_RULE_ADD(mapipropsdump, TOOLS)
18  OC_RULE_ADD(exchange2ical, TOOLS)
19  #OC_RULE_ADD(rpcextract, TOOLS)
20  OC_RULE_ADD(openchangepfadmin, TOOLS)
21 -OC_RULE_ADD(mapitest, TOOLS)
22 +#OC_RULE_ADD(mapitest, TOOLS)
23  OC_RULE_ADD(mapiprofile, TOOLS)
24  OC_RULE_ADD(openchangemapidump, TOOLS)
25  OC_RULE_ADD(schemaIDGUID, TOOLS)
26 diff -up openchange-openchange-2.3-VULCAN/libexchange2ical/exchange2ical_property.c.samba44 openchange-openchange-2.3-VULCAN/libexchange2ical/exchange2ical_property.c
27 --- openchange-openchange-2.3-VULCAN/libexchange2ical/exchange2ical_property.c.samba44  2016-02-09 11:46:45.211994266 +0100
28 +++ openchange-openchange-2.3-VULCAN/libexchange2ical/exchange2ical_property.c  2016-02-09 12:04:07.330950109 +0100
29 @@ -22,6 +22,37 @@
30  #include "libexchange2ical/libexchange2ical.h"
31  #include <ldb.h>
32  
33 +static void openchange_all_string_sub(char *s,const char *pattern,const char *insert, size_t len)
34 +{
35 +       char *p;
36 +       ssize_t ls,lp,li;
37 +
38 +       if (!insert || !pattern || !s)
39 +               return;
40 +
41 +       ls = (ssize_t)strlen(s);
42 +       lp = (ssize_t)strlen(pattern);
43 +       li = (ssize_t)strlen(insert);
44 +
45 +       if (!*pattern)
46 +               return;
47 +
48 +       if (len == 0)
49 +               len = ls + 1; /* len is number of *bytes* */
50 +
51 +       while (lp <= ls && (p = strstr_m(s,pattern))) {
52 +               if (ls + (li-lp) >= len) {
53 +                       break;
54 +               }
55 +               if (li != lp) {
56 +                       memmove(p+li,p+lp,strlen(p+lp)+1);
57 +               }
58 +               memcpy(p, insert, li);
59 +               s = p + li;
60 +               ls += (li-lp);
61 +       }
62 +}
63 +
64  struct RRULE_byday {
65         uint16_t        DayOfWeek;
66         const char      *DayName;
67 @@ -1019,7 +1050,7 @@ void ical_property_RESOURCES(struct exch
68         if (!exchange2ical->NonSendableBcc) return;
69         
70         NonSendableBcc = talloc_strdup(exchange2ical->mem_ctx, exchange2ical->NonSendableBcc);
71 -       all_string_sub(NonSendableBcc, ";", ",", 0);
72 +       openchange_all_string_sub(NonSendableBcc, ";", ",", 0);
73         prop = icalproperty_new_resources(NonSendableBcc);
74         icalcomponent_add_property(exchange2ical->vevent, prop);
75         talloc_free(NonSendableBcc);
76 diff -up openchange-openchange-2.3-VULCAN/libmapiadmin/mapiadmin_user.c.samba44 openchange-openchange-2.3-VULCAN/libmapiadmin/mapiadmin_user.c
77 --- openchange-openchange-2.3-VULCAN/libmapiadmin/mapiadmin_user.c.samba44      2015-05-16 17:22:04.000000000 +0200
78 +++ openchange-openchange-2.3-VULCAN/libmapiadmin/mapiadmin_user.c      2016-02-08 22:19:17.750956440 +0100
79 @@ -24,19 +24,251 @@
80     along with this program.  If not, see <http://www.gnu.org/licenses/>.
81   */
82  
83 +#include <ldb.h>
84 +
85  #include "libmapiadmin/libmapiadmin.h"
86  
87  #include <param.h>
88  #include <credentials.h>
89 +#include <ctype.h>
90  #include <ldb_errors.h>
91  #include <ldb_wrap.h>
92 -#include <ldap_ndr.h>
93  
94  #include <gen_ndr/ndr_samr.h>
95  #include <gen_ndr/ndr_samr_c.h>
96  
97  #include <time.h>
98  
99 +static ssize_t openchange_sys_read(int fd, void *buf, size_t count)
100 +{
101 +       ssize_t ret;
102 +
103 +       do {
104 +               ret = read(fd, buf, count);
105 +       } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
106 +                              errno == EWOULDBLOCK));
107 +
108 +       return ret;
109 +}
110 +
111 +static ssize_t openchange_read_data(int fd, void *buffer, size_t n)
112 +{
113 +       ssize_t nread;
114 +
115 +       nread = 0;
116 +
117 +       while (nread < n) {
118 +               ssize_t ret;
119 +               ret = openchange_sys_read(fd, ((char *)buffer) + nread, n - nread);
120 +               if (ret <= 0) {
121 +                       return ret;
122 +               }
123 +               nread += ret;
124 +       }
125 +
126 +       return nread;
127 +}
128 +
129 +static int openchange_urand_fd = -1;
130 +static void openchange_open_urandom(void)
131 +{
132 +       if (openchange_urand_fd != -1) {
133 +               return;
134 +       }
135 +       openchange_urand_fd = open( "/dev/urandom", O_RDONLY,0);
136 +       if (openchange_urand_fd == -1) {
137 +               abort();
138 +       }
139 +}
140 +
141 +static void openchange_generate_random_buffer(uint8_t *out, int len)
142 +{
143 +       ssize_t rw_ret;
144 +
145 +       openchange_open_urandom();
146 +
147 +       rw_ret = openchange_read_data(openchange_urand_fd, out, len);
148 +       if (rw_ret != len) {
149 +               abort();
150 +       }
151 +}
152 +
153 +static enum ndr_err_code openchange_ndr_push_dom_sid(struct ndr_push *ndr, int ndr_flags, const struct dom_sid *r)
154 +{
155 +       uint32_t cntr_sub_auths_0;
156 +       if (ndr_flags & NDR_SCALARS) {
157 +               NDR_CHECK(ndr_push_align(ndr, 4));
158 +               NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, r->sid_rev_num));
159 +               NDR_CHECK(ndr_push_int8(ndr, NDR_SCALARS, r->num_auths));
160 +               NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, r->id_auth, 6));
161 +               if (r->num_auths < 0 || r->num_auths > ARRAY_SIZE(r->sub_auths)) {
162 +                       return ndr_push_error(ndr, NDR_ERR_RANGE, "value out of range");
163 +               }
164 +               for (cntr_sub_auths_0 = 0; cntr_sub_auths_0 < r->num_auths; cntr_sub_auths_0++) {
165 +                       NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, r->sub_auths[cntr_sub_auths_0]));
166 +               }
167 +       }
168 +       return NDR_ERR_SUCCESS;
169 +}
170 +
171 +static char *openchange_ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
172 +{
173 +#undef ldb_val
174 +       DATA_BLOB blob;
175 +       struct ldb_val val;
176 +       enum ndr_err_code ndr_err;
177 +       char *ret;
178 +       ndr_err = ndr_push_struct_blob(&blob, mem_ctx, sid,
179 +                                      (ndr_push_flags_fn_t)openchange_ndr_push_dom_sid);
180 +       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
181 +               return NULL;
182 +       }
183 +       val.data = blob.data;
184 +       val.length = blob.length;
185 +       ret = ldb_binary_encode(mem_ctx, val);
186 +       data_blob_free(&blob);
187 +       return ret;
188 +}
189 +
190 +static bool openchange_check_password_quality(const char *pwd)
191 +{
192 +       size_t ofs = 0;
193 +       size_t num_chars = 0;
194 +       size_t num_digits = 0;
195 +       size_t num_upper = 0;
196 +       size_t num_lower = 0;
197 +       size_t num_nonalpha = 0;
198 +       size_t num_unicode = 0;
199 +       size_t num_categories = 0;
200 +
201 +       if (pwd == NULL) {
202 +               return false;
203 +       }
204 +
205 +       while (true) {
206 +               const char *s = &pwd[ofs];
207 +               size_t len = 0;
208 +               codepoint_t c;
209 +
210 +               c = next_codepoint(s, &len);
211 +               if (c == INVALID_CODEPOINT) {
212 +                       return false;
213 +               } else if (c == 0) {
214 +                       break;
215 +               }
216 +               ofs += len;
217 +               num_chars += 1;
218 +
219 +               if (len == 1) {
220 +                       const char *na = "~!@#$%^&*_-+=`|\\(){}[]:;\"'<>,.?/";
221 +
222 +                       if (isdigit(c)) {
223 +                               num_digits += 1;
224 +                               continue;
225 +                       }
226 +
227 +                       if (isupper(c)) {
228 +                               num_upper += 1;
229 +                               continue;
230 +                       }
231 +
232 +                       if (islower(c)) {
233 +                               num_lower += 1;
234 +                               continue;
235 +                       }
236 +
237 +                       if (strchr(na, c)) {
238 +                               num_nonalpha += 1;
239 +                               continue;
240 +                       }
241 +
242 +                       /*
243 +                        * the rest does not belong to
244 +                        * a category.
245 +                        */
246 +                       continue;
247 +               }
248 +
249 +               if (isupper_m(c)) {
250 +                       num_upper += 1;
251 +                       continue;
252 +               }
253 +
254 +               if (islower_m(c)) {
255 +                       num_lower += 1;
256 +                       continue;
257 +               }
258 +
259 +               /*
260 +                * Note: for now do not check if the unicode category is
261 +                *       alphabetic character
262 +                *
263 +                * We would have to import the details from
264 +                * ftp://ftp.unicode.org/Public/6.3.0/ucd/UnicodeData-6.3.0d1.txt
265 +                */
266 +               num_unicode += 1;
267 +               continue;
268 +       }
269 +
270 +       if (num_digits > 0) {
271 +               num_categories += 1;
272 +       }
273 +       if (num_upper > 0) {
274 +               num_categories += 1;
275 +       }
276 +       if (num_lower > 0) {
277 +               num_categories += 1;
278 +       }
279 +       if (num_nonalpha > 0) {
280 +               num_categories += 1;
281 +       }
282 +       if (num_unicode > 0) {
283 +               num_categories += 1;
284 +       }
285 +
286 +       if (num_categories >= 3) {
287 +               return true;
288 +       }
289 +
290 +       return false;
291 +}
292 +
293 +static char *openchange_generate_random_str_list(TALLOC_CTX *mem_ctx, size_t len, const char *list)
294 +{
295 +       size_t i;
296 +       size_t list_len = strlen(list);
297 +
298 +       char *retstr = talloc_array(mem_ctx, char, len + 1);
299 +       if (!retstr) return NULL;
300 +
301 +       openchange_generate_random_buffer((uint8_t *)retstr, len);
302 +       for (i = 0; i < len; i++) {
303 +               retstr[i] = list[retstr[i] % list_len];
304 +       }
305 +       retstr[i] = '\0';
306 +
307 +       return retstr;
308 +}
309 +
310 +static char *openchange_generate_random_str(TALLOC_CTX *mem_ctx, size_t len)
311 +{
312 +       char *retstr;
313 +       const char *c_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_-#.,";
314 +
315 +again:
316 +       retstr = openchange_generate_random_str_list(mem_ctx, len, c_list);
317 +       if (!retstr) return NULL;
318 +
319 +       /* we need to make sure the random string passes basic quality tests
320 +          or it might be rejected by windows as a password */
321 +       if (len >= 7 && !openchange_check_password_quality(retstr)) {
322 +               talloc_free(retstr);
323 +               goto again;
324 +       }
325 +
326 +       return retstr;
327 +}
328 +
329  /**
330         \file
331         User management functions for mapiadmin
332 @@ -232,10 +464,10 @@ _PUBLIC_ enum MAPISTATUS mapiadmin_user_
333         /* Search the user_dn */
334         account_dn = samdb_search_dn(remote_ldb, mem_ctx, NULL, 
335                                      "(&(objectSid=%s)(objectClass=user))", 
336 -                                    ldap_encode_ndr_dom_sid(mem_ctx, dom_sid));
337 +                                    openchange_ldap_encode_ndr_dom_sid(mem_ctx, dom_sid));
338  
339         ret = ldb_search(remote_ldb, mem_ctx, &res, account_dn, LDB_SCOPE_SUBTREE, dom_attrs, "(objectSid=%s)",
340 -                        ldap_encode_ndr_dom_sid(mem_ctx, dom_sid));
341 +                        openchange_ldap_encode_ndr_dom_sid(mem_ctx, dom_sid));
342         MAPI_RETVAL_IF(ret != LDB_SUCCESS, MAPI_E_NOT_FOUND, mem_ctx);
343         MAPI_RETVAL_IF(res->count != 1, MAPI_E_NOT_FOUND, mem_ctx);
344  
345 @@ -422,7 +654,7 @@ again:
346         }
347  
348         if (!mapiadmin_ctx->password) {
349 -               mapiadmin_ctx->password = generate_random_str(mapiadmin_ctx->user_ctx, MAX(8, policy_min_pw_len));
350 +               mapiadmin_ctx->password = openchange_generate_random_str(mapiadmin_ctx->user_ctx, MAX(8, policy_min_pw_len));
351         }
352  
353         OC_DEBUG(3, "Setting account password '%s'", mapiadmin_ctx->password);
354 diff -up openchange-openchange-2.3-VULCAN/libmapi/mapidump.c.samba44 openchange-openchange-2.3-VULCAN/libmapi/mapidump.c
355 --- openchange-openchange-2.3-VULCAN/libmapi/mapidump.c.samba44 2016-02-09 11:03:18.565104717 +0100
356 +++ openchange-openchange-2.3-VULCAN/libmapi/mapidump.c 2016-02-09 11:03:29.508104254 +0100
357 @@ -119,7 +119,7 @@ _PUBLIC_ void mapidump_SPropValue(struct
358                 data = get_SPropValue_data(&lpProp);
359                 if (data) {
360                         printf("%s%s:\n", sep?sep:"", proptag);
361 -                       dump_data(0, ((const struct Binary_r *)data)->lpb, ((const struct Binary_r *)data)->cb);
362 +                       oc_dump_data(0, ((const struct Binary_r *)data)->lpb, ((const struct Binary_r *)data)->cb);
363                 } else {
364                         printf("%s%s: (NULL)\n", sep?sep:"", proptag);
365                 }
366 @@ -153,7 +153,7 @@ _PUBLIC_ void mapidump_SPropValue(struct
367                 printf("%s%s: ARRAY(%d)\n", sep?sep:"", proptag, BinaryArray_r->cValues);
368                 for (i = 0; i < BinaryArray_r->cValues; i++) {
369                         printf("\tPT_MV_BINARY [%d]:\n", i);
370 -                       dump_data(0, BinaryArray_r->lpbin[i].lpb, BinaryArray_r->lpbin[i].cb);
371 +                       oc_dump_data(0, BinaryArray_r->lpbin[i].lpb, BinaryArray_r->lpbin[i].cb);
372                 }
373                 break;
374         default:
375 diff -up openchange-openchange-2.3-VULCAN/libmapi/mapi_object.c.samba44 openchange-openchange-2.3-VULCAN/libmapi/mapi_object.c
376 --- openchange-openchange-2.3-VULCAN/libmapi/mapi_object.c.samba44      2016-02-09 11:02:57.062105628 +0100
377 +++ openchange-openchange-2.3-VULCAN/libmapi/mapi_object.c      2016-02-09 11:03:01.012105461 +0100
378 @@ -412,7 +412,7 @@ _PUBLIC_ enum MAPISTATUS mapi_object_boo
379         while (bookmark) {
380                 OC_DEBUG(0, "mapi_object_bookmark {");
381                 OC_DEBUG(0, ".index == %u", bookmark->index);
382 -               dump_data(0, bookmark->bin.lpb, bookmark->bin.cb);
383 +               oc_dump_data(0, bookmark->bin.lpb, bookmark->bin.cb);
384                 OC_DEBUG(0, "};");
385  
386                 bookmark = bookmark->next;
387 diff -up openchange-openchange-2.3-VULCAN/libmapi/oc_log.c.samba44 openchange-openchange-2.3-VULCAN/libmapi/oc_log.c
388 --- openchange-openchange-2.3-VULCAN/libmapi/oc_log.c.samba44   2016-02-09 10:49:20.292140237 +0100
389 +++ openchange-openchange-2.3-VULCAN/libmapi/oc_log.c   2016-02-09 11:30:13.912036271 +0100
390 @@ -21,6 +21,12 @@
391  
392  #include "libmapi/libmapi.h"
393  #include <stdio.h>
394 +#include <stdlib.h>
395 +#include <ctype.h>
396 +
397 +#ifndef MIN
398 +#define MIN(a,b) ((a)<(b)?(a):(b))
399 +#endif
400  
401  int _oc_log_samba_level = 0;
402  
403 @@ -84,3 +90,119 @@ void oc_log_init_server(const char *prog
404  {
405         setup_logging(progname, DEBUG_FILE);
406  }
407 +
408 +void oc_panic(const char *why)
409 +{
410 +       if (why) {
411 +               fprintf(stderr, "PANIC: %s\n", why);
412 +               fflush(stderr);
413 +       }
414 +
415 +       abort();
416 +}
417 +static void oc_debugadd_cb(const char *buf, void *private_data)
418 +{
419 +       int *plevel = (int *)private_data;
420 +       if (plevel && *plevel <= _oc_log_samba_level) {
421 +               printf ("%s", buf);
422 +       }
423 +}
424 +
425 +static void oc_print_asc_cb(const uint8_t *buf, int len,
426 +                           void (*cb)(const char *buf, void *private_data),
427 +                           void *private_data)
428 +{
429 +       int i;
430 +       char s[2];
431 +       s[1] = 0;
432 +
433 +       for (i=0; i<len; i++) {
434 +               s[0] = isprint(buf[i]) ? buf[i] : '.';
435 +               cb(s, private_data);
436 +       }
437 +}
438 +
439 +static void oc_dump_data_cb(const uint8_t *buf, int len,
440 +                           bool omit_zero_bytes,
441 +                           void (*cb)(const char *buf, void *private_data),
442 +                           void *private_data)
443 +{
444 +       int i=0;
445 +       static const uint8_t empty[16] = { 0, };
446 +       bool skipped = false;
447 +       char tmp[16];
448 +
449 +       if (len<=0) return;
450 +
451 +       for (i=0;i<len;) {
452 +
453 +               if (i%16 == 0) {
454 +                       if ((omit_zero_bytes == true) &&
455 +                           (i > 0) &&
456 +                           (len > i+16) &&
457 +                           (memcmp(&buf[i], &empty, 16) == 0))
458 +                       {
459 +                               i +=16;
460 +                               continue;
461 +                       }
462 +
463 +                       if (i<len)  {
464 +                               snprintf(tmp, sizeof(tmp), "[%04X] ", i);
465 +                               cb(tmp, private_data);
466 +                       }
467 +               }
468 +
469 +               snprintf(tmp, sizeof(tmp), "%02X ", (int)buf[i]);
470 +               cb(tmp, private_data);
471 +               i++;
472 +               if (i%8 == 0) {
473 +                       cb("  ", private_data);
474 +               }
475 +               if (i%16 == 0) {
476 +
477 +                       oc_print_asc_cb(&buf[i-16], 8, cb, private_data);
478 +                       cb(" ", private_data);
479 +                       oc_print_asc_cb(&buf[i-8], 8, cb, private_data);
480 +                       cb("\n", private_data);
481 +
482 +                       if ((omit_zero_bytes == true) &&
483 +                           (len > i+16) &&
484 +                           (memcmp(&buf[i], &empty, 16) == 0)) {
485 +                               if (!skipped) {
486 +                                       cb("skipping zero buffer bytes\n",
487 +                                          private_data);
488 +                                       skipped = true;
489 +                               }
490 +                       }
491 +               }
492 +       }
493 +
494 +       if (i%16) {
495 +               int n;
496 +               n = 16 - (i%16);
497 +               cb("  ", private_data);
498 +               if (n>8) {
499 +                       cb(" ", private_data);
500 +               }
501 +               while (n--) {
502 +                       cb("   ", private_data);
503 +               }
504 +               n = MIN(8,i%16);
505 +               oc_print_asc_cb(&buf[i-(i%16)], n, cb, private_data);
506 +               cb(" ", private_data);
507 +               n = (i%16) - n;
508 +               if (n>0) {
509 +                       oc_print_asc_cb(&buf[i-n], n, cb, private_data);
510 +               }
511 +               cb("\n", private_data);
512 +       }
513 +
514 +}
515 +
516 +void oc_dump_data(int level, const uint8_t *buf,int len)
517 +{
518 +       if (_oc_log_samba_level < level || !buf || !len)
519 +               return;
520 +
521 +       oc_dump_data_cb(buf, len, false, oc_debugadd_cb, &level);
522 +}
523 diff -up openchange-openchange-2.3-VULCAN/libmapi/oc_log.h.samba44 openchange-openchange-2.3-VULCAN/libmapi/oc_log.h
524 --- openchange-openchange-2.3-VULCAN/libmapi/oc_log.h.samba44   2016-02-09 10:49:16.132140414 +0100
525 +++ openchange-openchange-2.3-VULCAN/libmapi/oc_log.h   2016-02-09 10:51:57.121133592 +0100
526 @@ -79,4 +79,7 @@ void oc_log_init_server(const char *prog
527  
528  extern int _oc_log_samba_level; /* Private, do not change it other than by SetMAPIDebugLevel() */
529  
530 +void oc_panic(const char *why);
531 +void oc_dump_data(int level, const uint8_t *buf,int len);
532 +
533  #endif /* _OC_LOG_H_ */
534 diff -up openchange-openchange-2.3-VULCAN/libmapi/property.c.samba44 openchange-openchange-2.3-VULCAN/libmapi/property.c
535 --- openchange-openchange-2.3-VULCAN/libmapi/property.c.samba44 2016-02-09 10:46:51.040146561 +0100
536 +++ openchange-openchange-2.3-VULCAN/libmapi/property.c 2016-02-09 10:48:47.626141621 +0100
537 @@ -777,7 +777,7 @@ _PUBLIC_ void mapi_copy_spropvalues(TALL
538                                 // TODO: Replace this with OC_PANIC() macro when it gets visible in libmapi too
539                                 OC_DEBUG(0, "Unexpected multi-value property type: %s.",
540                                                 get_proptag_name(source_value->ulPropTag));
541 -                               smb_panic("Unexpected multi-value property type while copying 'struct SPropValue'");
542 +                               oc_panic("Unexpected multi-value property type while copying 'struct SPropValue'");
543                         }
544                 }
545         }
546 diff -up openchange-openchange-2.3-VULCAN/libmapi/socket/interface.c.samba44 openchange-openchange-2.3-VULCAN/libmapi/socket/interface.c
547 --- openchange-openchange-2.3-VULCAN/libmapi/socket/interface.c.samba44 2016-02-09 11:09:43.147088421 +0100
548 +++ openchange-openchange-2.3-VULCAN/libmapi/socket/interface.c 2016-02-09 11:31:47.664032298 +0100
549 @@ -90,6 +90,213 @@ static void add_interface(TALLOC_CTX *me
550         OC_DEBUG(2, "added interface ip=%s nmask=%s", iface->ip_s, iface->nmask_s);
551  }
552  
553 +enum oc_protocol_types {
554 +       PROTOCOL_DEFAULT=-1,
555 +       PROTOCOL_NONE=0,
556 +       PROTOCOL_CORE,
557 +       PROTOCOL_COREPLUS,
558 +       PROTOCOL_LANMAN1,
559 +       PROTOCOL_LANMAN2,
560 +       PROTOCOL_NT1,
561 +       PROTOCOL_SMB2_02,
562 +       PROTOCOL_SMB2_10,
563 +       PROTOCOL_SMB2_22,
564 +       PROTOCOL_SMB2_24,
565 +       PROTOCOL_SMB3_00,
566 +       PROTOCOL_SMB3_02,
567 +       PROTOCOL_SMB3_10,
568 +       PROTOCOL_SMB3_11
569 +};
570 +
571 +static int openchange_null_match(const char *p)
572 +{
573 +       for (;*p;p++) {
574 +               if (*p != '*' &&
575 +                   *p != '<' &&
576 +                   *p != '"' &&
577 +                   *p != '>') return -1;
578 +       }
579 +       return 0;
580 +}
581 +
582 +/*
583 +  the max_n structure is purely for efficiency, it doesn't contribute
584 +  to the matching algorithm except by ensuring that the algorithm does
585 +  not grow exponentially
586 +*/
587 +struct max_n {
588 +       const char *predot;
589 +       const char *postdot;
590 +};
591 +
592 +
593 +/*
594 +  p and n are the pattern and string being matched. The max_n array is
595 +  an optimisation only. The ldot pointer is NULL if the string does
596 +  not contain a '.', otherwise it points at the last dot in 'n'.
597 +*/
598 +static int openchange_ms_fnmatch_core(const char *p, const char *n, 
599 +                                     struct max_n *max_n, const char *ldot)
600 +{
601 +       codepoint_t c, c2;
602 +       int i;
603 +       size_t size, size_n;
604 +
605 +       while ((c = next_codepoint(p, &size))) {
606 +               p += size;
607 +
608 +               switch (c) {
609 +               case '*':
610 +                       /* a '*' matches zero or more characters of any type */
611 +                       if (max_n->predot && max_n->predot <= n) {
612 +                               return openchange_null_match(p);
613 +                       }
614 +                       for (i=0; n[i]; i += size_n) {
615 +                               next_codepoint(n+i, &size_n);
616 +                               if (openchange_ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) {
617 +                                       return 0;
618 +                               }
619 +                       }
620 +                       if (!max_n->predot || max_n->predot > n) max_n->predot = n;
621 +                       return openchange_null_match(p);
622 +
623 +               case '<':
624 +                       /* a '<' matches zero or more characters of
625 +                          any type, but stops matching at the last
626 +                          '.' in the string. */
627 +                       if (max_n->predot && max_n->predot <= n) {
628 +                               return openchange_null_match(p);
629 +                       }
630 +                       if (max_n->postdot && max_n->postdot <= n && n <= ldot) {
631 +                               return -1;
632 +                       }
633 +                       for (i=0; n[i]; i += size_n) {
634 +                               next_codepoint(n+i, &size_n);
635 +                               if (openchange_ms_fnmatch_core(p, n+i, max_n+1, ldot) == 0) return 0;
636 +                               if (n+i == ldot) {
637 +                                       if (openchange_ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot) == 0) return 0;
638 +                                       if (!max_n->postdot || max_n->postdot > n) max_n->postdot = n;
639 +                                       return -1;
640 +                               }
641 +                       }
642 +                       if (!max_n->predot || max_n->predot > n) max_n->predot = n;
643 +                       return openchange_null_match(p);
644 +
645 +               case '?':
646 +                       /* a '?' matches any single character */
647 +                       if (! *n) {
648 +                               return -1;
649 +                       }
650 +                       next_codepoint(n, &size_n);
651 +                       n += size_n;
652 +                       break;
653 +
654 +               case '>':
655 +                       /* a '?' matches any single character, but
656 +                          treats '.' specially */
657 +                       if (n[0] == '.') {
658 +                               if (! n[1] && openchange_null_match(p) == 0) {
659 +                                       return 0;
660 +                               }
661 +                               break;
662 +                       }
663 +                       if (! *n) return openchange_null_match(p);
664 +                       next_codepoint(n, &size_n);
665 +                       n += size_n;
666 +                       break;
667 +
668 +               case '"':
669 +                       /* a bit like a soft '.' */
670 +                       if (*n == 0 && openchange_null_match(p) == 0) {
671 +                               return 0;
672 +                       }
673 +                       if (*n != '.') return -1;
674 +                       next_codepoint(n, &size_n);
675 +                       n += size_n;
676 +                       break;
677 +
678 +               default:
679 +                       c2 = next_codepoint(n, &size_n);
680 +                       if (c != c2 && codepoint_cmpi(c, c2) != 0) {
681 +                               return -1;
682 +                       }
683 +                       n += size_n;
684 +                       break;
685 +               }
686 +       }
687 +       
688 +       if (! *n) {
689 +               return 0;
690 +       }
691 +       
692 +       return -1;
693 +}
694 +
695 +static int openchange_ms_fnmatch_protocol(const char *pattern, const char *string, int protocol)
696 +{
697 +       int ret, count, i;
698 +       struct max_n *max_n = NULL;
699 +
700 +       if (strcmp(string, "..") == 0) {
701 +               string = ".";
702 +       }
703 +
704 +       if (strpbrk(pattern, "<>*?\"") == NULL) {
705 +               /* this is not just an optimisation - it is essential
706 +                  for LANMAN1 correctness */
707 +               return strcasecmp_m(pattern, string);
708 +       }
709 +
710 +       if (protocol <= PROTOCOL_LANMAN2) {
711 +               char *p = talloc_strdup(NULL, pattern);
712 +               if (p == NULL) {
713 +                       return -1;
714 +               }
715 +               /*
716 +                 for older negotiated protocols it is possible to
717 +                 translate the pattern to produce a "new style"
718 +                 pattern that exactly matches w2k behaviour
719 +               */
720 +               for (i=0;p[i];i++) {
721 +                       if (p[i] == '?') {
722 +                               p[i] = '>';
723 +                       } else if (p[i] == '.' && 
724 +                                  (p[i+1] == '?' || 
725 +                                   p[i+1] == '*' ||
726 +                                   p[i+1] == 0)) {
727 +                               p[i] = '"';
728 +                       } else if (p[i] == '*' && 
729 +                                  p[i+1] == '.') {
730 +                               p[i] = '<';
731 +                       }
732 +               }
733 +               ret = openchange_ms_fnmatch_protocol(p, string, PROTOCOL_NT1);
734 +               talloc_free(p);
735 +               return ret;
736 +       }
737 +
738 +       for (count=i=0;pattern[i];i++) {
739 +               if (pattern[i] == '*' || pattern[i] == '<') count++;
740 +       }
741 +
742 +       max_n = talloc_zero_array(NULL, struct max_n, count);
743 +       if (max_n == NULL) {
744 +               return -1;
745 +       }
746 +
747 +       ret = openchange_ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.'));
748 +
749 +       talloc_free(max_n);
750 +
751 +       return ret;
752 +}
753 +
754 +
755 +/** a generic fnmatch function - uses for non-CIFS pattern matching */
756 +static int openchange_gen_fnmatch(const char *pattern, const char *string)
757 +{
758 +       return openchange_ms_fnmatch_protocol(pattern, string, PROTOCOL_NT1);
759 +}
760  
761  
762  /**
763 @@ -119,7 +326,7 @@ static void interpret_interface(TALLOC_C
764         
765         /* first check if it is an interface name */
766         for (i=0;i<total_probed;i++) {
767 -               if (gen_fnmatch(token, probed_ifaces[i].name) == 0) {
768 +               if (openchange_gen_fnmatch(token, probed_ifaces[i].name) == 0) {
769                         add_interface(mem_ctx, probed_ifaces[i].ip,
770                                       probed_ifaces[i].netmask,
771                                       local_interfaces);
772 diff -up openchange-openchange-2.3-VULCAN/mapiproxy/servers/default/emsmdb/emsmdbp.c.samba44 openchange-openchange-2.3-VULCAN/mapiproxy/servers/default/emsmdb/emsmdbp.c
773 --- openchange-openchange-2.3-VULCAN/mapiproxy/servers/default/emsmdb/emsmdbp.c.samba44 2015-05-16 17:22:04.000000000 +0200
774 +++ openchange-openchange-2.3-VULCAN/mapiproxy/servers/default/emsmdb/emsmdbp.c 2016-02-08 17:43:52.578645298 +0100
775 @@ -31,8 +31,6 @@
776  #include "mapiproxy/libmapiserver/libmapiserver.h"
777  #include "mapiproxy/libmapiproxy/fault_util.h"
778  
779 -#include <ldap_ndr.h>
780 -
781  /* Expose samdb_connect prototype */
782  struct ldb_context *samdb_connect(TALLOC_CTX *, struct tevent_context *,
783                                   struct loadparm_context *,
784 diff -up openchange-openchange-2.3-VULCAN/ndr_mapi.c.samba44 openchange-openchange-2.3-VULCAN/ndr_mapi.c
785 --- openchange-openchange-2.3-VULCAN/ndr_mapi.c.samba44 2016-02-09 11:04:30.054101688 +0100
786 +++ openchange-openchange-2.3-VULCAN/ndr_mapi.c 2016-02-09 11:04:49.763100853 +0100
787 @@ -1616,7 +1616,7 @@ _PUBLIC_ void ndr_print_EcDoRpcExt(struc
788                                 if (ndr_pull_mapi2k7_request(ndr_pull, NDR_SCALARS|NDR_BUFFERS, mapi_request) == NDR_ERR_SUCCESS) {
789                                         ndr_print_mapi2k7_request(ndr, "mapi_request", (const struct mapi2k7_request *)mapi_request);
790                                 } else {
791 -                                       dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
792 +                                       oc_dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
793                                         talloc_free(mapi_request);
794                                         break;
795                                 }
796 @@ -1662,7 +1662,7 @@ _PUBLIC_ void ndr_print_EcDoRpcExt(struc
797                                 if (ndr_pull_mapi2k7_response(ndr_pull, NDR_SCALARS|NDR_BUFFERS, mapi_response) == NDR_ERR_SUCCESS) {
798                                         ndr_print_mapi2k7_response(ndr, "mapi_response", (const struct mapi2k7_response *)mapi_response);
799                                 } else {
800 -                                       dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
801 +                                       oc_dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
802                                         talloc_free(mapi_response);
803                                         break;
804                                 }
805 @@ -1735,7 +1735,7 @@ _PUBLIC_ void ndr_print_EcDoRpcExt2(stru
806                                 if (ndr_pull_mapi2k7_request(ndr_pull, NDR_SCALARS|NDR_BUFFERS, mapi_request) == NDR_ERR_SUCCESS) {
807                                         ndr_print_mapi2k7_request(ndr, "mapi_request", (const struct mapi2k7_request *)mapi_request);
808                                 } else {
809 -                                       dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
810 +                                       oc_dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
811                                         talloc_free(mapi_request);
812                                         return;
813                                 }
814 @@ -1786,7 +1786,7 @@ _PUBLIC_ void ndr_print_EcDoRpcExt2(stru
815                                 if (ndr_pull_mapi2k7_response(ndr_pull, NDR_SCALARS|NDR_BUFFERS, mapi_response) == NDR_ERR_SUCCESS) {
816                                         ndr_print_mapi2k7_response(ndr, "mapi_response", (const struct mapi2k7_response *)mapi_response);
817                                 } else {
818 -                                       dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
819 +                                       oc_dump_data(0, ndr_pull->data + ndr_pull->offset, ndr_pull->data_size - ndr_pull->offset);
820                                         talloc_free(mapi_response);
821                                         break;
822                                 }
823 @@ -2041,7 +2041,7 @@ _PUBLIC_ void ndr_print_SBinary_short(st
824                 uint32_t _flags_save_STRUCT = ndr->flags;
825                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
826                 ndr->depth++;
827 -               dump_data(0, r->lpb, r->cb);
828 +               oc_dump_data(0, r->lpb, r->cb);
829                 ndr->depth--;
830                 ndr->flags = _flags_save_STRUCT;
831         }
832 @@ -2054,7 +2054,7 @@ _PUBLIC_ void ndr_print_Binary_r(struct
833                 uint32_t _flags_save_STRUCT = ndr->flags;
834                 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_NOALIGN);
835                 ndr->depth++;
836 -               dump_data(0, r->lpb, r->cb);
837 +               oc_dump_data(0, r->lpb, r->cb);
838                 ndr->depth--;
839                 ndr->flags = _flags_save_STRUCT;
840         }
841 diff -up openchange-openchange-2.3-VULCAN/utils/mapipropsdump.c.samba44 openchange-openchange-2.3-VULCAN/utils/mapipropsdump.c
842 --- openchange-openchange-2.3-VULCAN/utils/mapipropsdump.c.samba44      2015-05-16 17:22:04.000000000 +0200
843 +++ openchange-openchange-2.3-VULCAN/utils/mapipropsdump.c      2016-02-09 10:35:42.207174902 +0100
844 @@ -24,6 +24,9 @@
845  #include "gen_ndr/ndr_exchange.h"
846  #include <popt.h>
847  #include <dlfcn.h>
848 +#include <sys/types.h>
849 +#include <sys/stat.h>
850 +#include <unistd.h>
851  
852  #define        PLUGIN          "libmapi.so"
853  #define        FUNCTION        0xB
854 @@ -97,6 +100,51 @@ static const const struct ndr_interface_
855         return p;
856  }
857  
858 +static char *openchange_fd_load(int fd, size_t *psize, size_t maxsize, TALLOC_CTX *mem_ctx)
859 +{
860 +       struct stat sbuf;
861 +       char *p;
862 +       size_t size;
863 +
864 +       if (fstat(fd, &sbuf) != 0) return NULL;
865 +
866 +       size = sbuf.st_size;
867 +
868 +       if (maxsize) {
869 +               size = size < maxsize ? size : maxsize;
870 +       }
871 +
872 +       p = (char *)talloc_size(mem_ctx, size+1);
873 +       if (!p) return NULL;
874 +
875 +       if (read(fd, p, size) != size) {
876 +               talloc_free(p);
877 +               return NULL;
878 +       }
879 +       p[size] = 0;
880 +
881 +       if (psize) *psize = size;
882 +
883 +       return p;
884 +}
885 +
886 +static char *openchange_file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx)
887 +{
888 +       int fd;
889 +       char *p;
890 +
891 +       if (!fname || !*fname) return NULL;
892 +
893 +       fd = open(fname,O_RDONLY);
894 +       if (fd == -1) return NULL;
895 +
896 +       p = openchange_fd_load(fd, size, maxsize, mem_ctx);
897 +
898 +       close(fd);
899 +
900 +       return p;
901 +}
902 +
903  static struct SPropTagArray *process_request(TALLOC_CTX *mem_ctx,
904                                              const struct ndr_interface_call *f,
905                                              const char *filename,
906 @@ -123,7 +171,7 @@ static struct SPropTagArray *process_req
907                 return NULL;
908         }
909  
910 -       data = (uint8_t *) file_load(filename, &size, 0, mem_ctx);
911 +       data = (uint8_t *) openchange_file_load(filename, &size, 0, mem_ctx);
912         if (!data) {
913                 perror(filename);
914                 return NULL;
915 @@ -224,7 +272,7 @@ static int process_response(TALLOC_CTX *
916                 return -1;
917         }
918  
919 -       data = (uint8_t *) file_load(filename, &size, 0, mem_ctx);
920 +       data = (uint8_t *) openchange_file_load(filename, &size, 0, mem_ctx);
921         if (!data) {
922                 perror(filename);
923                 return -1;
924 diff -up openchange-openchange-2.3-VULCAN/utils/mapitest/modules/module_lzxpress.c.samba44 openchange-openchange-2.3-VULCAN/utils/mapitest/modules/module_lzxpress.c
925 --- openchange-openchange-2.3-VULCAN/utils/mapitest/modules/module_lzxpress.c.samba44   2016-02-09 11:06:00.717097846 +0100
926 +++ openchange-openchange-2.3-VULCAN/utils/mapitest/modules/module_lzxpress.c   2016-02-09 11:48:38.200989479 +0100
927 @@ -19,11 +19,61 @@
928     along with this program.  If not, see <http://www.gnu.org/licenses/>.
929  */
930  
931 +#include <sys/types.h>
932 +#include <sys/stat.h>
933 +#include <unistd.h>
934 +
935  #include "utils/mapitest/mapitest.h"
936  #include "utils/mapitest/proto.h"
937  #include "gen_ndr/ndr_exchange.h"
938 +#include "libmapi/libmapi.h"
939  #include "libmapi/libmapi_private.h"
940  
941 +static char *openchange_fd_load(int fd, size_t *psize, size_t maxsize, TALLOC_CTX *mem_ctx)
942 +{
943 +       struct stat sbuf;
944 +       char *p;
945 +       size_t size;
946 +
947 +       if (fstat(fd, &sbuf) != 0) return NULL;
948 +
949 +       size = sbuf.st_size;
950 +
951 +       if (maxsize) {
952 +               size = size < maxsize ? size : maxsize;
953 +       }
954 +
955 +       p = (char *)talloc_size(mem_ctx, size+1);
956 +       if (!p) return NULL;
957 +
958 +       if (read(fd, p, size) != size) {
959 +               talloc_free(p);
960 +               return NULL;
961 +       }
962 +       p[size] = 0;
963 +
964 +       if (psize) *psize = size;
965 +
966 +       return p;
967 +}
968 +
969 +static char *openchange_file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx)
970 +{
971 +       int fd;
972 +       char *p;
973 +
974 +       if (!fname || !*fname) return NULL;
975 +
976 +       fd = open(fname,O_RDONLY);
977 +       if (fd == -1) return NULL;
978 +
979 +       p = openchange_fd_load(fd, size, maxsize, mem_ctx);
980 +
981 +       close(fd);
982 +
983 +       return p;
984 +}
985 +
986  /**
987     \file module_lzxpress.c
988  
989 @@ -51,7 +101,7 @@ _PUBLIC_ bool mapitest_lzxpress_validate
990         /* Step 1. Load Test File 001_Outlook_2007_in_ModifyRecipients_comp.dat */
991         filename = talloc_asprintf(mt->mem_ctx, "%s/001_Outlook_2007_in_ModifyRecipients_comp.dat", LZXPRESS_DATADIR);
992  /*     filename = talloc_asprintf(mt->mem_ctx, "%s/002_Outlook_2007_in_Tables_operations_comp.dat", LZXPRESS_DATADIR); */
993 -       data = (uint8_t *)file_load(filename, &size, 0, mt->mem_ctx);
994 +       data = (uint8_t *)openchange_file_load(filename, &size, 0, mt->mem_ctx);
995         if (!data) {
996                 perror(filename);
997                 mapitest_print_retval_fmt(mt, "lzxpress_validate", "Error while loading %s", filename);
998 @@ -137,12 +187,12 @@ _PUBLIC_ bool mapitest_lzxpress_validate
999  
1000         mapitest_print(mt, "Compressed rgbIn by Outlook\n");
1001         mapitest_print(mt, "==============================\n");
1002 -       dump_data(0, r.in.rgbIn, r.in.cbIn);
1003 +       oc_dump_data(0, r.in.rgbIn, r.in.cbIn);
1004         mapitest_print(mt, "==============================\n");
1005  
1006         mapitest_print(mt, "Compressed rgbIn by OpenChange\n");
1007         mapitest_print(mt, "==============================\n");
1008 -       dump_data(0, ndr_rgbIn->data, ndr_rgbIn->offset);
1009 +       oc_dump_data(0, ndr_rgbIn->data, ndr_rgbIn->offset);
1010         mapitest_print(mt, "==============================\n");
1011  
1012         talloc_free(ndr_rgbIn);
1013 diff -up openchange-openchange-2.3-VULCAN/utils/openchangeclient.c.samba44 openchange-openchange-2.3-VULCAN/utils/openchangeclient.c
1014 --- openchange-openchange-2.3-VULCAN/utils/openchangeclient.c.samba44   2015-05-16 17:22:04.000000000 +0200
1015 +++ openchange-openchange-2.3-VULCAN/utils/openchangeclient.c   2016-02-08 22:24:59.212942206 +0100
1016 @@ -97,6 +97,52 @@ static void init_oclient(struct oclient
1017         oclient->ocpf_dump = NULL;
1018  }
1019  
1020 +static char **openchange_str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
1021 +{
1022 +       int num_elements = 0;
1023 +       char **ret = NULL;
1024 +
1025 +       if (sep == NULL) {
1026 +               sep = " \t,\n\r";
1027 +       }
1028 +
1029 +       ret = talloc_array(mem_ctx, char *, 1);
1030 +       if (ret == NULL) {
1031 +               return NULL;
1032 +       }
1033 +
1034 +       while (string && *string) {
1035 +               size_t len = strcspn(string, sep);
1036 +               char **ret2;
1037 +               
1038 +               if (len == 0) {
1039 +                       string += strspn(string, sep);
1040 +                       continue;
1041 +               }
1042 +
1043 +               ret2 = talloc_realloc(mem_ctx, ret, char *,
1044 +                       num_elements+2);
1045 +               if (ret2 == NULL) {
1046 +                       talloc_free(ret);
1047 +                       return NULL;
1048 +               }
1049 +               ret = ret2;
1050 +
1051 +               ret[num_elements] = talloc_strndup(ret, string, len);
1052 +               if (ret[num_elements] == NULL) {
1053 +                       talloc_free(ret);
1054 +                       return NULL;
1055 +               }
1056 +
1057 +               num_elements++;
1058 +               string += len;
1059 +       }
1060 +
1061 +       ret[num_elements] = NULL;
1062 +
1063 +       return ret;
1064 +}
1065 +
1066  static enum MAPISTATUS openchangeclient_getdir(TALLOC_CTX *mem_ctx,
1067                                                mapi_object_t *obj_container,
1068                                                mapi_object_t *obj_child,
1069 @@ -115,7 +161,7 @@ static enum MAPISTATUS openchangeclient_
1070         uint32_t                i;
1071  
1072         /* Step 1. Extract the folder list from full path */
1073 -       folder = str_list_make(mem_ctx, path, "/");
1074 +       folder = openchange_str_list_make(mem_ctx, path, "/");
1075         mapi_object_copy(&obj_folder, obj_container);
1076  
1077         for (i = 0; folder[i]; i++) {
This page took 0.291576 seconds and 3 git commands to generate.