#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
+#include <fcntl.h> // O_*
#include <string.h>
#include <limits.h>
#include <stdarg.h>
return ;
}
-#if 0
+ // Fork into background
if( gbServer_RunInBackground )
{
+ int newin, newout, newerr;
int pid = fork();
if( pid == -1 ) {
fprintf(stderr, "ERROR: Unable to fork\n");
// Parent, quit
exit(0);
}
- // In child, sort out stdin/stdout
- reopen(0, "/dev/null", O_READ);
- reopen(1, gsServer_LogFile, O_CREAT|O_APPEND);
- reopen(2, gsServer_ErrorLog, O_CREAT|O_APPEND);
+ // In child
+ // - Sort out stdin/stdout
+ newin = open("/dev/null", O_RDONLY);
+ newout = open(gsServer_LogFile, O_CREAT|O_APPEND, 0644);
+ newerr = open(gsServer_ErrorLog, O_CREAT|O_APPEND, 0644);
+ dup2(newin, 0);
+ dup2(newout, 1);
+ dup2(newerr, 2);
}
-#endif
// Listen
if( listen(giServer_Socket, MAX_CONNECTION_QUEUE) < 0 ) {
if( Server_int_ParseArgs(1, CommandString, &command, &args, NULL) )
{
if( command == NULL ) return ;
-// printf("command=%s, args=%s\n", command, args);
// Is this an error? (just ignore for now)
- //args = "";
}
sendf(Client->Socket, "407 SETEUSER expects an argument\n");
return ;
}
+
+ // Check authentication
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
// Check user permissions
userFlags = Bank_GetFlags(Client->UID);
case 1: sendf(Client->Socket, "501 Unable to dispense\n"); return ;
case 2: sendf(Client->Socket, "402 Poor You\n"); return ;
default:
- sendf(Client->Socket, "500 Dispense Error\n");
+ sendf(Client->Socket, "500 Dispense Error (%i)\n", ret);
return ;
}
}
sendf(Client->Socket, "407 GIVE takes only 3 arguments\n");
return ;
}
+
// Check for authed
if( !Client->bIsAuthed ) {
sendf(Client->Socket, "401 Not Authenticated\n");
return ;
}
+ // Check authentication
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
+ return ;
+ }
+
// Check permissions
if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) ) {
sendf(Client->Socket, "403 Not a coke admin\n");
void Server_Cmd_USERFLAGS(tClient *Client, char *Args)
{
- char *username, *flags;
+ char *username, *flags, *reason=NULL;
int mask=0, value=0;
int uid;
// Parse arguments
- if( Server_int_ParseArgs(0, Args, &username, &flags, NULL) ) {
- sendf(Client->Socket, "407 USER_FLAGS takes 2 arguments\n");
+ if( Server_int_ParseArgs(1, Args, &username, &flags, &reason, NULL) ) {
+ if( !flags ) {
+ sendf(Client->Socket, "407 USER_FLAGS takes at least 2 arguments\n");
+ return ;
+ }
+ reason = "";
+ }
+
+ // Check authentication
+ if( !Client->bIsAuthed ) {
+ sendf(Client->Socket, "401 Not Authenticated\n");
return ;
}
// Apply flags
Bank_SetFlags(uid, mask, value);
+
+ // Log the change
+ Log_Info("Updated '%s' with flag set '%s' - Reason: %s",
+ username, flags, reason);
// Return OK
sendf(Client->Socket, "200 User Updated\n");