* \param Ammount Amount of money (in cents) to transfer
* \param Reason Reason for the transfer
*/
-extern int Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
+extern int Bank_Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
/**
* \brief Get flags on an account
* \param User UID to get flags from
* \see eCokebank_Flags
*/
-extern int GetFlags(int User);
+extern int Bank_GetFlags(int User);
/**
* \brief Set an account's flags
* \param User UID to set flags on
* \param Mask Mask of flags changed
* \param Value Final value of changed flags
*/
-extern int SetFlags(int User, int Mask, int Value);
+extern int Bank_SetFlags(int User, int Mask, int Value);
/**
* \brief Get an account's balance
* \param User UID to query
*/
-extern int GetBalance(int User);
+extern int Bank_GetBalance(int User);
/**
* \brief Get the name associated with an account
* \return Heap string
*/
-extern char *GetUserName(int User);
+extern char *Bank_GetUserName(int User);
/**
* \brief Get a UID from a passed name
*/
-extern int GetUserID(const char *Username);
+extern int Bank_GetUserID(const char *Username);
/**
* \brief Create a new account
*/
-extern int CreateUser(const char *Username);
+extern int Bank_CreateUser(const char *Username);
/**
* \brief Get the maximum UID
* \note Used for iterating accounts
*/
-extern int GetMaxID(void);
+extern int Bank_GetMaxID(void);
/**
* \brief Validates a user's authentication
* \param Salt Salt given to the client for hashing the password
* \param Username Username used
* \param Password Password sent by the client
*/
-extern int GetUserAuth(const char *Salt, const char *Username, const char *Password);
+extern int Bank_GetUserAuth(const char *Salt, const char *Username, const char *Password);
#endif
BIN := ../../cokebank.so
-OBJ := main.o bank.o
+OBJ := main.o
CPPFLAGS :=
-CFLAGS := -Wall -Werror -g -fPIC
+CFLAGS := -Wall -Wextra -Werror -g -fPIC -Wmissing-prototypes -Wstrict-prototypes
LDFLAGS := -shared -Wl,-soname,cokebank.so
ifneq ($(USE_LDAP),)
LDFLAGS += -lldap
endif
+DEPFILES := $(OBJ:%.o=%.d)
+
.PHONY: all clean
all: $(BIN)
clean:
- $(RM) $(BIN) $(OBJ)
+ $(RM) $(BIN) $(OBJ) $(DEPFILES)
$(BIN): $(OBJ)
$(CC) $(LDFLAGS) -o $(BIN) $(OBJ)
%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+ @cpp $< -MM -MF $*.d
+
+-include $(DEPFILES)
+++ /dev/null
-/*
- * OpenDispense 2
- * UCC (University [of WA] Computer Club) Electronic Accounting System
- * - Cokebank (Basic Version)
- *
- * bank.c - Actual bank database
- *
- * This file is licenced under the 3-clause BSD Licence. See the file COPYING
- * for full details.
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <pwd.h>
-#include <grp.h>
-#include "common.h"
-
-#define USE_UNIX_GROUPS 1
-
-// === PROTOTYPES ===
-static int GetUnixID(const char *Username);
-
-// === GLOBALS ===
-tUser *gaBank_Users;
- int giBank_NumUsers;
-FILE *gBank_File;
-
-// === CODE ===
-static int Bank_int_WriteEntry(int ID)
-{
- if( ID < 0 || ID >= giBank_NumUsers ) {
- return -1;
- }
-
- // Commit to file
- fseek(gBank_File, ID*sizeof(gaBank_Users[0]), SEEK_SET);
- fwrite(&gaBank_Users[ID], sizeof(gaBank_Users[0]), 1, gBank_File);
-
- return 0;
-}
-
-int Bank_GetUserByName(const char *Username)
-{
- int i, uid;
-
- uid = GetUnixID(Username);
-
- // Expensive search :(
- for( i = 0; i < giBank_NumUsers; i ++ )
- {
- if( gaBank_Users[i].UnixID == uid )
- return i;
- }
-
- return -1;
-}
-
-int Bank_GetUserBalance(int ID)
-{
- if( ID < 0 || ID >= giBank_NumUsers )
- return INT_MIN;
-
- return gaBank_Users[ID].Balance;
-}
-
-int Bank_GetUserFlags(int ID)
-{
- if( ID < 0 || ID >= giBank_NumUsers )
- return -1;
-
- // root
- if( gaBank_Users[ID].UnixID == 0 ) {
- gaBank_Users[ID].Flags |= USER_FLAG_WHEEL|USER_FLAG_COKE;
- }
-
- #if USE_UNIX_GROUPS
- // TODO: Implement checking the PAM groups and status instead, then
- // fall back on the database. (and update if there is a difference)
- if( gaBank_Users[ID].UnixID > 0 )
- {
- struct passwd *pwd;
- struct group *grp;
- int i;
-
- // Get username
- pwd = getpwuid( gaBank_Users[ID].UnixID );
-
- // Check for additions to the "coke" group
- grp = getgrnam("coke");
- if( grp ) {
- for( i = 0; grp->gr_mem[i]; i ++ )
- {
- if( strcmp(grp->gr_mem[i], pwd->pw_name) == 0 ) {
- gaBank_Users[ID].Flags |= USER_FLAG_COKE;
- break ;
- }
- }
- }
-
- // Check for additions to the "wheel" group
- grp = getgrnam("wheel");
- if( grp ) {
- for( i = 0; grp->gr_mem[i]; i ++ )
- {
- if( strcmp(grp->gr_mem[i], pwd->pw_name) == 0 ) {
- gaBank_Users[ID].Flags |= USER_FLAG_WHEEL;
- break ;
- }
- }
- }
- }
- #endif
-
- return gaBank_Users[ID].Flags;
-}
-
-int Bank_SetUserFlags(int ID, int Mask, int Value)
-{
- // Sanity
- if( ID < 0 || ID >= giBank_NumUsers )
- return -1;
-
- // Silently ignore changes to root and meta accounts
- if( gaBank_Users[ID].UnixID <= 0 ) return 0;
-
- gaBank_Users[ID].Flags &= ~Mask;
- gaBank_Users[ID].Flags |= Value;
-
- Bank_int_WriteEntry(ID);
-
- return 0;
-}
-
-int Bank_AlterUserBalance(int ID, int Delta)
-{
- // Sanity
- if( ID < 0 || ID >= giBank_NumUsers )
- return -1;
-
- // Update
- gaBank_Users[ID].Balance += Delta;
-
- Bank_int_WriteEntry(ID);
-
- return 0;
-}
-
-int Bank_GetMinAllowedBalance(int ID)
-{
- int flags;
- if( ID < 0 || ID >= giBank_NumUsers )
- return 0;
-
- flags = Bank_GetUserFlags(ID);
-
- // Internal accounts have no limit
- if( (flags & USER_FLAG_INTERNAL) )
- return INT_MIN;
-
- // Wheel is allowed to go to -$100
- if( (flags & USER_FLAG_WHEEL) )
- return -10000;
-
- // Coke is allowed to go to -$20
- if( (flags & USER_FLAG_COKE) )
- return -2000;
-
- // For everyone else, no negative
- return 0;
-}
-
-/**
- * \brief Create a new user in our database
- */
-int Bank_AddUser(const char *Username)
-{
- void *tmp;
- int uid = GetUnixID(Username);
-
- // Can has moar space plz?
- tmp = realloc(gaBank_Users, (giBank_NumUsers+1)*sizeof(gaBank_Users[0]));
- if( !tmp ) return -1;
- gaBank_Users = tmp;
-
- // Crete new user
- gaBank_Users[giBank_NumUsers].UnixID = uid;
- gaBank_Users[giBank_NumUsers].Balance = 0;
- gaBank_Users[giBank_NumUsers].Flags = 0;
-
- if( strcmp(Username, COKEBANK_DEBT_ACCT) == 0 ) {
- gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_INTERNAL;
- }
- else if( strcmp(Username, COKEBANK_SALES_ACCT) == 0 ) {
- gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_INTERNAL;
- }
- else if( strcmp(Username, "root") == 0 ) {
- gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_WHEEL|USER_FLAG_COKE;
- }
-
- // Increment count
- giBank_NumUsers ++;
-
- Bank_int_WriteEntry(giBank_NumUsers - 1);
-
- return 0;
-}
-
-// ---
-// Unix user dependent code
-// TODO: Modify to keep its own list of usernames
-// ---
-char *Bank_GetUserName(int ID)
-{
- struct passwd *pwd;
-
- if( ID < 0 || ID >= giBank_NumUsers )
- return NULL;
-
- if( gaBank_Users[ID].UnixID == -1 )
- return strdup(COKEBANK_SALES_ACCT);
-
- if( gaBank_Users[ID].UnixID == -2 )
- return strdup(COKEBANK_DEBT_ACCT);
-
- pwd = getpwuid(gaBank_Users[ID].UnixID);
- if( !pwd ) return NULL;
-
- return strdup(pwd->pw_name);
-}
-
-static int GetUnixID(const char *Username)
-{
- int uid;
-
- if( strcmp(Username, COKEBANK_SALES_ACCT) == 0 ) { // Pseudo account that sales are made into
- uid = -1;
- }
- else if( strcmp(Username, COKEBANK_DEBT_ACCT) == 0 ) { // Pseudo acount that money is added from
- uid = -2;
- }
- else {
- struct passwd *pwd;
- // Get user ID
- pwd = getpwnam(Username);
- if( !pwd ) return -1;
- uid = pwd->pw_uid;
- }
- return uid;
-}
int Flags;
} tUser;
-// === IMPORTS ===
-extern int Bank_GetMinAllowedBalance(int ID);
-extern int Bank_GetUserBalance(int ID);
-extern int Bank_AlterUserBalance(int ID, int Delta);
-extern char *Bank_GetUserName(int ID);
-extern int Bank_GetUserFlags(int ID);
-extern int Bank_SetUserFlags(int ID, int Mask, int Value);
-extern int Bank_GetUserByName(const char *Username);
-extern int Bank_AddUser(const char *Username);
-extern FILE *gBank_File;
-extern tUser *gaBank_Users;
-extern int giBank_NumUsers;
-
#endif
#include <stdint.h>
#include <stdio.h>
#include <string.h>
+#include <string.h>
+#include <limits.h>
+#include <pwd.h>
+#include <grp.h>
#include <openssl/sha.h>
#include "common.h"
#if USE_LDAP
*
*/
-// === HACKS ===
+#define USE_UNIX_GROUPS 1
#define HACK_TPG_NOAUTH 1
#define HACK_ROOT_NOAUTH 1
// === PROTOTYPES ===
void Init_Cokebank(const char *Argument);
- int Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
- int GetBalance(int User);
-char *GetUserName(int User);
- int GetUserID(const char *Username);
- int GetMaxID(void);
- int GetUserAuth(const char *Salt, const char *Username, const char *PasswordString);
+ int Bank_Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason);
+ int Bank_CreateUser(const char *Username);
+ int Bank_GetMaxID(void);
+static int Bank_int_WriteEntry(int ID);
+ int Bank_GetUserID(const char *Username);
+ int Bank_GetBalance(int User);
+ int Bank_GetFlags(int User);
+ int Bank_SetFlags(int User, int Mask, int Value);
+ int Bank_int_AlterUserBalance(int ID, int Delta);
+ int Bank_int_GetMinAllowedBalance(int ID);
+ int Bank_int_AddUser(const char *Username);
+char *Bank_GetUserName(int User);
+ int Bank_int_GetUnixID(const char *Username);
+ int Bank_GetUserAuth(const char *Salt, const char *Username, const char *PasswordString);
#if USE_LDAP
char *ReadLDAPValue(const char *Filter, char *Value);
#endif
char *gsLDAPPath = "ldapi:///";
LDAP *gpLDAP;
#endif
+tUser *gaBank_Users;
+ int giBank_NumUsers;
+FILE *gBank_File;
// === CODE ===
/**
* \param Reason Reason for the transfer (essentially a comment)
* \return Boolean failure
*/
-int Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason)
+int Bank_Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason)
{
- int srcBal = Bank_GetUserBalance(SourceUser);
- int dstBal = Bank_GetUserBalance(DestUser);
+ int srcBal = Bank_GetBalance(SourceUser);
+ int dstBal = Bank_GetBalance(DestUser);
- if( srcBal - Ammount < Bank_GetMinAllowedBalance(SourceUser) )
+ if( srcBal - Ammount < Bank_int_GetMinAllowedBalance(SourceUser) )
return 1;
- if( dstBal + Ammount < Bank_GetMinAllowedBalance(DestUser) )
+ if( dstBal + Ammount < Bank_int_GetMinAllowedBalance(DestUser) )
return 1;
- Bank_AlterUserBalance(DestUser, Ammount);
- Bank_AlterUserBalance(SourceUser, -Ammount);
+ Bank_int_AlterUserBalance(DestUser, Ammount);
+ Bank_int_AlterUserBalance(SourceUser, -Ammount);
fprintf(gBank_LogFile, "Transfer %ic #%i{%i} > #%i{%i} [%i, %i] (%s)\n",
Ammount, SourceUser, srcBal, DestUser, dstBal,
srcBal - Ammount, dstBal + Ammount, Reason);
return 0;
}
-int GetFlags(int User)
+int Bank_CreateUser(const char *Username)
{
- return Bank_GetUserFlags(User);
+ int ret;
+
+ ret = Bank_GetUserID(Username);
+ if( ret != -1 ) return -1;
+
+ return Bank_int_AddUser(Username);
}
-int SetFlags(int User, int Mask, int Flags)
+int Bank_GetMaxID(void)
{
- return Bank_SetUserFlags(User, Mask, Flags);
+ return giBank_NumUsers;
}
-/**
- * \brief Get the balance of the passed user
- */
-int GetBalance(int User)
+static int Bank_int_WriteEntry(int ID)
{
- return Bank_GetUserBalance(User);
+ if( ID < 0 || ID >= giBank_NumUsers ) {
+ return -1;
+ }
+
+ // Commit to file
+ fseek(gBank_File, ID*sizeof(gaBank_Users[0]), SEEK_SET);
+ fwrite(&gaBank_Users[ID], sizeof(gaBank_Users[0]), 1, gBank_File);
+
+ return 0;
}
/**
- * \brief Return the name the passed user
+ * \brief Get the User ID of the named user
*/
-char *GetUserName(int User)
+int Bank_GetUserID(const char *Username)
+{
+ int i, uid;
+
+ uid = Bank_int_GetUnixID(Username);
+
+ // Expensive search :(
+ for( i = 0; i < giBank_NumUsers; i ++ )
+ {
+ if( gaBank_Users[i].UnixID == uid )
+ return i;
+ }
+
+ return -1;
+}
+
+int Bank_GetBalance(int ID)
+{
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return INT_MIN;
+
+ return gaBank_Users[ID].Balance;
+}
+
+int Bank_GetFlags(int ID)
+{
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return -1;
+
+ // root
+ if( gaBank_Users[ID].UnixID == 0 ) {
+ gaBank_Users[ID].Flags |= USER_FLAG_WHEEL|USER_FLAG_COKE;
+ }
+
+ #if USE_UNIX_GROUPS
+ // TODO: Implement checking the PAM groups and status instead, then
+ // fall back on the database. (and update if there is a difference)
+ if( gaBank_Users[ID].UnixID > 0 )
+ {
+ struct passwd *pwd;
+ struct group *grp;
+ int i;
+
+ // Get username
+ pwd = getpwuid( gaBank_Users[ID].UnixID );
+
+ // Check for additions to the "coke" group
+ grp = getgrnam("coke");
+ if( grp ) {
+ for( i = 0; grp->gr_mem[i]; i ++ )
+ {
+ if( strcmp(grp->gr_mem[i], pwd->pw_name) == 0 ) {
+ gaBank_Users[ID].Flags |= USER_FLAG_COKE;
+ break ;
+ }
+ }
+ }
+
+ // Check for additions to the "wheel" group
+ grp = getgrnam("wheel");
+ if( grp ) {
+ for( i = 0; grp->gr_mem[i]; i ++ )
+ {
+ if( strcmp(grp->gr_mem[i], pwd->pw_name) == 0 ) {
+ gaBank_Users[ID].Flags |= USER_FLAG_WHEEL;
+ break ;
+ }
+ }
+ }
+ }
+ #endif
+
+ return gaBank_Users[ID].Flags;
+}
+
+int Bank_SetFlags(int ID, int Mask, int Value)
+{
+ // Sanity
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return -1;
+
+ // Silently ignore changes to root and meta accounts
+ if( gaBank_Users[ID].UnixID <= 0 ) return 0;
+
+ gaBank_Users[ID].Flags &= ~Mask;
+ gaBank_Users[ID].Flags |= Value;
+
+ Bank_int_WriteEntry(ID);
+
+ return 0;
+}
+
+int Bank_int_AlterUserBalance(int ID, int Delta)
{
- return Bank_GetUserName(User);
+ // Sanity
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return -1;
+
+ // Update
+ gaBank_Users[ID].Balance += Delta;
+
+ Bank_int_WriteEntry(ID);
+
+ return 0;
+}
+
+int Bank_int_GetMinAllowedBalance(int ID)
+{
+ int flags;
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return 0;
+
+ flags = Bank_GetFlags(ID);
+
+ // Internal accounts have no limit
+ if( (flags & USER_FLAG_INTERNAL) )
+ return INT_MIN;
+
+ // Wheel is allowed to go to -$100
+ if( (flags & USER_FLAG_WHEEL) )
+ return -10000;
+
+ // Coke is allowed to go to -$20
+ if( (flags & USER_FLAG_COKE) )
+ return -2000;
+
+ // For everyone else, no negative
+ return 0;
}
/**
- * \brief Get the User ID of the named user
+ * \brief Create a new user in our database
*/
-int GetUserID(const char *Username)
+int Bank_int_AddUser(const char *Username)
{
- return Bank_GetUserByName(Username);
+ void *tmp;
+ int uid = Bank_int_GetUnixID(Username);
+
+ // Can has moar space plz?
+ tmp = realloc(gaBank_Users, (giBank_NumUsers+1)*sizeof(gaBank_Users[0]));
+ if( !tmp ) return -1;
+ gaBank_Users = tmp;
+
+ // Crete new user
+ gaBank_Users[giBank_NumUsers].UnixID = uid;
+ gaBank_Users[giBank_NumUsers].Balance = 0;
+ gaBank_Users[giBank_NumUsers].Flags = 0;
+
+ if( strcmp(Username, COKEBANK_DEBT_ACCT) == 0 ) {
+ gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_INTERNAL;
+ }
+ else if( strcmp(Username, COKEBANK_SALES_ACCT) == 0 ) {
+ gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_INTERNAL;
+ }
+ else if( strcmp(Username, "root") == 0 ) {
+ gaBank_Users[giBank_NumUsers].Flags = USER_FLAG_WHEEL|USER_FLAG_COKE;
+ }
+
+ // Increment count
+ giBank_NumUsers ++;
+
+ Bank_int_WriteEntry(giBank_NumUsers - 1);
+
+ return 0;
}
-int CreateUser(const char *Username)
+// ---
+// Unix user dependent code
+// TODO: Modify to keep its own list of usernames
+// ---
+/**
+ * \brief Return the name the passed user
+ */
+char *Bank_GetUserName(int ID)
{
- int ret;
+ struct passwd *pwd;
- ret = Bank_GetUserByName(Username);
- if( ret != -1 ) return -1;
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return NULL;
- return Bank_AddUser(Username);
+ if( gaBank_Users[ID].UnixID == -1 )
+ return strdup(COKEBANK_SALES_ACCT);
+
+ if( gaBank_Users[ID].UnixID == -2 )
+ return strdup(COKEBANK_DEBT_ACCT);
+
+ pwd = getpwuid(gaBank_Users[ID].UnixID);
+ if( !pwd ) return NULL;
+
+ return strdup(pwd->pw_name);
}
-int GetMaxID(void)
+int Bank_int_GetUnixID(const char *Username)
{
- return giBank_NumUsers;
+ int uid;
+
+ if( strcmp(Username, COKEBANK_SALES_ACCT) == 0 ) { // Pseudo account that sales are made into
+ uid = -1;
+ }
+ else if( strcmp(Username, COKEBANK_DEBT_ACCT) == 0 ) { // Pseudo acount that money is added from
+ uid = -2;
+ }
+ else {
+ struct passwd *pwd;
+ // Get user ID
+ pwd = getpwnam(Username);
+ if( !pwd ) return -1;
+ uid = pwd->pw_uid;
+ }
+ return uid;
}
+
/**
* \brief Authenticate a user
* \return User ID, or -1 if authentication failed
*/
-int GetUserAuth(const char *Salt, const char *Username, const char *PasswordString)
+int Bank_GetUserAuth(const char *Salt, const char *Username, const char *PasswordString)
{
#if USE_LDAP
uint8_t hash[20];
char *passhash;
#endif
+ #if 1
+ // Only here to shut GCC up (until password auth is implemented
+ if( Salt == NULL )
+ return -1;
+ if( PasswordString == NULL )
+ return -1;
+ #endif
+
#if HACK_TPG_NOAUTH
if( strcmp(Username, "tpg") == 0 )
- return GetUserID("tpg");
+ return Bank_GetUserID("tpg");
#endif
#if HACK_ROOT_NOAUTH
if( strcmp(Username, "root") == 0 ) {
- int ret = GetUserID("root");
+ int ret = Bank_GetUserID("root");
if( ret == -1 )
- return CreateUser("root");
+ return Bank_CreateUser("root");
return ret;
}
#endif
OBJ += handler_coke.o handler_snack.o handler_door.o
BIN := ../../dispsrv
+DEPFILES := $(OBJ:%.o=%.d)
+
LINKFLAGS := -g ../../cokebank.so
CPPFLAGS :=
-CFLAGS := -Wall -g
+CFLAGS := -Wall -Wextra -Werror -g
.PHONY: all clean
$(BIN): $(OBJ)
$(CC) -o $(BIN) $(LINKFLAGS) $(OBJ)
+%.o: %.c
+ $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+ @cpp $< -MM -MF $*.d
+
+-include $(DEPFILES)
+
#define _EXPSTR(x) #x
#define EXPSTR(x) _EXPSTR(x)
+#define UNUSED(var) unused__##var __attribute__((__unused__))
+
// === STRUCTURES ===
typedef struct sItem tItem;
typedef struct sUser tUser;
// Subtract the balance
reason = mkstr("Dispense - %s:%i %s", handler->Name, Item->ID, Item->Name);
if( !reason ) reason = Item->Name; // TODO: Should I instead return an error?
- ret = Transfer( User, GetUserID(COKEBANK_SALES_ACCT), Item->Price, reason);
+ ret = Bank_Transfer( User, Bank_GetUserID(COKEBANK_SALES_ACCT), Item->Price, reason);
free(reason);
if(ret) return 2; // 2: No balance
// Get username for debugging
- username = GetUserName(User);
+ username = Bank_GetUserName(User);
// Actually do the dispense
if( handler->DoDispense ) {
if(ret) {
Log_Error("Dispense failed after deducting cost (%s dispensing %s - %ic)",
username, Item->Name, Item->Price);
- Transfer( GetUserID(COKEBANK_SALES_ACCT), User, Item->Price, "rollback" );
+ Bank_Transfer( Bank_GetUserID(COKEBANK_SALES_ACCT), User, Item->Price, "rollback" );
free( username );
return -1; // 1: Unkown Error again
}
}
- actualUsername = GetUserName(ActualUser);
+ actualUsername = Bank_GetUserName(ActualUser);
// And log that it happened
Log_Info("dispense '%s' (%s:%i) for %s by %s [cost %i, balance %i cents]",
Item->Name, handler->Name, Item->ID,
- username, actualUsername, Item->Price, GetBalance(User)
+ username, actualUsername, Item->Price, Bank_GetBalance(User)
);
free( username );
if( Ammount < 0 ) return 1; // Um... negative give? Not on my watch!
- ret = Transfer( SrcUser, DestUser, Ammount, ReasonGiven );
+ ret = Bank_Transfer( SrcUser, DestUser, Ammount, ReasonGiven );
if(ret) return 2; // No Balance
- srcName = GetUserName(SrcUser);
- dstName = GetUserName(DestUser);
- actualUsername = GetUserName(ActualUser);
+ srcName = Bank_GetUserName(SrcUser);
+ dstName = Bank_GetUserName(DestUser);
+ actualUsername = Bank_GetUserName(ActualUser);
- Log_Info("give %i to %s from %s by %s (%s)",
- Ammount, dstName, srcName, actualUsername, ReasonGiven
+ Log_Info("give %i to %s from %s by %s (%s) [balances %i, %i]",
+ Ammount, dstName, srcName, actualUsername, ReasonGiven,
+ Bank_GetBalance(SrcUser), Bank_GetBalance(DestUser)
);
free(srcName);
int ret;
char *dstName, *byName;
- ret = Transfer( GetUserID(COKEBANK_DEBT_ACCT), User, Ammount, ReasonGiven );
+ ret = Bank_Transfer( Bank_GetUserID(COKEBANK_DEBT_ACCT), User, Ammount, ReasonGiven );
if(ret) return 2;
- byName = GetUserName(ByUser);
- dstName = GetUserName(User);
+ byName = Bank_GetUserName(ByUser);
+ dstName = Bank_GetUserName(User);
- Log_Info("add %i to %s by %s (%s)",
- Ammount, dstName, byName, ReasonGiven
+ Log_Info("add %i to %s by %s (%s) [balance %i]",
+ Ammount, dstName, byName, ReasonGiven, Bank_GetBalance(User)
);
free(byName);
return 0;
}
-int Coke_CanDispense(int User, int Item)
+int Coke_CanDispense(int UNUSED(User), int Item)
{
char tmp[40], *status;
regmatch_t matches[4];
/**
* \brief Actually do a dispense from the coke machine
*/
-int Coke_DoDispense(int User, int Item)
+int Coke_DoDispense(int UNUSED(User), int Item)
{
char tmp[32];
int i, ret;
// Sanity please
if( Item == 0 ) return -1;
+ if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
+ return 1;
+
return 0;
}
*/
int Door_DoDispense(int User, int Item)
{
-
// Sanity please
if( Item != 0 ) return -1;
// Check if user is in door
+ if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
+ return 1;
// llogin or other
return 0;
}
-int Snack_CanDispense(int User, int Item)
+int Snack_CanDispense(int UNUSED(User), int Item)
{
// Sanity please
if( Item < 0 || Item > 99 ) return -1;
/**
* \brief Actually do a dispense from the coke machine
*/
-int Snack_DoDispense(int User, int Item)
+int Snack_DoDispense(int UNUSED(User), int Item)
{
char tmp[32];
regmatch_t matches[4];
{"USER_ADD", Server_Cmd_USERADD},
{"USER_FLAGS", Server_Cmd_USERFLAGS}
};
-#define NUM_COMMANDS (sizeof(gaServer_Commands)/sizeof(gaServer_Commands[0]))
+#define NUM_COMMANDS ((int)(sizeof(gaServer_Commands)/sizeof(gaServer_Commands[0])))
// === GLOBALS ===
int giServer_Port = 1020;
char *buf = inbuf;
int remspace = INPUT_BUFFER_SIZE-1;
int bytes = -1;
- tClient clientInfo = {0};
+ tClient clientInfo;
+
+ memset(&clientInfo, 0, sizeof(clientInfo));
// Initialise Client info
clientInfo.Socket = Socket;
if(space) *space = '\0'; // Remove characters after the ' '
// Pass on to cokebank
- Client->UID = GetUserAuth(Client->Salt, Client->Username, Args);
+ Client->UID = Bank_GetUserAuth(Client->Salt, Client->Username, Args);
if( Client->UID != -1 ) {
Client->bIsAuthed = 1;
}
// Get UID
- Client->UID = GetUserID( Args );
+ Client->UID = Bank_GetUserID( Args );
if( Client->UID < 0 ) {
if(giDebugLevel)
printf("Client %i: Unknown user '%s'\n", Client->ID, Args);
}
// You can't be an internal account
- if( GetFlags(Client->UID) & USER_FLAG_INTERNAL ) {
+ if( Bank_GetFlags(Client->UID) & USER_FLAG_INTERNAL ) {
Client->UID = -1;
sendf(Client->Socket, "401 Auth Failure\n");
return ;
}
// Check user permissions
- if( !(GetFlags(Client->UID) & USER_FLAG_COKE) ) {
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_COKE) ) {
sendf(Client->Socket, "403 Not in coke\n");
return ;
}
// Set id
- Client->EffectiveUID = GetUserID(Args);
+ Client->EffectiveUID = Bank_GetUserID(Args);
if( Client->EffectiveUID == -1 ) {
sendf(Client->Socket, "404 User not found\n");
return ;
}
// You can't be an internal account
- if( GetFlags(Client->EffectiveUID) & USER_FLAG_INTERNAL ) {
+ if( Bank_GetFlags(Client->EffectiveUID) & USER_FLAG_INTERNAL ) {
Client->EffectiveUID = -1;
sendf(Client->Socket, "404 User not found\n");
return ;
{
int i;
+ if( Args != NULL || strlen(Args) ) {
+ sendf(Client->Socket, "407 ENUM_ITEMS takes no arguments\n");
+ return ;
+ }
+
sendf(Client->Socket, "201 Items %i\n", giNumItems);
for( i = 0; i < giNumItems; i ++ ) {
reason ++;
// Get recipient
- uid = GetUserID(recipient);
+ uid = Bank_GetUserID(recipient);
if( uid == -1 ) {
sendf(Client->Socket, "404 Invalid target user\n");
return ;
}
// You can't alter an internal account
- if( GetFlags(uid) & USER_FLAG_INTERNAL ) {
+ if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
sendf(Client->Socket, "404 Invalid target user\n");
return ;
}
reason ++;
// Check user permissions
- if( !(GetFlags(Client->UID) & USER_FLAG_COKE) ) {
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_COKE) ) {
sendf(Client->Socket, "403 Not in coke\n");
return ;
}
// Get recipient
- uid = GetUserID(user);
+ uid = Bank_GetUserID(user);
if( uid == -1 ) {
sendf(Client->Socket, "404 Invalid user\n");
return ;
}
// You can't alter an internal account
- if( GetFlags(uid) & USER_FLAG_INTERNAL ) {
+ if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
sendf(Client->Socket, "404 Invalid user\n");
return ;
}
{
int i, numRet = 0;
int maxBal = INT_MAX, minBal = INT_MIN;
- int numUsr = GetMaxID();
+ int numUsr = Bank_GetMaxID();
// Parse arguments
if( Args && strlen(Args) )
// Get return number
for( i = 0; i < numUsr; i ++ )
{
- int bal = GetBalance(i);
+ int bal = Bank_GetBalance(i);
if( bal == INT_MIN ) continue;
for( i = 0; i < numUsr; i ++ )
{
- int bal = GetBalance(i);
+ int bal = Bank_GetBalance(i);
if( bal == INT_MIN ) continue;
if(space) *space = '\0';
// Get recipient
- uid = GetUserID(user);
+ uid = Bank_GetUserID(user);
if( uid == -1 ) {
sendf(Client->Socket, "404 Invalid user");
return ;
void _SendUserInfo(tClient *Client, int UserID)
{
char *type, *disabled="", *door="";
- int flags = GetFlags(UserID);
+ int flags = Bank_GetFlags(UserID);
if( flags & USER_FLAG_INTERNAL ) {
type = "internal";
// TODO: User flags/type
sendf(
Client->Socket, "202 User %s %i %s%s\n",
- GetUserName(UserID), GetBalance(UserID),
+ Bank_GetUserName(UserID), Bank_GetBalance(UserID),
type, disabled
);
}
char *username, *space;
// Check permissions
- if( !(GetFlags(Client->UID) & USER_FLAG_WHEEL) ) {
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_WHEEL) ) {
sendf(Client->Socket, "403 Not Wheel\n");
return ;
}
if(space) *space = '\0';
// Try to create user
- if( CreateUser(username) == -1 ) {
+ if( Bank_CreateUser(username) == -1 ) {
sendf(Client->Socket, "404 User exists\n");
return ;
}
int uid;
// Check permissions
- if( !(GetFlags(Client->UID) & USER_FLAG_WHEEL) ) {
+ if( !(Bank_GetFlags(Client->UID) & USER_FLAG_WHEEL) ) {
sendf(Client->Socket, "403 Not Wheel\n");
return ;
}
if(space) *space = '\0';
// Get UID
- uid = GetUserID(username);
+ uid = Bank_GetUserID(username);
if( uid == -1 ) {
sendf(Client->Socket, "404 User '%s' not found\n", username);
return ;
} while(space);
// Apply flags
- SetFlags(uid, mask, value);
+ Bank_SetFlags(uid, mask, value);
// Return OK
sendf(Client->Socket, "200 User Updated\n");