Fixing client (clipping item names, balance display), made server delete pidfile
[tpg/opendispense2.git] / src / server / server.c
index 806ecce..5102f62 100644 (file)
@@ -143,6 +143,13 @@ void Server_Start(void)
        
        printf("Listening on 0.0.0.0:%i\n", giServer_Port);
        
+       // write pidfile
+       {
+               FILE *fp = fopen("/var/run/dispsrv.pid", "w");
+               fprintf(fp, "%i", getpid());
+               fclose(fp);
+       }
+
        for(;;)
        {
                uint    len = sizeof(client_addr);
@@ -208,8 +215,9 @@ void Server_Start(void)
 
 void Server_Cleanup(void)
 {
-       printf("Close(%i)\n", giServer_Socket);
+       printf("\nClose(%i)\n", giServer_Socket);
        close(giServer_Socket);
+       unlink("/var/run/dispsrv");
 }
 
 /**
@@ -303,6 +311,7 @@ void Server_ParseClientCommand(tClient *Client, char *CommandString)
        
        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 = "";
@@ -438,7 +447,7 @@ void Server_Cmd_AUTOAUTH(tClient *Client, char *Args)
        if( Client->UID < 0 ) {
                if(giDebugLevel)
                        Debug(Client, "Unknown user '%s'", username);
-               sendf(Client->Socket, "401 Auth Failure\n");
+               sendf(Client->Socket, "403 Auth Failure\n");
                return ;
        }
        
@@ -501,17 +510,20 @@ void Server_Cmd_SETEUSER(tClient *Client, char *Args)
        }
        
        // You can't be an internal account
-       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 ;
+       if( !(userFlags & USER_FLAG_ADMIN) )
+       {
+               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 ) {
+                       Client->EffectiveUID = -1;
+                       sendf(Client->Socket, "403 Account disabled\n");
+                       return ;
+               }
        }
        
        sendf(Client->Socket, "200 User set\n");
@@ -808,9 +820,13 @@ void Server_Cmd_ADD(tClient *Client, char *Args)
        }
        
        // You can't alter an internal account
-       if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
-               sendf(Client->Socket, "404 Invalid user\n");
-               return ;
+       if( !(Bank_GetFlags(Client->UID) & USER_FLAG_ADMIN) )
+       {
+               if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
+                       sendf(Client->Socket, "404 Invalid user\n");
+                       return ;
+               }
+               // TODO: Maybe disallow changes to disabled?
        }
 
        // Parse ammount
@@ -863,12 +879,6 @@ void Server_Cmd_SET(tClient *Client, char *Args)
                sendf(Client->Socket, "404 Invalid user\n");
                return ;
        }
-       
-       // You can't alter an internal account
-       if( Bank_GetFlags(uid) & USER_FLAG_INTERNAL ) {
-               sendf(Client->Socket, "404 Invalid user\n");
-               return ;
-       }
 
        // Parse ammount
        iAmmount = atoi(ammount);

UCC git Repository :: git.ucc.asn.au