connman: package systemd files
[openembedded.git] / contrib / oeaudit / freebsd.py
blob5765e8a726f796d5d9cfed617b59dd58fe46bbf6
1 """
2 Handle FreeBSD port audit files and map the names to OpenEmbedded
3 """
5 class freebsd_info:
6 """
7 Handles an entry like the one below:
8 vulnerability-test-port>=2000<2010.02.26|http://cvsweb.freebsd.org/ports/security/vulnerability-test-port/|Not vulnerable, just a test port (database: 2010-02-26)
9 """
10 def __init__(self, name, versions, link, kind):
11 self.name = name
12 self.versions = versions
13 self.link = link
15 @classmethod
16 def split_versions(self, input):
17 """
18 Split versions by <, >, >=, >=
19 """
20 versions = []
21 last_pos = 0
23 # Try to determine <, >, >=, <=
24 # we will have to carry stuff on to find the
25 # version..
26 i = 0
27 while i < len(input) - 1:
28 c1 = input[i]
29 c2 = input[i+1]
30 if c1 != '<' and c1 != '>' and c1 != '=':
31 i = i + 1
32 continue
34 # is a '=' coming behind it?
35 next = i + 1
36 if c2 == '=':
37 next = next + 1
39 # submit
40 if last_pos != 0:
41 versions.append((next_type, input[last_pos:i]))
43 # remember stuff
44 next_type = input[i:next]
45 last_pos = next
46 i = next
48 assert last_pos != 0
49 versions.append((next_type, input[last_pos:len(input)]))
50 return versions
52 def __repr__(self):
53 return "%s: %s" % (self.name, self.versions)
56 def map_names(str):
57 """Map a FreeBSD name to OE"""
58 maps = {
59 "libpurple" : "pidgin",
60 "php4" : "php",
61 "php5" : "php",
62 "expat2" : "expat",
63 "freeciv-gtk" : "freeciv",
64 "pcre" : "libpcre",
65 "vim-gnome" : "vim",
66 "python23" : "python",
67 "python24" : "python",
68 "python25" : "python",
69 "python+ipv6" : "python",
70 "wget-devel" : "wget",
71 "xchat2" : "xchat",
72 "freetype" : "freetype",
73 "qemu-devel" : "qemu",
74 "krb5-beta" : "krb5",
75 "freeciv-gtk2": "freeciv",
76 "gtk" : "gtk+",
77 "wget+ipv6" : "wget",
78 "ja-gd" : "gd",
79 "openvpn-devel" : "openvpn",
80 "mpeg123-esound" : "mpeg123",
81 "mpeg123-nas" : "mpeg123",
82 "cdrtools-cjk" : "cdrtools",
83 "apache+mod_ssl+mod_deflate" : "apache2",
84 "apache+mod_ssl*" : "apache2",
85 "vim-gtk2" : "vim",
86 "zh-emacs" : "emacs",
87 "{ja-,}bugzilla" : "bugzilla",
88 "zh-tin" : "tin",
89 "mozilla+ipv6": "mozilla",
90 "mozilla-embeddded" : "mozilla",
91 "rar" : "unrar",
92 "libsndfile" : "libsndfile1",
93 "sylpheed-gtk2": "sylpheed",
94 "cdrtools-devel": "cdrtools",
95 "pine4-ssl": "pine",
96 "apache" : "apache2",
97 "ghostscript-gpl" : "gs",
98 "ghostscript-gnu-nox11" : "gs",
99 "ghostscript8" : "gs",
100 "ghostscript-afpl-nox11" : "gs",
101 "ghostscript-afpl" : "gs",
102 "isc-dhcp" : "dhcp",
103 "mplayer-gtk" : "mplayer",
104 "xerces-c2" : "xerces-c",
105 "libxml" : "libxml2",
106 "vim+ruby" : "vim",
107 "mplayer{,-gtk}{,-esound}" : "mplayer",
108 "proftpd-devel": "proftpd",
109 "neon28" : "neon",
110 "php4-dba" : "php",
111 "php5-{cgi,cli}" : "php",
115 try:
116 return maps[str]
117 except:
118 return str
120 def is_not_in_oe(name):
121 """Method to reject packages not in OE"""
122 not_in = [
123 # packages that we will never have...
124 "linux-firefox", "fr-linux-netscape", "linux-netscape-{communicator,navigator}",
125 "linux_base", "ja-netscape7", "{ja,ko}-netscape-{communicator,navigator}-linux", "zhTW-linux-mozillafirebird", "ja-linux-mozillafirebird-gtk1", "el-linux-mozillafirebird", "mozilla-firebird", "netscape7",
126 "acroread4", "acroread7", "acroread5",
127 "linux-openmotif", "linux-flock", "linux-jdk", "linux-curl", "linux-png", "linux-firefox-devel",
129 # packages that we don't have now but maybe will have in
130 # the future and blacklisting them here might be a problem
131 "openoffice.org-2-devel", "openoffice.org-2", "it-openoffice", "ca-openoffice","sl-openoffice-SI", "ja-openoffice",
132 "drupal4", "drupal5", "drupal6", "drupal-pubcookie",
133 "gpdf",
134 "nagios",
135 "kdenetwork", "ja-kdelibs", "kdegraphics", "kdepim", "kdebase4-runtime",
136 "xemacs-devel", "xemacs-devel-21.5", "xemacs-mule", "zh-xemacs", "zh-xemacs-mule",
137 "geeklog", "apach13-ssl", "nvidia-driver", "eGroupWare", "varnish", "heimdal",
138 "bugzilla", "agenda-snow-libs", "mozilla",
141 return name in not_in
143 def create_infos(line):
144 split = line.split("|")
145 for i in range(0, len(split[0])):
146 c = split[0][i]
147 if c != '<' and c != '=' and c != '>':
148 continue
149 name = map_names(split[0][0:i])
150 versions = freebsd_info.split_versions(split[0][i:])
151 break
153 if is_not_in_oe(name):
154 #print "Not in oe %s" % name
155 return []
157 link = split[1]
158 kind = split[2]
159 return [freebsd_info(name, versions, link, kind)]
162 def read_auditfile(filename):
164 Read an uncompressed audit file from freebsd
166 f = open(filename)
167 packages = {}
168 for line in f:
169 if line.startswith("#"):
170 continue
172 infos = create_infos(line)
173 for info in infos:
174 try:
175 packages[info.name].append(info)
176 except:
177 packages[info.name] = []
178 packages[info.name].append(info)
179 return packages
182 def prepare_version(bsd_version):
184 FreeBSD is adding ,1 for revisions.. remove that
186 # FIXME return a tuple with a revision...
187 rev = "r0"
188 split = bsd_version.rsplit(',', 1)
189 split = split[0]
190 split = split.rsplit('_', 1)
191 if len(split) == 2:
192 rev = "r%s" % split[1]
193 return (split[0], rev)