#define DEBUG_TRACE_SERVER 0
#define USE_AUTOAUTH 1
-#define MAX_TXT_ARGS 4 // Maximum number of textual arguments (including command)
+#define MAX_TXT_ARGS 5 // Maximum number of textual arguments (including command)
enum eUI_Modes
{
int main(int argc, char *argv[])
{
int sock;
- int i;
+ int i, ret = 0;
char buffer[BUFSIZ];
char *text_args[MAX_TXT_ARGS]; // Non-flag arguments
int text_argc = 0;
// Add new user?
if( strcmp(text_args[1], "add") == 0 )
{
- if( text_argc != 2 ) {
+ if( text_argc != 3 ) {
fprintf(stderr, "Error: `dispense user add` requires an argument\n");
ShowUsage();
exit(1);
// Update a user
else if( strcmp(text_args[1], "type") == 0 )
{
- if( text_argc != 3 ) {
+ if( text_argc != 4 ) {
fprintf(stderr, "Error: `dispense user type` requires two arguments\n");
ShowUsage();
exit(1);
if( strcmp(text_args[0], "donate") == 0 )
{
// Check argument count
- if( text_argc != 2 ) {
+ if( text_argc != 3 ) {
fprintf(stderr, "Error: `dispense donate` requires two arguments\n");
ShowUsage();
exit(1);
Dispense_ItemInfo(sock, gaItems[i].Type, gaItems[i].ID);
Authenticate(sock);
- DispenseItem(sock, gaItems[i].Type, gaItems[i].ID);
+ ret = DispenseItem(sock, gaItems[i].Type, gaItems[i].ID);
close(sock);
}
- return 0;
+ return ret;
}
void ShowUsage(void)
fprintf(stderr, "Failed to create socket\n");
return -1;
}
+
+// printf("geteuid() = %i, getuid() = %i\n", geteuid(), getuid());
- if( geteuid() == 0 )
+ if( geteuid() == 0 || getuid() == 0 )
{
int i;
struct sockaddr_in localAddr;
localAddr.sin_family = AF_INET; // IPv4
// Loop through all the top ports until one is avaliable
- for( i = 1001; i < 1024; i ++)
+ for( i = 512; i < 1024; i ++)
{
localAddr.sin_port = htons(i); // IPv4
// Attempt to bind to low port for autoauth
}
if( i == 1024 )
printf("Warning: AUTOAUTH unavaliable\n");
+// else
+// printf("Bound to 0.0.0.0:%i\n", i);
}
if( connect(sock, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0 ) {