DWORD WINAPI _RfidReader(LPVOID lpParameter)
{
	Serial* s = new Serial();

	char *lastTag = new char[128];
	memset(lastTag, '\0', 128);
	while(lastTag[0] != '\0');

	int tagCount = 0;

	while(rfidThreadRunning){

		Sleep(50);

		char *id = new char[128];
		memset(id, '\0', 128);
		while(id[0] != '\0');

		if(tagCount >= 128){
			tagCount = 0;
			memset(lastTag, '\0', 128);
			while(lastTag[0] != '\0');
		}

		s->ReadData(id, 1);

		if(strlen(id) > 0){
			for(int i = 0; i < strlen(id); i++){
				lastTag[tagCount++] = id[i];
			}
		}

		delete id;


		for(int i = 0; i < strlen(lastTag); i++){
			if(lastTag[i] == 0x03){
				char* fullTag = sanatizeRfidReading(lastTag);

				printf(fullTag);

				getCredentials(fullTag);

				tagCount = 0;
				memset(lastTag, '\0', 128);
				while(lastTag[0] != '\0');

				delete fullTag;

				break;
			}
		}
	}

	delete lastTag;
	delete s;

	return 0;
}
void GetCredentialsJob::Private::getCredentials()
{
    Accounts::Account *acc = manager->account(id);
    if (!acc) {
        qWarning() << "Unable to find account for id" << id;
        if (repeatedTries < 3) {
            qDebug() << "Retrying in 2s";
            QTimer::singleShot(2000, q, SLOT(getCredentials()));
            repeatedTries++;
        } else {
            qDebug() << repeatedTries << "ending with error";
            q->setError(KJob::UserDefinedError);
            q->setErrorText(QLatin1String("Could not find account"));
            q->emitResult();
        }
        return;
    }

    Accounts::AccountService *service = new Accounts::AccountService(acc, manager->service(serviceType), q);

    Accounts::AuthData serviceAuthData = service->authData();
    authData = serviceAuthData.parameters();
    SignOn::Identity *identity = SignOn::Identity::existingIdentity(acc->credentialsId(), q);

    if (!identity) {
        qWarning() << "Unable to find identity for account id" << id;
        q->setError(KJob::UserDefinedError);
        q->setErrorText(QLatin1String("Could not find credentials"));
        q->emitResult();
        return;
    }

    authData["AccountUsername"] = acc->value(QLatin1String("username")).toString();
    QPointer<SignOn::AuthSession> authSession = identity->createSession(authMethod.isEmpty() ? serviceAuthData.method() : authMethod);
    if (!authSession) {
        qWarning() << "Unable to create auth session for" << authMethod << serviceAuthData.method();
        q->setError(KJob::UserDefinedError);
        q->setErrorText(QLatin1String("Could not create auth session"));
        q->emitResult();
        return;
    }

    QObject::connect(authSession.data(), &SignOn::AuthSession::response,
    [this, identity](const SignOn::SessionData &data) {
        sessionData = data;
        q->emitResult();
    });

    QObject::connect(authSession.data(), &SignOn::AuthSession::error,
    [this](const SignOn::Error &error) {
        qDebug() << error.message();
        q->setError(KJob::UserDefinedError);
        q->setErrorText(error.message());
        q->emitResult();
    });

    authSession->process(serviceAuthData.parameters(), authMechanism.isEmpty() ? serviceAuthData.mechanism() : authMechanism);
}
Exemple #3
0
UtlBoolean SipLine::IsDuplicateRealm(const UtlString realm, const UtlString scheme)
{
   UtlString userID;
   UtlString passToken;
   if (getCredentials(scheme, realm, &userID, &passToken))
      return TRUE;
   else
      return FALSE;
}
Krb5Credentials Krb5CCache::getCredentials(
  krb5_principal sprinc, krb5_flags options) {

  Krb5Principal cprinc = getClientPrincipal();

  krb5_creds in_creds;
  memset(&in_creds, 0, sizeof(in_creds));
  in_creds.client = cprinc.get();
  in_creds.server = sprinc;

  return getCredentials(in_creds, options);
}
std::vector<std::map<std::string, std::string> > ConfigurationManager::getCredentials(
    const std::string& accountID)
{
    const auto sipaccount = Manager::instance().getAccount<SIPAccount>(accountID);

    std::vector<std::map<std::string, std::string> > credentialInformation;

    if (!sipaccount)
        return credentialInformation;
    else
        return sipaccount->getCredentials();
}
Exemple #6
0
void    Credentials::handleCredentials(const QNetworkProxy& proxy,
                                       QAuthenticator* auth)
{
  const QStringList credentials = getCredentials(proxy.hostName());
#ifndef QT_NO_DEBUG
  qDebug() << "[Credentials::handleCredentials]"
	   << "credentials size:" << credentials.size();
#endif
  if (credentials.size() == 2)
    {
      auth->setUser(credentials.at(0));
      auth->setPassword(credentials.at(1));
    }
}
bool Napisy24DownloadEngine::lookForSubtitles(QString lang) {
  if (lang != "pl") return false;

  const QUrl url = QUrl("http://napisy24.pl/run/CheckSubAgent.php");

  auto credentials = getCredentials();

  QUrlQuery params(url);
  params.addQueryItem("postAction", "CheckSub");
  params.addQueryItem("ua", credentials.first);
  params.addQueryItem("ap", credentials.second);
  params.addQueryItem("fh", checkSum);
  params.addQueryItem("fs", QString::number(fileSize));
  params.addQueryItem("fn", QFileInfo(movie).fileName());
  // API N24 ignoruje ten parametr; jeśli nie ma napisów w żądanym języku, to i
  // tak zwraca napisy w jęz. polskim params.addQueryItem("nl", lang);
  QByteArray data = params.query().toUtf8();

  SyncHTTP http;
  QNetworkRequest req(url);
  req.setHeader(QNetworkRequest::ContentTypeHeader,
                "application/x-www-form-urlencoded");

  QNetworkReply *reply = http.syncPost(req, data);
  if (reply->error() != QNetworkReply::NoError) return false;

  QByteArray respData = reply->readAll();
  if (!respData.startsWith("OK-2")) return false;

  QString tmpPackedFile = generateTmpPath();

  QFile file(tmpPackedFile);
  if (file.exists()) file.remove();
  if (!file.open(QIODevice::WriteOnly)) return false;

  long r = file.write(respData.mid(respData.indexOf("||") + 2));
  file.close();
  if (!r) return false;

  subtitlesList << SubtitleInfo(lang, meta().name(), tmpPackedFile,
                                QFileInfo(movie).completeBaseName(), "", "txt",
                                SUBTITLE_UNKNOWN);

  return true;
}
void CalaosConnection::onConnected()
{
    if (con_state == CALAOS_CON_NONE)
    {
        con_state = CALAOS_CON_LOGIN;

        //Get username/password
        string username;
        string password;
        getCredentials(username, password);

        json_t *jlogin = json_pack("{s:s, s:s}",
                                   "cn_user", username.c_str(),
                                   "cn_pass", password.c_str());
        sendJson("login", jlogin);

        cDebugDom("network.connection") << "trying to log in.";
    }
}
Exemple #9
0
void start_loop(int socket)
{
	Credentials c;
	bool haveCredentials = false;
	bool looping = true;

	/* our command strings */
	char *str_poweroff = "poweroff";
	char *str_quit = getString(cmd_quit, language_code);
	char *str_balance = getString(cmd_balance, language_code);
	char *str_deposit = getString(cmd_deposit, language_code);
	char *str_withdraw = getString(cmd_withdraw, language_code);
	char *str_unknown_command = getString(error_unknown_command,
			language_code);
	char *str_help = getString(msg_help, language_code);
	char *str_help_cmd = getString(cmd_help, language_code);
	char *str_change_language = "change language";

	
	/* main loop */
	while (looping == true) {
		if (haveCredentials == false) {
			char *str = getString(msg_welcome, language_code);
			printf("%s\n", str);
			getCredentials(&c);
			haveCredentials = true;
			free(str);
		}

		char *line = readline(">> ");
		add_history(line);

		/* do something with the command */
		if (strcmp(line, str_poweroff) == 0) {
			looping = false;
		} else if (strcmp(line, str_quit) == 0) {
			haveCredentials = false;
		} else if (strcmp(line, str_balance) == 0) {
			show_balance(socket, &c);
		} else if (strcmp(line, str_deposit) == 0) {
			deposit_money(socket, &c);
		} else if (strcmp(line, str_withdraw) == 0) {
			withdraw_money(socket, &c);
		} else if (strcmp(line, str_help_cmd) == 0) {
			printf("%s\n", str_help);
		} else if (strcmp(line, "") == 0) {
			/* do nothing */
		} else if (strcmp(line, str_change_language) == 0) {
			changeLanguage();
			language_is_changed = true;
		} else {
			printf("%s\n", str_unknown_command);
		}

		if (language_is_changed == true) {
			free(str_quit);
			free(str_balance);
			free(str_deposit);
			free(str_withdraw);
			free(str_unknown_command);
			free(str_help);
			free(str_help_cmd);
			str_quit = getString(cmd_quit, language_code);
			str_balance = getString(cmd_balance, language_code);
			str_deposit = getString(cmd_deposit, language_code);
			str_withdraw = getString(cmd_withdraw, language_code);
			str_unknown_command = getString(error_unknown_command,
					language_code);
			str_help = getString(msg_help, language_code);
			str_help_cmd = getString(cmd_help, language_code);
		}
		free(line);
	}

	Message m = {.message_id = close_connection};
	sendMessage(socket, &m);

	/* free the command strings */
	free(str_quit);
	free(str_balance);
	free(str_deposit);
	free(str_withdraw);
	free(str_unknown_command);
	free(str_help);
	free(str_help_cmd);
}
void HTTPRequest::getProxyCredentials(std::string& scheme, std::string& authInfo) const
{
	getCredentials(PROXY_AUTHORIZATION, scheme, authInfo);
}
StatusWith<std::tuple<bool, std::string>> SASLPlainServerMechanism::stepImpl(
    OperationContext* opCtx, StringData inputData) {
    if (_authenticationDatabase == "$external") {
        return Status(ErrorCodes::AuthenticationFailed,
                      "PLAIN mechanism must be used with internal users");
    }

    AuthorizationManager* authManager = AuthorizationManager::get(opCtx->getServiceContext());

    // Expecting user input on the form: [authz-id]\0authn-id\0pwd
    std::string input = inputData.toString();

    SecureAllocatorAuthDomain::SecureString pwd = "";
    try {
        size_t firstNull = inputData.find('\0');
        if (firstNull == std::string::npos) {
            return Status(
                ErrorCodes::AuthenticationFailed,
                str::stream()
                    << "Incorrectly formatted PLAIN client message, missing first NULL delimiter");
        }
        size_t secondNull = inputData.find('\0', firstNull + 1);
        if (secondNull == std::string::npos) {
            return Status(
                ErrorCodes::AuthenticationFailed,
                str::stream()
                    << "Incorrectly formatted PLAIN client message, missing second NULL delimiter");
        }

        std::string authorizationIdentity = input.substr(0, firstNull);
        ServerMechanismBase::_principalName =
            input.substr(firstNull + 1, (secondNull - firstNull) - 1);
        if (ServerMechanismBase::_principalName.empty()) {
            return Status(ErrorCodes::AuthenticationFailed,
                          str::stream()
                              << "Incorrectly formatted PLAIN client message, empty username");
        } else if (!authorizationIdentity.empty() &&
                   authorizationIdentity != ServerMechanismBase::_principalName) {
            return Status(ErrorCodes::AuthenticationFailed,
                          str::stream()
                              << "SASL authorization identity must match authentication identity");
        }
        pwd = SecureAllocatorAuthDomain::SecureString(input.substr(secondNull + 1).c_str());
        if (pwd->empty()) {
            return Status(ErrorCodes::AuthenticationFailed,
                          str::stream()
                              << "Incorrectly formatted PLAIN client message, empty password");
        }
    } catch (std::out_of_range&) {
        return Status(ErrorCodes::AuthenticationFailed,
                      str::stream() << "Incorrectly formatted PLAIN client message");
    }

    // The authentication database is also the source database for the user.
    auto swUser = authManager->acquireUser(
        opCtx, UserName(ServerMechanismBase::_principalName, _authenticationDatabase));

    if (!swUser.isOK()) {
        return swUser.getStatus();
    }

    auto userObj = std::move(swUser.getValue());
    const auto creds = userObj->getCredentials();

    const auto sha256Status = trySCRAM<SHA256Block>(creds, pwd->c_str());
    if (!sha256Status.isOK()) {
        return sha256Status.getStatus();
    }
    if (sha256Status.getValue()) {
        return std::make_tuple(true, std::string());
    }

    const auto authDigest = createPasswordDigest(ServerMechanismBase::_principalName, pwd->c_str());
    const auto sha1Status = trySCRAM<SHA1Block>(creds, authDigest);
    if (!sha1Status.isOK()) {
        return sha1Status.getStatus();
    }
    if (sha1Status.getValue()) {
        return std::make_tuple(true, std::string());
    }

    return Status(ErrorCodes::AuthenticationFailed, str::stream() << "No credentials available.");


    return std::make_tuple(true, std::string());
}
Exemple #12
0
void Request::getProxyCredentials(std::string& scheme, std::string& authInfo) const
{
    getCredentials("Proxy-Authorization", scheme, authInfo);
}