~davewalker/ubuntu/maverick/eucalyptus/lp611144

« back to all changes in this revision

Viewing changes to util/dd-lv

  • Committer: Dave Walker (Daviey)
  • Date: 2010-06-21 12:59:20 UTC
  • mfrom: (1048.1.14 ubuntu)
  • Revision ID: davewalker@ubuntu.com-20100621125920-60uhixwq174elnj1
* New major upstream version merge, 1.7 (r1200).
* debian/patches/:
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Refreshed.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# Copyright (C) 2009, Canonical, Ltd.
 
3
# Author: Kees Cook <kees@ubuntu.com>
 
4
# License: GPLv3
 
5
#
 
6
# Attempt to sanitize the dd arguments, even though this still allows for arbitrary read/write
 
7
# and DoS of any LVs.
 
8
 
 
9
import sys, os, glob
 
10
 
 
11
if len(sys.argv)<3:
 
12
    print >>sys.stderr, "Invalid arguments"
 
13
    sys.exit(1)
 
14
 
 
15
opts = dict()
 
16
for arg in sys.argv[1:]:
 
17
    for opt in ['if','of']:
 
18
        if arg.startswith(opt+'='):
 
19
            if opts.has_key(opt):
 
20
                print >>sys.stderr, "Option '%s' repeated" % (opt)
 
21
                sys.exit(1)
 
22
            opts.setdefault(opt,arg.split('=',1)[1])
 
23
if 'if' not in opts or 'of' not in opts:
 
24
    print >>sys.stderr, "Missing 'if' or 'of' arguments"
 
25
    sys.exit(1)
 
26
 
 
27
# Allowed:
 
28
# - /dev/zero -> anywhere
 
29
# - devmapper -> anywhere
 
30
# - anywhere -> devmapper
 
31
if opts['if'] != '/dev/zero':
 
32
    found = False
 
33
 
 
34
    for device in [opts['if'], opts['of']]:
 
35
        try:
 
36
            src = os.stat(device)
 
37
        except:
 
38
            continue
 
39
        for dm in glob.glob('/dev/mapper/*'):
 
40
            if dm.endswith('/control'):
 
41
                continue
 
42
            if os.stat(dm).st_rdev == src.st_rdev:
 
43
                found = True
 
44
                break
 
45
        if found:
 
46
            break
 
47
 
 
48
    if not found:
 
49
        print >>sys.stderr, "Source is not /dev/zero or source/target is not a devmapper device"
 
50
        sys.exit(1)
 
51
 
 
52
args = ['/bin/dd'] + sys.argv[1:]
 
53
os.execl('/bin/dd', *args)