@@ -241,17 +241,13 @@ typedef off_t loff_t;
241
241
#ifndef MOD_WEBDAV_BUILD_MINIMAL
242
242
#if defined(HAVE_LIBXML_H ) && defined(HAVE_SQLITE3_H )
243
243
244
+ #define USE_LOCKS
244
245
#define USE_PROPPATCH
245
246
/* minor: libxml2 includes stdlib.h in headers, too */
246
247
#include <libxml/tree.h>
247
248
#include <libxml/parser.h>
248
249
#include <sqlite3.h>
249
250
250
- #if defined(HAVE_LIBUUID ) && defined(HAVE_UUID_UUID_H )
251
- #define USE_LOCKS
252
- #include <uuid/uuid.h>
253
- #endif
254
-
255
251
#endif /* defined(HAVE_LIBXML_H) && defined(HAVE_SQLITE3_H) */
256
252
#endif /* MOD_WEBDAV_BUILD_MINIMAL */
257
253
@@ -5607,6 +5603,54 @@ webdav_conflicting_lock_cb (void * const vdata,
5607
5603
}
5608
5604
5609
5605
5606
+ #include "rand.h" /* li_rand_pseudo_bytes() */
5607
+
5608
+ static void
5609
+ webdav_uuid_v4 (char * const s ) /* s receives 36 chars of output */
5610
+ {
5611
+ /* generate UUID version 4: random number based */
5612
+ char uuid [16 ];
5613
+ /*(could have written into s+20 instead of uuid[] of stack
5614
+ * except that would violate 'restrict' keyword on li_tohex_lc() args)*/
5615
+ /*(li_rand_pseudo_bytes() aims to produce high-quality pseudorandom bytes)*/
5616
+ /*(If using li_rand_bytes() instead, then check return value)*/
5617
+ li_rand_pseudo_bytes ((unsigned char * )uuid , sizeof (uuid ));
5618
+
5619
+ /* set version 4 */
5620
+ uuid [6 ] &= 0x0f ;
5621
+ uuid [6 ] |= 0x40 ;
5622
+
5623
+ /* set variant (always DCE 1.1 only) */
5624
+ uuid [8 ] &= 0x3f ;
5625
+ uuid [8 ] |= 0x80 ;
5626
+
5627
+ /* stringify UUID */
5628
+ #if 0 /* write string into hex[] and then memcpy() into s */
5629
+ char hex [32 ];
5630
+ li_tohex_lc (hex , sizeof (hex ), uuid , sizeof (uuid ));
5631
+ memcpy (s , hex , 8 );
5632
+ s [8 ] = '-' ;
5633
+ memcpy (s + 9 , hex , 4 );
5634
+ s [13 ] = '-' ;
5635
+ memcpy (s + 14 , hex , 4 );
5636
+ s [18 ] = '-' ;
5637
+ memcpy (s + 19 , hex , 4 );
5638
+ s [23 ] = '-' ;
5639
+ memcpy (s + 24 , hex , 12 );
5640
+ #else /* write string into s and then memmove() in-place */
5641
+ li_tohex_lc (s + 4 , 36 - 4 , uuid , sizeof (uuid ));
5642
+ memmove (s , s + 4 , 8 );
5643
+ s [8 ] = '-' ;
5644
+ memmove (s + 9 , s + 4 + 8 , 4 );
5645
+ s [13 ] = '-' ;
5646
+ memmove (s + 14 , s + 4 + 8 + 4 , 4 );
5647
+ s [18 ] = '-' ;
5648
+ memmove (s + 19 , s + 4 + 8 + 4 + 4 , 4 );
5649
+ s [23 ] = '-' ;
5650
+ #endif
5651
+ }
5652
+
5653
+
5610
5654
static handler_t
5611
5655
mod_webdav_lock (request_st * const r , const plugin_config * const pconf )
5612
5656
{
@@ -5861,13 +5905,12 @@ mod_webdav_lock (request_st * const r, const plugin_config * const pconf)
5861
5905
lockdata .depth = 0 ; /* force Depth: 0 on non-collections */
5862
5906
5863
5907
/* create locktoken
5864
- * (uuid_unparse() output is 36 chars + '\0') */
5865
- uuid_t id ;
5908
+ * (uuid v4 string is 36 chars) */
5866
5909
char lockstr [sizeof ("<urn:uuid:>" ) + 36 ] = "<urn:uuid:" ;
5867
5910
lockdata .locktoken .ptr = lockstr + 1 ; /*(without surrounding <>)*/
5868
5911
lockdata .locktoken .used = sizeof (lockstr )- 2 ;/*(without surrounding <>)*/
5869
- uuid_generate ( id ) ;
5870
- uuid_unparse ( id , lockstr + sizeof ("<urn:uuid:" )- 1 );
5912
+ lockstr [ sizeof ( lockstr ) - 2 ] = '\0' ;
5913
+ webdav_uuid_v4 ( lockstr + sizeof ("<urn:uuid:" )- 1 );
5871
5914
5872
5915
/* XXX: consider fix TOC-TOU race condition by starting transaction
5873
5916
* and re-running webdav_lock_activelocks() check before running
0 commit comments