Blame view

sources/3rdparty/sabre/dav/lib/Sabre/DAV/Locks/Plugin.php 20.6 KB
03e52840d   Kload   Init
1
  <?php
6d9380f96   Cédric Dupont   Update sources OC...
2
3
4
  namespace Sabre\DAV\Locks;
  
  use Sabre\DAV;
03e52840d   Kload   Init
5
6
7
8
9
10
  /**
   * Locking plugin
   *
   * This plugin provides locking support to a WebDAV server.
   * The easiest way to get started, is by hooking it up as such:
   *
6d9380f96   Cédric Dupont   Update sources OC...
11
12
   * $lockBackend = new Sabre\DAV\Locks\Backend\File('./mylockdb');
   * $lockPlugin = new Sabre\DAV\Locks\Plugin($lockBackend);
03e52840d   Kload   Init
13
14
   * $server->addPlugin($lockPlugin);
   *
6d9380f96   Cédric Dupont   Update sources OC...
15
16
17
   * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/).
   * @author Evert Pot (http://evertpot.com/)
   * @license http://sabre.io/license/ Modified BSD License
03e52840d   Kload   Init
18
   */
6d9380f96   Cédric Dupont   Update sources OC...
19
  class Plugin extends DAV\ServerPlugin {
03e52840d   Kload   Init
20
21
22
23
  
      /**
       * locksBackend
       *
6d9380f96   Cédric Dupont   Update sources OC...
24
       * @var Backend\Backend\Interface
03e52840d   Kload   Init
25
26
27
28
29
30
       */
      protected $locksBackend;
  
      /**
       * server
       *
6d9380f96   Cédric Dupont   Update sources OC...
31
       * @var Sabre\DAV\Server
03e52840d   Kload   Init
32
33
34
35
36
37
       */
      protected $server;
  
      /**
       * __construct
       *
6d9380f96   Cédric Dupont   Update sources OC...
38
       * @param Backend\BackendInterface $locksBackend
03e52840d   Kload   Init
39
       */
6d9380f96   Cédric Dupont   Update sources OC...
40
      public function __construct(Backend\BackendInterface $locksBackend = null) {
03e52840d   Kload   Init
41
42
43
44
45
46
47
48
49
50
  
          $this->locksBackend = $locksBackend;
  
      }
  
      /**
       * Initializes the plugin
       *
       * This method is automatically called by the Server class after addPlugin.
       *
6d9380f96   Cédric Dupont   Update sources OC...
51
       * @param DAV\Server $server
03e52840d   Kload   Init
52
53
       * @return void
       */
6d9380f96   Cédric Dupont   Update sources OC...
54
      public function initialize(DAV\Server $server) {
03e52840d   Kload   Init
55
56
57
58
59
60
61
62
63
64
65
66
  
          $this->server = $server;
          $server->subscribeEvent('unknownMethod',array($this,'unknownMethod'));
          $server->subscribeEvent('beforeMethod',array($this,'beforeMethod'),50);
          $server->subscribeEvent('afterGetProperties',array($this,'afterGetProperties'));
  
      }
  
      /**
       * Returns a plugin name.
       *
       * Using this name other plugins will be able to access other plugins
6d9380f96   Cédric Dupont   Update sources OC...
67
       * using Sabre\DAV\Server::getPlugin
03e52840d   Kload   Init
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
       *
       * @return string
       */
      public function getPluginName() {
  
          return 'locks';
  
      }
  
      /**
       * This method is called by the Server if the user used an HTTP method
       * the server didn't recognize.
       *
       * This plugin intercepts the LOCK and UNLOCK methods.
       *
       * @param string $method
       * @param string $uri
       * @return bool
       */
      public function unknownMethod($method, $uri) {
  
          switch($method) {
  
              case 'LOCK'   : $this->httpLock($uri); return false;
              case 'UNLOCK' : $this->httpUnlock($uri); return false;
  
          }
  
      }
  
      /**
       * This method is called after most properties have been found
       * it allows us to add in any Lock-related properties
       *
       * @param string $path
       * @param array $newProperties
       * @return bool
       */
      public function afterGetProperties($path, &$newProperties) {
  
          foreach($newProperties[404] as $propName=>$discard) {
  
              switch($propName) {
  
                  case '{DAV:}supportedlock' :
                      $val = false;
                      if ($this->locksBackend) $val = true;
6d9380f96   Cédric Dupont   Update sources OC...
115
                      $newProperties[200][$propName] = new DAV\Property\SupportedLock($val);
03e52840d   Kload   Init
116
117
118
119
                      unset($newProperties[404][$propName]);
                      break;
  
                  case '{DAV:}lockdiscovery' :
6d9380f96   Cédric Dupont   Update sources OC...
120
                      $newProperties[200][$propName] = new DAV\Property\LockDiscovery($this->getLocks($path));
03e52840d   Kload   Init
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
                      unset($newProperties[404][$propName]);
                      break;
  
              }
  
  
          }
          return true;
  
      }
  
  
      /**
       * This method is called before the logic for any HTTP method is
       * handled.
       *
       * This plugin uses that feature to intercept access to locked resources.
       *
       * @param string $method
       * @param string $uri
       * @return bool
       */
      public function beforeMethod($method, $uri) {
  
          switch($method) {
  
              case 'DELETE' :
                  $lastLock = null;
                  if (!$this->validateLock($uri,$lastLock, true))
6d9380f96   Cédric Dupont   Update sources OC...
150
                      throw new DAV\Exception\Locked($lastLock);
03e52840d   Kload   Init
151
152
153
154
155
156
157
                  break;
              case 'MKCOL' :
              case 'PROPPATCH' :
              case 'PUT' :
              case 'PATCH' :
                  $lastLock = null;
                  if (!$this->validateLock($uri,$lastLock))
6d9380f96   Cédric Dupont   Update sources OC...
158
                      throw new DAV\Exception\Locked($lastLock);
03e52840d   Kload   Init
159
160
161
162
163
164
165
                  break;
              case 'MOVE' :
                  $lastLock = null;
                  if (!$this->validateLock(array(
                        $uri,
                        $this->server->calculateUri($this->server->httpRequest->getHeader('Destination')),
                      ),$lastLock, true))
6d9380f96   Cédric Dupont   Update sources OC...
166
                          throw new DAV\Exception\Locked($lastLock);
03e52840d   Kload   Init
167
168
169
170
171
172
                  break;
              case 'COPY' :
                  $lastLock = null;
                  if (!$this->validateLock(
                        $this->server->calculateUri($this->server->httpRequest->getHeader('Destination')),
                        $lastLock, true))
6d9380f96   Cédric Dupont   Update sources OC...
173
                          throw new DAV\Exception\Locked($lastLock);
03e52840d   Kload   Init
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
                  break;
          }
  
          return true;
  
      }
  
      /**
       * Use this method to tell the server this plugin defines additional
       * HTTP methods.
       *
       * This method is passed a uri. It should only return HTTP methods that are
       * available for the specified uri.
       *
       * @param string $uri
       * @return array
       */
      public function getHTTPMethods($uri) {
  
          if ($this->locksBackend)
              return array('LOCK','UNLOCK');
  
          return array();
  
      }
  
      /**
       * Returns a list of features for the HTTP OPTIONS Dav: header.
       *
       * In this case this is only the number 2. The 2 in the Dav: header
       * indicates the server supports locks.
       *
       * @return array
       */
      public function getFeatures() {
  
          return array(2);
  
      }
  
      /**
       * Returns all lock information on a particular uri
       *
6d9380f96   Cédric Dupont   Update sources OC...
217
       * This function should return an array with Sabre\DAV\Locks\LockInfo objects. If there are no locks on a file, return an empty array.
03e52840d   Kload   Init
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
       *
       * Additionally there is also the possibility of locks on parent nodes, so we'll need to traverse every part of the tree
       * If the $returnChildLocks argument is set to true, we'll also traverse all the children of the object
       * for any possible locks and return those as well.
       *
       * @param string $uri
       * @param bool $returnChildLocks
       * @return array
       */
      public function getLocks($uri, $returnChildLocks = false) {
  
          $lockList = array();
  
          if ($this->locksBackend)
              $lockList = array_merge($lockList,$this->locksBackend->getLocks($uri, $returnChildLocks));
  
          return $lockList;
  
      }
  
      /**
       * Locks an uri
       *
       * The WebDAV lock request can be operated to either create a new lock on a file, or to refresh an existing lock
       * If a new lock is created, a full XML body should be supplied, containing information about the lock such as the type
       * of lock (shared or exclusive) and the owner of the lock
       *
       * If a lock is to be refreshed, no body should be supplied and there should be a valid If header containing the lock
       *
       * Additionally, a lock can be requested for a non-existent file. In these case we're obligated to create an empty file as per RFC4918:S7.3
       *
       * @param string $uri
       * @return void
       */
      protected function httpLock($uri) {
  
          $lastLock = null;
          if (!$this->validateLock($uri,$lastLock)) {
  
              // If the existing lock was an exclusive lock, we need to fail
6d9380f96   Cédric Dupont   Update sources OC...
258
              if (!$lastLock || $lastLock->scope == LockInfo::EXCLUSIVE) {
03e52840d   Kload   Init
259
                  //var_dump($lastLock);
6d9380f96   Cédric Dupont   Update sources OC...
260
                  throw new DAV\Exception\ConflictingLock($lastLock);
03e52840d   Kload   Init
261
262
263
264
265
266
267
268
269
              }
  
          }
  
          if ($body = $this->server->httpRequest->getBody(true)) {
              // This is a new lock request
              $lockInfo = $this->parseLockRequest($body);
              $lockInfo->depth = $this->server->getHTTPDepth();
              $lockInfo->uri = $uri;
6d9380f96   Cédric Dupont   Update sources OC...
270
              if($lastLock && $lockInfo->scope != LockInfo::SHARED) throw new DAV\Exception\ConflictingLock($lastLock);
03e52840d   Kload   Init
271
272
273
274
275
276
277
278
279
280
281
282
  
          } elseif ($lastLock) {
  
              // This must have been a lock refresh
              $lockInfo = $lastLock;
  
              // The resource could have been locked through another uri.
              if ($uri!=$lockInfo->uri) $uri = $lockInfo->uri;
  
          } else {
  
              // There was neither a lock refresh nor a new lock request
6d9380f96   Cédric Dupont   Update sources OC...
283
              throw new DAV\Exception\BadRequest('An xml body is required for lock requests');
03e52840d   Kload   Init
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  
          }
  
          if ($timeout = $this->getTimeoutHeader()) $lockInfo->timeout = $timeout;
  
          $newFile = false;
  
          // If we got this far.. we should go check if this node actually exists. If this is not the case, we need to create it first
          try {
              $this->server->tree->getNodeForPath($uri);
  
              // We need to call the beforeWriteContent event for RFC3744
              // Edit: looks like this is not used, and causing problems now.
              //
              // See Issue 222
              // $this->server->broadcastEvent('beforeWriteContent',array($uri));
6d9380f96   Cédric Dupont   Update sources OC...
300
          } catch (DAV\Exception\NotFound $e) {
03e52840d   Kload   Init
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
  
              // It didn't, lets create it
              $this->server->createFile($uri,fopen('php://memory','r'));
              $newFile = true;
  
          }
  
          $this->lockNode($uri,$lockInfo);
  
          $this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
          $this->server->httpResponse->setHeader('Lock-Token','<opaquelocktoken:' . $lockInfo->token . '>');
          $this->server->httpResponse->sendStatus($newFile?201:200);
          $this->server->httpResponse->sendBody($this->generateLockResponse($lockInfo));
  
      }
  
      /**
       * Unlocks a uri
       *
       * This WebDAV method allows you to remove a lock from a node. The client should provide a valid locktoken through the Lock-token http header
       * The server should return 204 (No content) on success
       *
       * @param string $uri
       * @return void
       */
      protected function httpUnlock($uri) {
  
          $lockToken = $this->server->httpRequest->getHeader('Lock-Token');
  
          // If the locktoken header is not supplied, we need to throw a bad request exception
6d9380f96   Cédric Dupont   Update sources OC...
331
          if (!$lockToken) throw new DAV\Exception\BadRequest('No lock token was supplied');
03e52840d   Kload   Init
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
  
          $locks = $this->getLocks($uri);
  
          // Windows sometimes forgets to include < and > in the Lock-Token
          // header
          if ($lockToken[0]!=='<') $lockToken = '<' . $lockToken . '>';
  
          foreach($locks as $lock) {
  
              if ('<opaquelocktoken:' . $lock->token . '>' == $lockToken) {
  
                  $this->unlockNode($uri,$lock);
                  $this->server->httpResponse->setHeader('Content-Length','0');
                  $this->server->httpResponse->sendStatus(204);
                  return;
  
              }
  
          }
  
          // If we got here, it means the locktoken was invalid
6d9380f96   Cédric Dupont   Update sources OC...
353
          throw new DAV\Exception\LockTokenMatchesRequestUri();
03e52840d   Kload   Init
354
355
356
357
358
359
360
361
362
363
  
      }
  
      /**
       * Locks a uri
       *
       * All the locking information is supplied in the lockInfo object. The object has a suggested timeout, but this can be safely ignored
       * It is important that if the existing timeout is ignored, the property is overwritten, as this needs to be sent back to the client
       *
       * @param string $uri
6d9380f96   Cédric Dupont   Update sources OC...
364
       * @param LockInfo $lockInfo
03e52840d   Kload   Init
365
366
       * @return bool
       */
6d9380f96   Cédric Dupont   Update sources OC...
367
      public function lockNode($uri,LockInfo $lockInfo) {
03e52840d   Kload   Init
368
369
370
371
  
          if (!$this->server->broadcastEvent('beforeLock',array($uri,$lockInfo))) return;
  
          if ($this->locksBackend) return $this->locksBackend->lock($uri,$lockInfo);
6d9380f96   Cédric Dupont   Update sources OC...
372
          throw new DAV\Exception\MethodNotAllowed('Locking support is not enabled for this resource. No Locking backend was found so if you didn\'t expect this error, please check your configuration.');
03e52840d   Kload   Init
373
374
375
376
377
378
379
380
381
  
      }
  
      /**
       * Unlocks a uri
       *
       * This method removes a lock from a uri. It is assumed all the supplied information is correct and verified
       *
       * @param string $uri
6d9380f96   Cédric Dupont   Update sources OC...
382
       * @param LockInfo $lockInfo
03e52840d   Kload   Init
383
384
       * @return bool
       */
6d9380f96   Cédric Dupont   Update sources OC...
385
      public function unlockNode($uri, LockInfo $lockInfo) {
03e52840d   Kload   Init
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
  
          if (!$this->server->broadcastEvent('beforeUnlock',array($uri,$lockInfo))) return;
          if ($this->locksBackend) return $this->locksBackend->unlock($uri,$lockInfo);
  
      }
  
  
      /**
       * Returns the contents of the HTTP Timeout header.
       *
       * The method formats the header into an integer.
       *
       * @return int
       */
      public function getTimeoutHeader() {
  
          $header = $this->server->httpRequest->getHeader('Timeout');
  
          if ($header) {
  
              if (stripos($header,'second-')===0) $header = (int)(substr($header,7));
6d9380f96   Cédric Dupont   Update sources OC...
407
408
              else if (strtolower($header)=='infinite') $header = LockInfo::TIMEOUT_INFINITE;
              else throw new DAV\Exception\BadRequest('Invalid HTTP timeout header');
03e52840d   Kload   Init
409
410
411
412
413
414
415
416
417
418
419
420
421
422
  
          } else {
  
              $header = 0;
  
          }
  
          return $header;
  
      }
  
      /**
       * Generates the response for successful LOCK requests
       *
6d9380f96   Cédric Dupont   Update sources OC...
423
       * @param LockInfo $lockInfo
03e52840d   Kload   Init
424
425
       * @return string
       */
6d9380f96   Cédric Dupont   Update sources OC...
426
      protected function generateLockResponse(LockInfo $lockInfo) {
03e52840d   Kload   Init
427

6d9380f96   Cédric Dupont   Update sources OC...
428
          $dom = new \DOMDocument('1.0','utf-8');
03e52840d   Kload   Init
429
430
431
432
433
434
435
          $dom->formatOutput = true;
  
          $prop = $dom->createElementNS('DAV:','d:prop');
          $dom->appendChild($prop);
  
          $lockDiscovery = $dom->createElementNS('DAV:','d:lockdiscovery');
          $prop->appendChild($lockDiscovery);
6d9380f96   Cédric Dupont   Update sources OC...
436
          $lockObj = new DAV\Property\LockDiscovery(array($lockInfo),true);
03e52840d   Kload   Init
437
438
439
440
441
442
443
444
445
446
447
          $lockObj->serialize($this->server,$lockDiscovery);
  
          return $dom->saveXML();
  
      }
  
      /**
       * validateLock should be called when a write operation is about to happen
       * It will check if the requested url is locked, and see if the correct lock tokens are passed
       *
       * @param mixed $urls List of relevant urls. Can be an array, a string or nothing at all for the current request uri
6d9380f96   Cédric Dupont   Update sources OC...
448
       * @param mixed $lastLock This variable will be populated with the last checked lock object (Sabre\DAV\Locks\LockInfo)
03e52840d   Kload   Init
449
450
451
452
453
454
455
456
457
458
       * @param bool $checkChildLocks If set to true, this function will also look for any locks set on child resources of the supplied urls. This is needed for for example deletion of entire trees.
       * @return bool
       */
      protected function validateLock($urls = null,&$lastLock = null, $checkChildLocks = false) {
  
          if (is_null($urls)) {
              $urls = array($this->server->getRequestUri());
          } elseif (is_string($urls)) {
              $urls = array($urls);
          } elseif (!is_array($urls)) {
6d9380f96   Cédric Dupont   Update sources OC...
459
              throw new DAV\Exception('The urls parameter should either be null, a string or an array');
03e52840d   Kload   Init
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
          }
  
          $conditions = $this->getIfConditions();
  
          // We're going to loop through the urls and make sure all lock conditions are satisfied
          foreach($urls as $url) {
  
              $locks = $this->getLocks($url, $checkChildLocks);
  
              // If there were no conditions, but there were locks, we fail
              if (!$conditions && $locks) {
                  reset($locks);
                  $lastLock = current($locks);
                  return false;
              }
  
              // If there were no locks or conditions, we go to the next url
              if (!$locks && !$conditions) continue;
  
              foreach($conditions as $condition) {
  
                  if (!$condition['uri']) {
                      $conditionUri = $this->server->getRequestUri();
                  } else {
                      $conditionUri = $this->server->calculateUri($condition['uri']);
                  }
  
                  // If the condition has a url, and it isn't part of the affected url at all, check the next condition
                  if ($conditionUri && strpos($url,$conditionUri)!==0) continue;
  
                  // The tokens array contians arrays with 2 elements. 0=true/false for normal/not condition, 1=locktoken
                  // At least 1 condition has to be satisfied
                  foreach($condition['tokens'] as $conditionToken) {
  
                      $etagValid = true;
                      $lockValid  = true;
  
                      // key 2 can contain an etag
                      if ($conditionToken[2]) {
  
                          $uri = $conditionUri?$conditionUri:$this->server->getRequestUri();
                          $node = $this->server->tree->getNodeForPath($uri);
6d9380f96   Cédric Dupont   Update sources OC...
502
                          $etagValid = $node instanceof DAV\IFile && $node->getETag()==$conditionToken[2];
03e52840d   Kload   Init
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
  
                      }
  
                      // key 1 can contain a lock token
                      if ($conditionToken[1]) {
  
                          $lockValid = false;
                          // Match all the locks
                          foreach($locks as $lockIndex=>$lock) {
  
                              $lockToken = 'opaquelocktoken:' . $lock->token;
  
                              // Checking NOT
                              if (!$conditionToken[0] && $lockToken != $conditionToken[1]) {
  
                                  // Condition valid, onto the next
                                  $lockValid = true;
                                  break;
                              }
                              if ($conditionToken[0] && $lockToken == $conditionToken[1]) {
  
                                  $lastLock = $lock;
                                  // Condition valid and lock matched
                                  unset($locks[$lockIndex]);
                                  $lockValid = true;
                                  break;
  
                              }
  
                          }
  
                      }
  
                      // If, after checking both etags and locks they are stil valid,
                      // we can continue with the next condition.
                      if ($etagValid && $lockValid) continue 2;
                 }
                 // No conditions matched, so we fail
6d9380f96   Cédric Dupont   Update sources OC...
541
                 throw new DAV\Exception\PreconditionFailed('The tokens provided in the if header did not match','If');
03e52840d   Kload   Init
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
              }
  
              // Conditions were met, we'll also need to check if all the locks are gone
              if (count($locks)) {
  
                  reset($locks);
  
                  // There's still locks, we fail
                  $lastLock = current($locks);
                  return false;
  
              }
  
  
          }
  
          // We got here, this means every condition was satisfied
          return true;
  
      }
  
      /**
       * This method is created to extract information from the WebDAV HTTP 'If:' header
       *
       * The If header can be quite complex, and has a bunch of features. We're using a regex to extract all relevant information
       * The function will return an array, containing structs with the following keys
       *
       *   * uri   - the uri the condition applies to. If this is returned as an
       *     empty string, this implies it's referring to the request url.
       *   * tokens - The lock token. another 2 dimensional array containing 2 elements (0 = true/false.. If this is a negative condition its set to false, 1 = the actual token)
       *   * etag - an etag, if supplied
       *
       * @return array
       */
      public function getIfConditions() {
  
          $header = $this->server->httpRequest->getHeader('If');
          if (!$header) return array();
  
          $matches = array();
  
          $regex = '/(?:\<(?P<uri>.*?)\>\s)?\((?P<not>Not\s)?(?:\<(?P<token>[^\>]*)\>)?(?:\s?)(?:\[(?P<etag>[^\]]*)\])?\)/im';
          preg_match_all($regex,$header,$matches,PREG_SET_ORDER);
  
          $conditions = array();
  
          foreach($matches as $match) {
  
              $condition = array(
                  'uri'   => $match['uri'],
                  'tokens' => array(
                      array($match['not']?0:1,$match['token'],isset($match['etag'])?$match['etag']:'')
                  ),
              );
  
              if (!$condition['uri'] && count($conditions)) $conditions[count($conditions)-1]['tokens'][] = array(
                  $match['not']?0:1,
                  $match['token'],
                  isset($match['etag'])?$match['etag']:''
              );
              else {
                  $conditions[] = $condition;
              }
  
          }
  
          return $conditions;
  
      }
  
      /**
6d9380f96   Cédric Dupont   Update sources OC...
613
       * Parses a webdav lock xml body, and returns a new Sabre\DAV\Locks\LockInfo object
03e52840d   Kload   Init
614
615
       *
       * @param string $body
6d9380f96   Cédric Dupont   Update sources OC...
616
       * @return DAV\Locks\LockInfo
03e52840d   Kload   Init
617
618
       */
      protected function parseLockRequest($body) {
6d9380f96   Cédric Dupont   Update sources OC...
619
620
621
622
  
          // Fixes an XXE vulnerability on PHP versions older than 5.3.23 or
          // 5.4.13.
          $previous = libxml_disable_entity_loader(true);
03e52840d   Kload   Init
623
          $xml = simplexml_load_string(
6d9380f96   Cédric Dupont   Update sources OC...
624
              DAV\XMLUtil::convertDAVNamespace($body),
03e52840d   Kload   Init
625
626
              null,
              LIBXML_NOWARNING);
6d9380f96   Cédric Dupont   Update sources OC...
627
          libxml_disable_entity_loader($previous);
03e52840d   Kload   Init
628
          $xml->registerXPathNamespace('d','urn:DAV');
6d9380f96   Cédric Dupont   Update sources OC...
629
          $lockInfo = new LockInfo();
03e52840d   Kload   Init
630
631
632
  
          $children = $xml->children("urn:DAV");
          $lockInfo->owner = (string)$children->owner;
6d9380f96   Cédric Dupont   Update sources OC...
633
634
          $lockInfo->token = DAV\UUIDUtil::getUUID();
          $lockInfo->scope = count($xml->xpath('d:lockscope/d:exclusive'))>0 ? LockInfo::EXCLUSIVE : LockInfo::SHARED;
03e52840d   Kload   Init
635
636
637
638
639
640
641
  
          return $lockInfo;
  
      }
  
  
  }