X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fclient%2Fmain.c;h=46e12593e2f70a56899e560a54caf769fa8f30a3;hb=f8d49ca9dfebf179382b1ddc3a47d503d719be11;hp=3ca95930e329e97ce3ab2efc8669c3897a0123f7;hpb=1d96d446ce969166330936ef990b304693cd28bd;p=tpg%2Fopendispense2.git diff --git a/src/client/main.c b/src/client/main.c index 3ca9593..46e1259 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -27,6 +27,7 @@ #define USE_NCURSES_INTERFACE 0 #define DEBUG_TRACE_SERVER 0 +#define USE_AUTOAUTH 1 // === TYPES === typedef struct sItem { @@ -65,7 +66,7 @@ char *trim(char *string); void CompileRegex(regex_t *regex, const char *pattern, int flags); // === GLOBALS === -char *gsDispenseServer = "localhost"; +char *gsDispenseServer = "heathred"; int giDispensePort = 11020; tItem *gaItems; @@ -346,18 +347,16 @@ int main(int argc, char *argv[]) } - // Connect to server again - sock = OpenConnection(gsDispenseServer, giDispensePort); - if( sock < 0 ) return -1; - - // Authenticate - Authenticate(sock); - // Check for a valid item ID if( i >= 0 ) + { + // Connect, Authenticate, dispense and close + sock = OpenConnection(gsDispenseServer, giDispensePort); + if( sock < 0 ) return -1; + Authenticate(sock); DispenseItem(sock, i); - - close(sock); + close(sock); + } return 0; } @@ -680,16 +679,24 @@ int OpenConnection(const char *Host, int Port) return -1; } - #if USE_AUTOAUTH + if( geteuid() == 0 ) { + int i; struct sockaddr_in localAddr; memset(&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; // IPv4 - localAddr.sin_port = 1023; // IPv4 - // Attempt to bind to low port for autoauth - bind(sock, &localAddr, sizeof(localAddr)); + + // Loop through all the top ports until one is avaliable + for( i = 1001; i < 1024; i ++) + { + localAddr.sin_port = htons(i); // IPv4 + // Attempt to bind to low port for autoauth + if( bind(sock, (struct sockaddr*)&localAddr, sizeof(localAddr)) == 0 ) + break; + } + if( i == 1024 ) + printf("Warning: AUTOAUTH unavaliable\n"); } - #endif if( connect(sock, (struct sockaddr *) &serverAddr, sizeof(serverAddr)) < 0 ) { fprintf(stderr, "Failed to connect to server\n");