import CryptoBoxPlugin from CryptoBoxExceptions import * class volume_props(CryptoBoxPlugin.CryptoBoxPlugin): pluginCapabilities = [ "volume" ] requestAuth = False 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"] = "EmptyCryptoPassword" elif not new_pw: self.hdf["Data.Warning"] = "EmptyNewCryptoPassword" elif new_pw != new_pw2: self.hdf["Data.Warning"] = "DifferentCryptoPasswords" 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"