Beispiel #1
0
static void *
map_db_credentials(char *key, char *line, size_t len)
{
	struct map_credentials *map_credentials = NULL;
	char *p;

	/* credentials are stored as user:password */
	if (len < 3)
		return NULL;

	/* too big to fit in a smtp session line */
	if (len >= MAX_LINE_SIZE)
		return NULL;

	p = strchr(line, ':');
	if (p == NULL)
		return NULL;

	if (p == line || p == line + len - 1)
		return NULL;
	*p++ = '\0';

	map_credentials = calloc(1, sizeof(struct map_credentials));
	if (map_credentials == NULL)
		fatalx("calloc");

	if (strlcpy(map_credentials->username, line,
		sizeof(map_credentials->username)) >=
	    sizeof(map_credentials->username))
		goto err;

	if (strlcpy(map_credentials->password, p,
		sizeof(map_credentials->password)) >=
	    sizeof(map_credentials->password))
		goto err;

	return map_credentials;

err:
	free(map_credentials);
	return NULL;
}
Beispiel #2
0
static void
lka_sig_handler(int sig, short event, void *p)
{
    int status;
    pid_t pid;

    switch (sig) {
    case SIGINT:
    case SIGTERM:
        lka_shutdown();
        break;
    case SIGCHLD:
        do {
            pid = waitpid(-1, &status, WNOHANG);
        } while (pid > 0 || (pid == -1 && errno == EINTR));
        break;
    default:
        fatalx("lka_sig_handler: unexpected signal");
    }
}
Beispiel #3
0
void
check_script(struct relayd *env, struct host *host)
{
	struct ctl_script	 scr;
	struct table		*table;

	if ((table = table_find(env, host->conf.tableid)) == NULL)
		fatalx("check_script: invalid table id");

	host->last_up = host->up;
	host->flags &= ~(F_CHECK_SENT|F_CHECK_DONE);

	scr.host = host->conf.id;
	strlcpy(scr.name, host->conf.name, sizeof(host->conf.name));
	strlcpy(scr.path, table->conf.path, sizeof(table->conf.path));
	memcpy(&scr.timeout, &table->conf.timeout, sizeof(scr.timeout));

	proc_compose_imsg(env->sc_ps, PROC_PARENT, 0, IMSG_SCRIPT,
	    -1, &scr, sizeof(scr));
}
Beispiel #4
0
long lrevcomp (long xx, int stringlen)
// consists of stringlen "mininibbles" (2 bits)
// could be rewritten to avoid array aa + 1 loop.
{
    int aa[32],  k, t ;
    long xxx ;

    if (stringlen > 32) fatalx("stringlen > 32\n") ;
    xxx = xx ;
    for (k=0; k<stringlen; ++k) {
        aa[k] = (xxx & 3) ^ 3 ;
        xxx = xxx >> 2 ;
    }
    xxx = 0 ;
    for (k=0; k<stringlen; ++k) {
        t = aa[k]  ;
        xxx = (xxx << 2) | t ;
    }
    return xxx ;
}
Beispiel #5
0
int string_binary(char *sx)
{
    int *aa, len, i, t ;
    char c ;

    len = strlen(sx) ;
    ZALLOC(aa, len, int) ;

    for (i=0; i<len; i++) {

        c = sx[i] ;
        if (c == '0') continue ;
        if (c != '1') fatalx("bad string: %s\n", sx) ;
        aa[i] = 1;
    }
    t = kodeitb(aa, len, 2) ;
    free(aa) ;
    return t ;

}
Beispiel #6
0
void
proc_sig_handler(int sig, short event, void *arg)
{
	struct privsep_proc	*p = arg;

	switch (sig) {
	case SIGINT:
	case SIGTERM:
		proc_shutdown(p);
		break;
	case SIGCHLD:
	case SIGHUP:
	case SIGPIPE:
		/* ignore */
		break;
	default:
		fatalx("proc_sig_handler: unexpected signal");
		/* NOTREACHED */
	}
}
Beispiel #7
0
static void checkconf(void)
{
	char	fn[SMALLBUF];
	PCONF_CTX_t	ctx;

	snprintf(fn, sizeof(fn), "%s/upssched.conf", confpath());

	pconf_init(&ctx, upssched_err);

	if (!pconf_file_begin(&ctx, fn)) {
		pconf_finish(&ctx);
		fatalx(EXIT_FAILURE, "%s", ctx.errmsg);
	}

	while (pconf_file_next(&ctx)) {
		if (pconf_parse_error(&ctx)) {
			upslogx(LOG_ERR, "Parse error: %s:%d: %s",
				fn, ctx.linenum, ctx.errmsg);
			continue;
		}

		if (ctx.numargs < 1)
			continue;

		if (!conf_arg(ctx.numargs, ctx.arglist)) {
			unsigned int	i;
			char	errmsg[SMALLBUF];

			snprintf(errmsg, sizeof(errmsg),
				"upssched.conf: invalid directive");

			for (i = 0; i < ctx.numargs; i++)
				snprintfcat(errmsg, sizeof(errmsg), " %s",
					ctx.arglist[i]);

			upslogx(LOG_WARNING, "%s", errmsg);
		}
	}

	pconf_finish(&ctx);
}
Beispiel #8
0
static void
filter_api_init(void)
{
	extern const char *__progname;
	struct passwd  *pw;
	static int	init = 0;

	if (init)
		return;

	init = 1;

	log_init(-1);
	log_verbose(1);

	pw = getpwnam(SMTPD_USER);
	if (pw == NULL) {
		log_warn("warn: filter-api:%s getpwnam", filter_name);
		fatalx("filter-api: exiting");
	}

	smtpd_process = PROC_FILTER;
	filter_name = __progname;

	tree_init(&queries);
	tree_init(&sessions);
	event_init();

	memset(&fi, 0, sizeof(fi));
	fi.p.proc = PROC_PONY;
	fi.p.name = "filter";
	fi.p.handler = filter_dispatch;
	fi.uid = pw->pw_uid;
	fi.gid = pw->pw_gid;
	fi.rootpath = PATH_CHROOT;

	/* XXX just for now */
	fi.hooks = ~0;

	mproc_init(&fi.p, 0);
}
static double betacf(double a, double b, double x)
/* Used by betai: Evaluates continued fraction for incomplete beta function 
   by modified Lentz's method.   */
{
#define MAXIT 100
#define EPS 3.0e-7
#define FPMIN 1.0e-30

	int m,m2;
	double aa,c,d,del,h,qab,qam,qap;

	qab=a+b;
	qap=a+1.0;	
	qam=a-1.0;	
	c=1.0;		/* First step of Lentz's method.  */
	d=1.0-qab*x/qap;
	if (fabs(d) < FPMIN) d=FPMIN;
	d=1.0/d;
	h=d;
	for (m=1;m<=MAXIT;m++) {
		m2=2*m;
		aa=m*(b-m)*x/((qam+m2)*(a+m2));
		d=1.0+aa*d;		/* One step (the even one) of the recurrence. */
		if (fabs(d) < FPMIN) d=FPMIN;
		c=1.0+aa/c;
		if (fabs(c) < FPMIN) c=FPMIN;
		d=1.0/d;
		h *= d*c;
		aa = -(a+m)*(qab+m)*x/((a+m2)*(qap+m2));
		d=1.0+aa*d;		/* Next step of the recurence the odd one) */
		if (fabs(d) < FPMIN) d=FPMIN;
		c=1.0+aa/c;
		if (fabs(c) < FPMIN) c=FPMIN;
		d=1.0/d;
		del=d*c;
		h *= del;
		if (fabs(del-1.0) < EPS) break;   /* Are we done? */
	}
	if (m > MAXIT) fatalx( "a or b too big, or MAXIT too small in betacf\n");
	return h;
}
Beispiel #10
0
int
control_create_socket(void)
{
	struct sockaddr_un	sun;
	int			fd;
	mode_t			old_umask;

	if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
		fatal("control: socket");

	memset(&sun, 0, sizeof(sun));
	sun.sun_family = AF_UNIX;
	if (strlcpy(sun.sun_path, SMTPD_SOCKET,
	    sizeof(sun.sun_path)) >= sizeof(sun.sun_path))
		fatal("control: socket name too long");

	if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0)
		fatalx("control socket already listening");

	if (unlink(SMTPD_SOCKET) == -1)
		if (errno != ENOENT)
			fatal("control: cannot unlink socket");

	old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
	if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
		(void)umask(old_umask);
		fatal("control: bind");
	}
	(void)umask(old_umask);

	if (chmod(SMTPD_SOCKET,
		S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1) {
		(void)unlink(SMTPD_SOCKET);
		fatal("control: chmod");
	}

	session_socket_blockmode(fd, BM_NONBLOCK);
	control_state.fd = fd;

	return fd;
}
Beispiel #11
0
void
tcp_host_up(struct ctl_tcp_event *cte)
{
	switch (cte->table->conf.check) {
	case CHECK_TCP:
		if (cte->table->conf.flags & F_TLS)
			break;
		tcp_close(cte, 0);
		hce_notify_done(cte->host, HCE_TCP_CONNECT_OK);
		return;
	case CHECK_HTTP_CODE:
		cte->validate_read = NULL;
		cte->validate_close = check_http_code;
		break;
	case CHECK_HTTP_DIGEST:
		cte->validate_read = NULL;
		cte->validate_close = check_http_digest;
		break;
	case CHECK_SEND_EXPECT:
		cte->validate_read = check_send_expect;
		cte->validate_close = check_send_expect;
		break;
	}

	if (cte->table->conf.flags & F_TLS) {
		ssl_transaction(cte);
		return;
	}

	if (cte->table->sendbuf != NULL) {
		cte->req = cte->table->sendbuf;
		event_again(&cte->ev, cte->s, EV_TIMEOUT|EV_WRITE, tcp_send_req,
		    &cte->tv_start, &cte->table->conf.timeout, cte);
		return;
	}

	if ((cte->buf = ibuf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL)
		fatalx("tcp_host_up: cannot create dynamic buffer");
	event_again(&cte->ev, cte->s, EV_TIMEOUT|EV_READ, tcp_read_buf,
	    &cte->tv_start, &cte->table->conf.timeout, cte);
}
Beispiel #12
0
void encode(void) {
  if ((len =read(encpipe[0], encinbuf.s, encin.size)) < 0)
    fatal("unable to read from prog");
  if (len == 0) {
    if (verbose > 2) info("eof reading from proc");
    if (quit == 0) {
      finish();
      _exit(0);
    } else {
      close(encpipe[0]); encpipe[0] = -1;
      if (shutdown(fdstdou, SHUT_WR) == 0) {
	fdstdou =-1;
	if (verbose > 2) info("shutdown network");
      } else {
	if (verbose > 2) info("close network");
	close(fdstdou); fdstdou =-1;
      }
      sig_catch(sig_alarm, quit_handler);
      alarm(quit);
      return;
    }
  }
  for (;;) {
    rc =matrixSslEncode(ssl, encin.buf, len, &encou);
    if (rc == SSL_ERROR) {
      close(fdstdou); fdstdou =-1;
      fatalx("unable to encode data");
    }
    if (rc == SSL_FULL) {
      if (! blowup(&encou, &encoubuf, bufsizeou)) die_nomem();
      if (verbose > 1) infou("encode output buffer size: ", encou.size);
      continue;
    }
    if (write(fdstdou, encou.start, encou.end -encou.start)
        != encou.end -encou.start) fatal("unable to write to network");
    if (verbose > 2) infou("write bytes: ", encou.end -encou.start);
    bytesou +=encou.end -encou.start;
    encou.start =encou.end =encou.buf =encoubuf.s;
    return;
  }
}
Beispiel #13
0
static int
queue_proc_envelope_load(uint64_t evpid, char *buf, size_t len)
{
	int	r;

	imsg_compose(&ibuf, PROC_QUEUE_ENVELOPE_LOAD, 0, 0, -1, &evpid,
	    sizeof(evpid));

	queue_proc_call();

	if (rlen > len) {
		log_warnx("warn: queue-proc: buf too small");
		fatalx("queue-proc: exiting");
	}

	r = rlen;
	queue_proc_read(buf, rlen);
	queue_proc_end();

	return (r);
}
Beispiel #14
0
/* Set cell as extended. */
static struct grid_cell *
grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
    const struct grid_cell *gc)
{
	struct grid_cell	*gcp;

	gl->flags |= GRID_LINE_EXTENDED;

	if (~gce->flags & GRID_FLAG_EXTENDED) {
		gl->extddata = xreallocarray(gl->extddata, gl->extdsize + 1,
		    sizeof *gl->extddata);
		gce->offset = gl->extdsize++;
		gce->flags = gc->flags | GRID_FLAG_EXTENDED;
	}
	if (gce->offset >= gl->extdsize)
		fatalx("offset too big");

	gcp = &gl->extddata[gce->offset];
	memcpy(gcp, gc, sizeof *gcp);
	return (gcp);
}
Beispiel #15
0
void
screen_resize_x(struct screen *s, u_int sx)
{
	struct grid		*gd = s->grid;

	if (sx == 0)
		fatalx("zero size");

	/*
	 * Treat resizing horizontally simply: just ensure the cursor is
	 * on-screen and change the size. Don't bother to truncate any lines -
	 * then the data should be accessible if the size is then incrased.
	 *
	 * The only potential wrinkle is if UTF-8 double-width characters are
	 * left in the last column, but UTF-8 terminals should deal with this
	 * sanely.
	 */
	if (s->cx >= sx)
		s->cx = sx - 1;
	gd->sx = sx;
}
Beispiel #16
0
struct tmuxproc *
proc_start(const char *name, struct event_base *base, int forkflag,
    void (*signalcb)(int))
{
	struct tmuxproc	*tp;

	if (forkflag) {
		switch (fork()) {
		case -1:
			fatal("fork failed");
		case 0:
			break;
		default:
			return (NULL);
		}
		if (daemon(1, 0) != 0)
			fatal("daemon failed");

		clear_signals(0);
		if (event_reinit(base) != 0)
			fatalx("event_reinit failed");
	}

	logfile(name);

#ifdef HAVE_SETPROCTITLE
	setproctitle("%s (%s)", name, socket_path);
#endif

	log_debug("%s started (%ld): socket %s, protocol %d", name,
	    (long)getpid(), socket_path, PROTOCOL_VERSION);

	tp = xcalloc(1, sizeof *tp);
	tp->name = xstrdup(name);

	tp->signalcb = signalcb;
	set_signals(proc_signal_cb, tp);

	return (tp);
}
Beispiel #17
0
static void *
map_stdio_alias(char *key, char *line, size_t len)
{
	char	       	*subrcpt;
	char	       	*endp;
	struct map_alias	*map_alias = NULL;
	struct expandnode	 expnode;

	map_alias = calloc(1, sizeof(struct map_alias));
	if (map_alias == NULL)
		fatalx("calloc");

	while ((subrcpt = strsep(&line, ",")) != NULL) {
		/* subrcpt: strip initial whitespace. */
		while (isspace((int)*subrcpt))
			++subrcpt;
		if (*subrcpt == '\0')
			goto error;

		/* subrcpt: strip trailing whitespace. */
		endp = subrcpt + strlen(subrcpt) - 1;
		while (subrcpt < endp && isspace((int)*endp))
			*endp-- = '\0';

		bzero(&expnode, sizeof (struct expandnode));
		if (! alias_parse(&expnode, subrcpt))
			goto error;

		expandtree_increment_node(&map_alias->expandtree, &expnode);
		map_alias->nbnodes++;
	}

	return map_alias;

error:
	/* free elements in map_alias->expandtree */
	expandtree_free_nodes(&map_alias->expandtree);
	free(map_alias);
	return NULL;
}
Beispiel #18
0
int
re_block(struct re *re, const void *buf, size_t len, struct rmlist *rml,
    char **cause)
{
	int	res, pm[NPMATCH * 3];
	u_int	i, j;

	if (len > INT_MAX)
		fatalx("buffer too big");

	if (rml != NULL)
		memset(rml, 0, sizeof *rml);

	/* If the regexp is empty, just check whether the buffer is empty. */
	if (*re->str == '\0') {
		if (len == 0)
			return (1);
		return (0);
	}

	res = pcre_exec(re->pcre, NULL, buf, len, 0, 0, pm, NPMATCH * 3);
	if (res < 0 && res != PCRE_ERROR_NOMATCH) {
		xasprintf(cause, "%s: regexec failed", re->str);
		return (-1);
	}

	if (rml != NULL) {
		for (i = 0; i < NPMATCH; i++) {
			j = i * 2;
			if (pm[j + 1] <= pm[j])
				break;
			rml->list[i].valid = 1;
			rml->list[i].so = pm[j];
			rml->list[i].eo = pm[j + 1];
		}
		rml->valid = 1;
	}

	return (res != PCRE_ERROR_NOMATCH);
}
Beispiel #19
0
/*
 * Send data over a socket and exit if something fails.
 */
void
send_data(int sock, void *buf, size_t len)
{
	ssize_t n;
	size_t pos = 0;
	char *ptr = buf;

	while (len > pos) {
		switch (n = write(sock, ptr + pos, len - pos)) {
		case 0:
			kill_slave("write failure");
			_exit(0);
			/* NOTREACHED */
		case -1:
			if (errno != EINTR && errno != EAGAIN)
				fatalx("send_data: %m");
			break;
		default:
			pos += n;
		}
	}
}
double ltlg1(double a, double x) 
{
    double r, s, tiny = 1.0e-14 ;
    double yk, y1, xam ;
    int k ; 

    s = 1.0/a ;  
    r= s ;
    for (k=1; k<=60; ++k) {  
     yk = (double) k ; 
     r *= (x/(a+yk)) ;
     s += r ;
     if (fabs(r/s) < tiny) break ;
    }
    xam = (a*log(x))-x ;
    y1 = xam  + log(s) ; 
    y1 -= xlgamma(a) ;
    y1 = exp(y1) ;
    if (isnan(y1)) fatalx("bad ltlg1\n") ;
    return y1 ;

}
double rtlg2(double a, double x) 
{
   double y1, y2 ;
   double yk, top, bot, t0, xam ;
   int k ;
   t0 = 0.0 ; 

// ZJ p 64 ff
   for (k=60; k>=1; --k) {  
    yk = (double) k ; 
    top = yk - a ; 
    bot = yk / (x+t0) ;
    ++bot  ;
    t0 = top/bot ;
   }
   xam = (a*log(x))-x ;
   y1 = xam - log(x+t0) ;   
   y1 -= xlgamma(a) ; 
   y1 = exp(y1) ;
   if (isnan(y1)) fatalx("bad rtlg2\n") ;
   return y1 ;
}
Beispiel #22
0
int
fsqueue_envelope(enum queue_kind qkind, enum queue_op qop, struct envelope *m)
{
        switch (qop) {
        case QOP_CREATE:
		return fsqueue_envelope_create(qkind, m);

        case QOP_DELETE:
		return fsqueue_envelope_delete(qkind, m);

        case QOP_LOAD:
		return fsqueue_envelope_load(qkind, m);

        case QOP_UPDATE:
		return fsqueue_envelope_update(qkind, m);

        default:
		fatalx("queue_fsqueue_envelope: unsupported operation.");
        }

	return 0;
}
Beispiel #23
0
void
clearld (double *ldmat, double *ldvv, int rsize, int n, int nclear)
{
  int i, j, lo, hi;

  if (nclear > rsize)
    fatalx ("bad nclear\n");

  lo = rsize - nclear;
  hi = rsize - 1;

  for (i = lo; i <= hi; ++i)
    {
      vzero (ldvv + i * n, n);
      for (j = 0; j <= hi; ++j)
        {
          ldmat[j * rsize + i] = ldmat[i * rsize + j] = 0.0;
        }
// force matrix non-singular 
      ldmat[i * rsize + i] = 1.0e-8;
    }
}
Beispiel #24
0
void
tcp_send_req(int s, short event, void *arg)
{
	struct ctl_tcp_event	*cte = arg;
	int			 bs;
	int			 len;

	if (event == EV_TIMEOUT) {
		cte->host->up = HOST_DOWN;
		close(cte->s);
		hce_notify_done(cte->host, HCE_TCP_WRITE_TIMEOUT);
		return;
	}
	len = strlen(cte->req);
	do {
		bs = write(s, cte->req, len);
		if (bs == -1) {
			if (errno == EAGAIN || errno == EINTR)
				goto retry;
			log_warnx("%s: cannot send request", __func__);
			cte->host->up = HOST_DOWN;
			close(cte->s);
			hce_notify_done(cte->host, HCE_TCP_WRITE_FAIL);
			return;
		}
		cte->req += bs;
		len -= bs;
	} while (len > 0);

	if ((cte->buf = ibuf_dynamic(SMALL_READ_BUF_SIZE, UINT_MAX)) == NULL)
		fatalx("tcp_send_req: cannot create dynamic buffer");
	event_again(&cte->ev, s, EV_TIMEOUT|EV_READ, tcp_read_buf,
	    &cte->tv_start, &cte->table->conf.timeout, cte);
	return;

 retry:
	event_again(&cte->ev, s, EV_TIMEOUT|EV_WRITE, tcp_send_req,
	    &cte->tv_start, &cte->table->conf.timeout, cte);
}
Beispiel #25
0
static void
authenticate(struct imsgev *iev, struct imsg *imsg)
{
	struct auth_req	*req = imsg->data;
	struct passwd	*pw;
	int		pair[2];

	if (auth_userokay(req->user, NULL, "auth-pop3", req->pass) == 0) {
		logit(LOG_INFO, "%u: auth [%s] failed",
		    imsg->hdr.peerid, req->user);
		pair[0] = -1;
		goto end;
	}

	logit(LOG_INFO, "%u: auth [%s] passed", imsg->hdr.peerid,
	    req->user);
	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) == -1)
		fatal("socketpair");

	set_nonblocking(pair[0]);
	set_nonblocking(pair[1]);
	if ((pw = getpwnam(req->user)) == NULL)
		fatalx("authenticate: getpwnam");

	if (maildrop_setup(imsg->hdr.peerid, pair, pw) == -1) {
		logit(LOG_INFO, "%u: unable to fork maildrop process",
		    imsg->hdr.peerid);
		close(pair[0]);
		close(pair[1]);
		pair[0] = -1;
		goto end;
	}

	close(pair[1]);
end:
	imsgev_xcompose(iev, IMSG_AUTH, imsg->hdr.peerid, 0,
	    pair[0], NULL, 0, "authenticate");
}
Beispiel #26
0
/* Set default format keys for a window pane. */
void
format_window_pane(struct format_tree *ft, struct window_pane *wp)
{
	struct grid		*gd = wp->base.grid;
	struct grid_line	*gl;
	unsigned long long	 size;
	u_int			 i;
	u_int			 idx;

	size = 0;
	for (i = 0; i < gd->hsize; i++) {
		gl = &gd->linedata[i];
		size += gl->cellsize * sizeof *gl->celldata;
		size += gl->utf8size * sizeof *gl->utf8data;
	}
	size += gd->hsize * sizeof *gd->linedata;

	if (window_pane_index(wp, &idx) != 0)
		fatalx("index not found");

	format_add(ft, "pane_width", "%u", wp->sx);
	format_add(ft, "pane_height", "%u", wp->sy);
	format_add(ft, "pane_title", "%s", wp->base.title);
	format_add(ft, "pane_index", "%u", idx);
	format_add(ft, "history_size", "%u", gd->hsize);
	format_add(ft, "history_limit", "%u", gd->hlimit);
	format_add(ft, "history_bytes", "%llu", size);
	format_add(ft, "pane_id", "%%%u", wp->id);
	format_add(ft, "pane_active", "%d", wp == wp->window->active);
	format_add(ft, "pane_dead", "%d", wp->fd == -1);
	if (wp->cmd != NULL)
		format_add(ft, "pane_start_command", "%s", wp->cmd);
	if (wp->cwd != NULL)
		format_add(ft, "pane_start_path", "%s", wp->cwd);
	format_add(ft, "pane_current_path", "%s", get_proc_cwd(wp->pid));
	format_add(ft, "pane_pid", "%ld", (long) wp->pid);
	format_add(ft, "pane_tty", "%s", wp->tty);
}
double tau(double x) 
/*
 derivative of psi 
*/
{
 double y, zz, term ;
 int k ;

 if (x<=0.0) fatalx("(tau) bad value:  %9.3f\n", x) ;
 bernload() ;
 if (x<10.0) return (tau(x+1.0) + 1.0/(x*x)) ;

 y = 1.0/x  + 1.0/(2.0*x*x) ;
 zz = 1.0/x ;
 for (k=1; k<= bernmax/2 ; k++)  {
  zz /= (x*x) ;
  term = bernum(2*k)/(double) (2*k) ;
  term *= zz ;
  term *= - (double) (2*k) ;
  y -= term ;
 }
 return y ;
}
Beispiel #28
0
void
tty_init(struct tty *tty, int fd, char *term)
{
	char	*path;

	memset(tty, 0, sizeof *tty);
	tty->log_fd = -1;

	if (term == NULL || *term == '\0')
		tty->termname = xstrdup("unknown");
	else
		tty->termname = xstrdup(term);
	tty->fd = fd;

	if ((path = ttyname(fd)) == NULL)
		fatalx("ttyname failed");
	tty->path = xstrdup(path);
	tty->cstyle = 0;
	tty->ccolour = xstrdup("");

	tty->flags = 0;
	tty->term_flags = 0;
}
Beispiel #29
0
/* Populate an options tree from a table. */
void
options_table_populate_tree(enum options_table_scope scope, struct options *oo)
{
	const struct options_table_entry	*oe;

	for (oe = options_table; oe->name != NULL; oe++) {
		if (oe->scope == OPTIONS_TABLE_NONE)
			fatalx("no scope for %s", oe->name);
		if (oe->scope != scope)
			continue;
		switch (oe->type) {
		case OPTIONS_TABLE_STRING:
			options_set_string(oo, oe->name, "%s", oe->default_str);
			break;
		case OPTIONS_TABLE_STYLE:
			options_set_style(oo, oe->name, oe->default_str, 0);
			break;
		default:
			options_set_number(oo, oe->name, oe->default_num);
			break;
		}
	}
}
Beispiel #30
0
/*
 * Sometimes mail has wrapped header lines, this undoubtedly looks neat but
 * makes them a pain to match using regexps. We build a list of the newlines
 * in all the wrapped headers in m->wrapped, and can then quickly unwrap them
 * for regexp matching and wrap them again for delivery.
 */
u_int
fill_wrapped(struct mail *m)
{
	char		*ptr;
	size_t		 end, off;
	u_int		 n;

	if (!ARRAY_EMPTY(&m->wrapped))
		fatalx("already wrapped");

	ARRAY_INIT(&m->wrapped);
	m->wrapchar = '\0';

	end = m->body;
	ptr = m->data;

	n = 0;
	for (;;) {
		ptr = memchr(ptr, '\n', m->size - (ptr - m->data));
		if (ptr == NULL)
			break;
		ptr++;
		off = ptr - m->data;
		if (off >= end)
			break;

		/* Check if the line starts with whitespace. */
		if (!isblank((u_char) *ptr))
			continue;

		/* Save the position. */
		ARRAY_ADD(&m->wrapped, off - 1);
		n++;
	}

	return (n);
}