Exemple #1
0
static int doit(char *q,char qtype[2],char ip[4])
{
    int r;
    uint32 dlen;
    unsigned int qlen;

    qlen = dns_domain_length(q);
    if (qlen > 255) return 0; /* impossible */

    if (byte_diff(qtype,2,DNS_T_A) && byte_diff(qtype,2,DNS_T_ANY)) goto REFUSE;

    key[0] = '%';
    byte_copy(key + 1,4,ip);

    r = cdb_find(&c,key,5);
    if (!r) r = cdb_find(&c,key,4);
    if (!r) r = cdb_find(&c,key,3);
    if (!r) r = cdb_find(&c,key,2);
    if (r == -1) return 0;

    key[0] = '+';
    byte_zero(key + 1,2);
    if (r && (cdb_datalen(&c) == 2))
        if (cdb_read(&c,key + 1,2,cdb_datapos(&c)) == -1) return 0;

    byte_copy(key + 3,qlen,q);
    case_lowerb(key + 3,qlen + 3);

    r = cdb_find(&c,key,qlen + 3);
    if (!r) {
        byte_zero(key + 1,2);
        r = cdb_find(&c,key,qlen + 3);
    }
    if (!r) goto REFUSE;
    if (r == -1) return 0;
    dlen = cdb_datalen(&c);

    if (dlen > 512) dlen = 512;
    if (cdb_read(&c,data,dlen,cdb_datapos(&c)) == -1) return 0;

    dns_sortip(data,dlen);

    if (dlen > 12) dlen = 12;
    while (dlen >= 4) {
        dlen -= 4;
        if (!response_rstart(q,DNS_T_A,"\0\0\0\5")) return 0;
        if (!response_addbytes(data + dlen,4)) return 0;
        response_rfinish(RESPONSE_ANSWER);
    }

    return 1;


REFUSE:
    response[2] &= ~4;
    response[3] &= ~15;
    response[3] |= 5;
    return 1;
}
Exemple #2
0
int main(void) {

    unsigned char b1[32];
    unsigned char b2[32];
    long long i, j;
    const char *x = "abcdefgh";
    char y[8];

    /* byte_zero test */
    for (i = 0; i < 32; ++i) {
        for (j = 0; j < sizeof b1; ++j) b1[j] = 0;
        for (j = 0; j < sizeof b2; ++j) b2[j] = 0;
        b1[i] = 0xff; b2[i] = 0xff;
        byte_zero(b1, sizeof b1);

        if (byte_isequal(b1, 32, b2) != 0) fail("byte_zero failure");
    }

    /* byte_isequal test */
    for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff;
    for (i = 0; i < sizeof b2; ++i) b2[i] = 0xff;

    if (byte_isequal(b1, 32, b2) == 0) fail("byte_isequal failure");

    for (i = 0; i < 32; ++i) {
        b1[i] = 0;
        if (byte_isequal(b1, 32, b2) != 0) fail("byte_isequal failure");
        b1[i] = 0xff;
    }

    /* byte_copy test */
    for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff;
    for (i = 0; i < sizeof b2; ++i) b2[i] = 0x00;

    byte_copy(b1, 32, b2);
    if (byte_isequal(b1, 32, b2) == 0) fail("byte_copy failure");
    
    for (i = 0; i < 32; ++i) {
        b1[i] = 0;
        byte_copy(b1, 32, b2);
        if (byte_isequal(b1, 32, b2) == 0) fail("byte_copy failure");
        b1[i] = 0xff;
    }

    byte_zero(y, 8);
    if (!byte_isequal(y, 8, "\0\0\0\0\0\0\0\0")) fail("byte_zero/byte_isequal failure");

    byte_copy(y, 8, x);
    if (!byte_isequal(y, 8, x)) fail("byte_copy/byte_isequal failure");

    byte_copy(y, 7, y + 1);
    if (!byte_isequal(y, 8, "bcdefghh")) fail("byte_copy/byte_isequal failure");

    byte_zero(y, 8);
    if (!byte_isequal(y, 8, "\0\0\0\0\0\0\0\0")) fail("byte_zero/byte_isequal failure");

    return 0;
}
Exemple #3
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();
}
Exemple #4
0
int tdlookup_init(void)
{
  char *x;
  char ch;
  int i;
  int j;
  int k;

  x = env_get("LAME_A");
  if (x)
    if (!ip4_scan(x,lameip))
      byte_zero(lameip,4);

  x = env_get("LAME_MX");
  if (x)
    if (!dns_domain_fromdot(&lamemx,x,str_len(x)))
      return 0;

  x = env_get("LAME_TXT");
  if (x) {
    i = 0;
    j = str_len(x);
    while (i < j) {
      k = j - i;
      if (k > 255) k = 255;
      ch = k;
      if (!stralloc_append(&lametxt,&ch)) return 0;
      if (!stralloc_catb(&lametxt,x + i,k)) return 0;
      i += k;
    }
  }

  return 1;
}
ssize_t socket_send6(int s,const char *buf,size_t len,const char ip[16],uint16 port,uint32 scope_id)
{
#ifdef LIBC_HAS_IP6
  struct sockaddr_in6 si;
#else
  struct sockaddr_in si;
#endif

  byte_zero(&si,sizeof si);
#ifdef LIBC_HAS_IP6
  if (noipv6) {
#endif
    if (ip6_isv4mapped(ip))
      return socket_send4(s,buf,len,ip+12,port);
    if (byte_equal(ip,16,V6loopback))
      return socket_send4(s,buf,len,ip4loopback,port);
#ifdef LIBC_HAS_IP6
    errno=EPROTONOSUPPORT;
    return -1;
  }
  si.sin6_family = AF_INET6;
  uint16_pack_big((char *) &si.sin6_port,port);
  byte_copy((char *) &si.sin6_addr,16,ip);
#ifdef LIBC_HAS_SCOPE_ID
  si.sin6_scope_id=scope_id;
#else
  si.sin6_scope_id=0;
#endif
  return winsock2errno(sendto(s,buf,len,0,(void*) &si,sizeof si));
#else
  errno=EPROTONOSUPPORT;
  return -1;
#endif
}
Exemple #6
0
int socket_connect6(int s,const char ip[16],uint16 port,uint32 scope_id)
{
#ifdef LIBC_HAS_IP6
  struct sockaddr_in6 sa;

  if (noipv6) {
#endif
    if (ip6_isv4mapped(ip))
      return socket_connect4(s,ip+12,port);
    if (byte_equal(ip,16,V6loopback))
      return socket_connect4(s,ip4loopback,port);
#ifdef LIBC_HAS_IP6
  }
  byte_zero(&sa,sizeof sa);
  sa.sin6_family = PF_INET6;
  uint16_pack_big((char *) &sa.sin6_port,port);
  sa.sin6_flowinfo = 0;
  sa.sin6_scope_id = scope_id;
  byte_copy((char *) &sa.sin6_addr,16,ip);

  return connect(s,(struct sockaddr *) &sa,sizeof sa);
#else
  errno=EPROTONOSUPPORT;
  return -1;
#endif
}
Exemple #7
0
PRIVATE char *format_addr6s(const addr6_t addr)
{
    static char s[FORMAT_ADDR6_LEN];
    byte_zero(s, sizeof s);
    format_addr6(s, addr);
    return s;
}
Exemple #8
0
PRIVATE char *format_ip4s(const ip4_t ip)
{
    static char s[FORMAT_IP4_LEN];
    byte_zero(s, sizeof s);
    format_ip4(s, ip);
    return s;
}
Exemple #9
0
int socket_send6(int s,const char *buf,unsigned int len,const char ip[16],uint16 port,uint32 scope_id)
{
#ifdef LIBC_HAS_IP6
    struct sockaddr_in6 sa;
#else
    struct sockaddr_in sa;
#endif

    byte_zero(&sa,sizeof sa);
#ifdef LIBC_HAS_IP6
    if (noipv6) {
#endif
        if (ip6_isv4mapped(ip))
            return socket_send4(s,buf,len,ip+12,port);
        if (byte_equal(ip,16,V6loopback))
            return socket_send4(s,buf,len,ip4loopback,port);
#ifdef LIBC_HAS_IP6
        errno=error_proto;
        return -1;
    }
    sa.sin6_family = AF_INET6;
    uint16_pack_big((char *) &sa.sin6_port,port);
    byte_copy((char *) &sa.sin6_addr,16,ip);
    return sendto(s,buf,len,0,(struct sockaddr *) &sa,sizeof sa);
#else
        errno=error_proto;
        return -1;
#endif
}
Exemple #10
0
int
socket_send4 (int s, char *buf, int len,
                const char ip[4], uint16 port, void *src)
{
    char cbuf[256];
    struct iovec iov;
    struct msghdr msgh;
    struct sockaddr_in sa;
    struct cmsghdr *cmsg = NULL;

    byte_zero (&sa, sizeof (sa));
    sa.sin_family = AF_INET;

    uint16_pack_big ((char *)&sa.sin_port, port);
    byte_copy ((char *)&sa.sin_addr, 4, ip);

    memset (cbuf, 0, sizeof (cbuf));
    memset (&msgh, 0, sizeof (msgh));

    iov.iov_len = len;
    iov.iov_base = buf;

    msgh.msg_iov = &iov;
    msgh.msg_iovlen = 1;

    msgh.msg_name = &sa;
    msgh.msg_namelen = sizeof (sa);

#ifdef IP_PKTINFO
    struct in_pktinfo *p = NULL;

    msgh.msg_control = cbuf;
    msgh.msg_controllen = CMSG_SPACE (sizeof (*p));

    cmsg = CMSG_FIRSTHDR (&msgh);
    cmsg->cmsg_type = IP_PKTINFO;
    cmsg->cmsg_level = IPPROTO_IP;
    cmsg->cmsg_len = CMSG_LEN (sizeof (*p));

    p = (struct in_pktinfo *) CMSG_DATA (cmsg);
    p->ipi_spec_dst = *(struct in_addr *)src;
#elif defined IP_SENDSRCADDR
    struct in_addr *p = NULL;

    msgh.msg_control = cbuf;
    msgh.msg_controllen = CMSG_SPACE (sizeof (*p));

    cmsg = CMSG_FIRSTHDR (&msgh);
    cmsg->cmsg_type = IP_SENDSRCADDR;
    cmsg->cmsg_level = IPPROTO_IP;
    cmsg->cmsg_len = CMSG_LEN (sizeof (*p));

    p = (struct in_addr *)CMSG_DATA (cmsg);
    p->s_addr = *(struct in_addr *)src;
#endif

    msgh.msg_flags = 0;
    msgh.msg_controllen = cmsg ? cmsg->cmsg_len : 0;
    return sendmsg (s, &msgh, 0);
}
Exemple #11
0
/* convert IPv6 address */
static char *iptostr6(char *strbuf, const unsigned char *ip) {

    long long first, last, i;
    unsigned long long ip2[8];
    char *s = strbuf;

    for (i = 7; i >= 0; --i) {
        ip2[i] = ip[2 * i];
        ip2[i] <<= 8;
        ip2[i] += ip[2 * i + 1];
    }

    countz(&first, &last, ip2);

    strbuf += IPTOSTR_LEN - 1;
    *strbuf = 0;

    for (i = 7; i >= 0; --i) {
        if (i <= last && i >= first && first != last) {
            if (i == last) *--strbuf = ':';
            if (i == 7) *--strbuf = ':';
            continue;
        }
        do {
            *--strbuf = "0123456789abcdef"[ip2[i] & 15];
            ip2[i] >>= 4;
        } while (ip2[i]);
        if (i > 0) *--strbuf = ':';
    }
    i = strbuf - s;
    byte_copy(s,  IPTOSTR_LEN - i, strbuf);
    byte_zero(s + IPTOSTR_LEN - i, i);
    return s;
}
Exemple #12
0
int respond(char *q,char qtype[2],char ip[4])
{
  int fd;
  int r;
  char key[6];

  tai_now(&now);
  fd = open_read("data.cdb");
  if (fd == -1) return 0;
  cdb_init(&c,fd);

  byte_zero(clientloc,2);
  key[0] = 0;
  key[1] = '%';
  byte_copy(key + 2,4,ip);
  r = cdb_find(&c,key,6);
  if (!r) r = cdb_find(&c,key,5);
  if (!r) r = cdb_find(&c,key,4);
  if (!r) r = cdb_find(&c,key,3);
  if (!r) r = cdb_find(&c,key,2);
  if (r == -1) return 0;
  if (r && (cdb_datalen(&c) == 2))
    if (cdb_read(&c,clientloc,2,cdb_datapos(&c)) == -1) return 0;

  r = doit(q,qtype);

  cdb_free(&c);
  close(fd);
  return r;
}
Exemple #13
0
int socket_recv6(int s,char *buf,unsigned int len,char ip[16],uint16 *port,uint32 *scope_id)
{
#ifdef LIBC_HAS_IP6
  struct sockaddr_in6 sa;
#else
  struct sockaddr_in sa;
#endif
  unsigned int dummy = sizeof sa;
  int r;

  byte_zero(&sa,dummy);
  r = recvfrom(s,buf,len,0,(struct sockaddr *) &sa,&dummy);
  if (r == -1) return -1;

#ifdef LIBC_HAS_IP6
  if (noipv6) {
    struct sockaddr_in *sa4=(struct sockaddr_in *)&sa;
    byte_copy(ip,12,V4mappedprefix);
    byte_copy(ip+12,4,(char *) &sa4->sin_addr);
    uint16_unpack_big((char *) &sa4->sin_port,port);
    return r;
  }
  byte_copy(ip,16,(char *) &sa.sin6_addr);
  uint16_unpack_big((char *) &sa.sin6_port,port);
  if (scope_id) *scope_id=sa.sin6_scope_id;
#else
  byte_copy(ip,12,(char *)V4mappedprefix);
  byte_copy(ip+12,4,(char *) &sa.sin_addr);
  uint16_unpack_big((char *) &sa.sin_port,port);
  if (scope_id) *scope_id=0;
#endif

  return r;
}
Exemple #14
0
int socket_recv4(int s,char *buf,int len,char ip[4],uint16 *port,char dstip[4])
{
  struct sockaddr_in sa;
  int dummy = sizeof sa;
  int r;

  if (dstip == NULL) {
    r = recvfrom(s,buf,len,0,(struct sockaddr *) &sa,&dummy);
    if (r == -1) return -1;
  } else {
    struct iovec iov;
    struct cmsghdr cmsg, *cmsgptr;
    struct msghdr msg;
    char cbuf[64];

    byte_zero(&cmsg, sizeof(cmsg));
    byte_zero(&msg, sizeof(msg));

    iov.iov_base = buf;
    iov.iov_len = len;

    msg.msg_name = &sa;
    msg.msg_namelen = dummy;
    msg.msg_iov = &iov;
    msg.msg_iovlen = 1;
    msg.msg_control = cbuf;
    msg.msg_controllen = sizeof(cbuf);

    r = recvmsg(s, &msg, 0);

    if (r == -1)
      return (-1);

    for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
      if (cmsgptr->cmsg_level == SOL_IP && cmsgptr->cmsg_type == IP_PKTINFO) {
        struct in_pktinfo *pki = (struct in_pktinfo *)CMSG_DATA(cmsgptr);
        byte_copy(dstip, 4, (char *)&(pki->ipi_addr));
      }
    }
  }

  byte_copy(ip,4,(char *) &sa.sin_addr);
  uint16_unpack_big((char *) &sa.sin_port,port);

  return r;
}
Exemple #15
0
int dns_domain_fromdot_static(unsigned char *name,const unsigned char *buf,long long n)
{
  unsigned char label[63];
  long long labellen = 0; /* <= sizeof label */
  long long namelen = 0; /* <= sizeof name */
  unsigned char ch;

  errno = EPROTO;
  if (n < 0) return 0;
  byte_zero(name, 256);

  for (;;) {
    if (!n) break;
    ch = *buf++; --n;
    if (ch == '.') {
      if (labellen > 0) {
        if (namelen + labellen + 1 > 255) return 0;
        name[namelen++] = labellen;
        byte_copy(name + namelen,labellen,label);
        namelen += labellen;
        labellen = 0;
      }
      continue;
    }
    if (ch == '\\') {
      if (!n) break;
      ch = *buf++; --n;
      if ((ch >= '0') && (ch <= '7')) {
        ch -= '0';
        if (n && (*buf >= '0') && (*buf <= '7')) {
          ch <<= 3;
          ch += *buf - '0';
          ++buf; --n;
          if (n && (*buf >= '0') && (*buf <= '7')) {
            ch <<= 3;
            ch += *buf - '0';
            ++buf; --n;
          }
        }
      }
    }
    if (labellen >= sizeof label) return 0;
    label[labellen++] = ch;
  }

  if (labellen > 0) {
    if (namelen + labellen + 1 > 255) return 0;
    name[namelen++] = labellen;
    byte_copy(name + namelen,labellen,label);
    namelen += labellen;
    labellen = 0;
  }

  if (namelen + 1 > 255) return 0;
  name[namelen++] = 0;

  return 1;
}
Exemple #16
0
/* Fetches stats from tracker */
size_t stats_top_txt( char * reply, int amount ) {
  size_t    j;
  ot_record top100s[100], top100c[100];
  char     *r  = reply, hex_out[42];
  int       idx, bucket;

  if( amount > 100 )
    amount = 100;

  byte_zero( top100s, sizeof( top100s ) );
  byte_zero( top100c, sizeof( top100c ) );

  for( bucket=0; bucket<OT_BUCKET_COUNT; ++bucket ) {
    ot_vector *torrents_list = mutex_bucket_lock( bucket );
    for( j=0; j<torrents_list->size; ++j ) {
      ot_peerlist *peer_list = ( ((ot_torrent*)(torrents_list->data))[j] ).peer_list;
      int idx = amount - 1; while( (idx >= 0) && ( peer_list->peer_count > top100c[idx].val ) ) --idx;
      if ( idx++ != amount - 1 ) {
        memmove( top100c + idx + 1, top100c + idx, ( amount - 1 - idx ) * sizeof( ot_record ) );
        top100c[idx].val = peer_list->peer_count;
        top100c[idx].torrent = (ot_torrent*)(torrents_list->data) + j;
      }
      idx = amount - 1; while( (idx >= 0) && ( peer_list->seed_count > top100s[idx].val ) ) --idx;
      if ( idx++ != amount - 1 ) {
        memmove( top100s + idx + 1, top100s + idx, ( amount - 1 - idx ) * sizeof( ot_record ) );
        top100s[idx].val = peer_list->seed_count;
        top100s[idx].torrent = (ot_torrent*)(torrents_list->data) + j;
      }
    }
    mutex_bucket_unlock( bucket, 0 );
    if( !g_opentracker_running )
      return 0;
  }

  r += sprintf( r, "Top %d torrents by peers:\n", amount );
  for( idx=0; idx<amount; ++idx )
    if( top100c[idx].torrent )
      r += sprintf( r, "\t%zd\t%s\n", top100c[idx].val, to_hex( hex_out, top100c[idx].torrent->hash) );
  r += sprintf( r, "Top %d torrents by seeds:\n", amount );
  for( idx=0; idx<amount; ++idx )
    if( top100s[idx].torrent )
      r += sprintf( r, "\t%zd\t%s\n", top100s[idx].val, to_hex( hex_out, top100s[idx].torrent->hash) );

  return r - reply;
}
Exemple #17
0
void sha512_final (SHA512Schedule *ctx, char *digest)
{
  register unsigned int i = 0 ;
  register unsigned int pad = ctx->len % 128;

  ctx->buf[pad++] = 0x80 ;
  if (pad > 112)
  {
    byte_zero(ctx->buf + pad, 128 - pad) ;
    sha512_transform(ctx, ctx->buf) ;
    pad = 0 ;
  }
  byte_zero(ctx->buf + pad, 120 - pad) ;
  uint64_pack_big((char *)ctx->buf + 120, ctx->len << 3) ;
  sha512_transform(ctx, ctx->buf) ;

  for (; i < 8 ; i++) uint64_pack_big(digest + (i << 3), ctx->h[i]) ;
}
Exemple #18
0
void
http_init(http* h, const char* host, uint16 port) {
  byte_zero(h, sizeof(http));
  h->sock = -1;
  stralloc_init(&h->host);
  stralloc_copys(&h->host, host);
  h->port = port;
  h->request = NULL;
}
Exemple #19
0
int socket_bind(int fd,const unsigned char *ip,const unsigned char *port)
{
  struct sockaddr_in sa;
  byte_zero(&sa,sizeof sa);
  sa.sin_family = PF_INET;
  byte_copy(&sa.sin_addr,4,ip);
  byte_copy(&sa.sin_port,2,port);
  return bind(fd,(struct sockaddr *) &sa,sizeof sa);
}
Exemple #20
0
ssize_t socket_send4(int s,const char *buf,size_t len,const char ip[4],uint16 port) {
  struct sockaddr_in si;

  byte_zero(&si,sizeof si);
  si.sin_family = AF_INET;
  uint16_pack_big((char*) &si.sin_port,port);
  *((uint32*)&si.sin_addr) = *((uint32*)ip);
  return winsock2errno(sendto(s,buf,len,0,(void*) &si,sizeof si));
}
Exemple #21
0
int
socket_connect4(int s, const char* ip, uint16 port) {
  struct sockaddr_in si;
  byte_zero(&si, sizeof(si));
  si.sin_family = AF_INET;
  uint16_pack_big((char*)&si.sin_port, port);
  *((uint32*)&si.sin_addr) = *((uint32*)ip);
  return winsock2errno(connect(s, (struct sockaddr*)&si, sizeof(si)));
}
Exemple #22
0
int socket_bind6 (int s, char const *ip6, uint16 port)
{
  struct sockaddr_in6 sa ;
  byte_zero(&sa, sizeof sa) ;
  sa.sin6_family = AF_INET6 ;
  uint16_pack_big((char *)&sa.sin6_port, port) ;
  byte_copy(sa.sin6_addr.s6_addr, 16, ip6) ;
  return bind(s, (struct sockaddr *)&sa, sizeof sa) ;
}
Exemple #23
0
int main(int argc, char **argv) {

    unsigned char *x;
    unsigned long long xlen;

    if (argv[0])
        if (argv[1]) {
            if (str_equal(argv[1], "-h"))
                die_usage(0);
        }

    /* get password  */
    x = (unsigned char *)env_get("PASSWORD");
    if (!x) { errno = 0; die_usage("$PASSWORD not set"); }
    xlen = str_len((char *)x);

    /* create salt */
    randombytes(s, sizeof s);

    /* derive key  */
    if (sha512hmacpbkdf2(h, sizeof h, x, xlen, s, sizeof s, ROUNDS) == -1) die_fatal("unable to derive keys", 0);
    byte_zero(x, xlen);

    /* create nonce */
    randombytes(n, sizeof n);
    uint64_pack(n, nanoseconds());
    sha512(nk, (unsigned char *)MAGIC, MAGICBYTES);
    crypto_block_aes256vulnerable(n, n, nk);

    /* initialize */
    crypto_init(&ctx, n, h, MAGIC);
    randombytes(h, sizeof h);
    sha512_init(&shactx);

    /* write header */
    if (writeall(1, MAGIC, MAGICBYTES) == -1) die_fatal("unable to write output", 0);
    if (writeall(1, s, sizeof s) == -1) die_fatal("unable to write output", 0);
    randombytes(s, sizeof s);
    if (writeall(1, n, sizeof n) == -1) die_fatal("unable to write output", 0);

    for (;;) {
        inlen = readblock(in, BLOCK);
        if (inlen != BLOCK) break;
        if (sha512_block(&shactx, in, inlen) != 0) die_fatal("unable to compute hash", 0);
        if (crypto_block(&ctx, in, inlen) != 0) die_fatal("unable to encrypt stream", 0);
        if (writeall(1, in, inlen) == -1) die_fatal("unable to write output", 0);
    }
    if (sha512_last(&shactx, h, in, inlen) != 0) die_fatal("unable to compute hash", 0);
    byte_copy(in + inlen, CHECKSUMBYTES, h);
    inlen += CHECKSUMBYTES;
    if (crypto_last(&ctx, in, inlen) != 0) die_fatal("unable to encrypt stream", 0);
    if (writeall(1, in, inlen) == -1) die_fatal("unable to write output", 0);

    if (fsyncfd(1) == -1) die_fatal("unable to write output", 0);
    cleanup();
    _exit(0);
}
Exemple #24
0
void clientextension_init(void)
{
  if (recent >= clientextensionloadtime) {
    clientextensionloadtime = recent + 30000000000LL;
    if (load("/etc/curvecpextension",clientextension,16) == -1)
      if (errno == ENOENT || errno == ENAMETOOLONG)
        byte_zero(clientextension,16);
  }
}
Exemple #25
0
qldap *
qldap_new(void)
{
	qldap *q;

	q = (qldap *)alloc(sizeof(qldap));
	if (q == 0) return (qldap *)0;
	byte_zero(q, sizeof(qldap));
	return q;
}
Exemple #26
0
int
qldap_free(qldap *q)
{
	qldap_free_results(q);
	if (!STATEIN(q, NEW) && !STATEIN(q, CLOSE))
		qldap_close(q);
	byte_zero(q, sizeof(qldap));
	alloc_free(q);
	return OK;
}
void accesslist_init( char *accesslist_filename_in ) {
  byte_zero( &accesslist, sizeof( accesslist ) );

  /* Passing "0" since read_blacklist_file also is SIGHUP handler */
  if( accesslist_filename_in ) {
    accesslist_filename = accesslist_filename_in;
    accesslist_readfile( 0 );
    signal( SIGHUP,  accesslist_readfile );
  }
}
Exemple #28
0
void s6rc_graph_closure (s6rc_db_t const *db, unsigned char *bits, unsigned int bitno, int h)
{
  unsigned int n = db->nshort + db->nlong ;
  unsigned int m = bitarray_div8(n) ;
  unsigned char mark[m] ;
  recinfo_t info = { .db = db, .n = n, .bits = bits, .mark = mark, .mask = 1 << (bitno & 7), .h = !!h } ;
  register unsigned int i = n ;
  byte_zero(mark, m) ;
  while (i--)
    if (bits[i] & info.mask) s6rc_graph_closure_rec(&info, i) ;
}
Exemple #29
0
void eval_push(struct eval *e, int flags) {
  byte_zero(e, sizeof(struct eval));
  e->flags = flags;
  e->parent = sh->eval;
  
  /* remember stack locations in current nesting level */
  e->fdstack = fdstack;
  e->varstack = varstack;
  
  sh->eval = e;
}
Exemple #30
0
int socket_connect4(int s,const char ip[4],uint16 port)
{
  struct sockaddr_in sa;

  byte_zero(&sa,sizeof sa);
  sa.sin_family = AF_INET;
  uint16_pack_big((char *) &sa.sin_port,port);
  byte_copy((char *) &sa.sin_addr,4,ip);

  return connect(s,(struct sockaddr *) &sa,sizeof sa);
}