예제 #1
0
        public static bool DeleteNullSession(string sServer)
        {
            Logger.Log(String.Format("Session::DeleteNullSession({0}) called", sServer), Logger.netAPILogLevel);

            bool result = false;
            int  nRet   = 0;

            sServer = Canon(sServer);
            try
            {
                // if there is no session, don't try to delete
                //HACK: this is removed due to issue 5006: bad creds can persist in the muxer after Quartz exist
                //and therefore may be present in a new instance of Quartz before creds are entered.
                //if (!alSessions.Contains(sServer))
                //   return;
                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    nRet = WindowsSession.WNetCancelConnection2(@"\\" + sServer + @"\IPC$", 1, true);
                }
                else
                {
                    nRet = WNetCancelConnection2(@"\\" + sServer + @"\IPC$", 1, true);
                }

                Logger.Log(String.Format(
                               "{0}(sServer={1}): nRet={2}",
                               "Session.DeleteNullSession(): WNetCancelConnection2",
                               sServer, nRet), Logger.netAPILogLevel);

                if (nRet == 0)
                {
                    result = true;
                }


                else
                {
                    result = true;
                }

                if (alSessions.Contains(sServer))
                {
                    alSessions.Remove(sServer);
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("Session.DeleteNullSession", ex);
            }

            if (nRet != 0)
            {
                throw new AuthSessionException(ErrorCodes.WIN32String(nRet), null);
            }

            return(result);
        }
예제 #2
0
        public static void DeleteAllCreatedNullSessions()
        {
            Logger.Log("Session::DeleteAllCreatedNullSessions() called", Logger.netAPILogLevel);


            foreach (string s in alSessions)
            {
                string sServer = Canon(s);
                try
                {
                    int nRet;
                    if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                    {
                        nRet = WindowsSession.WNetCancelConnection2(@"\\" + sServer + @"\IPC$", 1, true);
                    }
                    else
                    {
                        nRet = WNetCancelConnection2(@"\\" + sServer + @"\IPC$", 1, true);
                    }

                    Logger.Log(String.Format(
                                   "{0}(sServer={1}): nRet={2}",
                                   "Session.DeleteAllCreatedNullSessions(): WNetCancelConnection2",
                                   sServer, nRet), Logger.netAPILogLevel);

                    if (nRet != 0)
                    {
                        throw new AuthSessionException(ErrorCodes.WIN32String(nRet), null);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException("Session.DeleteAllCreatedNullSessions", ex);
                }
            }
            alSessions.Clear();
        }
예제 #3
0
#pragma warning restore 414
#endif

        #endregion

        #region Static Interface
        public static bool CreateNullSession(string sServer, string sShortname, CredentialEntry ce)
        {
            Logger.Log(
                String.Format("Session.CreateNullSession({0}, {1}, {2}) called", sServer, sShortname, ce),
                Logger.netAPILogLevel);

            int nErr;

            // set up the user name and password; map "root" as needed
            string sUsername;
            string sPassword;

            if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
            {
                if (ce != null && !ce.DefaultCreds && ce.Password != new String('*', 16))
                {
                    if (ce.UserName.IndexOf('\\') < 0 && !String.IsNullOrEmpty(ce.Domain))
                    {
                        sUsername = String.Format("{0}\\{1}", ce.Domain, ce.UserName);
                    }
                    else
                    {
                        sUsername = ce.UserName;
                    }
                    sPassword = ce.Password;
                }
                else
                {
                    // setup for default creds
                    sUsername = null;
                    sPassword = null;
                    Logger.Log("CreateNullSession(): Using default creds", Logger.netAPILogLevel);
                }
            }
            else
            {
                if (ce.UserName.IndexOf(@"\") < 0 && !String.IsNullOrEmpty(ce.Domain))
                {
                    sUsername = String.Format("{0}\\{1}", ce.Domain, ce.UserName);
                }
                else
                {
                    sUsername = ce.UserName;
                }
                sPassword = ce.Password;
            }

            // set up a NETRESOURCE structure
            NETRESOURCE nr = new NETRESOURCE();

            nr.dwScope       = 0;
            nr.dwType        = 0;
            nr.dwDisplayType = 0;
            nr.dwUsage       = 0;
            nr.LocalName     = null;
            nr.RemoteName    = @"\\" + sServer + @"\IPC$";
            nr.Comment       = null;
            nr.Provider      = null;

            // try the operation. Throws exception if it fails.
            if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
            {
                nErr = WindowsSession.WNetAddConnection2(nr, sPassword, sUsername, 0);
            }
            else
            {
                nErr = WNetAddConnection2(nr, sPassword, sUsername, 0);
            }

            //HACK: WNetAddConnection2 appears to return 'access denied' even when it has just granted access!
            //this is a workaround with the side-effect that the user will never be warned when their password
            //is invalid.
            if (nErr == (int)ErrorCodes.WIN32Enum.ERROR_ACCESS_DENIED)
            {
                Logger.Log(String.Format("CreateNullSession(): Ignoring error!  nErr={0}: {1}",
                                         nErr, ErrorCodes.WIN32String(nErr)), Logger.LogLevel.Error);

                System.Windows.Forms.MessageBox.Show("WNetAddConnection2 success but ERROR_ACCESS_DENIED");

                return(true);
            }
            else if (nErr != 0)
            {
                ce.Invalidate(sServer);

                Logger.Log(String.Format("CreateNullSession(): nErr={0}: {1}",
                                         nErr, ErrorCodes.WIN32String(nErr)), Logger.LogLevel.Error);
                return(false);
            }

            Logger.Log("CreateNullSession() successful", Logger.netAPILogLevel);

            return(true);
        }