if ((hp = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET)) == NULL){ neterror("gethostbyaddr", h_errno); hname = "unknown"; } else hname = hp->h_name;The filter uses the host name in the routine mpopen, which provides a safe environment for spawning subprocesses (it resets the PATH and IFS shell variables to known safe values, among other things) but otherwise acts like popen(3):
len = strlen(hname) + strlen("mail -s %s root") + 1; if ((p = malloc(len * sizeof(char))) == NULL){ syserror("malloc", errno); goto ohdarn; } (void) sprintf(p, "mail -s %s root", hname); if ((pp = mpopen(p, "w")) == NULL){ syserror("mpopen", errno); goto ohdarn; } tick = time(NULL); fprintf(pp, "Connection from this host made at %s", ctime(&tick)); fclose(pp);
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562