/* static */
		LoginInfo::UserInformation LoginInfo::GetUserInformation(int session_id)
		{
			// Write a log message to the service
			std::wstring pipeName = pGina::Registry::GetString(L"ServicePipeName", L"Unknown");
			std::wstring pipePath = L"\\\\.\\pipe\\";
			pipePath += pipeName;

			pGina::NamedPipes::PipeClient pipeClient(pipePath, 100);	
			
			if( pipeClient.Connect() )
			{
				// Start a cleanup pool for messages we collect along the way
				pGina::Memory::ObjectCleanupPool cleanup;

				// Always send hello first, expect hello in return
				pGina::Protocol::HelloMessage hello;
				pGina::Protocol::MessageBase * reply = pGina::Protocol::SendRecvPipeMessage(pipeClient, hello);		
				cleanup.Add(reply);

				if(reply && reply->Type() != pGina::Protocol::Hello)
					return UserInformation();

				// Then send a request message, expect a response message
				pGina::Protocol::UserInformationRequestMessage request(session_id);
				reply = pGina::Protocol::SendRecvPipeMessage(pipeClient, request);
				cleanup.Add(reply);

				if(reply && reply->Type() != pGina::Protocol::UserInfoResponse)
					return UserInformation();

				// Get the reply
				pGina::Protocol::UserInformationResponseMessage * responseMsg = 
					static_cast<pGina::Protocol::UserInformationResponseMessage *>(reply);

				// Send disconnect, expect ack, then close
				pGina::Protocol::DisconnectMessage disconnect;
				reply = pGina::Protocol::SendRecvPipeMessage(pipeClient, disconnect);
				cleanup.Add(reply);		

				// We close regardless, no need to check reply type..
				pipeClient.Close();

				return UserInformation(responseMsg->OriginalUsername(), responseMsg->Username(), responseMsg->Domain());
			}
			else
			{
				Log::Warn(L"Unable to connect to pGina service pipe - LastError: 0x%08x, giving up.", GetLastError());
			}

			return UserInformation();
		}
struct answer* getAnswer(){
	struct answer req;
	static long seq_number = 0;
	int recvcc; /* Length of message */
	int remoteAddrSize = sizeof(struct sockaddr_in6);
	char * reqchar;
	/* Receive a message from a socket */
	
	reqchar = (char *) malloc(sizeof(req));
	recvcc = recvfrom(ConnSocket, reqchar, sizeof (req), 0, (struct sockaddr *) &remoteAddr, &remoteAddrSize);
	memcpy(&req,reqchar,sizeof(req));

	if(WSAGetLastError() == 10035) return NULL;

	if (recvcc == SOCKET_ERROR) {
		fprintf(stderr, "recv() failed: error %d\n" ,WSAGetLastError());
		closesocket(ConnSocket);
		WSACleanup();
		exit(-1);
	}
	
	if (recvcc == 0){
		printf("Client closed connection\n" );
		closesocket(ConnSocket);
		WSACleanup ();
		exit(-1);
	}

	UserInformation(3,NULL,&req);

	return (&req);
}
void sendRequest(struct request *paket){
	int sendtostat;
	sendtostat = sendto(ConnSocket, (char*)paket,sizeof(struct request),0,(struct sockaddr *) &remoteAddr,sizeof(remoteAddr));
	if (sendtostat == SOCKET_ERROR) {
		fprintf(stderr, "send() failed: error %d\n",WSAGetLastError());
	}
	UserInformation(4,paket,NULL);
}
Beispiel #4
0
AAssociate
::AAssociate(std::istream & stream)
{
    this->_item.read(stream, "PDU-type", Item::Field::Type::unsigned_int_8);
    auto const type = this->_item.as_unsigned_int_8("PDU-type");
    if(type != 0x01 && type != 0x02)
    {
        throw Exception("Invalid PDU type");
    }

    this->_item.read(stream, "Reserved-1", Item::Field::Type::unsigned_int_8);
    this->_item.read(stream, "PDU-length", Item::Field::Type::unsigned_int_32);

    auto const begin = stream.tellg();

    this->_item.read(
        stream, "Protocol-version", Item::Field::Type::unsigned_int_16);
    this->_item.read(stream, "Reserved-2", Item::Field::Type::unsigned_int_16);
    this->_item.read(stream, "Called-AE-title", Item::Field::Type::string, 16);
    this->_item.read(stream, "Calling-AE-title", Item::Field::Type::string, 16);
    this->_item.read(stream, "Reserved-3", Item::Field::Type::string, 32);

    auto const length = this->_item.as_unsigned_int_32("PDU-length");

    this->_item.add("Variable-items", std::vector<Item>());
    auto & variable_items = this->_item.as_items("Variable-items");
    while(stream.tellg()-begin < length)
    {
        auto const type = stream.peek();
        Item sub_item;
        if(type == 0x10)
        {
            sub_item = ApplicationContext(stream).get_item();
        }
        else if(type == 0x20 || type == 0x21)
        {
            sub_item = PresentationContext(stream).get_item();
        }
        else if(type == 0x50)
        {
            sub_item = UserInformation(stream).get_item();
        }
        else
        {
            throw Exception("Invalid sub-item");
        }

        variable_items.push_back(sub_item);
    }

    this->_item.as_unsigned_int_32("PDU-length") = this->_compute_length();
}
Beispiel #5
0
UserInformation
AAssociate
::get_user_information() const
{
    auto const & sub_items = this->_item.as_items("Variable-items");
    auto const it = std::find_if(
        sub_items.begin(), sub_items.end(),
        [](Item const & x) {
            return x.as_unsigned_int_8("Item-type") == 0x50; });
    if(it == sub_items.end())
    {
        throw Exception("No User Information");
    }

    std::stringstream stream;
    stream << *it;
    return UserInformation(stream);
}
void initConnection(char *empfIP,char *port, char* file, int fenstergroesse){
	struct request nachricht;
	char* reqChar;
	int retSend, reqLen,test;
	unsigned long addr;
	struct hostent *host_info;

	WSADATA wsaData;
	WORD wVersionRequested;
	FILE *fp;

	//komplett von http://msdn.microsoft.com/de-de/library/windows/desktop/ms738630(v=vs.85).aspx übernommen
	int RetVal,testi,AddrLen;
	ADDRINFO Hints, *AddrInfo;
	char AddrName[NI_MAXHOST];
	struct sockaddr_storage Addr;
	//komplett von http://msdn.microsoft.com/de-de/library/windows/desktop/ms738630(v=vs.85).aspx übernommen


	wVersionRequested = MAKEWORD(2,1);
	if( WSAStartup( wVersionRequested,&wsaData ) == SOCKET_ERROR ){
		printf( "Error: WSAStartup() throws error nr. %d!\n" ,WSAGetLastError());
		exit(-1);
	}

	//komplett von http://msdn.microsoft.com/de-de/library/windows/desktop/ms738630(v=vs.85).aspx übernommen
	memset(&Hints, 0, sizeof (Hints));
    Hints.ai_family = AF_INET6;
    Hints.ai_socktype = SOCK_DGRAM;
    RetVal = getaddrinfo(empfIP, port, &Hints, &AddrInfo);
    if (RetVal != 0) {
        fprintf(stderr,
                "Cannot resolve address [%s] and port [%s], error %d: %s\n",
                empfIP, port, RetVal, gai_strerror(RetVal));
        WSACleanup();
        exit(-1);
    }
	//
    // Try each address getaddrinfo returned, until we find one to which
    // we can successfully connect.
    //
	for (AI = AddrInfo; AI != NULL; AI = AI->ai_next) {
		// Open a socket with the correct address family for this address.
		ConnSocket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
		printf("socket call with family: %d socktype: %d, protocol: %d\n",
               AI->ai_family, AI->ai_socktype, AI->ai_protocol);
        if (ConnSocket == INVALID_SOCKET)
            printf("socket call failed with %d\n", WSAGetLastError());
		 if (ConnSocket == INVALID_SOCKET) {
            fprintf(stderr, "Error Opening socket, error %d\n",
                    WSAGetLastError());
            continue;
        }
		  printf("Attempting to connect to: %s\n", empfIP ? empfIP : "localhost");
        if (connect(ConnSocket, AI->ai_addr, (int) AI->ai_addrlen) != SOCKET_ERROR)
            break;

        testi = WSAGetLastError();
        if (getnameinfo(AI->ai_addr, (int) AI->ai_addrlen, AddrName,
                        sizeof (AddrName), NULL, 0, NI_NUMERICHOST) != 0)
            strcpy_s(AddrName, sizeof (AddrName), UNKNOWN_NAME);
        fprintf(stderr, "connect() to %s failed with error %d\n",
                AddrName, testi);
        closesocket(ConnSocket);
    }

	 if (AI == NULL) {
        fprintf(stderr, "Fatal error: unable to connect to the server.\n");
        WSACleanup();
        exit(-1);
    }
	 AddrLen = sizeof (Addr);
    if (getpeername(ConnSocket, (LPSOCKADDR) & Addr, (int *) &AddrLen) == SOCKET_ERROR) {
        fprintf(stderr, "getpeername() failed with error %d\n",
                WSAGetLastError());
    } else {
        if (getnameinfo((LPSOCKADDR) & Addr, AddrLen, AddrName,
                        sizeof (AddrName), NULL, 0, NI_NUMERICHOST) != 0)
            strcpy_s(AddrName, sizeof (AddrName), UNKNOWN_NAME);
        printf("Connected to %s, port %d, protocol %s, protocol family %s\n",
               AddrName, ntohs(SS_PORT(&Addr)),
               (AI->ai_socktype == SOCK_STREAM) ? "TCP" : "UDP",
               (AI->ai_family == PF_INET) ? "PF_INET" : "PF_INET6");
    }
	//komplett von http://msdn.microsoft.com/de-de/library/windows/desktop/ms738630(v=vs.85).aspx übernommen

	
	//schicke erste nachricht
	nachricht.FlNr = (long) fenstergroesse; //fenstergröße
	if(file != NULL) memcpy(nachricht.fname,file,sizeof(nachricht.fname));//dateiname
	nachricht.fname[strlen(file)] = '\0';
	nachricht.ReqType = ReqHello;//nachrichtentyp
	nachricht.name[0] = '\0';

	fp = openFile(file);
	nachricht.SeNr = getFileSize();//größe der datei
	closeFile(fp);
	
	//umwandeln des struct request in char*
	reqChar = (char*) malloc(sizeof(nachricht));
	memcpy(reqChar,&nachricht,sizeof(nachricht));
	sizeof(nachricht);
	UserInformation(2,&nachricht,NULL);

	//senden der ersten nachricht
	retSend = sendto(ConnSocket,reqChar,sizeof(nachricht),0,AI->ai_addr, (int) AI->ai_addrlen);

	//auswerten des returnwertes von send
	if(retSend != sizeof(nachricht)){
		printf("Error: Es wurden nicht alle Daten versand!");
	}
	
}