syslogd log.c

2017-03-15 Thread Alexander Bluhm
Hi,

I want to replace the home grown syslogd(8) internal debug and
logging functions with a more common log.c implementation.  But of
course I cannot use openlog(3), so I need something special.  I
have copied log.[ch] form ospfd(8) and adapted it to syslogd's
needs.  As the messages are limited to ERRBUFSIZE anyway, I can
avoid malloc(3) in the error logging code.

The whole diff converting all the messages has more than 2000 lines
as it touches every part of syslogd code.  I would refuse to review
such a huge diff, so I have splitted it.  Let's start with the log.c
implementation.

ok?

bluhm

Index: usr.sbin/syslogd/Makefile
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- usr.sbin/syslogd/Makefile   18 Jan 2015 19:37:59 -  1.7
+++ usr.sbin/syslogd/Makefile   16 Mar 2017 00:03:30 -
@@ -1,7 +1,8 @@
 #  $OpenBSD: Makefile,v 1.7 2015/01/18 19:37:59 bluhm Exp $
 
 PROG=  syslogd
-SRCS=  syslogd.c ttymsg.c privsep.c privsep_fdpass.c ringbuf.c evbuffer_tls.c
+SRCS=  evbuffer_tls.c log.c privsep.c privsep_fdpass.c ringbuf.c syslogd.c \
+   ttymsg.c
 MAN=   syslogd.8 syslog.conf.5
 LDADD= -levent -ltls -lssl -lcrypto
 DPADD= ${LIBEVENT} ${LIBTLS} ${LIBSSL} ${LIBCRYPTO}
Index: usr.sbin/syslogd/log.c
===
RCS file: usr.sbin/syslogd/log.c
diff -N usr.sbin/syslogd/log.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ usr.sbin/syslogd/log.c  16 Mar 2017 01:08:11 -
@@ -0,0 +1,208 @@
+/* $OpenBSD$   */
+
+/*
+ * Copyright (c) 2003, 2004 Henning Brauer 
+ * Copyright (c) 2017 Alexander Bluhm 
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "log.h"
+#include "syslogd.h"
+
+static int  debug;
+static int  verbose;
+static int  facility;
+static const char  *log_procname;
+
+void
+log_init(int n_debug, int fac)
+{
+   extern char *__progname;
+
+   debug = n_debug;
+   verbose = n_debug;
+   facility = fac;
+   log_procinit(__progname);
+
+   tzset();
+}
+
+void
+log_procinit(const char *procname)
+{
+   if (procname != NULL)
+   log_procname = procname;
+}
+
+void
+log_setdebug(int d)
+{
+   debug = d;
+}
+
+int
+log_getdebug(void)
+{
+   return (debug);
+}
+
+void
+log_setverbose(int v)
+{
+   verbose = v;
+}
+
+int
+log_getverbose(void)
+{
+   return (verbose);
+}
+
+void
+logit(int pri, const char *fmt, ...)
+{
+   va_list ap;
+
+   va_start(ap, fmt);
+   vlog(pri, fmt, ap);
+   va_end(ap);
+}
+
+void
+vlog(int pri, const char *fmt, va_list ap)
+{
+   char ebuf[ERRBUFSIZE];
+   size_t   l;
+   int  saved_errno = errno;
+
+   if (debug) {
+   l = snprintf(ebuf, sizeof(ebuf), "%s: ", log_procname);
+   if (l < sizeof(ebuf))
+   vsnprintf(ebuf+l, sizeof(ebuf)-l, fmt, ap);
+   fprintf(stderr, "%s\n", ebuf);
+   fflush(stderr);
+   } else
+   vlogmsg(pri, log_procname, fmt, ap);
+
+   errno = saved_errno;
+}
+
+void
+log_warn(const char *emsg, ...)
+{
+   char ebuf[ERRBUFSIZE];
+   size_t   l;
+   va_list  ap;
+   int  saved_errno = errno;
+
+   /* best effort to even work in out of memory situations */
+   if (emsg == NULL)
+   logit(LOG_ERR, "%s", strerror(saved_errno));
+   else {
+   va_start(ap, emsg);
+   l = vsnprintf(ebuf, sizeof(ebuf), emsg, ap);
+   if (l < sizeof(ebuf))
+   snprintf(ebuf+l, sizeof(ebuf)-l, ": %s",
+   strerror(saved_errno));
+   logit(LOG_ERR, "%s", ebuf);
+   va_end(ap);
+   }
+   errno = saved_errno;
+}
+
+void
+log_warnx(const char *emsg, ...)
+{
+   va_list  ap;
+
+   va_start(ap, emsg);
+   vlog(LOG_ERR, emsg, ap);
+   va_end(ap);
+}
+
+void
+log_info(int pri, const char *emsg, ...)
+{
+   va_list  ap;
+
+   va_start(ap, emsg);
+   vlog(pri, emsg, ap);
+

Re: [patch 1/2] doas(1): Moved some parsing from env.c into parse.y

2017-03-15 Thread bytevolcano
On Wed, 15 Mar 2017 20:15:26 -0400
"Ted Unangst"  wrote:

> Did I get it backwards? If you have setenv { HERE= there }, your diff
> changes behavior.
> 

Now I see where you are coming from. It's meant to empty $HERE, and copy
$there. Thanks, I'll look into this.



Re: Making it easier to install clang alongside gcc

2017-03-15 Thread Jonathan Gray
On Wed, Mar 15, 2017 at 09:53:41PM +0100, Mark Kettenis wrote:
> It's currently a bit of a pain to install clang and ld.lld, but keep
> gcc and ld.bfd as the default compiler/linker.  You can't rebuild
> clang with base gcc and you really want to rebuild it with clang
> instead of the ports gcc after boostrapping.  And overwriting the
> default compiler/linker links is annoying.  Especially on platforms
> where lld doesn't work yet.  The diff below would make my life easier
> and hopefully get more people involved.
> 
> This partly reverts the changes made by jsg@ in Brisbane, but I think
> we need this if we want clang/lld on more platforms than just arm64.
> 
> ok?
> 
> 
> Index: gnu/usr.bin/clang/Makefile.inc
> ===
> RCS file: /cvs/src/gnu/usr.bin/clang/Makefile.inc,v
> retrieving revision 1.4
> diff -u -p -u -p -r1.4 Makefile.inc
> --- gnu/usr.bin/clang/Makefile.inc16 Feb 2017 02:08:42 -  1.4
> +++ gnu/usr.bin/clang/Makefile.inc15 Mar 2017 20:21:06 -
> @@ -6,6 +6,9 @@ BOOTSTRAP_CLANG?=no
>  .if ${BOOTSTRAP_CLANG} == "yes"
>  CC=  egcc
>  CXX= eg++
> +.else
> +CC=  clang
> +CXX= clang++
>  .endif

This entire block should be just

.if ${COMPILER_VERSION:L} == "gcc4"
CC= clang
CXX=clang++
.endif

A list of compilers that don't handle the latest c++ standard.

>  
>  DEBUG=
> Index: gnu/usr.bin/clang/clang/Makefile
> ===
> RCS file: /cvs/src/gnu/usr.bin/clang/clang/Makefile,v
> retrieving revision 1.6
> diff -u -p -u -p -r1.6 Makefile
> --- gnu/usr.bin/clang/clang/Makefile  24 Jan 2017 08:44:47 -  1.6
> +++ gnu/usr.bin/clang/clang/Makefile  15 Mar 2017 20:21:06 -
> @@ -13,15 +13,18 @@ LDADD+=   -ltermlib
>  DPADD+=  ${LIBTERMLIB}
>  
>  LINKS=   ${BINDIR}/clang ${BINDIR}/clang++ \
> - ${BINDIR}/clang ${BINDIR}/clang-cpp \
> - ${BINDIR}/clang ${BINDIR}/cc \
> + ${BINDIR}/clang ${BINDIR}/clang-cpp
> +MLINKS=  clang.1 clang++.1 \
> + clang.1 clang-cpp.1
> +
> +.if ${COMPILER_VERSION:L} == "clang"
> +LINKS+=  ${BINDIR}/clang ${BINDIR}/cc \
>   ${BINDIR}/clang ${BINDIR}/c++ \
>   ${BINDIR}/clang ${LIBEXECDIR}/cpp
> -MLINKS=  clang.1 clang++.1 \
> - clang.1 clang-cpp.1 \
> - clang.1 cc.1 \
> +MLINKS+=clang.1 cc.1 \
>   clang.1 c++.1 \
>   clang.1 cpp.1
> +.endif
>  
>  CPPFLAGS+=   -I${.CURDIR}/../../../llvm/tools/clang/include
>  
> Index: gnu/usr.bin/clang/lld/Makefile
> ===
> RCS file: /cvs/src/gnu/usr.bin/clang/lld/Makefile,v
> retrieving revision 1.6
> diff -u -p -u -p -r1.6 Makefile
> --- gnu/usr.bin/clang/lld/Makefile24 Jan 2017 08:44:47 -  1.6
> +++ gnu/usr.bin/clang/lld/Makefile15 Mar 2017 20:21:07 -
> @@ -10,7 +10,9 @@ NOMAN=
>  LDADD+=  -ltermlib
>  DPADD+=  ${LIBTERMLIB}
>  
> +.if ${COMPILER_VERSION:L} == "clang"
>  LINKS=   ${BINDIR}/ld.lld ${BINDIR}/ld
> +.endif
>  
>  CPPFLAGS+=   ${CLANG_INCLUDES}
>  CPPFLAGS+=   -I${.CURDIR}/../../../llvm/tools/lld/include
> 



Re: [patch 1/2] doas(1): Moved some parsing from env.c into parse.y

2017-03-15 Thread Ted Unangst
bytevolc...@safe-mail.net wrote:
> > Also, I'm not sure how you tested this, because it doesn't work like
> > you say it does. setenv { HERE=there } copies both $HERE and $there
> > from the current environment. It does not set HERE=there. That's very
> > wrong.
> > 
> 
> How are you getting that result? Here is what I am getting:
> 
>   $ export HERE=hello
>   $ export there=world
>   $ echo $HERE $there
>   hello world
>   $ doas ~/test.sh
>   HERE is there
>   there is

Did I get it backwards? If you have setenv { HERE= there }, your diff
changes behavior.



Re: syslogd fd_tls variable

2017-03-15 Thread Alexander Bluhm
On Mon, Jan 09, 2017 at 10:46:42AM +0100, Alexander Bluhm wrote:
> To implement multiple tls listen sockets in syslogd, I have to get
> rid of the global variable fd_tls first.

Looks like this diff got forgotten.  Any ok?

> Index: usr.sbin/syslogd/syslogd.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
> retrieving revision 1.227
> diff -u -p -r1.227 syslogd.c
> --- usr.sbin/syslogd/syslogd.c2 Jan 2017 15:58:02 -   1.227
> +++ usr.sbin/syslogd/syslogd.c9 Jan 2017 09:30:25 -
> @@ -272,7 +272,7 @@ size_tctl_reply_offset = 0;   /* Number o
>  char *linebuf;
>  int   linesize;
>  
> -int   fd_ctlconn, fd_udp, fd_udp6, fd_tls;
> +int   fd_ctlconn, fd_udp, fd_udp6;
>  struct event *ev_ctlaccept, *ev_ctlread, *ev_ctlwrite;
>  
>  struct peer {
> @@ -291,6 +291,8 @@ void   unix_readcb(int, short, void *);
>  int   reserve_accept4(int, int, struct event *,
>  void (*)(int, short, void *), struct sockaddr *, socklen_t *, int);
>  void  tcp_acceptcb(int, short, void *);
> +void  tls_acceptcb(int, short, void *);
> +void  acceptcb(int, short, void *, int);
>  int   octet_counting(struct evbuffer *, char **, int);
>  int   non_transparent_framing(struct evbuffer *, char **);
>  void  tcp_readcb(struct bufferevent *, void *);
> @@ -354,7 +356,7 @@ main(int argc, char *argv[])
>   int  ch, i;
>   int  lockpipe[2] = { -1, -1}, pair[2], nullfd, fd;
>   int  fd_ctlsock, fd_klog, fd_sendsys, *fd_bind, *fd_listen;
> - int *fd_unix, nbind, nlisten;
> + int  fd_tls, *fd_unix, nbind, nlisten;
>   char**bind_host, **bind_port, **listen_host, **listen_port;
>   char*tls_hostport, *tls_host, *tls_port;
>  
> @@ -772,7 +774,7 @@ main(int argc, char *argv[])
>   for (i = 0; i < nlisten; i++)
>   event_set(_listen[i], fd_listen[i], EV_READ|EV_PERSIST,
>   tcp_acceptcb, _listen[i]);
> - event_set(ev_tls, fd_tls, EV_READ|EV_PERSIST, tcp_acceptcb, ev_tls);
> + event_set(ev_tls, fd_tls, EV_READ|EV_PERSIST, tls_acceptcb, ev_tls);
>   for (i = 0; i < nunix; i++)
>   event_set(_unix[i], fd_unix[i], EV_READ|EV_PERSIST,
>   unix_readcb, _unix[i]);
> @@ -1088,6 +1090,18 @@ reserve_accept4(int lfd, int event, stru
>  void
>  tcp_acceptcb(int lfd, short event, void *arg)
>  {
> + acceptcb(lfd, event, arg, 0);
> +}
> +
> +void
> +tls_acceptcb(int lfd, short event, void *arg)
> +{
> + acceptcb(lfd, event, arg, 1);
> +}
> +
> +void
> +acceptcb(int lfd, short event, void *arg, int usetls)
> +{
>   struct event*ev = arg;
>   struct peer *p;
>   struct sockaddr_storage  ss;
> @@ -1132,7 +1146,7 @@ tcp_acceptcb(int lfd, short event, void 
>   return;
>   }
>   p->p_ctx = NULL;
> - if (lfd == fd_tls) {
> + if (usetls) {
>   if (tls_accept_socket(server_ctx, >p_ctx, fd) < 0) {
>   snprintf(ebuf, sizeof(ebuf), "tls_accept_socket \"%s\"",
>   peername);



syslogd ttymsg fd leak

2017-03-15 Thread Alexander Bluhm
Hi,

I think there is a file descriotor leak in the syslogd(8) ttymsg()
error path.  When we return early with an error, we must close the
newly opened file descriptor first.

ok?

bluhm

Index: usr.sbin/syslogd/ttymsg.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/ttymsg.c,v
retrieving revision 1.11
diff -u -p -r1.11 ttymsg.c
--- usr.sbin/syslogd/ttymsg.c   16 Aug 2016 18:41:57 -  1.11
+++ usr.sbin/syslogd/ttymsg.c   15 Mar 2017 02:01:34 -
@@ -137,7 +137,7 @@ ttymsg(struct iovec *iov, int iovcnt, ch
if (tty_delayed >= TTYMAXDELAY) {
(void) snprintf(ebuf, sizeof(ebuf),
"%s: too many delayed writes", device);
-   return (ebuf);
+   goto error;
}
logdebug("ttymsg delayed write\n");
if (iov != localiov) {
@@ -148,7 +148,7 @@ ttymsg(struct iovec *iov, int iovcnt, ch
if ((td = malloc(sizeof(*td))) == NULL) {
(void) snprintf(ebuf, sizeof(ebuf),
"%s: malloc: %s", device, strerror(errno));
-   return (ebuf);
+   goto error;
}
td->td_length = 0;
if (left > MAXLINE)
@@ -176,9 +176,10 @@ ttymsg(struct iovec *iov, int iovcnt, ch
 */
if (errno == ENODEV || errno == EIO)
break;
-   (void) close(fd);
(void) snprintf(ebuf, sizeof(ebuf),
"%s: %s", device, strerror(errno));
+ error:
+   (void) close(fd);
return (ebuf);
}
 



Re: SVM instructions

2017-03-15 Thread Mark Kettenis
> Date: Wed, 15 Mar 2017 16:23:33 -0700
> From: Mike Larkin 
> 
> On Wed, Mar 15, 2017 at 09:05:56PM +0100, Mark Kettenis wrote:
> > Clang only accepts SVM instructions with explicit operands, for
> > example:
> > 
> >   vmload %rax
> > 
> > Unfortunately gas doesn't accept this form.  It does accept the
> > instruction without any operands:
> > 
> >   vmload
> > 
> > and the incorrect form:
> > 
> >   vmload (%rax)
> > 
> > The diff below fixes this.
> > 
> > Slight flaw with this diff is that it will also accept the incorrect
> > 
> >   vmload %rbx
> > 
> > which will be silently translated into
> > 
> >   vmload %rax
> > 
> > But I don't think that is a huge issue.
> > 
> > ok?
> > 
> 
> If the svm bits in the tree still build, sure.
> 
> I had planned to change this to a #define like other OSes do but
> this fix is just as good. no complaints from me.

Still builds and produces the same instructions.

> > Index: gnu/usr.bin/binutils-2.17/include/opcode/i386.h
> > ===
> > RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/include/opcode/i386.h,v
> > retrieving revision 1.9
> > diff -u -p -r1.9 i386.h
> > --- gnu/usr.bin/binutils-2.17/include/opcode/i386.h 21 Dec 2015 20:56:22 
> > -  1.9
> > +++ gnu/usr.bin/binutils-2.17/include/opcode/i386.h 15 Mar 2017 19:59:40 
> > -
> > @@ -1464,17 +1464,21 @@ static const template i386_optab[] =
> >  {"clgi", 0, 0x0f01, 0xdd, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> >  {"invlpga",  0, 0x0f01, 0xdf, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> >  /* Need to ensure only "invlpga ...,%ecx" is accepted.  */
> > -{"invlpga",  2, 0x0f01, 0xdf, CpuSVME, NoSuf|ImmExt,   { 
> > AnyMem, Reg32, 0 } },
> > +{"invlpga",  2, 0x0f01, 0xdf, CpuSVME|CpuNo64, NoSuf|ImmExt,   { 
> > Reg32, Reg32, 0 } },
> > +{"invlpga",  2, 0x0f01, 0xdf, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { 
> > Reg64, Reg32, 0 } },
> >  {"skinit",   0, 0x0f01, 0xde, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> > -{"skinit",   1, 0x0f01, 0xde, CpuSVME, NoSuf|ImmExt,   { 
> > AnyMem, 0, 0 } },
> > +{"skinit",   1, 0x0f01, 0xde, CpuSVME, NoSuf|ImmExt,   { 
> > Reg32, 0, 0 } },
> >  {"stgi", 0, 0x0f01, 0xdc, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> >  {"vmload",   0, 0x0f01, 0xda, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> > -{"vmload",   1, 0x0f01, 0xda, CpuSVME, NoSuf|ImmExt,   { 
> > AnyMem, 0, 0 } },
> > +{"vmload",   1, 0x0f01, 0xda, CpuSVME|CpuNo64, NoSuf|ImmExt,   { 
> > Reg32, 0, 0 } },
> > +{"vmload",   1, 0x0f01, 0xda, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { 
> > Reg64, 0, 0 } },
> >  {"vmmcall",  0, 0x0f01, 0xd9, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> >  {"vmrun",0, 0x0f01, 0xd8, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> > -{"vmrun",1, 0x0f01, 0xd8, CpuSVME, NoSuf|ImmExt,   { 
> > AnyMem, 0, 0 } },
> > +{"vmrun",1, 0x0f01, 0xd8, CpuSVME|CpuNo64, NoSuf|ImmExt,   { 
> > Reg32, 0, 0 } },
> > +{"vmrun",1, 0x0f01, 0xd8, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { 
> > Reg64, 0, 0 } },
> >  {"vmsave",   0, 0x0f01, 0xdb, CpuSVME, NoSuf|ImmExt,   { 0, 0, 
> > 0 } },
> > -{"vmsave",   1, 0x0f01, 0xdb, CpuSVME, NoSuf|ImmExt,   { 
> > AnyMem, 0, 0 } },
> > +{"vmsave",   1, 0x0f01, 0xdb, CpuSVME|CpuNo64, NoSuf|ImmExt,   { 
> > Reg32, 0, 0 } },
> > +{"vmsave",   1, 0x0f01, 0xdb, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { 
> > Reg64, 0, 0 } },
> >  
> >  /* VIA PadLock extensions.  */
> >  {"xstore-rng",0, 0x000fa7, 0xc0, Cpu686|CpuPadLock, NoSuf|IsString|ImmExt, 
> > { 0, 0, 0} },
> > 
> > 
> > 
> 



Re: newsyslog timestamp

2017-03-15 Thread Alexander Bluhm
On Mon, Mar 13, 2017 at 11:14:36PM +0100, Alexander Bluhm wrote:
> I think the combination of local time and time zone without fractions
> of seconds is the best choice for newsyslog.  Or should we use
> 2017-03-13T21:30:04.822Z in newsyslogd?

Regarding all the Feedback I summarize:
- we need newsyslog not only for rotating syslogd log files
- there are logfiles without content for a while, so always having
  timestamp at the beginning is useful
- I do not plan to move the rotating functionality into syslogd now
- I stick to RFC 5424 and will not implement another short ISO format

But I came to the conclusion to have a new different format is bad,
so I propose this diff now.

With syslogd -Z you get:

2017-03-15T23:14:09.969Z t430s newsyslog[35784]: logfile turned over
2017-03-15T23:14:50.734Z t430s bluhm: foo

And with this default traditional sylogd format

2017-03-15T23:15:16.743Z t430s newsyslog[32804]: logfile turned over
Mar 16 00:16:20 t430s bluhm: bar

ok?

bluhm

Index: usr.bin/newsyslog/newsyslog.c
===
RCS file: /data/mirror/openbsd/cvs/src/usr.bin/newsyslog/newsyslog.c,v
retrieving revision 1.101
diff -u -p -r1.101 newsyslog.c
--- usr.bin/newsyslog/newsyslog.c   1 Jun 2016 16:57:48 -   1.101
+++ usr.bin/newsyslog/newsyslog.c   15 Mar 2017 23:13:28 -
@@ -142,7 +142,7 @@ int force = 0;  /* Force the logs to be 
 char   *conf = CONF;   /* Configuration file to use */
 time_t timenow;
 char   hostname[HOST_NAME_MAX+1]; /* Hostname */
-char   *daytime;   /* timenow in human readable form */
+char   daytime[33];/* timenow in human readable form */
 char   *arcdir;/* Dir to put archives in (if it exists) */
 
 FILE   *openmail(void);
@@ -402,12 +402,18 @@ send_signal(char *pidfile, int signal)
 void
 parse_args(int argc, char **argv)
 {
+   struct timeval now;
+   struct tm *tm;
+   size_t l;
char *p;
int ch;
 
-   timenow = time(NULL);
-   daytime = ctime() + 4;
-   daytime[15] = '\0';
+   gettimeofday(, NULL);
+   timenow = now.tv_sec;
+   tm = gmtime(_sec);
+   l = strftime(daytime, sizeof(daytime), "%FT%T", tm);
+   snprintf(daytime + l, sizeof(daytime) - l, ".%03ldZ",
+   now.tv_usec / 1000);
 
/* Let's get our hostname */
(void)gethostname(hostname, sizeof(hostname));



Re: SVM instructions

2017-03-15 Thread Mike Larkin
On Wed, Mar 15, 2017 at 09:05:56PM +0100, Mark Kettenis wrote:
> Clang only accepts SVM instructions with explicit operands, for
> example:
> 
>   vmload %rax
> 
> Unfortunately gas doesn't accept this form.  It does accept the
> instruction without any operands:
> 
>   vmload
> 
> and the incorrect form:
> 
>   vmload (%rax)
> 
> The diff below fixes this.
> 
> Slight flaw with this diff is that it will also accept the incorrect
> 
>   vmload %rbx
> 
> which will be silently translated into
> 
>   vmload %rax
> 
> But I don't think that is a huge issue.
> 
> ok?
> 

If the svm bits in the tree still build, sure.

I had planned to change this to a #define like other OSes do but
this fix is just as good. no complaints from me.

> 
> Index: gnu/usr.bin/binutils-2.17/include/opcode/i386.h
> ===
> RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/include/opcode/i386.h,v
> retrieving revision 1.9
> diff -u -p -r1.9 i386.h
> --- gnu/usr.bin/binutils-2.17/include/opcode/i386.h   21 Dec 2015 20:56:22 
> -  1.9
> +++ gnu/usr.bin/binutils-2.17/include/opcode/i386.h   15 Mar 2017 19:59:40 
> -
> @@ -1464,17 +1464,21 @@ static const template i386_optab[] =
>  {"clgi", 0, 0x0f01, 0xdd, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
>  {"invlpga",  0, 0x0f01, 0xdf, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
>  /* Need to ensure only "invlpga ...,%ecx" is accepted.  */
> -{"invlpga",  2, 0x0f01, 0xdf, CpuSVME,   NoSuf|ImmExt,   { 
> AnyMem, Reg32, 0 } },
> +{"invlpga",  2, 0x0f01, 0xdf, CpuSVME|CpuNo64, NoSuf|ImmExt, { Reg32, Reg32, 
> 0 } },
> +{"invlpga",  2, 0x0f01, 0xdf, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 
> Reg32, 0 } },
>  {"skinit",   0, 0x0f01, 0xde, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
> -{"skinit",   1, 0x0f01, 0xde, CpuSVME,   NoSuf|ImmExt,   { 
> AnyMem, 0, 0 } },
> +{"skinit",   1, 0x0f01, 0xde, CpuSVME,   NoSuf|ImmExt,   { 
> Reg32, 0, 0 } },
>  {"stgi", 0, 0x0f01, 0xdc, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
>  {"vmload",   0, 0x0f01, 0xda, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
> -{"vmload",   1, 0x0f01, 0xda, CpuSVME,   NoSuf|ImmExt,   { 
> AnyMem, 0, 0 } },
> +{"vmload",   1, 0x0f01, 0xda, CpuSVME|CpuNo64, NoSuf|ImmExt, { Reg32, 0, 0 } 
> },
> +{"vmload",   1, 0x0f01, 0xda, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 
> 0, 0 } },
>  {"vmmcall",  0, 0x0f01, 0xd9, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
>  {"vmrun",0, 0x0f01, 0xd8, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
> -{"vmrun",1, 0x0f01, 0xd8, CpuSVME,   NoSuf|ImmExt,   { 
> AnyMem, 0, 0 } },
> +{"vmrun",1, 0x0f01, 0xd8, CpuSVME|CpuNo64, NoSuf|ImmExt, { Reg32, 0, 0 } 
> },
> +{"vmrun",1, 0x0f01, 0xd8, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 
> 0, 0 } },
>  {"vmsave",   0, 0x0f01, 0xdb, CpuSVME,   NoSuf|ImmExt,   { 0, 0, 
> 0 } },
> -{"vmsave",   1, 0x0f01, 0xdb, CpuSVME,   NoSuf|ImmExt,   { 
> AnyMem, 0, 0 } },
> +{"vmsave",   1, 0x0f01, 0xdb, CpuSVME|CpuNo64, NoSuf|ImmExt, { Reg32, 0, 0 } 
> },
> +{"vmsave",   1, 0x0f01, 0xdb, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 
> 0, 0 } },
>  
>  /* VIA PadLock extensions.  */
>  {"xstore-rng",0, 0x000fa7, 0xc0, Cpu686|CpuPadLock, NoSuf|IsString|ImmExt, { 
> 0, 0, 0} },
> 
> 
> 



Re: [patch 1/2] doas(1): Moved some parsing from env.c into parse.y

2017-03-15 Thread bytevolcano
On Wed, 15 Mar 2017 13:22:53 -0400
"Ted Unangst"  wrote:
...
> > 1. Loops - Use C99 style initialisation?
> > for(int i = 0; i < monsters; i < 666)  
> 
> No.
> 
> > 3. Anything of major concern.  
> 
> Adding a new character to the lexer potentially breaks existing
> config files.

I was considering that, considering that maybe someone will want
"foo=bar" parameters in their command lines.
Which is why I am thinking it is best to strike here while the iron is
hot rather than, say, 5 years later, when people have come up with
complex and tuned-over-the-years configurations. Not something difficult to
fix either, just enclose in quotes or escape, as necessary with curly
braces.

There is a way around this (such as not moving to "eow" on special
characters, when the lexer is in a 'command-line argument-parsing
mode') but that may require code added to the lexer. How much
extra code is needed, I don't know.

This function of parsing is the lexer's domain, and seems neater than
having what is essentially two separate lexers; all I am doing here is
merging the "mini-lexer" into the main lexer.

> 
> Also, I'm not sure how you tested this, because it doesn't work like
> you say it does. setenv { HERE=there } copies both $HERE and $there
> from the current environment. It does not set HERE=there. That's very
> wrong.
> 

How are you getting that result? Here is what I am getting:

$ export HERE=hello
$ export there=world
$ echo $HERE $there
hello world
$ doas ~/test.sh
HERE is there
there is

The shell script:

#!/bin/sh
echo "HERE" is $HERE
echo "there" is $there

And /etc/doas.conf:

permit persist setenv { HERE=there } :wheel
permit nopass keepenv root

This test behaves correctly on my end.



Re: httpd: expand HTTP Host

2017-03-15 Thread Reyk Floeter
OK reyk - go for it

 Florian Obser :
> 
> This is OK florian@ or I can commit it if someone else OKs it.
> 
>> On Wed, Mar 15, 2017 at 05:55:35PM +, Rivo Nurges wrote:
>> Hi!
>> 
>> New simplified version of the patch.
>> 
>> Test results:
>> HTTP 1.1 with Host:
>> HTTP/1.0 301 Moved Permanently
>> Location: https://testhttp.int/
>> 
>> HTTP 1.0 with Host:
>> HTTP/1.0 301 Moved Permanently
>> Location: https://testhttp.int/
>> 
>> HTTP 1.1 without Host:
>> HTTP/1.0 400 Bad Request
>> 
>> HTTP 1.0 without Host:
>> HTTP/1.0 301 Moved Permanently
>> Location: https://10.10.10.10/
>> 
>> GET /:
>> HTTP/1.0 400 Bad Request
>> 
>> 
>> Rivo
>> 
>> Index: usr.sbin/httpd/server_http.c
>> ===
>> RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
>> retrieving revision 1.115
>> diff -u -p -r1.115 server_http.c
>> --- usr.sbin/httpd/server_http.c10 Mar 2017 21:06:43 -1.115
>> +++ usr.sbin/httpd/server_http.c15 Mar 2017 17:51:14 -
>> @@ -1068,6 +1068,14 @@ server_expand_http(struct client *clt, c
>>if (ret != 0)
>>return (NULL);
>>}
>> +if (strstr(val, "$HTTP_HOST") != NULL) {
>> +if (desc->http_host == NULL)
>> +return (NULL);
>> +if ((str = url_encode(desc->http_host)) == NULL)
>> +return (NULL);
>> +expand_string(buf, len, "$HTTP_HOST", str);
>> +free(str);
>> +}
>>if (strstr(val, "$REMOTE_") != NULL) {
>>if (strstr(val, "$REMOTE_ADDR") != NULL) {
>>if (print_host(>clt_ss,
>> Index: usr.sbin/httpd/httpd.conf.5
>> ===
>> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
>> retrieving revision 1.79
>> diff -u -p -r1.79 httpd.conf.5
>> --- usr.sbin/httpd/httpd.conf.57 Feb 2017 12:27:42 -1.79
>> +++ usr.sbin/httpd/httpd.conf.515 Mar 2017 17:51:14 -
>> @@ -221,6 +221,8 @@ The configured IP address of the server.
>> The configured TCP server port of the server.
>> .It Ic $SERVER_NAME
>> The name of the server.
>> +.It Ic $HTTP_HOST
>> +The host from the HTTP Host header.
>> .It Pf % Ar n
>> The capture index
>> .Ar n
>> 
>> begin-base64 644 http_host.diff
>> SW5kZXg6IHVzci5zYmluL2h0dHBkL3NlcnZlcl9odHRwLmMKPT09PT09PT09PT09PT09PT09PT09
>> PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTog
>> L2N2cy9zcmMvdXNyLnNiaW4vaHR0cGQvc2VydmVyX2h0dHAuYyx2CnJldHJpZXZpbmcgcmV2aXNp
>> b24gMS4xMTUKZGlmZiAtdSAtcCAtcjEuMTE1IHNlcnZlcl9odHRwLmMKLS0tIHVzci5zYmluL2h0
>> dHBkL3NlcnZlcl9odHRwLmMJMTAgTWFyIDIwMTcgMjE6MDY6NDMgLTAwMDAJMS4xMTUKKysrIHVz
>> ci5zYmluL2h0dHBkL3NlcnZlcl9odHRwLmMJMTUgTWFyIDIwMTcgMTc6NTE6MTQgLTAwMDAKQEAg
>> LTEwNjgsNiArMTA2OCwxNCBAQCBzZXJ2ZXJfZXhwYW5kX2h0dHAoc3RydWN0IGNsaWVudCAqY2x0
>> LCBjCiAJCWlmIChyZXQgIT0gMCkKIAkJCXJldHVybiAoTlVMTCk7CiAJfQorCWlmIChzdHJzdHIo
>> dmFsLCAiJEhUVFBfSE9TVCIpICE9IE5VTEwpIHsKKwkJaWYgKGRlc2MtPmh0dHBfaG9zdCA9PSBO
>> VUxMKQorCQkJcmV0dXJuIChOVUxMKTsKKwkJaWYgKChzdHIgPSB1cmxfZW5jb2RlKGRlc2MtPmh0
>> dHBfaG9zdCkpID09IE5VTEwpCisJCQlyZXR1cm4gKE5VTEwpOworCQlleHBhbmRfc3RyaW5nKGJ1
>> ZiwgbGVuLCAiJEhUVFBfSE9TVCIsIHN0cik7CisJCWZyZWUoc3RyKTsKKwl9CiAJaWYgKHN0cnN0
>> cih2YWwsICIkUkVNT1RFXyIpICE9IE5VTEwpIHsKIAkJaWYgKHN0cnN0cih2YWwsICIkUkVNT1RF
>> X0FERFIiKSAhPSBOVUxMKSB7CiAJCQlpZiAocHJpbnRfaG9zdCgmY2x0LT5jbHRfc3MsCkluZGV4
>> OiB1c3Iuc2Jpbi9odHRwZC9odHRwZC5jb25mLjUKPT09PT09PT09PT09PT09PT09PT09PT09PT09
>> PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2N2cy9z
>> cmMvdXNyLnNiaW4vaHR0cGQvaHR0cGQuY29uZi41LHYKcmV0cmlldmluZyByZXZpc2lvbiAxLjc5
>> CmRpZmYgLXUgLXAgLXIxLjc5IGh0dHBkLmNvbmYuNQotLS0gdXNyLnNiaW4vaHR0cGQvaHR0cGQu
>> Y29uZi41CTcgRmViIDIwMTcgMTI6Mjc6NDIgLTAwMDAJMS43OQorKysgdXNyLnNiaW4vaHR0cGQv
>> aHR0cGQuY29uZi41CTE1IE1hciAyMDE3IDE3OjUxOjE0IC0wMDAwCkBAIC0yMjEsNiArMjIxLDgg
>> QEAgVGhlIGNvbmZpZ3VyZWQgSVAgYWRkcmVzcyBvZiB0aGUgc2VydmVyLgogVGhlIGNvbmZpZ3Vy
>> ZWQgVENQIHNlcnZlciBwb3J0IG9mIHRoZSBzZXJ2ZXIuCiAuSXQgSWMgJFNFUlZFUl9OQU1FCiBU
>> aGUgbmFtZSBvZiB0aGUgc2VydmVyLgorLkl0IEljICRIVFRQX0hPU1QKK1RoZSBob3N0IGZyb20g
>> dGhlIEhUVFAgSG9zdCBoZWFkZXIuCiAuSXQgUGYgJSBBciBuCiBUaGUgY2FwdHVyZSBpbmRleAog
>> LkFyIG4K
>>  
>> 
> 
> -- 
> I'm not entirely sure you are real.
> 



Making it easier to install clang alongside gcc

2017-03-15 Thread Mark Kettenis
It's currently a bit of a pain to install clang and ld.lld, but keep
gcc and ld.bfd as the default compiler/linker.  You can't rebuild
clang with base gcc and you really want to rebuild it with clang
instead of the ports gcc after boostrapping.  And overwriting the
default compiler/linker links is annoying.  Especially on platforms
where lld doesn't work yet.  The diff below would make my life easier
and hopefully get more people involved.

This partly reverts the changes made by jsg@ in Brisbane, but I think
we need this if we want clang/lld on more platforms than just arm64.

ok?


Index: gnu/usr.bin/clang/Makefile.inc
===
RCS file: /cvs/src/gnu/usr.bin/clang/Makefile.inc,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 Makefile.inc
--- gnu/usr.bin/clang/Makefile.inc  16 Feb 2017 02:08:42 -  1.4
+++ gnu/usr.bin/clang/Makefile.inc  15 Mar 2017 20:21:06 -
@@ -6,6 +6,9 @@ BOOTSTRAP_CLANG?=no
 .if ${BOOTSTRAP_CLANG} == "yes"
 CC=egcc
 CXX=   eg++
+.else
+CC=clang
+CXX=   clang++
 .endif
 
 DEBUG=
Index: gnu/usr.bin/clang/clang/Makefile
===
RCS file: /cvs/src/gnu/usr.bin/clang/clang/Makefile,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 Makefile
--- gnu/usr.bin/clang/clang/Makefile24 Jan 2017 08:44:47 -  1.6
+++ gnu/usr.bin/clang/clang/Makefile15 Mar 2017 20:21:06 -
@@ -13,15 +13,18 @@ LDADD+= -ltermlib
 DPADD+=${LIBTERMLIB}
 
 LINKS= ${BINDIR}/clang ${BINDIR}/clang++ \
-   ${BINDIR}/clang ${BINDIR}/clang-cpp \
-   ${BINDIR}/clang ${BINDIR}/cc \
+   ${BINDIR}/clang ${BINDIR}/clang-cpp
+MLINKS=clang.1 clang++.1 \
+   clang.1 clang-cpp.1
+
+.if ${COMPILER_VERSION:L} == "clang"
+LINKS+=${BINDIR}/clang ${BINDIR}/cc \
${BINDIR}/clang ${BINDIR}/c++ \
${BINDIR}/clang ${LIBEXECDIR}/cpp
-MLINKS=clang.1 clang++.1 \
-   clang.1 clang-cpp.1 \
-   clang.1 cc.1 \
+MLINKS+=clang.1 cc.1 \
clang.1 c++.1 \
clang.1 cpp.1
+.endif
 
 CPPFLAGS+= -I${.CURDIR}/../../../llvm/tools/clang/include
 
Index: gnu/usr.bin/clang/lld/Makefile
===
RCS file: /cvs/src/gnu/usr.bin/clang/lld/Makefile,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 Makefile
--- gnu/usr.bin/clang/lld/Makefile  24 Jan 2017 08:44:47 -  1.6
+++ gnu/usr.bin/clang/lld/Makefile  15 Mar 2017 20:21:07 -
@@ -10,7 +10,9 @@ NOMAN=
 LDADD+=-ltermlib
 DPADD+=${LIBTERMLIB}
 
+.if ${COMPILER_VERSION:L} == "clang"
 LINKS= ${BINDIR}/ld.lld ${BINDIR}/ld
+.endif
 
 CPPFLAGS+= ${CLANG_INCLUDES}
 CPPFLAGS+= -I${.CURDIR}/../../../llvm/tools/lld/include



Re: httpd: expand HTTP Host

2017-03-15 Thread Florian Obser
This is OK florian@ or I can commit it if someone else OKs it.

On Wed, Mar 15, 2017 at 05:55:35PM +, Rivo Nurges wrote:
> Hi!
> 
> New simplified version of the patch.
> 
> Test results:
> HTTP 1.1 with Host:
> HTTP/1.0 301 Moved Permanently
> Location: https://testhttp.int/
> 
> HTTP 1.0 with Host:
> HTTP/1.0 301 Moved Permanently
> Location: https://testhttp.int/
> 
> HTTP 1.1 without Host:
> HTTP/1.0 400 Bad Request
> 
> HTTP 1.0 without Host:
> HTTP/1.0 301 Moved Permanently
> Location: https://10.10.10.10/
> 
> GET /:
> HTTP/1.0 400 Bad Request
> 
> 
> Rivo
> 
> Index: usr.sbin/httpd/server_http.c
> ===
> RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
> retrieving revision 1.115
> diff -u -p -r1.115 server_http.c
> --- usr.sbin/httpd/server_http.c  10 Mar 2017 21:06:43 -  1.115
> +++ usr.sbin/httpd/server_http.c  15 Mar 2017 17:51:14 -
> @@ -1068,6 +1068,14 @@ server_expand_http(struct client *clt, c
>   if (ret != 0)
>   return (NULL);
>   }
> + if (strstr(val, "$HTTP_HOST") != NULL) {
> + if (desc->http_host == NULL)
> + return (NULL);
> + if ((str = url_encode(desc->http_host)) == NULL)
> + return (NULL);
> + expand_string(buf, len, "$HTTP_HOST", str);
> + free(str);
> + }
>   if (strstr(val, "$REMOTE_") != NULL) {
>   if (strstr(val, "$REMOTE_ADDR") != NULL) {
>   if (print_host(>clt_ss,
> Index: usr.sbin/httpd/httpd.conf.5
> ===
> RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
> retrieving revision 1.79
> diff -u -p -r1.79 httpd.conf.5
> --- usr.sbin/httpd/httpd.conf.5   7 Feb 2017 12:27:42 -   1.79
> +++ usr.sbin/httpd/httpd.conf.5   15 Mar 2017 17:51:14 -
> @@ -221,6 +221,8 @@ The configured IP address of the server.
>  The configured TCP server port of the server.
>  .It Ic $SERVER_NAME
>  The name of the server.
> +.It Ic $HTTP_HOST
> +The host from the HTTP Host header.
>  .It Pf % Ar n
>  The capture index
>  .Ar n
> 
> begin-base64 644 http_host.diff
> SW5kZXg6IHVzci5zYmluL2h0dHBkL3NlcnZlcl9odHRwLmMKPT09PT09PT09PT09PT09PT09PT09
> PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTog
> L2N2cy9zcmMvdXNyLnNiaW4vaHR0cGQvc2VydmVyX2h0dHAuYyx2CnJldHJpZXZpbmcgcmV2aXNp
> b24gMS4xMTUKZGlmZiAtdSAtcCAtcjEuMTE1IHNlcnZlcl9odHRwLmMKLS0tIHVzci5zYmluL2h0
> dHBkL3NlcnZlcl9odHRwLmMJMTAgTWFyIDIwMTcgMjE6MDY6NDMgLTAwMDAJMS4xMTUKKysrIHVz
> ci5zYmluL2h0dHBkL3NlcnZlcl9odHRwLmMJMTUgTWFyIDIwMTcgMTc6NTE6MTQgLTAwMDAKQEAg
> LTEwNjgsNiArMTA2OCwxNCBAQCBzZXJ2ZXJfZXhwYW5kX2h0dHAoc3RydWN0IGNsaWVudCAqY2x0
> LCBjCiAJCWlmIChyZXQgIT0gMCkKIAkJCXJldHVybiAoTlVMTCk7CiAJfQorCWlmIChzdHJzdHIo
> dmFsLCAiJEhUVFBfSE9TVCIpICE9IE5VTEwpIHsKKwkJaWYgKGRlc2MtPmh0dHBfaG9zdCA9PSBO
> VUxMKQorCQkJcmV0dXJuIChOVUxMKTsKKwkJaWYgKChzdHIgPSB1cmxfZW5jb2RlKGRlc2MtPmh0
> dHBfaG9zdCkpID09IE5VTEwpCisJCQlyZXR1cm4gKE5VTEwpOworCQlleHBhbmRfc3RyaW5nKGJ1
> ZiwgbGVuLCAiJEhUVFBfSE9TVCIsIHN0cik7CisJCWZyZWUoc3RyKTsKKwl9CiAJaWYgKHN0cnN0
> cih2YWwsICIkUkVNT1RFXyIpICE9IE5VTEwpIHsKIAkJaWYgKHN0cnN0cih2YWwsICIkUkVNT1RF
> X0FERFIiKSAhPSBOVUxMKSB7CiAJCQlpZiAocHJpbnRfaG9zdCgmY2x0LT5jbHRfc3MsCkluZGV4
> OiB1c3Iuc2Jpbi9odHRwZC9odHRwZC5jb25mLjUKPT09PT09PT09PT09PT09PT09PT09PT09PT09
> PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2N2cy9z
> cmMvdXNyLnNiaW4vaHR0cGQvaHR0cGQuY29uZi41LHYKcmV0cmlldmluZyByZXZpc2lvbiAxLjc5
> CmRpZmYgLXUgLXAgLXIxLjc5IGh0dHBkLmNvbmYuNQotLS0gdXNyLnNiaW4vaHR0cGQvaHR0cGQu
> Y29uZi41CTcgRmViIDIwMTcgMTI6Mjc6NDIgLTAwMDAJMS43OQorKysgdXNyLnNiaW4vaHR0cGQv
> aHR0cGQuY29uZi41CTE1IE1hciAyMDE3IDE3OjUxOjE0IC0wMDAwCkBAIC0yMjEsNiArMjIxLDgg
> QEAgVGhlIGNvbmZpZ3VyZWQgSVAgYWRkcmVzcyBvZiB0aGUgc2VydmVyLgogVGhlIGNvbmZpZ3Vy
> ZWQgVENQIHNlcnZlciBwb3J0IG9mIHRoZSBzZXJ2ZXIuCiAuSXQgSWMgJFNFUlZFUl9OQU1FCiBU
> aGUgbmFtZSBvZiB0aGUgc2VydmVyLgorLkl0IEljICRIVFRQX0hPU1QKK1RoZSBob3N0IGZyb20g
> dGhlIEhUVFAgSG9zdCBoZWFkZXIuCiAuSXQgUGYgJSBBciBuCiBUaGUgY2FwdHVyZSBpbmRleAog
> LkFyIG4K
>  
> 

-- 
I'm not entirely sure you are real.



SVM instructions

2017-03-15 Thread Mark Kettenis
Clang only accepts SVM instructions with explicit operands, for
example:

  vmload %rax

Unfortunately gas doesn't accept this form.  It does accept the
instruction without any operands:

  vmload

and the incorrect form:

  vmload (%rax)

The diff below fixes this.

Slight flaw with this diff is that it will also accept the incorrect

  vmload %rbx

which will be silently translated into

  vmload %rax

But I don't think that is a huge issue.

ok?


Index: gnu/usr.bin/binutils-2.17/include/opcode/i386.h
===
RCS file: /cvs/src/gnu/usr.bin/binutils-2.17/include/opcode/i386.h,v
retrieving revision 1.9
diff -u -p -r1.9 i386.h
--- gnu/usr.bin/binutils-2.17/include/opcode/i386.h 21 Dec 2015 20:56:22 
-  1.9
+++ gnu/usr.bin/binutils-2.17/include/opcode/i386.h 15 Mar 2017 19:59:40 
-
@@ -1464,17 +1464,21 @@ static const template i386_optab[] =
 {"clgi", 0, 0x0f01, 0xdd, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
 {"invlpga",  0, 0x0f01, 0xdf, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
 /* Need to ensure only "invlpga ...,%ecx" is accepted.  */
-{"invlpga",  2, 0x0f01, 0xdf, CpuSVME, NoSuf|ImmExt,   { AnyMem, 
Reg32, 0 } },
+{"invlpga",  2, 0x0f01, 0xdf, CpuSVME|CpuNo64, NoSuf|ImmExt,   { Reg32, Reg32, 
0 } },
+{"invlpga",  2, 0x0f01, 0xdf, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 
Reg32, 0 } },
 {"skinit",   0, 0x0f01, 0xde, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
-{"skinit",   1, 0x0f01, 0xde, CpuSVME, NoSuf|ImmExt,   { AnyMem, 0, 0 
} },
+{"skinit",   1, 0x0f01, 0xde, CpuSVME, NoSuf|ImmExt,   { Reg32, 0, 0 } 
},
 {"stgi", 0, 0x0f01, 0xdc, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
 {"vmload",   0, 0x0f01, 0xda, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
-{"vmload",   1, 0x0f01, 0xda, CpuSVME, NoSuf|ImmExt,   { AnyMem, 0, 0 
} },
+{"vmload",   1, 0x0f01, 0xda, CpuSVME|CpuNo64, NoSuf|ImmExt,   { Reg32, 0, 0 } 
},
+{"vmload",   1, 0x0f01, 0xda, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 0, 
0 } },
 {"vmmcall",  0, 0x0f01, 0xd9, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
 {"vmrun",0, 0x0f01, 0xd8, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
-{"vmrun",1, 0x0f01, 0xd8, CpuSVME, NoSuf|ImmExt,   { AnyMem, 0, 0 
} },
+{"vmrun",1, 0x0f01, 0xd8, CpuSVME|CpuNo64, NoSuf|ImmExt,   { Reg32, 0, 0 } 
},
+{"vmrun",1, 0x0f01, 0xd8, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 0, 
0 } },
 {"vmsave",   0, 0x0f01, 0xdb, CpuSVME, NoSuf|ImmExt,   { 0, 0, 0 } },
-{"vmsave",   1, 0x0f01, 0xdb, CpuSVME, NoSuf|ImmExt,   { AnyMem, 0, 0 
} },
+{"vmsave",   1, 0x0f01, 0xdb, CpuSVME|CpuNo64, NoSuf|ImmExt,   { Reg32, 0, 0 } 
},
+{"vmsave",   1, 0x0f01, 0xdb, CpuSVME|Cpu64, NoSuf|ImmExt|NoRex64, { Reg64, 0, 
0 } },
 
 /* VIA PadLock extensions.  */
 {"xstore-rng",0, 0x000fa7, 0xc0, Cpu686|CpuPadLock, NoSuf|IsString|ImmExt, { 
0, 0, 0} },





Re: httpd: expand HTTP Host

2017-03-15 Thread Rivo Nurges
Hi!

New simplified version of the patch.

Test results:
HTTP 1.1 with Host:
HTTP/1.0 301 Moved Permanently
Location: https://testhttp.int/

HTTP 1.0 with Host:
HTTP/1.0 301 Moved Permanently
Location: https://testhttp.int/

HTTP 1.1 without Host:
HTTP/1.0 400 Bad Request

HTTP 1.0 without Host:
HTTP/1.0 301 Moved Permanently
Location: https://10.10.10.10/

GET /:
HTTP/1.0 400 Bad Request


Rivo

Index: usr.sbin/httpd/server_http.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.115
diff -u -p -r1.115 server_http.c
--- usr.sbin/httpd/server_http.c10 Mar 2017 21:06:43 -  1.115
+++ usr.sbin/httpd/server_http.c15 Mar 2017 17:51:14 -
@@ -1068,6 +1068,14 @@ server_expand_http(struct client *clt, c
if (ret != 0)
return (NULL);
}
+   if (strstr(val, "$HTTP_HOST") != NULL) {
+   if (desc->http_host == NULL)
+   return (NULL);
+   if ((str = url_encode(desc->http_host)) == NULL)
+   return (NULL);
+   expand_string(buf, len, "$HTTP_HOST", str);
+   free(str);
+   }
if (strstr(val, "$REMOTE_") != NULL) {
if (strstr(val, "$REMOTE_ADDR") != NULL) {
if (print_host(>clt_ss,
Index: usr.sbin/httpd/httpd.conf.5
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.79
diff -u -p -r1.79 httpd.conf.5
--- usr.sbin/httpd/httpd.conf.5 7 Feb 2017 12:27:42 -   1.79
+++ usr.sbin/httpd/httpd.conf.5 15 Mar 2017 17:51:14 -
@@ -221,6 +221,8 @@ The configured IP address of the server.
 The configured TCP server port of the server.
 .It Ic $SERVER_NAME
 The name of the server.
+.It Ic $HTTP_HOST
+The host from the HTTP Host header.
 .It Pf % Ar n
 The capture index
 .Ar n

begin-base64 644 http_host.diff
SW5kZXg6IHVzci5zYmluL2h0dHBkL3NlcnZlcl9odHRwLmMKPT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTog
L2N2cy9zcmMvdXNyLnNiaW4vaHR0cGQvc2VydmVyX2h0dHAuYyx2CnJldHJpZXZpbmcgcmV2aXNp
b24gMS4xMTUKZGlmZiAtdSAtcCAtcjEuMTE1IHNlcnZlcl9odHRwLmMKLS0tIHVzci5zYmluL2h0
dHBkL3NlcnZlcl9odHRwLmMJMTAgTWFyIDIwMTcgMjE6MDY6NDMgLTAwMDAJMS4xMTUKKysrIHVz
ci5zYmluL2h0dHBkL3NlcnZlcl9odHRwLmMJMTUgTWFyIDIwMTcgMTc6NTE6MTQgLTAwMDAKQEAg
LTEwNjgsNiArMTA2OCwxNCBAQCBzZXJ2ZXJfZXhwYW5kX2h0dHAoc3RydWN0IGNsaWVudCAqY2x0
LCBjCiAJCWlmIChyZXQgIT0gMCkKIAkJCXJldHVybiAoTlVMTCk7CiAJfQorCWlmIChzdHJzdHIo
dmFsLCAiJEhUVFBfSE9TVCIpICE9IE5VTEwpIHsKKwkJaWYgKGRlc2MtPmh0dHBfaG9zdCA9PSBO
VUxMKQorCQkJcmV0dXJuIChOVUxMKTsKKwkJaWYgKChzdHIgPSB1cmxfZW5jb2RlKGRlc2MtPmh0
dHBfaG9zdCkpID09IE5VTEwpCisJCQlyZXR1cm4gKE5VTEwpOworCQlleHBhbmRfc3RyaW5nKGJ1
ZiwgbGVuLCAiJEhUVFBfSE9TVCIsIHN0cik7CisJCWZyZWUoc3RyKTsKKwl9CiAJaWYgKHN0cnN0
cih2YWwsICIkUkVNT1RFXyIpICE9IE5VTEwpIHsKIAkJaWYgKHN0cnN0cih2YWwsICIkUkVNT1RF
X0FERFIiKSAhPSBOVUxMKSB7CiAJCQlpZiAocHJpbnRfaG9zdCgmY2x0LT5jbHRfc3MsCkluZGV4
OiB1c3Iuc2Jpbi9odHRwZC9odHRwZC5jb25mLjUKPT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2N2cy9z
cmMvdXNyLnNiaW4vaHR0cGQvaHR0cGQuY29uZi41LHYKcmV0cmlldmluZyByZXZpc2lvbiAxLjc5
CmRpZmYgLXUgLXAgLXIxLjc5IGh0dHBkLmNvbmYuNQotLS0gdXNyLnNiaW4vaHR0cGQvaHR0cGQu
Y29uZi41CTcgRmViIDIwMTcgMTI6Mjc6NDIgLTAwMDAJMS43OQorKysgdXNyLnNiaW4vaHR0cGQv
aHR0cGQuY29uZi41CTE1IE1hciAyMDE3IDE3OjUxOjE0IC0wMDAwCkBAIC0yMjEsNiArMjIxLDgg
QEAgVGhlIGNvbmZpZ3VyZWQgSVAgYWRkcmVzcyBvZiB0aGUgc2VydmVyLgogVGhlIGNvbmZpZ3Vy
ZWQgVENQIHNlcnZlciBwb3J0IG9mIHRoZSBzZXJ2ZXIuCiAuSXQgSWMgJFNFUlZFUl9OQU1FCiBU
aGUgbmFtZSBvZiB0aGUgc2VydmVyLgorLkl0IEljICRIVFRQX0hPU1QKK1RoZSBob3N0IGZyb20g
dGhlIEhUVFAgSG9zdCBoZWFkZXIuCiAuSXQgUGYgJSBBciBuCiBUaGUgY2FwdHVyZSBpbmRleAog
LkFyIG4K
 



Re: [patch 1/2] doas(1): Moved some parsing from env.c into parse.y

2017-03-15 Thread Ted Unangst
bytevolc...@safe-mail.net wrote:
> Instead of having to use another 1KB buffer just to figure out where
> the '=' sign is, use the parser infrastructure already present. Also
> allows for variable timeout option. Another (negligible) advantage: if
> one day someone wants to change the maximum line length, they only need
> to do so in one spot.
> 
> I haven't touched the code in env.c that handles the '-' and '$' since
> these are extremely simple anyway, and aren't needed for the next patch.
> 
> This patch doesn't need changes to doas(1) or doas.conf(5) man pages, but 
> there
> is no mention of characters that are required to be escaped when specifying 
> args.
> Tested with all kinds of variable names and values, works fine:
> 
>   ... keepenv { FIRE SWITCH=1 NO_PLACE_LIKE=$HOME WATER}
> 
> Things I would like feedback on, in particular:
> 
> 1. Loops - Use C99 style initialisation?
>   for(int i = 0; i < monsters; i < 666)

No.

> 3. Anything of major concern.

Adding a new character to the lexer potentially breaks existing config files.

Also, I'm not sure how you tested this, because it doesn't work like you say
it does. setenv { HERE=there } copies both $HERE and $there from the current
environment. It does not set HERE=there. That's very wrong.



Re: whois: remove pointless realloc()

2017-03-15 Thread Theo de Raadt
> - for (name = *argv; (name = *argv) != NULL; argv++)
> - rval += whois(name, host ? host : choose_server(name, country),
> - port_whois, flags);
> - exit(rval);
> + for (name = *argv; (name = *argv) != NULL; argv++) {
> + server = host ? host : choose_server(name, country);
> + rval += whois(name, server, port_whois, flags);
> + if (host == NULL)
> + free(server);

 4 byte indent should be tab

> + }
> + return (rval);
>  }

Looks good to me.



Re: whois: remove pointless realloc()

2017-03-15 Thread Todd C. Miller
On Wed, 15 Mar 2017 09:57:26 -0600, "Todd C. Miller" wrote:

> There's no need to realloc() a chunk of memory when you don't care
> about the old contents, we don't want have to memcpy() the old
> contents to the new chunk only to throw it away.
> While here, use asprintf() to simplify things.

Updated diff that frees the server string if it is allocated.  We
are headed for exit() anyway but if there are multiple things being
looked up it is probably best to clean up before going on to the
next one.

 - todd

Index: usr.bin/whois/whois.c
===
RCS file: /cvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.53
diff -u -p -u -r1.53 whois.c
--- usr.bin/whois/whois.c   9 Dec 2015 19:29:49 -   1.53
+++ usr.bin/whois/whois.c   15 Mar 2017 16:21:20 -
@@ -79,7 +79,7 @@ int
 main(int argc, char *argv[])
 {
int ch, flags, rval;
-   char *host, *name, *country;
+   char *host, *name, *country, *server;
 
country = host = NULL;
flags = rval = 0;
@@ -147,10 +147,13 @@ main(int argc, char *argv[])
 
if (host == NULL && country == NULL && !(flags & WHOIS_QUICK))
flags |= WHOIS_RECURSE;
-   for (name = *argv; (name = *argv) != NULL; argv++)
-   rval += whois(name, host ? host : choose_server(name, country),
-   port_whois, flags);
-   exit(rval);
+   for (name = *argv; (name = *argv) != NULL; argv++) {
+   server = host ? host : choose_server(name, country);
+   rval += whois(name, server, port_whois, flags);
+   if (host == NULL)
+   free(server);
+   }
+   return (rval);
 }
 
 int
@@ -279,11 +282,9 @@ whois(const char *query, const char *ser
 char *
 choose_server(const char *name, const char *country)
 {
-   static char *server;
+   char *server;
const char *qhead;
-   char *nserver;
char *ep;
-   size_t len;
struct addrinfo hints, *res;
 
memset(, 0, sizeof(hints));
@@ -307,16 +308,13 @@ choose_server(const char *name, const ch
return (NICHOST);
} else if (isdigit((unsigned char)*(++qhead)))
return (ANICHOST);
-   len = strlen(qhead) + sizeof(QNICHOST_TAIL);
-   if ((nserver = realloc(server, len)) == NULL)
-   err(1, "realloc");
-   server = nserver;
 
/*
 * Post-2003 ("new") gTLDs are all supposed to have "whois.nic.domain"
 * (per registry agreement), some older gTLDs also support this...
 */
-   snprintf(server, len, "whois.nic.%s", qhead);
+   if (asprintf(, "whois.nic.%s", qhead) == -1)
+   err(1, NULL);
 
/* most ccTLDs don't do this, but QNICHOST/whois-servers mostly works */
if ((strlen(qhead) == 2 ||
@@ -333,8 +331,9 @@ choose_server(const char *name, const ch
strcasecmp(qhead, "museum") == 0 ||
 /* for others, if whois.nic.TLD doesn't exist, try whois-servers */
getaddrinfo(server, NULL, , ) != 0)) {
-   strlcpy(server, qhead, len);
-   strlcat(server, QNICHOST_TAIL, len);
+   free(server);
+   if (asprintf(, "%s%s", qhead, QNICHOST_TAIL) == -1)
+   err(1, NULL);
}
 
return (server);



whois: remove pointless realloc()

2017-03-15 Thread Todd C. Miller
There's no need to realloc() a chunk of memory when you don't care
about the old contents, we don't want have to memcpy() the old
contents to the new chunk only to throw it away.
While here, use asprintf() to simplify things.

 - todd

Index: usr.bin/whois/whois.c
===
RCS file: /cvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.53
diff -u -p -u -r1.53 whois.c
--- usr.bin/whois/whois.c   9 Dec 2015 19:29:49 -   1.53
+++ usr.bin/whois/whois.c   15 Mar 2017 15:51:58 -
@@ -279,11 +279,9 @@ whois(const char *query, const char *ser
 char *
 choose_server(const char *name, const char *country)
 {
-   static char *server;
+   char *server;
const char *qhead;
-   char *nserver;
char *ep;
-   size_t len;
struct addrinfo hints, *res;
 
memset(, 0, sizeof(hints));
@@ -307,16 +305,13 @@ choose_server(const char *name, const ch
return (NICHOST);
} else if (isdigit((unsigned char)*(++qhead)))
return (ANICHOST);
-   len = strlen(qhead) + sizeof(QNICHOST_TAIL);
-   if ((nserver = realloc(server, len)) == NULL)
-   err(1, "realloc");
-   server = nserver;
 
/*
 * Post-2003 ("new") gTLDs are all supposed to have "whois.nic.domain"
 * (per registry agreement), some older gTLDs also support this...
 */
-   snprintf(server, len, "whois.nic.%s", qhead);
+   if (asprintf(, "whois.nic.%s", qhead) == -1)
+   err(1, NULL);
 
/* most ccTLDs don't do this, but QNICHOST/whois-servers mostly works */
if ((strlen(qhead) == 2 ||
@@ -333,8 +328,9 @@ choose_server(const char *name, const ch
strcasecmp(qhead, "museum") == 0 ||
 /* for others, if whois.nic.TLD doesn't exist, try whois-servers */
getaddrinfo(server, NULL, , ) != 0)) {
-   strlcpy(server, qhead, len);
-   strlcat(server, QNICHOST_TAIL, len);
+   free(server);
+   if (asprintf(, "%s%s", qhead, QNICHOST_TAIL) == -1)
+   err(1, NULL);
}
 
return (server);



[patch 1/2] doas(1): Moved some parsing from env.c into parse.y

2017-03-15 Thread bytevolcano
Instead of having to use another 1KB buffer just to figure out where
the '=' sign is, use the parser infrastructure already present. Also
allows for variable timeout option. Another (negligible) advantage: if
one day someone wants to change the maximum line length, they only need
to do so in one spot.

I haven't touched the code in env.c that handles the '-' and '$' since
these are extremely simple anyway, and aren't needed for the next patch.

This patch doesn't need changes to doas(1) or doas.conf(5) man pages, but there
is no mention of characters that are required to be escaped when specifying 
args.
Tested with all kinds of variable names and values, works fine:

... keepenv { FIRE SWITCH=1 NO_PLACE_LIKE=$HOME WATER}

Things I would like feedback on, in particular:

1. Loops - Use C99 style initialisation?
for(int i = 0; i < monsters; i < 666)
...

2. Initialisation of arrays of two-member structs, where one member
   is initially set to NULL:

struct envar safeset[] = {{"DISPLAY"}, {"HOME"}, ...};
   or
struct envar safeset[] = {{"DISPLAY",NULL}, {"HOME",NULL}, ...};

3. Anything of major concern.

 - - - - - - - - - - - - - - - - - 

Index: usr.bin/doas/doas.h
===
RCS file: /cvs/src/usr.bin/doas/doas.h,v
retrieving revision 1.12
diff -u -p -r1.12 doas.h
--- usr.bin/doas/doas.h 5 Oct 2016 17:40:25 -   1.12
+++ usr.bin/doas/doas.h 15 Mar 2017 15:11:31 -
@@ -15,6 +15,11 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+struct envar {
+   const char *name;
+   const char *value;
+};
+
 struct rule {
int action;
int options;
@@ -22,7 +27,7 @@ struct rule {
const char *target;
const char *cmd;
const char **cmdargs;
-   const char **envlist;
+   struct envar *envlist;
 };
 
 extern struct rule **rules;
Index: usr.bin/doas/env.c
===
RCS file: /cvs/src/usr.bin/doas/env.c,v
retrieving revision 1.5
diff -u -p -r1.5 env.c
--- usr.bin/doas/env.c  15 Sep 2016 00:58:23 -  1.5
+++ usr.bin/doas/env.c  15 Mar 2017 15:11:31 -
@@ -134,51 +134,39 @@ flattenenv(struct env *env)
 }
 
 static void
-fillenv(struct env *env, const char **envlist)
+fillenv(struct env *env, const struct envar *envlist)
 {
struct envnode *node, key;
-   const char *e, *eq;
+   struct envar ev;
const char *val;
-   char name[1024];
u_int i;
-   size_t len;
 
-   for (i = 0; envlist[i]; i++) {
-   e = envlist[i];
-
-   /* parse out env name */
-   if ((eq = strchr(e, '=')) == NULL)
-   len = strlen(e);
-   else
-   len = eq - e;
-   if (len > sizeof(name) - 1)
-   continue;
-   memcpy(name, e, len);
-   name[len] = '\0';
+   for (i = 0; envlist[i].name; i++) {
+   ev = envlist[i];
 
/* delete previous copies */
-   key.key = name;
-   if (*name == '-')
-   key.key = name + 1;
+   key.key = ev.name;
+   if (*ev.name == '-')
+   key.key = ev.name + 1;
if ((node = RB_FIND(envtree, >root, ))) {
RB_REMOVE(envtree, >root, node);
freenode(node);
env->count--;
}
-   if (*name == '-')
+   if (*ev.name == '-')
continue;
 
/* assign value or inherit from environ */
-   if (eq) {
-   val = eq + 1;
+   if (ev.value) {
+   val = ev.value;
if (*val == '$')
val = getenv(val + 1);
} else {
-   val = getenv(name);
+   val = getenv(ev.name);
}
/* at last, we have something to insert */
if (val) {
-   node = createnode(name, val);
+   node = createnode(ev.name, val);
RB_INSERT(envtree, >root, node);
env->count++;
}
@@ -188,10 +176,10 @@ fillenv(struct env *env, const char **en
 char **
 prepenv(struct rule *rule)
 {
-   static const char *safeset[] = {
-   "DISPLAY", "HOME", "LOGNAME", "MAIL",
-   "PATH", "TERM", "USER", "USERNAME",
-   NULL
+   static const struct envar safeset[] = {
+   {"DISPLAY"}, {"HOME"}, {"LOGNAME"}, {"MAIL"},
+   {"PATH"}, {"TERM"}, {"USER"}, {"USERNAME"},
+   {NULL}
};
struct env *env;
 
Index: usr.bin/doas/parse.y

Re: man.cgi(8): add unique HTML titles

2017-03-15 Thread Ingo Schwarze
Hi,

Anton Lindqvist wrote on Sun, Feb 05, 2017 at 10:30:32AM +0100:

> Here's a proposal to add unique HTML titles to man-pages served
> using man.cgi.  The name of the man-page is used as a title prefix

That made sense to me, so i committed the version below
and installed it on man.openbsd.org.  Please tell me if you see
anything that goes wrong.

> (inspired by NetBSD's adoption of mandoc).

What?  They talked about wanting to use the mandoc-based man.cgi(8)
in the past, but it doesn't look like they actually implemented it.
The following still uses some other man.cgi implementation:

  http://netbsd.gw.com/cgi-bin/man-cgi

But it does have the manual page name and section prefixed to
the HTML title, maybe that's what you meant.

> There might be a more elegant way to produce the title given the
> filename.

True, ETOOMUCHMALLOC.

I implemented it as shown below, without any additional dynamic
memory allocation.

Thanks for the idea and the patch,
  Ingo


Log Message:
---
Mention the manual page name and section in the HTML page .
Based on a patch from ,
but simplified and also covering apropos(1) search results.

Modified Files:
--
mdocml:
cgi.c
man.cgi.3

Revision Data
-
Index: cgi.c
===
RCS file: /home/cvs/mdocml/mdocml/cgi.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -Lcgi.c -Lcgi.c -u -p -r1.149 -r1.150
--- cgi.c
+++ cgi.c
@@ -81,7 +81,7 @@ staticvoid pg_search(const struct req
 static void pg_searchres(const struct req *,
struct manpage *, size_t);
 static void pg_show(struct req *, const char *);
-static void resp_begin_html(int, const char *);
+static void resp_begin_html(int, const char *, const char *);
 static void resp_begin_http(int, const char *);
 static void resp_catman(const struct req *, const char *);
 static void resp_copy(const char *);
@@ -346,8 +346,9 @@ resp_copy(const char *filename)
 }
 
 static void
-resp_begin_html(int code, const char *msg)
+resp_begin_html(int code, const char *msg, const char *file)
 {
+   char*cp;
 
resp_begin_http(code, msg);
 
@@ -357,10 +358,20 @@ resp_begin_html(int code, const char *ms
   "  \n"
   "  \n"
-  "  %s\n"
+  "  ",
+  CSS_DIR);
+   if (file != NULL) {
+   if ((cp = strrchr(file, '/')) != NULL)
+   file = cp + 1;
+   if ((cp = strrchr(file, '.')) != NULL) {
+   printf("%.*s(%s) - ", (int)(cp - file), file, cp + 1);
+   } else
+   printf("%s - ", file);
+   }
+   printf("%s\n"
   "\n"
   "\n",
-  CSS_DIR, CUSTOMIZE_TITLE);
+  CUSTOMIZE_TITLE);
 
resp_copy(MAN_DIR "/header.html");
 }
@@ -493,7 +504,7 @@ static void
 pg_index(const struct req *req)
 {
 
-   resp_begin_html(200, NULL);
+   resp_begin_html(200, NULL, NULL);
resp_searchform(req, FOCUS_QUERY);
printf("\n"
   "This web interface is documented in the\n"
@@ -510,7 +521,7 @@ pg_index(const struct req *req)
 static void
 pg_noresult(const struct req *req, const char *msg)
 {
-   resp_begin_html(200, NULL);
+   resp_begin_html(200, NULL, NULL);
resp_searchform(req, FOCUS_QUERY);
puts("");
puts(msg);
@@ -522,7 +533,7 @@ static void
 pg_error_badrequest(const char *msg)
 {
 
-   resp_begin_html(400, "Bad Request");
+   resp_begin_html(400, "Bad Request", NULL);
puts("Bad Request\n"
 "\n");
puts(msg);
@@ -535,7 +546,7 @@ pg_error_badrequest(const char *msg)
 static void
 pg_error_internal(void)
 {
-   resp_begin_html(500, "Internal Server Error");
+   resp_begin_html(500, "Internal Server Error", NULL);
puts("Internal Server Error");
resp_end_html();
 }
@@ -591,36 +602,13 @@ pg_searchres(const struct req *req, stru
return;
}
 
-   resp_begin_html(200, NULL);
-   resp_searchform(req,
-   req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);
-
-   if (sz > 1) {
-   puts("");
-   for (i = 0; i < sz; i++) {
-   printf("  \n"
-  ""
-  "",
-   scriptname, *scriptname == '\0' ? "" : "/",
-   req->q.manpath, r[i].file);
-   html_print(r[i].names);
-   printf("\n"
-  "");
-   html_print(r[i].output);
-   puts("\n"
-"  ");
-   }
-   puts("");
-   }
-
/*
 * In man(1) mode, show one of the pages

Re: newsyslog timestamp

2017-03-15 Thread Craig Skinner
Hiya,

On Wed, 15 Mar 2017 02:19:10 +1100 bytevolcano wrote:
> Is it worth making newsyslog use the syslog API instead of directly
> writing to the top of the file?

From syslogd(8):

CAVEATS
syslogd does not create files, it only logs to existing ones.

Cheers,
-- 
Craig Skinner | http://linkd.in/yGqkv7



Re: [PATCH] sensorsd - Command line switch for alternative configuration file

2017-03-15 Thread Silamael
On 14.03.2017 12:55, Alexander Bluhm wrote:
> All other error messages are lower case.  I would write "err(1,
> "access configuration file %s", configfile)" as err(3) privides a
> reason anyway.
> 
> apart from that OK bluhm@
> 

Upated diff.

-- Matthias

Index: sensorsd.8
===
RCS file: /mount/cvsdev/cvs/openbsd/src/usr.sbin/sensorsd/sensorsd.8,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 sensorsd.8
--- sensorsd.8  27 Jul 2015 17:28:40 -  1.22
+++ sensorsd.8  15 Mar 2017 07:45:39 -
@@ -26,6 +26,7 @@
 .Nm sensorsd
 .Op Fl d
 .Op Fl c Ar check
+.Op Fl f Ar file
 .Sh DESCRIPTION
 The
 .Nm
@@ -68,6 +69,11 @@ Do not daemonize.
 If this option is specified,
 .Nm
 will run in the foreground.
+.It Fl f Ar file
+Read configuration from
+.Ar file
+instead of the default configuration file
+.Pa /etc/sensorsd.conf .
 .El
 .Sh FILES
 .Bl -tag -width "/etc/sensorsd.conf"
Index: sensorsd.c
===
RCS file: /mount/cvsdev/cvs/openbsd/src/usr.sbin/sensorsd/sensorsd.c,v
retrieving revision 1.59
diff -u -p -u -p -r1.59 sensorsd.c
--- sensorsd.c  12 Dec 2015 20:04:23 -  1.59
+++ sensorsd.c  15 Mar 2017 07:46:02 -
@@ -101,7 +101,8 @@ void
 usage(void)
 {
extern char *__progname;
-   fprintf(stderr, "usage: %s [-d] [-c check]\n", __progname);
+   fprintf(stderr, "usage: %s [-d] [-c check] [-f file]\n",
+   __progname);
exit(1);
 }

@@ -115,7 +116,7 @@ main(int argc, char *argv[])
if (pledge("stdio rpath proc exec", NULL) == -1)
err(1, "pledge");

-   while ((ch = getopt(argc, argv, "c:d")) != -1) {
+   while ((ch = getopt(argc, argv, "c:df:")) != -1) {
switch (ch) {
case 'c':
check_period = strtonum(optarg, 1, 600, );
@@ -124,6 +125,12 @@ main(int argc, char *argv[])
break;
case 'd':
debug = 1;
+   break;
+   case 'f':
+   configfile = optarg;
+   if (access(configfile, R_OK) != 0)
+   err(1, "access configuration file %s",
+   configfile);
break;
default:
usage();