Exemplo n.º 1
0
    private static void RunMain()
    {
        while (true)
        {
            // start listening
            while (true)
            {
                TcpListener listener  = SslTcpServer.RunServer();
                TcpClient   client    = listener.AcceptTcpClient();
                SslStream   sslStream = SslTcpServer.ProcessClient(client);

                // get nonce request from client
                String clientUsername = SslTcpServer.GetNonceRequest(sslStream);
                // verify nonce request
                if (clientUsername == null)
                {
                    SslTcpServer.AnswerNonceRequest(sslStream, "Error during nonce sending");
                    client.Close();
                    listener.Stop();
                    break;
                }
                // verify username
                if (!GetUserInfo.IsUserSystemMember(clientUsername))
                {
                    SslTcpServer.AnswerNonceRequest(sslStream, "Error during nonce sending");
                    client.Close();
                    listener.Stop();
                    break;
                }

                String clientNonce = Security.SendNonce(clientUsername);
                // answer nonce request
                if (clientNonce != null)
                {
                    SslTcpServer.AnswerNonceRequest(sslStream, "Nonce send");
                }

                // wait for command request
                String[] clientCommandRequest = SslTcpServer.GetCommandRequest(sslStream);
                // verify command request
                if (clientCommandRequest == null)
                {
                    SslTcpServer.AnswerCommandRequest(sslStream, "Error during command execution");
                    client.Close();
                    listener.Stop();
                    break;
                }

                String clientCommand         = clientCommandRequest[0];
                String clientUsernameCommand = clientCommandRequest[1];
                String clientNonceCommand    = clientCommandRequest[2];
                // verify username
                if (clientUsernameCommand != clientUsername || !GetUserInfo.IsUserSystemMember(clientUsernameCommand))
                {
                    SslTcpServer.AnswerCommandRequest(sslStream, "Unauthorized");
                    client.Close();
                    listener.Stop();
                    break;
                }
                // verify nonce
                if (clientNonceCommand != clientNonce)
                {
                    SslTcpServer.AnswerCommandRequest(sslStream, "Unauthorized");
                    client.Close();
                    listener.Stop();
                    break;
                }
                // verify access to command
                int retAuth = GetAuthorization.IsUserGranted(clientUsernameCommand, clientCommand);
                if (retAuth == 2)
                {
                    SslTcpServer.AnswerCommandRequest(sslStream, "Unauthorized");
                    client.Close();
                    listener.Stop();
                    break;
                }
                else if (retAuth == 1)
                {
                    SslTcpServer.AnswerCommandRequest(sslStream, "Password");
                    client.Close();
                    listener.Stop();
                    break;
                }


                // answer command request
                SslTcpServer.AnswerCommandRequest(sslStream, "OK");

                String commandResult = RunPowershell.RunSudoersCommand(clientCommand);

                // send command result
                SslTcpServer.SendCommandResult(sslStream, commandResult);
                client.Close();
                listener.Stop();
            }
        }
    }
Exemplo n.º 2
0
Arquivo: router.cs Projeto: berak/cs
 /// <remarks/>
 public void GetAuthorizationAsync(GetAuthorization GetAuthorization1, object userState)
 {
     if ((this.GetAuthorizationOperationCompleted == null)) {
         this.GetAuthorizationOperationCompleted = new System.Threading.SendOrPostCallback(this.OnGetAuthorizationOperationCompleted);
     }
     this.InvokeAsync("GetAuthorization", new object[] {
                 GetAuthorization1}, this.GetAuthorizationOperationCompleted, userState);
 }
Exemplo n.º 3
0
Arquivo: router.cs Projeto: berak/cs
 /// <remarks/>
 public System.IAsyncResult BeginGetAuthorization(GetAuthorization GetAuthorization1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("GetAuthorization", new object[] {
                 GetAuthorization1}, callback, asyncState);
 }
Exemplo n.º 4
0
Arquivo: router.cs Projeto: berak/cs
 /// <remarks/>
 public void GetAuthorizationAsync(GetAuthorization GetAuthorization1)
 {
     this.GetAuthorizationAsync(GetAuthorization1, null);
 }
Exemplo n.º 5
0
		public  AuthorizationResponse GetAuthorization( GetAuthorization request)
		{
			
			var httpRequest = RequestContext.Get<IHttpRequest>();	
			IAuthSession session = httpRequest.GetSession();
			
			if (!session.HasRole(RoleNames.Admin))
			{
				request.UserId= int.Parse(session.UserAuthId);
			}
			
			List<AuthRole> roles = new List<AuthRole>();
			List<AuthPermission> permissions= new List<AuthPermission>();
			
			List<AuthRoleUser> aur= new List<AuthRoleUser>();
			List<AuthRole> rol = new List<AuthRole>();
			List<AuthPermission> per = new List<AuthPermission>();
			List<AuthRolePermission> rol_per = new List<AuthRolePermission>();

			AuthRepoProxy.Execute(db=>{

				aur=  db.Select<AuthRoleUser>(q=>q.UserId==request.UserId);
				rol= db.Select<AuthRole>();
				per= db.Select<AuthPermission>();
				rol_per= db.Select<AuthRolePermission>();
				
				foreach( var r in aur)
				{
					AuthRole ar= rol.First(x=>x.Id== r.AuthRoleId);
					roles.Add(ar);
					rol_per.Where(q=>q.AuthRoleId==ar.Id).ToList().ForEach(y=>{
						AuthPermission up=  per.First( p=> p.Id== y.AuthPermissionId);
						if( permissions.FindIndex(f=>f.Name==up.Name)<0) // .IndexOf(up) <0)
							permissions.Add(up);
					}) ;
				};    
				
			});
			
			return new AuthorizationResponse(){
				Permissions= permissions,
				Roles= roles,
			};
		}