Exemple #1
0
 public void Store(OutputStream output)
 {
     StreamWriter sw = new StreamWriter(output);
     foreach (var key in _properties.Keys)
     {
         string line = string.Format("{0}={1}", key, _properties[key]);
         sw.WriteLine(line);
     }
 }
 public WrappedSystemStream(OutputStream ost)
 {
     this._ost = ost;
 }
Exemple #3
0
 /// <exception cref="System.IO.IOException"></exception>
 public static void Store(OutputStream output, string header)
 {
     _prp.Store(output);
 }
		public OutputStreamWriter (OutputStream stream) : base(stream.GetWrappedStream ())
		{
		}
		public OutputStreamWriter (OutputStream stream, Encoding encoding) : base(stream.GetWrappedStream (), encoding)
		{
		}
		public OutputStreamWriter (OutputStream stream, string encoding) : base(stream.GetWrappedStream (), Extensions.GetEncoding (encoding))
		{
		}
		/// <summary>
		/// Return the <code>OutputStream</code> used to write
		/// information to this pipe instance.
		/// </summary>
		/// <remarks>
		/// Return the <code>OutputStream</code> used to write
		/// information to this pipe instance. The act of writing data
		/// to this stream will result in response data recieved in the
		/// <code>InputStream</code> associated with this Named Pipe
		/// instance (unless of course it does not elicite a response or the pipe is write-only).
		/// </remarks>
		/// <exception cref="System.IO.IOException"></exception>
		public virtual OutputStream GetNamedPipeOutputStream()
		{
			if (PipeOut == null)
			{
				if ((PipeType & PipeTypeCall) == PipeTypeCall || (PipeType & PipeTypeTransact
					) == PipeTypeTransact)
				{
					PipeOut = new TransactNamedPipeOutputStream(this);
				}
				else
				{
					PipeOut = new SmbFileOutputStream(this, false, (PipeType & unchecked((int)(0xFFFF00FF
						))) | OExcl);
				}
			}
			return PipeOut;
		}
Exemple #8
0
        /// <exception cref="System.IO.IOException"></exception>
        private void Negotiate(int port, ServerMessageBlock resp)
        {
            lock (Sbuf)
            {
                if (port == 139)
                {
                    Ssn139();
                }
                else
                {
                    if (port == -1)
                    {
                        port = SmbConstants.DefaultPort;
                    }
                    // 445
                    Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    if (LocalAddr != null)
                    {
                        Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort));
                    }

                    Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), port), SmbConstants.ConnTimeout);
                    Socket.SoTimeOut = SmbConstants.SoTimeout;
                    Out = Socket.GetOutputStream();
                    In = Socket.GetInputStream();
                }
                if (++Mid == 32000)
                {
                    Mid = 1;
                }
                NegotiateRequest.Mid = Mid;
                int n = NegotiateRequest.Encode(Sbuf, 4);
                Encdec.Enc_uint32be(n & 0xFFFF, Sbuf, 0);
                if (Log.Level >= 4)
                {
                    Log.WriteLine(NegotiateRequest);
                    if (Log.Level >= 6)
                    {
                        Hexdump.ToHexdump(Log, Sbuf, 4, n);
                    }
                }
                Out.Write(Sbuf, 0, 4 + n);
                Out.Flush();
                if (PeekKey() == null)
                {
                    throw new IOException("transport closed in negotiate");
                }
                int size = Encdec.Dec_uint16be(Sbuf, 2) & 0xFFFF;
                if (size < 33 || (4 + size) > Sbuf.Length)
                {
                    throw new IOException("Invalid payload size: " + size);
                }
                Readn(In, Sbuf, 4 + 32, size - 32);
                resp.Decode(Sbuf, 4);
                if (Log.Level >= 4)
                {
                    Log.WriteLine(resp);
                    if (Log.Level >= 6)
                    {
                        Hexdump.ToHexdump(Log, Sbuf, 4, n);
                    }
                }
            }
        }
Exemple #9
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void Ssn139()
        {
            Name calledName = new Name(Address.FirstCalledName(), 0x20, null
                );
            do
            {
                Socket = new SocketEx(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                if (LocalAddr != null)
                {
                    Socket.Bind2(new IPEndPoint(LocalAddr, LocalPort));
                }

                Socket.Connect(new IPEndPoint(IPAddress.Parse(Address.GetHostAddress()), 139), SmbConstants.ConnTimeout);
                Socket.SoTimeOut = SmbConstants.SoTimeout;

                Out = Socket.GetOutputStream();
                In = Socket.GetInputStream();
                SessionServicePacket ssp = new SessionRequestPacket(calledName, NbtAddress.GetLocalName
                    ());
                Out.Write(Sbuf, 0, ssp.WriteWireFormat(Sbuf, 0));
                if (Readn(In, Sbuf, 0, 4) < 4)
                {
                    try
                    {
                        Socket.Dispose();
                    }
                    catch (IOException)
                    {
                    }
                    throw new SmbException("EOF during NetBIOS session request");
                }
                switch (Sbuf[0] & 0xFF)
                {
                    case SessionServicePacket.PositiveSessionResponse:
                        {
                            if (Log.Level >= 4)
                            {
                                Log.WriteLine("session established ok with " + Address);
                            }
                            return;
                        }

                    case SessionServicePacket.NegativeSessionResponse:
                        {
                            int errorCode = In.Read() & 0xFF;
                            switch (errorCode)
                            {
                                case NbtException.CalledNotPresent:
                                case NbtException.NotListeningCalled:
                                    {
                                        Socket.Dispose();
                                        break;
                                    }

                                default:
                                    {
                                        Disconnect(true);
                                        throw new NbtException(NbtException.ErrSsnSrvc, errorCode);
                                    }
                            }
                            break;
                        }

                    case -1:
                        {
                            Disconnect(true);
                            throw new NbtException(NbtException.ErrSsnSrvc, NbtException.ConnectionRefused
                                );
                        }

                    default:
                        {
                            Disconnect(true);
                            throw new NbtException(NbtException.ErrSsnSrvc, 0);
                        }
                }
            }
            while ((calledName.name = Address.NextCalledName()) != null);
            throw new IOException("Failed to establish session with " + Address);
        }
		public ObjectOutputStream (OutputStream os)
		{
			_bw = new BinaryWriter (os.GetWrappedStream ());
		}
Exemple #11
0
 public WrappedSystemStream(OutputStream ost)
 {
     this._ost = ost;
 }
Exemple #12
0
 internal static OutputStream Wrap(Stream s)
 {
     OutputStream stream = new OutputStream ();
     stream.Wrapped = s;
     return stream;
 }