#!/usr/bin/python # $Header: /home/cvsroot/gentoo-projects/gentoo-security/GLSA/user-tools/glsa-check.py,v 1.6 2003/12/22 03:38:13 genone Exp $ # This program is licensed under the GPL, version 2 import os,string,sys from getopt import getopt,GetoptError __program__ = "glsa-check" __author__ = "Marius Mauch " __version__ = "0.4" optionmap = [ ["-l", "--list", "list all unapplied GLSA"], ["-d", "--dump", "--print", "show all information about the given GLSA"], ["-t", "--test", "test if this system is affected by the given GLSA"], ["-p", "--pretend", "show the necessary commands to apply this GLSA"], ["-f", "--fix", "try to auto-apply this GLSA (experimental)"], ["-i", "--inject", "inject the given GLSA into the checkfile"], ["-h", "--help", "show this help message"], ["-v", "--version", "some information about this tool"] ] # print a warning as this is beta code sys.stderr.write("WARNING: This tool is completely new and not very tested, so it should not be\n") sys.stderr.write("used on production systems. It's mainly a test tool for the new GLSA release\n") sys.stderr.write("and distribution system. Please report any success or failure to with this tool to:\n") sys.stderr.write(" "+__author__+"\n\n") # option parsing args = [] params = [] try: args, params = getopt(sys.argv[1:], "dplfchivt", \ ["dump", "print", "list", "pretend", "fix", "inject", "help", "info", "version", "test"]) args = [a for a,b in args] # sanity checking if len(args) <= 0: print "no option given: what should I do ?" mode="help" elif len(args) > 1: print "please use only one option per call" mode = "help" else: # in what mode are we ? args = args[0] for m in optionmap: if args in [o for o in m[:-1]]: mode = m[1][2:] except GetoptError: print "unknown option given" mode = "help" # we need a set of glsa for most operation modes if len(params) <= 0 and mode in ["fix", "test", "pretend", "dump", "inject"]: print print "no GLSA given, so we'll do nothing for now. " print "If you want to run on all GLSA please tell me so " print "(specify \"all\" as parameter)" print mode = "help" elif len(params) <= 0 and mode == "list": params.append("new") # show help message if mode == "help": print print "Syntax: glsa-check