More refucktoring of main code, LDAP DN->UID
parent
966bcd0291
commit
32d161b51e
|
@ -93,3 +93,35 @@ finalize:
|
|||
ldap_unbind_s(ld);
|
||||
return result;
|
||||
}
|
||||
|
||||
// because fuck you that's why
|
||||
int ldap_uid_from_dn(char *DN, char *UIDOut)
|
||||
{
|
||||
char *KeyPair = DN;
|
||||
int KeyPairLength = 0;
|
||||
|
||||
for (char *i = DN; i < DN + strlen(DN); i++)
|
||||
{
|
||||
if (*i == ',')
|
||||
{
|
||||
char *KeyPairSplit;
|
||||
for (KeyPairSplit = KeyPair; *KeyPairSplit != '='; KeyPairSplit++) {}
|
||||
|
||||
int KeyLength = KeyPairSplit - KeyPair;
|
||||
char *Key = KeyPair;
|
||||
int ValueLength = KeyPairLength - KeyLength - 1;
|
||||
char *Value = KeyPairSplit + 1;
|
||||
|
||||
if (strncmp(Key, "uid", KeyLength > 3 ? 3 : KeyLength) == 0)
|
||||
{
|
||||
memcpy(UIDOut, Value, ValueLength);
|
||||
UIDOut[ValueLength] = 0;
|
||||
}
|
||||
|
||||
KeyPair = i + 1;
|
||||
KeyPairLength = 0;
|
||||
}
|
||||
else
|
||||
KeyPairLength++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
int ldap_dn_by_mifare(char *MifareID, char *DNOut, int *DNLength);
|
||||
int hash_mifare(char *MifareID, char *salt, char* target);
|
||||
int ldap_uid_from_dn(char *DN, char *UIDOut);
|
||||
const int NO_SUCH_CARD;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include "nfc.h"
|
||||
#include "barcode.h"
|
||||
#include "ldap.h"
|
||||
#include "tts.h"
|
||||
#include "config.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
@ -13,19 +15,67 @@ int main(int argc, char **argv)
|
|||
tts_speak("Nie można było zainicjalizować czytnika mifare.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("NFC initialization successful\n");
|
||||
|
||||
if (barcode_initialize(BARCODE_PORT))
|
||||
{
|
||||
printf("Barcode initialization failed\n");
|
||||
tts_speak("Nie można było zainicjalizować czytnika kodów kreskowych.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Barcode initialization successful\n");
|
||||
|
||||
tts_speak("Refryżyrator gotowy do pracy.");
|
||||
|
||||
char UID[128];
|
||||
char MifareID[128];
|
||||
char Barcode[14];
|
||||
while (1)
|
||||
{
|
||||
int NFCResult = nfc_read(UID);
|
||||
int NFCResult = nfc_read(MifareID);
|
||||
|
||||
if (NFCResult == 0)
|
||||
{
|
||||
// Do barcode stuff here
|
||||
char DN[256];
|
||||
int DNLength = 256;
|
||||
int LDAPResult = ldap_dn_by_mifare(MifareID, DN, &DNLength);
|
||||
|
||||
if (LDAPResult > 0)
|
||||
{
|
||||
if (LDAPResult == NO_SUCH_CARD)
|
||||
{
|
||||
tts_speak("Nieznana karta.");
|
||||
printf("NFC: Unknown card.\n");
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
tts_speak("Błąd eldapa.");
|
||||
printf("LDAP: Unknown error %i\n", LDAPResult);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
printf("LDAP DN: %s\n", DN);
|
||||
char UID[128];
|
||||
ldap_uid_from_dn(DN, UID);
|
||||
printf("LDAP uid: %s\n", UID);
|
||||
|
||||
tts_speak("Zeskanuj produkt.\n");
|
||||
|
||||
int BarcodeResult = barcode_read(Barcode);
|
||||
if (BarcodeResult == 0)
|
||||
{
|
||||
printf("Scanned barcode %s\n", Barcode);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Barcode error %i\n", BarcodeResult);
|
||||
// Do error handling here
|
||||
}
|
||||
}
|
||||
else if (NFCResult != NFC_TIMEOUT)
|
||||
{
|
||||
printf("NFC error %i\n", NFCResult);
|
||||
// Do error handling here
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ const nfc_modulation_t g_NFCModulations[5] = {
|
|||
};
|
||||
const size_t g_NFCModulationCount = 5;
|
||||
|
||||
int nfc_read(char *UIDOut)
|
||||
int nfc_read(char *MifareOut)
|
||||
{
|
||||
nfc_target_t Target;
|
||||
bool Result = nfc_initiator_poll_target(g_NFCDevice, g_NFCModulations, g_NFCModulationCount, 20, 2, &Target);
|
||||
|
@ -41,29 +41,7 @@ int nfc_read(char *UIDOut)
|
|||
|
||||
printf("Scanned Mifare %x.\n", *(int *)Target.nti.nai.abtUid);
|
||||
|
||||
char MifareID[5];
|
||||
sprintf(MifareID, "%02x%02x%02x%02x", Target.nti.nai.abtUid[0], Target.nti.nai.abtUid[1], Target.nti.nai.abtUid[2], Target.nti.nai.abtUid[3]);
|
||||
|
||||
char DN[128];
|
||||
int DNLength = 128;
|
||||
int LDAPResult = ldap_dn_by_mifare(MifareID, DN, &DNLength);
|
||||
|
||||
if (LDAPResult > 0)
|
||||
{
|
||||
if (LDAPResult == NO_SUCH_CARD)
|
||||
{
|
||||
tts_speak("Nieznana karta.");
|
||||
printf("NFC: Unknown card.\n");
|
||||
return E_NO_SUCH_USER;
|
||||
}
|
||||
else
|
||||
{
|
||||
tts_speak("Nieznany błąd przy połączeniu z eldapem.");
|
||||
return E_FUCKUP;
|
||||
}
|
||||
}
|
||||
printf("This appears to be %s.\n", DN);
|
||||
strncpy(UIDOut, DN, 128);
|
||||
sprintf(MifareOut, "%02x%02x%02x%02x", Target.nti.nai.abtUid[0], Target.nti.nai.abtUid[1], Target.nti.nai.abtUid[2], Target.nti.nai.abtUid[3]);
|
||||
return 0;
|
||||
}
|
||||
return E_TIMEOUT;
|
||||
|
|
Reference in New Issue