From: John Hodge Date: Mon, 21 Feb 2011 12:06:43 +0000 (+0800) Subject: Cleanups ready for distribution X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=807782b480c770ea3b64f41035abe50a4749b2df;p=tpg%2Fopendispense2.git Cleanups ready for distribution - Added help message to the server - Made door password a file instead of an option (keeps it out of ps) --- diff --git a/src/server/Makefile b/src/server/Makefile index 4abf037..86e5a42 100644 --- a/src/server/Makefile +++ b/src/server/Makefile @@ -8,7 +8,7 @@ BIN := ../../dispsrv DEPFILES := $(OBJ:%.o=%.d) -LINKFLAGS := -g ../../cokebank.so -lutil +LINKFLAGS := -g ../../cokebank.so -lutil -Wl,-rpath,. CPPFLAGS := CFLAGS := -Wall -Wextra -Werror -g diff --git a/src/server/main.c b/src/server/main.c index c1b883e..f95637f 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -49,6 +49,21 @@ void sigint_handler() 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; @@ -72,7 +87,8 @@ int main(int argc, char *argv[]) break; default: // Usage Error? - break; + PrintUsage(argv[0]); + return -1; } } else if( arg[0] == '-' && arg[1] == '-' ) { @@ -89,15 +105,28 @@ int main(int argc, char *argv[]) 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; } } diff --git a/src/server/server.c b/src/server/server.c index bae6fa9..806ecce 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -99,7 +99,7 @@ const struct sClientCommand { #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; @@ -377,7 +377,8 @@ void Server_Cmd_USER(tClient *Client, char *Args) 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"); @@ -387,13 +388,25 @@ void Server_Cmd_PASS(tClient *Client, char *Args) // 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"); } /** @@ -404,6 +417,7 @@ void Server_Cmd_PASS(tClient *Client, char *Args) void Server_Cmd_AUTOAUTH(tClient *Client, char *Args) { char *username; + int userflags; if( Server_int_ParseArgs(0, Args, &username, NULL) ) { @@ -428,12 +442,20 @@ void Server_Cmd_AUTOAUTH(tClient *Client, char *Args) 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 ; } @@ -451,6 +473,7 @@ void Server_Cmd_AUTOAUTH(tClient *Client, char *Args) void Server_Cmd_SETEUSER(tClient *Client, char *Args) { char *username; + int eUserFlags, userFlags; if( Server_int_ParseArgs(0, Args, &username, NULL) ) { @@ -464,7 +487,8 @@ void Server_Cmd_SETEUSER(tClient *Client, char *Args) } // 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 ; } @@ -477,11 +501,18 @@ void Server_Cmd_SETEUSER(tClient *Client, char *Args) } // 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"); }