Example #1
0
        /// <summary>
        ///   Disconnectes the given session
        /// </summary>
        /// <param name = "sessionname">name of the session</param>
        public static void DisconnectSession(string sessionname)
        {
            ICifsSession session = LookupSession(sessionname);

            if (session == null)
            {
                throw new CifsIoException("SS2", sessionname);
            }

            session.Disconnect();
        }
Example #2
0
 private static void ShowServer(ICifsSession service)
 {
     try
     {
         string os = service.ServerOs;
         string lm = service.ServerLanMan;
         string pd = service.ServerPrimaryDomain;
         Console.WriteLine(service.ToString());
         Console.WriteLine("[OS=" + os + ", LanMan=" + lm + ", PrimaryDomain=" + pd + "]");
     }
     catch (Exception)
     {
     }
 }
Example #3
0
 private static void ShowServer(ICifsSession service)
 {
     try
     {
         string os = service.ServerOs;
         string lm = service.ServerLanMan;
         string pd = service.ServerPrimaryDomain;
         Console.WriteLine(service.ToString());
         Console.WriteLine("[OS=" + os + ", LanMan=" + lm + ", PrimaryDomain=" + pd + "]");
     }
     catch (Exception)
     {
     }
 }
Example #4
0
        /// <summary>
        ///   Connect to Remote Admin Protocol
        /// </summary>
        /// <param name = "sessionname">local alias name for this connection</param>
        /// <param name = "host">host name</param>
        /// <param name = "login">authentication data</param>
        public static ICifsRemoteAdmin ConnectRemoteAdmin(string sessionname, string host, CifsLogin login)
        {
            // check if the admname connection is already open
            ICifsSession session = LookupSession(sessionname);

            if (session != null)
            {
                throw new CifsIoException("SS1", sessionname);
            }

            if (login == null)
            {
                login = fDefaultLogin;
            }

            var share = new Share(login);

            share.SetInfo(Share.IPC, host, "IPC$");

            var        nbt = new NbtSession();
            SmbMessage smb = CifsSession.AllocateSmbMessage();

            int             protocol;
            CifsRemoteAdmin admin = null;

            try
            {
                protocol = CifsSession.Negotiate(nbt, share.HostName, smb);
                admin    = new CifsRemoteAdmin(sessionname, protocol, share, nbt, smb);
                admin.Connect();
            }
            catch (IOException e)
            {
                //nbt.doHangup();
                if (admin != null)
                {
                    admin.Dispose();
                }
                else
                {
                    nbt.DoHangup();
                }


                throw;
            }

            return(admin);
        }
Example #5
0
        private static void DoRemoteAdmin()
        {
            var login           = new CifsLogin("guest", null);
            ICifsRemoteAdmin ra = null;

            try
            {
                // in this example, "test" is the session name, "athena" the hostname.
                // you can enter any validly resolving entry for the hostname (IP, computername, etc)
                ra = CifsSessionManager.ConnectRemoteAdmin("test", "athena", login);

                ShowServer(ra);

                Console.WriteLine("\nShare's");
                DoShares(ra);

                Console.WriteLine("\nWorkstation Info");
                DoWInfo(ra);

                Console.WriteLine("\nServer Info");
                DoSInfo(ra);


                Console.Read(); // pause

                ICifsSession s = ra;

                s.Disconnect();
            }
            catch (Exception) // ignore all
            {
                if (ra != null)
                {
                    ICifsSession s = ra;
                    s.Disconnect();
                }
            }
        }
Example #6
0
 internal static void AddSession(string sessionname, ICifsSession session)
 {
     lock (fSessionTable)
     {
         //fSessionTable.Add(sessionname, session);
     }
 }