Python Library Documentation: module srvtab_edit NAME srvtab_edit FILE /home/users/mokrejs/proj/srvtab_edit.py DESCRIPTION srvtab_edit.py is a Python module enabling you to manipulate keys in srvtab formatted file. The aim is to have a tool to take individual keys out of a file and write them to separate file(s), or to write different combination of individual keys into a file. One can use then `ksrvutil -f srvtab.new change' to update host keys without the need to kerberos administrator. (You can of course forget this all, delete the srvtab and use `ksrvutil get' to download them from KDC or create them, if you know the administrators password.) ;) `ksrvutil -f srvtab.new change' will ensure you that the keys in *THAT* file match Kerberos KDC (matched before change and as the update went fine, the new key stored in that file must also match KDC). You can then use `cat(1)' to merge those files together to get a srvtab with more keys, or use this module in interactive session (see below). srvtab_edit.py does *NOT* implement delete function to delete keys, *BUT* you are expected to copy selected keys away into a new file. Although you need to be root to get read access on /etc/srvtab, you don't have to run this code as root. This program is available as is, without any warranty. Use it freely. ;) Martin Mokrejs http://www.natur.cuni.cz/~mmokrejs/afs 21. 9. 2002 version 1.0 Usage: python srvtab_edit.py The program will ask you for path to srvtab file, then show recognised keys in enumerated output. Afterwards you can type in numbers (representing position of the key in original srvtab file) of keys to be copied to another file. If they are present, they will be written to such a new file. After creating the new srvtab file, you can reopen it in srvtab_edit.py *AND* `ksrvutil list' to see the result. Of course, `od -c srvtab' is also fine. On the other hand, you can use this module directly from interactive python session: shell$ start "python" >>> from srvtab_edit import * >>> tuple,count = readkeys("/etc/srvtab") >>> print "There are " + str(count) + " keys." >>> firstkey = instantiatekey(0,tuple) >>> secondkey = instantiatekey(1,tuple) ... and so on (do "ksrvutil -f /etc/srvtab list" before running python to see which keys you want to copy out) >>> print firstkey >>> print secondkey ... and so on [ ... you may open another srvtab and read from it other keys ] [ >>> tuple,count = readkeys("./srvtab-2") ] [ >>> print "There are " + str(count) + " keys." ] [ >>> tenthkey = instantiatekey(0,tuple) ] [ >>> eleventhkey = instantiatekey(11,tuple) ] >>> towrite = [] >>> towrite.append(firstkey) >>> towrite.append(secondkey) ... and so on [ >>> owrite.append(eleventhkey) ] >>> print "Keys listed here will be copied to a new file: " + str(towrite) >>> writekeys("/etc/srvtab.new",towrite) Creating new file etc/srvtab.new Writing key ftp.pf-i400@NATUR.CUNI.CZ KVNO: 2. Writing key rcmd.pf-i400@NATUR.CUNI.CZ KVNO: 2. >>> CTRL-D CLASSES Key class Key | | __init__(self, principal, host, realm, kvno, key) | | __repr__(self) | | write(self, file) FUNCTIONS instantiatekey(keypos, tu) instantiatekey(keypos,tu) find the key in position `keypos' in the tuple `tu' and returns whole key as an instance consisting of self.principal, self.host, self.realm, self.kvno, self.key attributes. main() readkeys(file) readkeys(file) returns 2 values. First is a tuple containing keys, second is a number of keys read from a file We split srvtab using octal 0 as delimiter, which is missing after the key and next principal name. For example having 4 keys in srvtab results in tuple of size 13 and fields are recognised as follows: principal = tuple[0] host = tuple[1] realm = tuple[2] key_plus_next_principal = tuple[3] writekeys(file, instlist) writekeys(file,instlist) writes all specified key instances to a *NEW* file. If the file is already present, writekeys() will *NOT* touch it at all! DATA IntType = ListType = StringType = __file__ = './srvtab_edit.py' __name__ = 'srvtab_edit'