cryptonas-branches/pythonrewrite/plugins/volume_props/volume_props.py
lars 11c2873934 moved "Rank" attribute from language file to plugin code
added plugin "plugin_manager"
added plugin "user_manager"
2006-10-11 15:50:24 +00:00

81 lines
2.6 KiB
Python

import CryptoBoxPlugin
from CryptoBoxExceptions import *
class volume_props(CryptoBoxPlugin.CryptoBoxPlugin):
pluginCapabilities = [ "volume" ]
requestAuth = False
rank = 40
def doAction(self, store=None, vol_name=None, old_pw=None, new_pw=None, new_pw2=None):
self.container = self.cbox.getContainer(self.device)
if not self.container:
return None
self.__prepareHDF()
if store == "set_name":
return self.__setVolumeName(vol_name)
elif store == "change_pw":
return self.__changePassword(old_pw, new_pw, new_pw2)
elif not store:
return "volume_properties"
else:
self.cbox.log.info("plugin 'volume_props' - unknown action: %s" % store)
return "volume_properties"
def getStatus(self):
self.container = self.cbox.getContainer(self.device)
if not self.container:
return "invalid device"
return "name=%s" % self.container.getName()
def __prepareHDF(self):
self.hdf[self.hdf_prefix + "vol_name"] = self.container.getName()
def __setVolumeName(self, vol_name):
if not vol_name:
self.hdf["Data.Warning"] = "Plugins.volume_props.InvalidVolumeName"
return "volume_properties"
if vol_name == self.container.getName():
## nothing has to be done
return "volume_properties"
try:
self.container.setName(vol_name)
except CBInvalidName:
self.hdf["Data.Warning"] = "Plugins.volume_props.InvalidVolumeName"
except CBNameActivelyUsed:
self.hdf["Data.Warning"] = "Plugins.volume_props.VolumeNameIsInUse"
except CBContainerError:
self.hdf["Data.Warning"] = "Plugins.volume_props.SetVolumeNameFailed"
## reread the volume name
self.__prepareHDF()
return "volume_properties"
def __changePassword(self, old_pw, new_pw, new_pw2):
if not old_pw:
self.hdf["Data.Warning"] = "EmptyPassword"
elif not new_pw:
self.hdf["Data.Warning"] = "EmptyNewPassword"
elif new_pw != new_pw2:
self.hdf["Data.Warning"] = "DifferentPasswords"
elif old_pw == new_pw:
## do nothing
pass
else:
try:
self.container.changePassword(old_pw, new_pw)
except CBInvalidType, errMsg:
self.cbox.log.info("plugin 'volume_props' - cannot change passphrase for non-encrypted container (%s): %s" % (self.device, errMsg))
except CBVolumeIsActive:
self.hdf["Data.Warning"] = "VolumeMayNotBeMounted"
except CBChangePasswordError, errMsg:
self.cbox.log.warn("plugin 'volume_props' - cannot change password for device (%s): %s" % (self.device, errMsg))
self.hdf["Data.Warning"] = "Plugins.volume_props.PasswordChange"
else:
self.hdf["Data.Success"] = "Plugins.volume_props.PasswordChange"
return "volume_properties"