exit(0);
}
+void PrintUsage(const char *progname)
+{
+ fprintf(stderr, "Usage: %s\n", progname);
+ fprintf(stderr, " -p Set server port (default 11020)\n");
+ fprintf(stderr, " -d Set debug level (0 - 2, default 0)\n");
+ fprintf(stderr, " --itemsfile\n");
+ fprintf(stderr, " Set debug level (0 - 2, default 0)\n");
+ fprintf(stderr, " --cokeport\n");
+ fprintf(stderr, " Coke machine serial port (Default \"/dev/ttyS0\")\n");
+ fprintf(stderr, " --doorpass\n");
+ fprintf(stderr, " Door LAT password file (Default empty password)\n");
+ fprintf(stderr, " --cokebank\n");
+ fprintf(stderr, " Coke bank database file (Default \"cokebank.db\")\n");
+}
+
int main(int argc, char *argv[])
{
int i;
break;
default:
// Usage Error?
- break;
+ PrintUsage(argv[0]);
+ return -1;
}
}
else if( arg[0] == '-' && arg[1] == '-' ) {
gsSnack_SerialPort = argv[++i];
}
else if( strcmp(arg, "--doorpass") == 0 ) {
+ FILE *fp;
+ char buf[30];
+ if( i + 1 >= argc ) return -1;
+ fp = fopen(argv[++i], "r");
+ fgets(buf, sizeof buf, fp);
+ fclose(fp);
+ gsDoor_Password = strdup(buf);;
+ }
+ else if( strcmp(arg, "--cokebank") == 0 ) {
if( i + 1 >= argc ) return -1;
- gsDoor_Password = argv[++i];
+ gsCokebankPath = argv[++i];
}
else {
// Usage error?
+ PrintUsage(argv[0]);
+ return -1;
}
}
else {
// Usage Error?
+ PrintUsage(argv[0]);
+ return -1;
}
}
#define NUM_COMMANDS ((int)(sizeof(gaServer_Commands)/sizeof(gaServer_Commands[0])))
// === GLOBALS ===
- int giServer_Port = 1020;
+ int giServer_Port = 11020;
int giServer_NextClientID = 1;
int giServer_Socket;
void Server_Cmd_PASS(tClient *Client, char *Args)
{
char *passhash;
-
+ int flags;
+
if( Server_int_ParseArgs(0, Args, &passhash, NULL) )
{
sendf(Client->Socket, "407 PASS takes 1 argument\n");
// Pass on to cokebank
Client->UID = Bank_GetUserAuth(Client->Salt, Client->Username, passhash);
- if( Client->UID != -1 ) {
- Client->bIsAuthed = 1;
- sendf(Client->Socket, "200 Auth OK\n");
+ if( Client->UID == -1 ) {
+ sendf(Client->Socket, "401 Auth Failure\n");
+ return ;
+ }
+
+ flags = Bank_GetFlags(Client->UID);
+ if( flags & USER_FLAG_DISABLED ) {
+ Client->UID = -1;
+ sendf(Client->Socket, "403 Account Disabled\n");
+ return ;
+ }
+ if( flags & USER_FLAG_INTERNAL ) {
+ Client->UID = -1;
+ sendf(Client->Socket, "403 Internal account\n");
return ;
}
- sendf(Client->Socket, "401 Auth Failure\n");
+ Client->bIsAuthed = 1;
+ sendf(Client->Socket, "200 Auth OK\n");
}
/**
void Server_Cmd_AUTOAUTH(tClient *Client, char *Args)
{
char *username;
+ int userflags;
if( Server_int_ParseArgs(0, Args, &username, NULL) )
{
return ;
}
+ userflags = Bank_GetFlags(Client->UID);
// You can't be an internal account
- if( Bank_GetFlags(Client->UID) & USER_FLAG_INTERNAL ) {
+ if( userflags & USER_FLAG_INTERNAL ) {
if(giDebugLevel)
Debug(Client, "Autoauth as '%s', not allowed", username);
Client->UID = -1;
- sendf(Client->Socket, "401 Auth Failure\n");
+ sendf(Client->Socket, "403 Account is internal\n");
+ return ;
+ }
+
+ // Disabled accounts
+ if( userflags & USER_FLAG_DISABLED ) {
+ Client->UID = -1;
+ sendf(Client->Socket, "403 Account disabled\n");
return ;
}
void Server_Cmd_SETEUSER(tClient *Client, char *Args)
{
char *username;
+ int eUserFlags, userFlags;
if( Server_int_ParseArgs(0, Args, &username, NULL) )
{
}
// Check user permissions
- if( !(Bank_GetFlags(Client->UID) & (USER_FLAG_COKE|USER_FLAG_ADMIN)) ) {
+ userFlags = Bank_GetFlags(Client->UID);
+ if( !(userFlags & (USER_FLAG_COKE|USER_FLAG_ADMIN)) ) {
sendf(Client->Socket, "403 Not in coke\n");
return ;
}
}
// You can't be an internal account
- if( Bank_GetFlags(Client->EffectiveUID) & USER_FLAG_INTERNAL ) {
+ eUserFlags = Bank_GetFlags(Client->EffectiveUID);
+ if( eUserFlags & USER_FLAG_INTERNAL ) {
Client->EffectiveUID = -1;
sendf(Client->Socket, "404 User not found\n");
return ;
}
+ // Disabled only avaliable to admins
+ if( (eUserFlags & USER_FLAG_DISABLED) && !(userFlags & USER_FLAG_ADMIN) ) {
+ Client->EffectiveUID = -1;
+ sendf(Client->Socket, "403 Account disabled\n");
+ return ;
+ }
sendf(Client->Socket, "200 User set\n");
}