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

« back to all changes in this revision

Viewing changes to subversion/bindings/swig/ruby/test/windows_util.rb

  • 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:
34
34
        end
35
35
      end
36
36
 
37
 
      def service_control(command, args={})
38
 
        args = args.collect do |key, value|
39
 
          "#{key}= #{Svnserve.escape_value(value)}"
40
 
        end.join(" ")
41
 
        result = `sc #{command} #{service_name} #{args}`
42
 
        if result.match(/FAILED/)
43
 
          raise "Failed to #{command} #{service_name}: #{args}"
44
 
        end
45
 
        /^\s*STATE\s*:\s\d+\s*(.*?)\s*$/ =~ result
46
 
        $1
47
 
      end
48
 
 
49
 
      def grant_everyone_full_access(dir)
50
 
        dir = dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)
51
 
        `cacls #{Svnserve.escape_value(dir)} /T /E /P Everyone:F`
52
 
      end
53
 
 
54
 
      def service_exists?
55
 
        begin
56
 
          service_control("query")
57
 
          true
58
 
        rescue
59
 
          false
60
 
        end
61
 
      end
62
 
 
63
 
      def service_stopped?
64
 
        "STOPPED" == service_control("query") rescue true
65
 
      end
66
 
 
67
37
      def setup_svnserve
68
38
        @svnserve_port = @svnserve_ports.last
69
39
        @repos_svnserve_uri = "svn://#{@svnserve_host}:#{@svnserve_port}"
70
 
        grant_everyone_full_access(@full_repos_path)
71
40
 
72
41
        @@service_created ||= begin
73
42
          @@service_created = true
74
 
          service_control('stop') unless service_stopped?
75
 
          service_control('delete') if service_exists?
76
 
 
77
 
          svnserve_dir = File.expand_path("svnserve")
78
 
          FileUtils.mkdir_p(svnserve_dir)
79
 
          at_exit do
80
 
            service_control('stop') unless service_stopped?
81
 
            service_control('delete') if service_exists?
82
 
            FileUtils.rm_rf(svnserve_dir)
83
 
          end
84
 
          trap("INT") do
85
 
            service_control('stop') unless service_stopped?
86
 
            service_control('delete') if service_exists?
87
 
            FileUtils.rm_rf(svnserve_dir)
88
 
          end
89
 
 
90
 
          config = SetupEnvironment.gen_make_opts
91
 
          apr_version_include = Pathname.new(config["--with-apr"])  +
92
 
              'include' + 'apr_version.h'
93
 
          %r'^\s*#define\s+APR_MAJOR_VERSION\s+(\d+)' =~ apr_version_include.read
94
 
          apr_major_version = $1 == '0' ? '' : "-#{$1}"
95
 
 
96
 
          cwd = Dir.getwd
97
 
          targets = %W(svnserve.exe libsvn_subr-1.dll libsvn_repos-1.dll
98
 
                       libsvn_fs-1.dll libsvn_delta-1.dll
99
 
                       libaprutil#{apr_major_version}.dll
100
 
                       libapr#{apr_major_version}.dll
101
 
                       libapriconv#{apr_major_version}.dll
102
 
                       libdb??.dll libdb??d.dll)
103
 
          ENV["PATH"].split(";").each do |path|
104
 
 
105
 
            # Change the cwd to path, but ignore non-existent paths.
106
 
            begin
107
 
              Dir.chdir(path)
108
 
            rescue Errno::ENOENT
109
 
              next
110
 
            end
111
 
 
112
 
            found_targets = []
113
 
            targets.each do |target|
114
 
              matching_paths = Dir.glob(target)
115
 
              matching_paths.each do |target_path|
116
 
                target_path = File.join(path.tr('\\', '/'), target_path)
117
 
                if File.exists?(target_path)
118
 
                  found_targets << target
119
 
                  retried = 0
120
 
                  begin
121
 
                    FileUtils.cp(target_path, svnserve_dir)
122
 
                  rescue Errno::EACCES
123
 
                    # On Windows the tests frequently fail spuriously with a
124
 
                    # 'Errno::EACCES: Permission denied - svnserve.exe' error.
125
 
                    # Sleeping for a few seconds avoids this.
126
 
                    if retried > 5
127
 
                      # Give up!
128
 
                      raise
129
 
                    else
130
 
                      # Wait a sec...
131
 
                      sleep(1)
132
 
                      retried += 1
133
 
                      retry
134
 
                    end
135
 
                  end
136
 
                end
137
 
              end
138
 
            end
139
 
            targets -= found_targets
140
 
            break if targets.empty?
141
 
          end
142
 
          Dir.chdir(cwd)
143
 
          # Remove optional targets instead of raising below.  If they are really
144
 
          # needed, svnserve won't start anyway.
145
 
          targets -= %W[libapriconv#{apr_major_version}.dll]
146
 
          # Ditto these four, since svnserve.exe might be a static build.
147
 
          targets -= %W[libsvn_subr-1.dll]
148
 
          targets -= %W[libsvn_repos-1.dll]
149
 
          targets -= %W[libsvn_fs-1.dll]
150
 
          targets -= %W[libsvn_delta-1.dll]
151
 
 
152
 
          unless targets.empty?
153
 
            raise "can't find libraries to work svnserve: #{targets.join(' ')}"
154
 
          end
155
 
 
156
 
          grant_everyone_full_access(svnserve_dir)
157
 
 
158
 
          svnserve_path = File.join(svnserve_dir, "svnserve.exe")
159
 
          svnserve_path = svnserve_path.tr(File::SEPARATOR,
160
 
                                           File::ALT_SEPARATOR)
 
43
 
 
44
          top_directory = File.join(File.dirname(__FILE__), "..", "..", "..", "..", "..")
 
45
          build_type = ENV["BUILD_TYPE"] || "Release"
 
46
          svnserve_path = File.join(top_directory, build_type, 'subversion', 'svnserve', 'svnserve.exe')
161
47
          svnserve_path = Svnserve.escape_value(svnserve_path)
162
48
 
163
49
          root = @full_repos_path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
 
50
          FileUtils.mkdir_p(root)
164
51
 
165
 
          args = ["--service", "--root", Svnserve.escape_value(root),
166
 
                  "--listen-host", @svnserve_host,
167
 
                  "--listen-port", @svnserve_port]
 
52
          IO.popen("#{svnserve_path} -d -r #{Svnserve.escape_value(root)} --listen-host #{@svnserve_host} --listen-port #{@svnserve_port} --pid-file #{@svnserve_pid_file}")
168
53
          user = ENV["USERNAME"] || Etc.getlogin
169
 
          service_control('create',
170
 
                          [["binPath", "#{svnserve_path} #{args.join(' ')}"],
171
 
                           ["DisplayName", service_name],
172
 
                           ["type", "own"]])
 
54
 
 
55
          # Give svnserve a bit of time to start
 
56
          sleep 1
173
57
        end
174
 
        service_control('start')
175
58
        true
176
59
      end
177
60
 
178
61
      def teardown_svnserve
179
 
        service_control('stop') unless service_stopped?
 
62
        # TODO:
 
63
        #   Load @svnserve_pid_file
 
64
        #   Kill process
180
65
      end
181
66
 
182
67
      def add_pre_revprop_change_hook