DF-0907 / fake139.c
/* Minimal TCP listener on 127.0.0.1:139 — accept + hold connections so the * smb iod SMB_TRAN_CONNECT() succeeds at the TCP level. Lets SMBIOC_LOOKUP * get past the iod connect step so we can reach smbfs_mount. */ #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <signal.h> int main(void){ int s, c, on=1; struct sockaddr_in sa; signal(SIGPIPE, SIG_IGN); s = socket(AF_INET, SOCK_STREAM, 0); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_port = htons(139); sa.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */ if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0) { perror("bind"); return 1; } listen(s, 5); printf("[fake139] listening on 127.0.0.1:139\n"); fflush(stdout); while (1) { c = accept(s, NULL, NULL); if (c < 0) continue; printf("[fake139] accepted conn\n"); fflush(stdout); /* hold the connection open; let the smb side time out on negotiate */ sleep(30); close(c); } return 0; } |