// === TYPES ===
typedef struct sItem {
- char *Ident;
+ char *Type;
+ int ID;
char *Desc;
int Price;
} tItem;
// > Code Type Count ...
CompileRegex(&gArrayRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+([0-9]+)", REG_EXTENDED); //
// > Code Type Ident Price Desc
- CompileRegex(&gItemRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+([A-Za-z0-9:]+?)\\s+([0-9]+)\\s+(.+)$", REG_EXTENDED);
+ CompileRegex(&gItemRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+([A-Za-z]+):([0-9]+)\\s+([0-9]+)\\s+(.+)$", REG_EXTENDED);
// > Code 'SALT' salt
CompileRegex(&gSaltRegex, "^([0-9]{3})\\s+([A-Za-z]+)\\s+(.+)$", REG_EXTENDED);
// > Code 'User' Username Balance Flags
else
{
for( i = 0; i < giNumItems; i ++ ) {
- printf("%2i %s\t%3i %s\n", i, gaItems[i].Ident, gaItems[i].Price, gaItems[i].Desc);
+ printf("%2i %s:%i\t%3i %s\n", i, gaItems[i].Type, gaItems[i].ID,
+ gaItems[i].Price, gaItems[i].Desc);
}
printf(" q Quit\n");
for(;;)
responseCode = atoi(buf);
switch( responseCode )
{
-
- case 200: // Authenticated, return :)
+ case 200: // Autoauth succeeded, return
free(buf);
break;
// Fetch item information
for( i = 0; i < giNumItems; i ++ )
{
- regmatch_t matches[6];
+ regmatch_t matches[7];
// Get item info
buf = ReadLine(Socket);
exit(-1);
}
- RunRegex(&gItemRegex, buf, 6, matches, "Malformed server response");
+ RunRegex(&gItemRegex, buf, 7, matches, "Malformed server response");
buf[ matches[3].rm_eo ] = '\0';
- gaItems[i].Ident = strdup( buf + matches[3].rm_so );
- gaItems[i].Price = atoi( buf + matches[4].rm_so );
- gaItems[i].Desc = strdup( buf + matches[5].rm_so );
+ gaItems[i].Type = strdup( buf + matches[3].rm_so );
+ gaItems[i].ID = atoi( buf + matches[4].rm_so );
+ gaItems[i].Price = atoi( buf + matches[5].rm_so );
+ gaItems[i].Desc = strdup( buf + matches[6].rm_so );
free(buf);
}
if( ItemID < 0 || ItemID > giNumItems ) return -1;
// Dispense!
- sendf(Socket, "DISPENSE %s\n", gaItems[ItemID].Ident);
+ sendf(Socket, "DISPENSE %s:%i\n", gaItems[ItemID].Type, gaItems[ItemID].ID);
buf = ReadLine(Socket);
responseCode = atoi(buf);
#if USE_LDAP
char *ReadLDAPValue(const char *Filter, char *Value);
#endif
-void HexBin(uint8_t *Dest, int BufSize, char *Src);
+void HexBin(uint8_t *Dest, int BufSize, const char *Src);
// === GLOBALS ===
FILE *gBank_LogFile;
#if USE_LDAP
-char *gsLDAPServer = "mussel";
- int giLDAPPort = 389;
+char *gsLDAPPath = "ldapi:///";
LDAP *gpLDAP;
#endif
fprintf(stderr, "ldap_create: %s\n", ldap_err2string(rv));
exit(1);
}
- rv = ldap_initialize(&gpLDAP, "ldap://mussel:389");
+ rv = ldap_initialize(&gpLDAP, gsLDAPPath);
if(rv) {
fprintf(stderr, "ldap_initialize: %s\n", ldap_err2string(rv));
exit(1);
cred.bv_val = "secret";
cred.bv_len = 6;
rv = ldap_sasl_bind_s(gpLDAP, "cn=root,dc=ucc,dc=gu,dc=uwa,dc=edu,dc=au",
- "", &cred, NULL, NULL, NULL);
+ "", &cred, NULL, NULL, &servcred);
if(rv) {
fprintf(stderr, "ldap_start_tls_s: %s\n", ldap_err2string(rv));
exit(1);
// Then create the hash from the provided salt
// Compare that with the provided hash
- if( giDebugLevel ) {
+ # if 1
+ {
int i;
- printf("Client %i: Password hash ", Client->ID);
- for(i=0;i<HASH_LENGTH;i++)
+ printf("Password hash ");
+ for(i=0;i<20;i++)
printf("%02x", hash[i]&0xFF);
printf("\n");
}
+ # endif
#endif
#endif
// TODO: Move to another file
-void HexBin(uint8_t *Dest, int BufSize, char *Src)
+void HexBin(uint8_t *Dest, int BufSize, const char *Src)
{
int i;
for( i = 0; i < BufSize; i ++ )