#! /bin/sh /usr/share/dpatch/dpatch-run ## 30_announce_list_only_torrents.dpatch by Cameron Dale ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Allow torrents which have "announce-list" but no "announce" key. ## DP: Taken from upstream's CVS. @DPATCH@ --- bittornado.orig/BitTornado/BT1/btformats.py +++ bittornado/BitTornado/BT1/btformats.py @@ -44,7 +44,8 @@ for p in path: if type(p) != StringType: raise ValueError, 'bad metainfo - bad path dir' - if not reg.match(p): + if p != '': + if not reg.match(p): raise ValueError, 'path %s disallowed for security reasons' % p for i in xrange(len(files)): for j in xrange(i): @@ -55,8 +56,21 @@ if type(message) != DictType: raise ValueError check_info(message.get('info')) - if type(message.get('announce')) != StringType: - raise ValueError + if not (message.has_key('announce') or message.has_key('announce-list')): + raise ValueError, 'no announce' + if type(message.get('announce', "")) != StringType: + raise ValueError, 'bad announce' + if message.has_key('announce-list'): + try: + ll = message.get('announce-list') + assert type(ll) == ListType + for l in ll: + assert type(l) == ListType + for s in l: + assert type(s) == StringType + except: + raise ValueError, 'bad announce-list' + def check_peers(message): if type(message) != DictType: --- bittornado.orig/btshowmetainfo.py +++ bittornado/btshowmetainfo.py @@ -21,58 +21,67 @@ exit(2) # common exit code for syntax error for metainfo_name in argv[1:]: + print 'metainfo file.: %s' % basename(metainfo_name) + metainfo_file = open(metainfo_name, 'rb') - metainfo = bdecode(metainfo_file.read()) -# print metainfo - info = metainfo['info'] - info_hash = sha(bencode(info)) + metainfo = metainfo_file.read() + metainfo_file.close() + metainfo = bdecode(metainfo) + try: + info = metainfo['info'] + info_hash = sha(bencode(info)) - print 'metainfo file.: %s' % basename(metainfo_name) - print 'info hash.....: %s' % info_hash.hexdigest() - piece_length = info['piece length'] - if info.has_key('length'): - # let's assume we just have a file - print 'file name.....: %s' % info['name'] - file_length = info['length'] - name ='file size.....:' - else: - # let's assume we have a directory structure - print 'directory name: %s' % info['name'] - print 'files.........: ' - file_length = 0; - for file in info['files']: - path = '' - for item in file['path']: - if (path != ''): - path = path + "/" - path = path + item - print ' %s (%d)' % (path, file['length']) - file_length += file['length'] - name ='archive size..:' - piece_number, last_piece_length = divmod(file_length, piece_length) - print '%s %i (%i * %i + %i)' \ - % (name,file_length, piece_number, piece_length, last_piece_length) - print 'announce url..: %s' % metainfo['announce'] - if metainfo.has_key('announce-list'): - list = [] - for tier in metainfo['announce-list']: - for tracker in tier: - list+=[tracker,','] + print 'info hash.....: %s' % info_hash.hexdigest() + piece_length = info['piece length'] + if info.has_key('length'): + # let's assume we just have a file + print 'file name.....: %s' % info['name'] + file_length = info['length'] + name ='file size.....:' + else: + # let's assume we have a directory structure + print 'directory name: %s' % info['name'] + print 'files.........: ' + file_length = 0; + for file in info['files']: + path = '' + for item in file['path']: + if (path != ''): + path = path + "/" + path = path + item + print ' %s (%d)' % (path, file['length']) + file_length += file['length'] + name ='archive size..:' + piece_number, last_piece_length = divmod(file_length, piece_length) + print '%s %i (%i * %i + %i)' \ + % (name,file_length, piece_number, piece_length, last_piece_length) + if metainfo.has_key('announce'): + print 'announce url..: %s' % metainfo['announce'] + else: + print '***WARNING*** - no announce key' + if metainfo.has_key('announce-list'): + list = [] + for tier in metainfo['announce-list']: + for tracker in tier: + list+=[tracker,','] + del list[-1] + list+=['|'] del list[-1] - list+=['|'] - del list[-1] - liststring = '' - for i in list: - liststring+=i - print 'announce-list.: %s' % liststring - if metainfo.has_key('httpseeds'): - list = [] - for seed in metainfo['httpseeds']: - list += [seed,'|'] - del list[-1] - liststring = '' - for i in list: - liststring+=i - print 'http seeds....: %s' % liststring - if metainfo.has_key('comment'): - print 'comment.......: %s' % metainfo['comment'] + liststring = '' + for i in list: + liststring+=i + print 'announce-list.: %s' % liststring + if metainfo.has_key('httpseeds'): + list = [] + for seed in metainfo['httpseeds']: + list += [seed,'|'] + del list[-1] + liststring = '' + for i in list: + liststring+=i + print 'http seeds....: %s' % liststring + if metainfo.has_key('comment'): + print 'comment.......: %s' % metainfo['comment'] + + except: + print '***ERROR*** - metainfo out of spec'