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

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/native/PropertyTable.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 PropertyTable.cpp
 
24
 * @brief Implementation of the class PropertyTable
 
25
 */
 
26
 
 
27
#include "PropertyTable.h"
 
28
#include "JNIUtil.h"
 
29
#include "JNIStringHolder.h"
 
30
#include "JNIByteArray.h"
 
31
#include "Array.h"
 
32
#include <apr_tables.h>
 
33
#include <apr_strings.h>
 
34
#include <apr_hash.h>
 
35
#include "svn_path.h"
 
36
#include "svn_props.h"
 
37
#include <iostream>
 
38
 
 
39
PropertyTable::~PropertyTable()
 
40
{
 
41
  if (m_revpropTable != NULL)
 
42
    JNIUtil::getEnv()->DeleteLocalRef(m_revpropTable);
 
43
}
 
44
 
 
45
apr_hash_t *PropertyTable::hash(const SVN::Pool &pool)
 
46
{
 
47
  if (!m_revpropTable && !m_empty_if_null)
 
48
    return NULL;
 
49
 
 
50
  apr_hash_t *revprop_table = apr_hash_make(pool.getPool());
 
51
 
 
52
  std::map<std::string, std::string>::const_iterator it;
 
53
  for (it = m_revprops.begin(); it != m_revprops.end(); ++it)
 
54
    {
 
55
      const char *propname = apr_pstrdup(pool.getPool(), it->first.c_str());
 
56
      if (!svn_prop_name_is_valid(propname))
 
57
        {
 
58
          const char *msg = apr_psprintf(pool.getPool(),
 
59
                                         "Invalid property name: '%s'",
 
60
                                         propname);
 
61
          JNIUtil::throwNativeException(JAVAHL_CLASS("/ClientException"), msg,
 
62
                                        NULL, SVN_ERR_CLIENT_PROPERTY_NAME);
 
63
          return NULL;
 
64
        }
 
65
 
 
66
      svn_string_t *propval = svn_string_ncreate(it->second.c_str(),
 
67
                                                 it->second.size(),
 
68
                                                 pool.getPool());
 
69
 
 
70
      apr_hash_set(revprop_table, propname, APR_HASH_KEY_STRING, propval);
 
71
    }
 
72
 
 
73
  return revprop_table;
 
74
}
 
75
 
 
76
PropertyTable::PropertyTable(jobject jrevpropTable, bool bytearray_values,
 
77
                             bool empty_if_null)
 
78
  : m_revpropTable(jrevpropTable),
 
79
    m_empty_if_null(empty_if_null)
 
80
{
 
81
  m_revpropTable = jrevpropTable;
 
82
 
 
83
  if (jrevpropTable != NULL)
 
84
    {
 
85
      static jmethodID keySet = 0, get = 0;
 
86
      JNIEnv *env = JNIUtil::getEnv();
 
87
 
 
88
      jclass mapClazz = env->FindClass("java/util/Map");
 
89
 
 
90
      if (keySet == 0)
 
91
        {
 
92
          keySet = env->GetMethodID(mapClazz, "keySet",
 
93
                                    "()Ljava/util/Set;");
 
94
          if (JNIUtil::isExceptionThrown())
 
95
            return;
 
96
        }
 
97
 
 
98
      jobject jkeySet = env->CallObjectMethod(jrevpropTable, keySet);
 
99
      if (JNIUtil::isExceptionThrown())
 
100
        return;
 
101
 
 
102
      if (get == 0)
 
103
        {
 
104
          get = env->GetMethodID(mapClazz, "get",
 
105
                                 "(Ljava/lang/Object;)Ljava/lang/Object;");
 
106
          if (JNIUtil::isExceptionThrown())
 
107
            return;
 
108
        }
 
109
 
 
110
      Array keyArray(jkeySet);
 
111
      std::vector<jobject> keys = keyArray.vector();
 
112
 
 
113
      for (std::vector<jobject>::const_iterator it = keys.begin();
 
114
            it < keys.end(); ++it)
 
115
        {
 
116
          JNIStringHolder propname((jstring)*it);
 
117
          if (JNIUtil::isExceptionThrown())
 
118
            return;
 
119
 
 
120
          jobject jpropval = env->CallObjectMethod(jrevpropTable, get, *it);
 
121
          if (JNIUtil::isExceptionThrown())
 
122
            return;
 
123
 
 
124
          std::string pv;
 
125
          if (bytearray_values)
 
126
            {
 
127
              JNIByteArray propval((jbyteArray)jpropval);
 
128
              if (JNIUtil::isExceptionThrown())
 
129
                return;
 
130
              if (!propval.isNull())
 
131
                pv = std::string(
 
132
                    reinterpret_cast<const char*>(propval.getBytes()),
 
133
                    propval.getLength());
 
134
            }
 
135
          else
 
136
            {
 
137
              JNIStringHolder propval((jstring)jpropval);
 
138
              if (JNIUtil::isExceptionThrown())
 
139
                return;
 
140
              if (NULL != static_cast<const char *>(propval))
 
141
                pv = static_cast<const char *>(propval);
 
142
            }
 
143
 
 
144
          m_revprops[std::string(static_cast<const char *>(propname))] = pv;
 
145
 
 
146
          JNIUtil::getEnv()->DeleteLocalRef(jpropval);
 
147
        }
 
148
 
 
149
      JNIUtil::getEnv()->DeleteLocalRef(jkeySet);
 
150
    }
 
151
}