コード例 #1
0
    def fs_unlink(self, path):
        '''
        Unlink (delete) a file.

        Args:
            path (str): Path to unlink.

        Examples:
            Delete a file::

                axon.fs_unlink('/myfile')

        Returns:
            None

        Raises:
            NoSuchFile: If the path does not exist.
        '''
        tufo = self.core.getTufoByProp('axon:path', path)
        if not tufo:
            raise s_common.NoSuchFile()

        ppath = tufo[1].get('axon:path:dir')
        self.core.delTufo(tufo)

        parentfo = self.core.getTufoByProp('axon:path', ppath)
        if parentfo:
            self.core.incTufoProp(parentfo, 'st_nlink', -1)
コード例 #2
0
    def _initDbInfo(self):
        name = self._link[1].get('path')[1:]
        if not name:
            raise s_common.NoSuchFile('No Path Specified!')

        if name.find(':') == -1:
            name = s_common.genpath(name)

        return {'name': name}
コード例 #3
0
ファイル: certdir.py プロジェクト: theassyrian/synapse
    def genClientCert(self, name, outp=None):
        '''
        Generates a user PKCS #12 archive.
        Please note that the resulting file will contain private key material.

        Args:
            name (str): The name of the user keypair.
            outp (synapse.lib.output.Output): The output buffer.

        Examples:
            Make the PKC12 object for user "myuser":

                myuserpkcs12 = cdir.genClientCert('myuser')

        Returns:
            OpenSSL.crypto.PKCS12: The PKCS #12 archive.
        '''
        ucert = self.getUserCert(name)
        if not ucert:
            raise s_common.NoSuchFile('missing User cert')

        cacert = self._loadCertPath(self._getCaPath(ucert))
        if not cacert:
            raise s_common.NoSuchFile('missing CA cert')

        ukey = self.getUserKey(name)
        if not ukey:
            raise s_common.NoSuchFile('missing User private key')

        ccert = crypto.PKCS12()
        ccert.set_friendlyname(name.encode('utf-8'))
        ccert.set_ca_certificates([cacert])
        ccert.set_certificate(ucert)
        ccert.set_privatekey(ukey)

        crtpath = self._saveP12To(ccert, 'users', '%s.p12' % name)
        if outp is not None:
            outp.printf('client cert saved: %s' % (crtpath, ))
コード例 #4
0
    def bytes(self, htype, hvalu):
        '''
        Yield chunks of bytes for the given hash value.

        Args:
            htype (str): Hash type.
            hvalu (str): Hash value.

        Examples:
            Get the bytes for a given guid and do stuff with them::

                for byts in axon.bytes('guid', axonblobguid):
                    dostuff(byts)


            Iteratively write bytes to a file for a given md5sum::

                for byts in axon.bytes('md5', md5sum):
                    fd.write(byts)

            Form a contiguous bytes object for a given sha512sum. This is not recommended for large files.::

                byts = b''.join((_byts for _byts in axon.bytes('sha512', sha512sum)))

        Notes:
            This API will raise an exception to the caller if the requested
            hash is not present in the axon. This is contrasted against the
            Axon.iterblob() API, which first requires the caller to first
            obtain an axon:blob tufo in order to start retrieving bytes from
            the axon.

        Yields:
            bytes:  A chunk of bytes for a given hash.

        Raises:
            NoSuchFile: If the requested hash is not present in the axon. This
            is raised when the generator is first consumed.
        '''
        blob = self.has(htype, hvalu)
        if blob:
            for byts in self.iterblob(blob):
                yield byts
        else:
            raise s_common.NoSuchFile(mesg='The requested blob was not found.',
                                      htype=htype,
                                      hvalu=hvalu)
コード例 #5
0
ファイル: axon.py プロジェクト: e2-ibm/synapse
    def fs_unlink(self, path):
        '''
        Deletes a file.
        Returns 0.

        Example:

            axon.fs_unlink('/myfile')

        '''
        tufo = self.core.getTufoByProp('axon:path', path)
        if not tufo:
            raise s_common.NoSuchFile()

        ppath = tufo[1].get('axon:path:dir')
        self.core.delTufo(tufo)

        parentfo = self.core.getTufoByProp('axon:path', ppath)
        if parentfo:
            self.core.incTufoProp(parentfo, 'st_nlink', -1)

        return 0
コード例 #6
0
    def importFile(self, path, mode, outp=None):
        '''
        Imports certs and keys into the Synapse cert directory

        Args:
            path (str): The path of the file to be imported.
            mode (str): The certdir subdirectory to import the file into.

        Examples:
            Import CA certifciate 'mycoolca.crt' to the 'cas' directory.

                certdir.importFile('mycoolca.crt', 'cas')

        Notes:
            importFile does not perform any validation on the files it imports.

        Returns:
            None
        '''
        if not os.path.isfile(path):
            raise s_common.NoSuchFile('File does not exist')

        fname = os.path.split(path)[1]
        parts = fname.rsplit('.', 1)
        ext = parts[1] if len(parts) is 2 else None

        if not ext or ext not in ('crt', 'key', 'p12'):
            mesg = 'importFile only supports .crt, .key, .p12 extensions'
            raise s_common.BadFileExt(mesg=mesg,
                                      ext=ext)

        newpath = s_common.genpath(self.certdir, mode, fname)
        if os.path.isfile(newpath):
            raise s_common.FileExists('File already exists')

        shutil.copy(path, newpath)
        if outp is not None:
            outp.printf('copied %s to %s' % (path, newpath))