util.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:partysig 作者: str4d 项目源码 文件源码
def secure_file(fname, remove_existing=False):
    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL  # Refer to "man 2 open".
    mode = stat.S_IRUSR | stat.S_IWUSR  # This is 0o600 in octal and 384 in decimal.

    if remove_existing:
        # For security, remove file with potentially elevated mode
        try:
            os.remove(fname)
        except OSError:
            pass

    # Open file descriptor
    umask_original = os.umask(0)
    try:
        fdesc = os.open(fname, flags, mode)
    finally:
        os.umask(umask_original)

    return fdesc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号