Пример #1
0
void doanddie(char *user, unsigned int userlen /* including 0 byte */,
    char *pass)
{
  int child;
  int wstat;
  int pi[2];
 
  close(3);
  if (pipe(pi) == -1) die_pipe();
  if (pi[0] != 3) die_pipe();
  switch(child = fork()) {
    case -1:
      die_fork();
    case 0:
      close(pi[1]);
      sig_pipedefault();
      execvp(*childargs,childargs);
      _exit(1);
  }
  close(pi[0]);
  substdio_fdbuf(&ssup,subwrite,pi[1],upbuf,sizeof upbuf);
  if (substdio_put(&ssup,user,userlen) == -1) die_write();
  if (substdio_put(&ssup,pass,str_len(pass) + 1) == -1) die_write();
  if (substdio_puts(&ssup,"<") == -1) die_write();
  if (substdio_puts(&ssup,unique) == -1) die_write();
  if (substdio_puts(&ssup,hostname) == -1) die_write();
  if (substdio_put(&ssup,">",2) == -1) die_write();
  if (substdio_flush(&ssup) == -1) die_write();
  close(pi[1]);
  byte_zero(pass,str_len(pass));
  byte_zero(upbuf,sizeof upbuf);
  if (wait_pid(&wstat,child) == -1) die();
  if (wait_crashed(wstat)) die_childcrashed();
  switch (wait_exitcode(wstat)) {
    case 0: die();
    case 1: die_1();
    case 2: die_2();
    case 25: die_25();
    case 3: die_3();
    case 4: die_4();
    case 5: die_5();
    case 6: die_6();
    case 61: die_61();
    case 62: die_62();
    case 7: die_7();
    case 8: die_nomem();
    default: die_unknown();
  }
  die();
}
Пример #2
0
int main(int argc,char *argv[])
//int argc;
//char *argv[];
{
  int dummy;
  char *proto;
  int opt;
  int flagremoteinfo;
  unsigned long timeout;
// struct sockaddr_in *v4;

  sig_pipeignore();

  flagremoteinfo = 1;
  timeout = 30;
  while ((opt = getopt(argc,argv,"rRt:")) != opteof)
    switch(opt)
    {
     case 'r': flagremoteinfo = 1; break;
     case 'R': flagremoteinfo = 0; break;
     case 't': scan_ulong(subgetoptarg,&timeout); break;
    }

  argv += subgetoptind;
  argc -= subgetoptind;

  if (argc < 1) die();
  if (!env_init()) die();

  proto = env_get("PROTO");
  if (!proto || str_diff(proto,"TCP"))
  {
    if (!env_puts("PROTO=TCP")) die();

    dummy = sizeof(salocal);
    if (getsockname(0,(struct sockaddr *) &salocal, (socklen_t *) &dummy) == -1) die();
    mappedtov4(&salocal);
    switch(salocal.sa.sa_family) {
    case AF_INET:
      localport = ntohs(salocal.sa4.sin_port);
      temp[fmt_ulong(temp,localport)] = 0;
    if (!env_put("TCPLOCALPORT",temp)) die();
      temp[ip4_fmt(temp,(char *) &salocal.sa4.sin_addr)] = 0;
    if (!env_put("TCPLOCALIP",temp)) die();

    switch(dns_ptr(&localname,&salocal.sa4.sin_addr)) {
      case DNS_MEM: die();
      case DNS_SOFT:
        if (!stralloc_copys(&localname,"softdnserror")) die();
      case 0:
        if (!stralloc_0(&localname)) die();
        case_lowers(localname.s);
        if (!env_put("TCPLOCALHOST",localname.s)) die();
        break;
      default:
        if (!env_unset("TCPLOCALHOST")) die();
    }
    break;
#ifdef INET6
    case AF_INET6:
      localport = ntohs(salocal.sa6.sin6_port);
      temp[fmt_ulong(temp,localport)] = 0;
      if (!env_put("TCPLOCALPORT",temp)) die();
      temp[ip6_fmt(temp,(char *) &salocal.sa6.sin6_addr)] = 0;
      if (!env_put("TCPLOCALIP",temp)) die();
      switch(dns_ptr6(&localname,&salocal.sa6.sin6_addr)) {
        case DNS_MEM: die();
        case DNS_SOFT:
             if (!stralloc_copys(&localname,"softdnserror")) die();
        case 0:
             if (!stralloc_0(&localname)) die();
          case_lowers(localname.s);
          if (!env_put("TCPLOCALHOST",localname.s)) die();
          break;
        default:
             if (!env_unset("TCPLOCALHOST")) die();
      }
      break;
#endif
    default:
      die();
    }

    dummy = sizeof(saremote);
    if (getpeername(0,(struct sockaddr *) &saremote, (socklen_t *) &dummy) == -1) die();
      mappedtov4(&saremote);

    switch(saremote.sa.sa_family) {
    case AF_INET:
      remoteport = ntohs(saremote.sa4.sin_port);
      temp[fmt_ulong(temp,remoteport)] = 0;
    if (!env_put("TCPREMOTEPORT",temp)) die();

    temp[ip4_fmt(temp,(char *)&saremote.sa4.sin_addr)] = 0;
    if (!env_put("TCPREMOTEIP",temp)) die();

    switch(dns_ptr(&remotename,&saremote.sa4.sin_addr)) {
    case DNS_MEM: die();
    case DNS_SOFT:
      if (!stralloc_copys(&remotename,"softdnserror")) die();
    case 0:
      if (!stralloc_0(&remotename)) die();
      case_lowers(remotename.s);
      if (!env_put("TCPREMOTEHOST",remotename.s)) die();
      break;
    default:
      if (!env_unset("TCPREMOTEHOST")) die();
    }
    break;
#ifdef INET6
    case AF_INET6:
    remoteport = ntohs(saremote.sa6.sin6_port);
      temp[fmt_ulong(temp,remoteport)] = 0;
    if (!env_put("TCPREMOTEPORT",temp)) die();
    temp[ip6_fmt(temp,(char *) &saremote.sa6.sin6_addr)] = 0;
    if (!env_put("TCPREMOTEIP",temp)) die();
    switch(dns_ptr6(&remotename,&saremote.sa6.sin6_addr)) {
     case DNS_MEM: die();
     case DNS_SOFT:
       if (!stralloc_copys(&remotename,"softdnserror")) die();
     case 0:
       if (!stralloc_0(&remotename)) die();
       case_lowers(remotename.s);
       if (!env_put("TCPREMOTEHOST",remotename.s)) die();
       break;
     default:
       if (!env_unset("TCPREMOTEHOST")) die();
    }
    break;
#endif
    default:
      die();
    }

    if (!env_unset("TCPREMOTEINFO")) die();

    if (flagremoteinfo)
    {
      char *rinfo;
      rinfo = remoteinfo_get(&saremote, &salocal,(int) timeout);
      if (rinfo)
        if (!env_put("TCPREMOTEINFO",rinfo)) die();
    }
  }

  sig_pipedefault();
  execvp(*argv,argv);
  die();
  return(0);  /* never reached */
}