Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
win_openssh.py57 linesDownload Raw Back to paramiko
1# Copyright (C) 2021 Lew Gordon <lew.gordon@genesys.com>2# Copyright (C) 2022 Patrick Spendrin <ps_ml@gmx.de>3#4# This file is part of paramiko.5#6# Paramiko is free software; you can redistribute it and/or modify it under the7# terms of the GNU Lesser General Public License as published by the Free8# Software Foundation; either version 2.1 of the License, or (at your option)9# any later version.10#11# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY12# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR13# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more14# details.15#16# You should have received a copy of the GNU Lesser General Public License17# along with Paramiko; if not, write to the Free Software Foundation, Inc.,18# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.19 20import os.path21import time22 23PIPE_NAME = r"\\.\pipe\openssh-ssh-agent"24 25 26def can_talk_to_agent():27    # use os.listdir() instead of os.path.exists(), because os.path.exists()28    # uses CreateFileW() API and the pipe cannot be reopen unless the server29    # calls DisconnectNamedPipe().30    dir_, name = os.path.split(PIPE_NAME)31    name = name.lower()32    return any(name == n.lower() for n in os.listdir(dir_))33 34 35class OpenSSHAgentConnection:36    def __init__(self):37        while True:38            try:39                self._pipe = os.open(PIPE_NAME, os.O_RDWR | os.O_BINARY)40            except OSError as e:41                # retry when errno 22 which means that the server has not42                # called DisconnectNamedPipe() yet.43                if e.errno != 22:44                    raise45            else:46                break47            time.sleep(0.1)48 49    def send(self, data):50        return os.write(self._pipe, data)51 52    def recv(self, n):53        return os.read(self._pipe, n)54 55    def close(self):56        return os.close(self._pipe)57 
codekingpro/portable-devtools · Team Ai