~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/native/LockTokenTable.cpp

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
3
 * ====================================================================
 
4
 *    Licensed to the Apache Software Foundation (ASF) under one
 
5
 *    or more contributor license agreements.  See the NOTICE file
 
6
 *    distributed with this work for additional information
 
7
 *    regarding copyright ownership.  The ASF licenses this file
 
8
 *    to you under the Apache License, Version 2.0 (the
 
9
 *    "License"); you may not use this file except in compliance
 
10
 *    with the License.  You may obtain a copy of the License at
 
11
 *
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 *    Unless required by applicable law or agreed to in writing,
 
15
 *    software distributed under the License is distributed on an
 
16
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
17
 *    KIND, either express or implied.  See the License for the
 
18
 *    specific language governing permissions and limitations
 
19
 *    under the License.
 
20
 * ====================================================================
 
21
 * @endcopyright
 
22
 *
 
23
 * @file LockTokenTable.cpp
 
24
 * @brief Implementation of the class LockTokenTable
 
25
 */
 
26
 
 
27
#include "LockTokenTable.h"
 
28
#include "JNIUtil.h"
 
29
#include "JNIStringHolder.h"
 
30
#include "Array.h"
 
31
#include <apr_hash.h>
 
32
 
 
33
LockTokenTable::~LockTokenTable()
 
34
{
 
35
  if (m_jlock_tokens)
 
36
    JNIUtil::getEnv()->DeleteLocalRef(m_jlock_tokens);
 
37
}
 
38
 
 
39
apr_hash_t*
 
40
LockTokenTable::hash(const SVN::Pool &pool, bool null_if_empty)
 
41
{
 
42
  if (m_lock_tokens.size() == 0 && null_if_empty)
 
43
    return NULL;
 
44
 
 
45
  apr_pool_t* result_pool = pool.getPool();
 
46
  apr_hash_t* lock_table = apr_hash_make(result_pool);
 
47
 
 
48
  for (lock_tokens_t::const_iterator it = m_lock_tokens.begin();
 
49
       it != m_lock_tokens.end(); ++it)
 
50
    {
 
51
      const char *path = apr_pstrdup(result_pool, it->first.c_str());
 
52
      const char *token = apr_pstrdup(result_pool, it->second.c_str());
 
53
      apr_hash_set(lock_table, path, APR_HASH_KEY_STRING, token);
 
54
    }
 
55
 
 
56
  return lock_table;
 
57
}
 
58
 
 
59
LockTokenTable::LockTokenTable(jobject jlock_tokens)
 
60
  : m_jlock_tokens(jlock_tokens)
 
61
{
 
62
 
 
63
  if (jlock_tokens != NULL)
 
64
    {
 
65
      JNIEnv *env = JNIUtil::getEnv();
 
66
 
 
67
      jclass lock_cls = env->FindClass(JAVAHL_CLASS("/types/Lock"));
 
68
      if (JNIUtil::isExceptionThrown())
 
69
        return;
 
70
 
 
71
      static jmethodID getPath_mid = 0;
 
72
      if (0 == getPath_mid)
 
73
        {
 
74
          getPath_mid = env->GetMethodID(lock_cls, "getPath",
 
75
                                         "()Ljava/lang/String;");
 
76
          if (JNIUtil::isExceptionThrown())
 
77
            return;
 
78
        }
 
79
 
 
80
      static jmethodID getToken_mid = 0;
 
81
      if (0 == getToken_mid)
 
82
        {
 
83
          getToken_mid = env->GetMethodID(lock_cls, "getToken",
 
84
                                          "()Ljava/lang/String;");
 
85
          if (JNIUtil::isExceptionThrown())
 
86
            return;
 
87
        }
 
88
 
 
89
      std::vector<jobject> locks = Array(jlock_tokens).vector();
 
90
      for (std::vector<jobject>::const_iterator it = locks.begin();
 
91
           it != locks.end(); ++it)
 
92
        {
 
93
          jobject jpath = env->CallObjectMethod(*it, getPath_mid);
 
94
          if (JNIUtil::isExceptionThrown())
 
95
            return;
 
96
          jobject jtoken = env->CallObjectMethod(*it, getToken_mid);
 
97
          if (JNIUtil::isExceptionThrown())
 
98
            return;
 
99
 
 
100
          JNIStringHolder path((jstring)jpath);
 
101
          if (JNIUtil::isExceptionThrown())
 
102
            return;
 
103
          JNIStringHolder token((jstring)jtoken);
 
104
          if (JNIUtil::isExceptionThrown())
 
105
            return;
 
106
 
 
107
          m_lock_tokens[std::string(static_cast<const char *>(path))] =
 
108
            std::string(static_cast<const char *>(token));
 
109
 
 
110
          env->DeleteLocalRef(jpath);
 
111
          env->DeleteLocalRef(jtoken);
 
112
        }
 
113
    }
 
114
}