示例#1
0
 def test_username_bad_domain_smbsr(self):
     junk_dconf = {
         "password_secret": "123",
         "username": "******"
     }
     junk_session = 123
     with self.assertRaises(cifutils.CIFSException) as cm:
         cifutils.getCIFCredentials(junk_dconf, junk_session)
     expected_message = ("A maximum of 2 tokens are expected "
                         "(<domain>\<username>). 3 were given.")
     the_exception = cm.exception
     self.assertEqual(the_exception.errstr, expected_message)
示例#2
0
    def mount(self, mountpoint=None):

        mountpoint = self.makeMountPoint(mountpoint)

        new_env, domain = cifutils.getCIFCredentials(self.dconf, self.session)

        options = self.getMountOptions(domain)
        if options:
            options = ",".join(str(x) for x in options if x)

        try:

            util.ioretry(lambda:
                util.pread(["mount.cifs", self.remoteserver,
                mountpoint, "-o", options], new_env=new_env),
                errlist=[errno.EPIPE, errno.EIO],
                maxretry=2, nofail=True)
        except util.CommandException as inst:
            raise SMBException("mount failed with return code %d" % inst.code)

        # Sanity check to ensure that the user has at least RO access to the
        # mounted share. Windows sharing and security settings can be tricky.
        try:
            util.listdir(mountpoint)
        except util.CommandException:
            try:
                self.unmount(mountpoint, True)
            except SMBException:
                util.logException('SMBSR.unmount()')
            raise SMBException("Permission denied. "
                                "Please check user privileges.")
示例#3
0
 def test_empty_credentials_and_domain_for_bad_dconf(self):
     junk_dconf = {"junk1": "123"}
     junk_session = 123
     credentials, domain = cifutils.getCIFCredentials(junk_dconf,
                                                      junk_session,
                                                      prefix="cifs")
     self.assertEquals(credentials, None)
     self.assertEquals(domain, None)
示例#4
0
 def test_password_and_username_domain_smbsr(self):
     junk_dconf = {"password": "******", "username": "******"}
     junk_session = 123
     credentials, domain = cifutils.getCIFCredentials(
         junk_dconf, junk_session)
     expected_credentials = {"USER": "******", "PASSWD": "123"}
     self.assertEquals(credentials, expected_credentials)
     self.assertEquals(domain, "citrix")
示例#5
0
 def test_password_and_username(self):
     junk_dconf = {"cifspassword": "******", "username": "******"}
     junk_session = 123
     credentials, domain = cifutils.getCIFCredentials(junk_dconf,
                                                      junk_session,
                                                      prefix="cifs")
     expected_credentials = {"USER": "******", "PASSWD": "123"}
     self.assertEquals(credentials, expected_credentials)
     self.assertEquals(domain, None)
示例#6
0
 def test_password_secret_and_username_smbsr(self, get_secret):
     junk_dconf = {"password_secret": "123", "username": "******"}
     junk_session = 123
     get_secret.return_value = 'winter2019'
     credentials, domain = cifutils.getCIFCredentials(
         junk_dconf, junk_session)
     expected_credentials = {"USER": "******", "PASSWD": "winter2019"}
     get_secret.assert_called_with(junk_session, "123")
     self.assertEquals(credentials, expected_credentials)
     self.assertEquals(domain, None)
示例#7
0
文件: ISOSR.py 项目: xcp-ng/sm
    def mountOverSMB(self, mountcmd):
        """This function raises util.CommandException"""
        new_env, domain = cifutils.getCIFCredentials(self.dconf,
                                                     self.session,
                                                     prefix="cifs")

        util.pread(mountcmd, True, new_env=new_env)
        try:
            if not self.is_smbversion_specified:
                # Store the successful smb version in PBD config
                self.updateSMBVersInPBDConfig()
        except Exception as exc:
            util.SMlog("Exception: %s" % str(exc))
            if self._checkmount():
                util.pread(["umount", self.mountpoint])
            raise util.CommandException
示例#8
0
文件: SMBSR.py 项目: xandrus/sm
    def mount(self, mountpoint=None):

        mountpoint = self.makeMountPoint(mountpoint)

        new_env, domain = cifutils.getCIFCredentials(self.dconf, self.session)

        options = self.getMountOptions(domain)
        if options:
            options = ",".join(str(x) for x in options if x)

        try:

            util.ioretry(lambda:
                util.pread(["mount.cifs", self.remoteserver,
                mountpoint, "-o", options], new_env=new_env),
                errlist=[errno.EPIPE, errno.EIO],
                maxretry=2, nofail=True)
        except util.CommandException, inst:
            raise SMBException("mount failed with return code %d" % inst.code)