9 #include <sys/socket.h>
11 #include <arpa/inet.h>
12 #include <netinet/in.h>
17 #define NNRPDREAL "/usr/sbin/nnrpd.real"
19 static void chopspaces(char *buf) {
22 while (n > 0 && isspace(buf[n-1])) n--;
26 int main(int argc, char **argv) {
28 unsigned char message[16+MAX_SECRET], expect[16];
29 char responsebuf[300];
30 char sesamebuf[MAX_SECRET*2+100];
31 struct sockaddr_in peername;
34 struct MD5Context md5ctx;
38 struct timeval timevab;
41 while ((p= *++argvs)) {
42 if (*p++ != '-') break;
48 printf("400 %s\r\n",*argvs); exit(1);
52 } else if (c == 's' || c == 'S') {
53 if (!*++argvs) --argvs;
60 if (gettimeofday(&timevab,(void*)0)) {
61 printf("400 what year is it: %s\r\n",strerror(errno));
64 memcpy(message,&timevab.tv_sec,4);
65 ul= timevab.tv_usec; memcpy(message+4,&ul,4);
66 namesize= sizeof(peername);
67 if (getsockname(fileno(stdin),(struct sockaddr*)&peername,&namesize) &&
68 namesize == sizeof(peername) &&
69 peername.sin_family == AF_INET) {
70 memcpy(message+8,&peername.sin_addr,4);
71 memcpy(message+12,&peername.sin_port,2);
73 memset(message+8,'x',6);
75 us= getpid(); memcpy(message+14,&us,2);
78 for (n=0; n<16; n++) {
79 printf("%s%02x", n?":":"", message[n]);
81 printf(" halt ! who goes there ?\r\n");
82 if (fflush(stdout) || ferror(stdout)) { perror("stdout challenge"); exit(1); }
83 if (!fgets(responsebuf,sizeof(responsebuf),stdin)) {
84 if (ferror(stdin)) perror("stdin response");
85 else fprintf(stderr,"stdin response EOF\n");
88 chopspaces(responsebuf);
89 p= strchr(responsebuf,' ');
91 if (!strcasecmp(responsebuf,"QUIT")) {
92 printf("205 please remember your papers next time.\r\n");
95 if (strcasecmp(responsebuf,"PASS")) {
96 printf("500 guards ! guards !\r\n"
97 "400 this client was just leaving.\r\n");
101 printf("501 fail.\r\n"
102 "400 we don't want failures here.\r\n");
105 file= fopen("/etc/news/sesame","r");
107 printf("400 suddenly i can't see anything: %s\r\n",strerror(errno));
111 if (!fgets(sesamebuf,sizeof(sesamebuf),file)) {
113 printf("400 i'm not sure about that: %s\r\n",strerror(errno));
115 printf("400 happiness is mandatory.\r\n");
119 chopspaces(sesamebuf);
120 } while (!*sesamebuf || *sesamebuf == '#' || !(q= strchr(sesamebuf,' ')));
123 if (l>MAX_SECRET) { printf("400 i feel all bloated.\r\n"); exit(1); }
124 memcpy(message+16,q,l);
127 MD5Update(&md5ctx,message,16+l);
128 MD5Final(expect,&md5ctx);
130 for (n=0; n<16; n++) sprintf(sesamebuf+n*3,"%02x:",expect[n]);
132 if (!strcasecmp(p,sesamebuf)) {
133 execvp(NNRPDREAL,argv);
134 printf("400 o master, i have failed you: %s\r\n",strerror(errno));
137 printf("502 impostor !\r\n"
138 "400 do not darken my door again.\r\n");