X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=make-secnet-sites;h=2fd182e29dcb3119cc625aba873a4bf071f0d60b;hb=d74dde997bca95c00ae14ee646e705ae7e9001b1;hp=4826a445caa5604ca2c61f75a3dc1c8730bc8cf1;hpb=7202dbe71ef448a188f20e389802f7a110514c71;p=secnet.git diff --git a/make-secnet-sites b/make-secnet-sites index 4826a44..2fd182e 100755 --- a/make-secnet-sites +++ b/make-secnet-sites @@ -105,19 +105,19 @@ class Tainted: assert(self._ok is not True) self._ok=False complain('bad parameter: %s: %s' % (what, why)) - return self + return False def _max_ok(self,what,maxlen): if len(self._s) > maxlen: - self._bad(what,'too long (max %d)' % maxlen) - return self + return self._bad(what,'too long (max %d)' % maxlen) + return True def _re_ok(self,bad,what,maxlen=None): if maxlen is None: maxlen=max[what] self._max_ok(what,maxlen) - if self._ok is False: return self + if self._ok is False: return False if bad.search(self._s): return self._bad(what,'bad syntax') - return self + return True def _rtnval(self, is_ok, ifgood, ifbad=''): if is_ok: @@ -149,8 +149,8 @@ class Tainted: bad_name=re.compile(r'^[^a-zA-Z]|[^-_0-9a-zA-Z]') # secnet accepts _ at start of names, but we reserve that bad_name_counter=0 - def name(self): - ok=self._re_ok(Tainted.bad_name,'name') + def name(self,what='name'): + ok=self._re_ok(Tainted.bad_name,what) return self._rtn(ok, '_line%d_%s' % (self._line, id(self))) @@ -211,9 +211,11 @@ def parse_args(): global header global groupfiledir global sitesfile + global outputfile global group global user global of + global prefix global key_prefix ap = argparse.ArgumentParser(description='process secnet sites files') @@ -228,6 +230,7 @@ def parse_args(): av = ap.parse_args() #print(repr(av), file=sys.stderr) service = 1 if av.userv else 0 + prefix = '' if av.prefix is None else av.prefix[0] key_prefix = av.conf_key_prefix if service: if len(av.arg)!=4: @@ -256,8 +259,6 @@ def parse_args(): print("Too many arguments") sys.exit(1) (inputfile, outputfile) = (av.arg + [None]*2)[0:2] - if outputfile is None: of=sys.stdout - else: of=open(outputfile,'w') parse_args() @@ -536,13 +537,12 @@ levels={'vpn':vpnlevel, 'location':locationlevel, 'site':sitelevel} def complain(msg): "Complain about a particular input line" - global complaints - print(("%s line %d: "%(file,line))+msg) - complaints=complaints+1 + moan(("%s line %d: "%(file,line))+msg) def moan(msg): "Complain about something in general" global complaints print(msg); + if complaints is None: sys.exit(1) complaints=complaints+1 class UntaintedRoot(): @@ -554,7 +554,6 @@ root=level([UntaintedRoot(x) for x in ['root','root']]) # All vpns are children of this node obstack=[root] allow_defs=0 # Level above which new definitions are permitted -prefix='' def set_property(obj,w): "Set a property on a configuration node" @@ -776,4 +775,11 @@ if service: f.close() os.rename(sitesfile+"-tmp",sitesfile) else: + if outputfile is None: + of=sys.stdout + else: + tmp_outputfile=outputfile+'~tmp~' + of=open(tmp_outputfile,'w') outputsites(of) + if outputfile is not None: + os.rename(tmp_outputfile,outputfile)