/* * Decodes the 8-digit-key-string from an FSP lock file into an IP * address and port number. If you see a lock file called ".FL87GHUiS2", * you can run this program with argument "87GHUiS2". * */ #include #include #include #include #include int decode_str(x) char x; { int i; static char code_str[] = "0123456789:_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; for (i = 0; code_str[i] != 0; i++) { if (x == code_str[i]) return i; } return -1; } int main(argc,argv) int argc; char **argv; { int digit[8], i; unsigned char ip[4]; unsigned char port[2]; int loop,discard; char comstring[30],hostname[80],username[40]; struct stat status; struct passwd pwfileentry; FILE *nslkpipe; if (argc < 2) { printf("\n%s \n",argv[0]); printf("\nWhere: = .FL?????\n"); return 1; } for (loop = 1; loop < argc;loop++) { if (!strncmp(argv[loop],".FL",3)) { sprintf(comstring,"/usr/tmp/%s",argv[loop]); if (stat(comstring,&status)==0 ) { pwfileentry = *getpwuid(status.st_uid); printf("User: %s. ", pwfileentry.pw_name); } else printf("Username not found. "); for (i = 0; i < 8; i++) digit[i] = decode_str(argv[loop][i+3]); ip[3] = digit[0] + ((digit[1] & 3) * 64); ip[2] = digit[1] / 4 + ((digit[2] & 15) * 16); ip[1] = digit[2] / 16 + (digit[3] * 4); ip[0] = digit[4] + ((digit[5] & 3) * 64); port[1] = digit[5] / 4 + ((digit[6] & 15) * 16); port[0] = digit[6] / 16 + (digit[7] * 4); sprintf(comstring,"nslookup %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); nslkpipe = popen(comstring,"r"); for (discard=0; discard<3; discard++) fgets(hostname,80,nslkpipe); fscanf(nslkpipe,"Name: %[^\n]%*c",hostname); pclose(nslkpipe); printf("host = %s (%d.%d.%d.%d) port = %d\n", hostname, ip[0], ip[1], ip[2], ip[3], port[1] + port[0] * 256); } else { printf("\nParameter must be of the form: .FL????????\n"); } } return 0; }