+void Authenticate(int Socket)
+{
+ struct passwd *pwd;
+ char buf[512];
+ int responseCode;
+
+ // Get user name
+ pwd = getpwuid( getuid() );
+
+ // Attempt automatic authentication
+ sendf(Socket, "AUTOAUTH %s\n", pwd->pw_name);
+
+ // Check if it worked
+ recv(Socket, buf, 511, 0);
+ trim(buf);
+
+ responseCode = atoi(buf);
+ switch( responseCode )
+ {
+ case 200: // Authenticated, return :)
+ return ;
+ case 401: // Untrusted, attempt password authentication
+ break;
+ case 404: // Bad Username
+ fprintf(stderr, "Bad Username '%s'\n", pwd->pw_name);
+ exit(-1);
+ default:
+ fprintf(stderr, "Unkown response code %i from server\n", responseCode);
+ printf("%s\n", buf);
+ exit(-1);
+ }
+
+ printf("%s\n", buf);
+}
+