コード例 #1
0
        private void listenForClients()
        {
            // Do the security stuff to allow any user to connect.
            // This was fixed in version 0.16 to allow users in the group
            // "users" to interact with the backend service.
            Boolean blSecOk = false;

            IntPtr ptrSec = IntPtr.Zero;
            SECURITY_ATTRIBUTES secAttrib = new SECURITY_ATTRIBUTES();
            SECURITY_DESCRIPTOR secDesc;

            if (InitializeSecurityDescriptor(out secDesc, 1))
            {
                if (SetSecurityDescriptorDacl(ref secDesc, true, IntPtr.Zero, false))
                {
                    secAttrib.lpSecurityDescriptor = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SECURITY_DESCRIPTOR)));
                    Marshal.StructureToPtr(secDesc, secAttrib.lpSecurityDescriptor, false);
                    secAttrib.bInheritHandle = false;
                    secAttrib.nLength = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES));
                    ptrSec = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)));
                    Marshal.StructureToPtr(secAttrib, ptrSec, false);
                    blSecOk = true;
                }
            }

            if (blSecOk)
            {
                while (true)
                {
                    SafeFileHandle clientHandle = CreateNamedPipe(@"\\.\pipe\" + strPipeName, DUPLEX | FILE_FLAG_OVERLAPPED, 0, 255, BUFFER_SIZE, BUFFER_SIZE, 0, ptrSec);

                    if (clientHandle.IsInvalid)
                        return;

                    int success = ConnectNamedPipe(clientHandle, IntPtr.Zero);

                    if (success == 0)
                        return;

                    Client client = new Client();
                    client.setHandle(clientHandle);

                    lock (clients)
                        this.clients.Add(client);

                    Thread readThread = new Thread(new ParameterizedThreadStart(read));
                    readThread.IsBackground = true;
                    readThread.Start(client);
                }
            }
        }
コード例 #2
0
ファイル: MOD_NamedPipes.cs プロジェクト: need2/fogproject
        private void ListenForClients()
        {
            while (true)
            {
                SafeFileHandle clientHandle =
                CreateNamedPipe(
                     this.pipeName,
                     DUPLEX | FILE_FLAG_OVERLAPPED,
                     0,
                     255,
                     BUFFER_SIZE,
                     BUFFER_SIZE,
                     0,
                     IntPtr.Zero);

                //could not create named pipe
                if (clientHandle.IsInvalid)
                    return;

                int success = ConnectNamedPipe(clientHandle, IntPtr.Zero);

                //could not connect client
                if (success == 0)
                    return;

                Client client = new Client();
                client.handle = clientHandle;

                lock (clients)
                    this.clients.Add(client);

                Thread readThread = new Thread(new ParameterizedThreadStart(Read));
                readThread.Start(client);
            }
        }
コード例 #3
0
 private void serverMessageReceived(Client c, String msg)
 {
     if (msg == "refresh")
     {
         if (blEnabled)
         {
             log(MOD_NAME, "Printer update was request from fog tray...");
             pullNewServerList();
             doInstallRemoveProcess();
             doSetDefault();
         }
         else
             log(MOD_NAME, "Sevice is disabled.");
     }
     else
     {
         log(MOD_NAME, "Unknown request: " + msg);
     }
 }
コード例 #4
0
ファイル: PipeServer.cs プロジェクト: uw-it-cte/fog-client
        //Wait for a client to try and connect
        private void ListenForClients()
        {
            var ptrSec = CreateSecurity();

            while (true)
            {
                var clientHandle = CreateNamedPipe(@"\\.\pipe\" + _pipeName, Duplex | FileFlagOverlapped,
                    0, 255, BufferSize, BufferSize, 0, ptrSec);

                if (clientHandle.IsInvalid)
                    return;

                var success = ConnectNamedPipe(clientHandle, IntPtr.Zero);

                if (success == 0)
                    return;

                var client = new Client();
                client.SetFileHandle(clientHandle);

                lock (_clients)
                    _clients.Add(client);

                var readThread = new Thread(Read) {IsBackground = true};
                readThread.Start(client);
            }
        }