Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the beginnings of modify functionality, including the modconf fun…

…ction in NymConf.
  • Loading branch information...
commit f284963735c1e2ecba4a12728fd6ad5583a48d2f 1 parent 53c4b14
@crooks authored
Showing with 63 additions and 64 deletions.
  1. +63 −64 nymserv/nymserv
View
127 nymserv/nymserv
@@ -258,6 +258,18 @@ class NymConf():
logging.warn('No config file found for %s' % nym)
raise IOError, '%s: File not found.' % userfile
+ def modconf(self, nym):
+ """Read the Nym configuration from the DB file held on disk.
+
+ """
+ userfile = os.path.join(config.get('paths', 'users'),
+ recipient + '.db')
+ if os.path.exists(userfile):
+ self.conf = shelve.open(userfile, flag='w')
+ else:
+ logging.warn('Cannot modify a non-existing user DB file.' % nym)
+ raise IOError, '%s: File not found.' % userfile
+
def create(self, nym):
"""Create a user shelve. This is strictly create only!.
@@ -288,13 +300,30 @@ class Inbound_Processing():
# Populate the reserved Nyms list.
resfile = os.path.join(config.get('paths', 'etc'), 'reserved_nyms')
self.reserved_nyms = nymserv.strutils.file2list(resfile)
- # THis is identical to normal gpg except that it uses a temporary
+ # This is identical to normal gpg except that it uses a temporary
# public keyring. This is used during new nym requests to test
# a key, without really importing it.
self.gpgtmp = nymserv.gnupg.GnuPGFunctions(
config.get('paths', 'keyring'),
'tmpring.gpg')
+ # The following variables are used during config modify operations.
+
+ # Match lines formatted as "option: value".
+ self.confopt_re = re.compile('([\w\-]+?):\s*(.{1,64})$')
+ # Valid fields are those that are deemed user-definable.
+ self.valid_fields = ['symmetric', 'hsub', 'delete', 'subject']
+ self.alternatives = {'hash-subject': 'hsub',
+ 'subject-password': 'hsub',
+ 'hash-key': 'hsub'}
+ ignore_fields = ['version'] # Public keys contain "Version: "
+ # We ignore the next two fields to prevent warnings about MIME content.
+ ignore_fields.append("content-type")
+ ignore_fields.append("content-disposition")
+ self.ignore_fields = ignore_fields
+
+ # Following is a dictionary of response message we send to Nymholders.
+
self.messages = {'reserved': (
"Error: %(sigfor)s is a reserved Nym.\n"
"\n"
@@ -595,24 +624,40 @@ class Inbound_Processing():
logging.info("%s: Nym was successfully created"
% self.conf['address'])
- # We're past the new Nym phase. Everything from here is common to all
- # messages sent to config@foo.
- logging.debug('%s: Entering config modify routine.' % sigfor)
- if not created:
- # If we haven't done a create, the userconf isn't open yet.
- userfile = os.path.join(config.get('paths', 'users'),
- sigfor + '.db')
- # This is a modify process, the user file must already exist.
- if os.path.isfile(userfile):
- userconf = shelve.open(userfile)
+ def config_modify(self, nym):
+ """Parse a block of text for lines in the format Key: Option.
+
+ """
+ logging.debug('%s: Entering config modify routine.' % nym)
+ moddict = {}
+ for line in self.payload.split("\n"):
+ confopt = self.confopt_re.match(line)
+ if not confopt:
+ continue
+ # Set field to the header name and value to its content.
+ field = confopt.group(1).lower()
+ value = confopt.group(2).rstrip()
+ # Some fields have alternative names.
+ if field in self.alternatives:
+ field = self.alternatives[field]
+ if field in moddict:
+ logmes = "%s: Duplicate field in modify request." % field
+ logging.info(logmes)
+ continue
+ # If we match a field:value pair, is it valid?
+ if not field in self.valid_fields:
+ if not field in self.ignore_fields:
+ logmes = "%s: Invalid field in modify " % field
+ logmes += "request"
+ logging.info(logmes)
+ continue
+ # None or False means set the field to False.
+ if value.lower() == 'none' or value.lower() == 'false':
+ moddict[field] = False
else:
- # In theory this can't happen. We can't be modifying a Nym that
- # doesn't already have a config file.
- logging.error("%s: File doesn't exist." % userconf)
- return False
- # user_update creates a new dict of keys that need to be created or changed
- # in the master userconf dict.
- moddict = updusr.make_moddict(payload)
+ moddict[field] = value
+ # That's it for creating the moddict
+
# Does the mod request include a Delete statement?
if 'delete' in moddict and moddict['delete'].lower() == 'yes':
logmessage = sigfor + ": Starting delete process "
@@ -740,53 +785,7 @@ class Mailbox():
class UpdateUser():
def __init__(self):
- # Valid fields are those that are deemed user-definable.
- self.valid_fields = ['symmetric', 'hsub', 'delete', 'subject']
- self.alternatives = {'hash-subject': 'hsub',
- 'subject-password': 'hsub',
- 'hash-key': 'hsub'}
- ignore_fields = ['version'] # Public keys contain "Version: "
- # We ignore the next two fields to prevent warnings about MIME content.
- ignore_fields.append("content-type")
- ignore_fields.append("content-disposition")
- self.confopt_re = re.compile('([\w\-]+?):\s*(.{1,64})$')
- self.ignore_fields = ignore_fields
-
- def make_moddict(self, text):
- """Parse a block of text for lines in the format Key: Option. Compare
- these with a list of valid fields and then construct a dictionary of
- these options for return.
- """
- lines = text.split('\n')
- moddict = {}
- for line in lines:
- confopt = self.confopt_re.match(line)
- if not confopt:
- continue
- # Set field to the header name and value to its content.
- field = confopt.group(1).lower()
- value = confopt.group(2).rstrip()
- # Some fields have alternative names.
- if field in self.alternatives:
- field = self.alternatives[field]
- if field in moddict:
- logmes = "%s: Duplicate field in modify request." % field
- logging.info(logmes)
- continue
- # If we match a field:value pair, is it valid?
- if not field in self.valid_fields:
- if not field in self.ignore_fields:
- logmes = "%s: Invalid field in modify " % field
- logmes += "request"
- logging.info(logmes)
- continue
- # None or False means set the field to False.
- if value.lower() == 'none' or value.lower() == 'false':
- moddict[field] = False
- else:
- moddict[field] = value
- return moddict
class PostPrep():
Please sign in to comment.
Something went wrong with that request. Please try again.