Flag to set from address in mail(1)

2015-01-03 Thread martin
Since the ability to pass arbitrary arguments to sendmail has been
removed from mail(1), I have added a variable and flag to pass a from
address to sendmail.

I considered making mail take the same arguments for this as it would
have when it was just passing onto sendmail but decided against that
because the code would be more complicated than necessary. But maybe
somebody wants the compatibility?

Thoughts?

-- Martin Brandenburg

Index: mail.1
===
RCS file: /cvs/src/usr.bin/mail/mail.1,v
retrieving revision 1.70
diff -u -p -r1.70 mail.1
--- mail.1  16 Dec 2014 18:37:17 -  1.70
+++ mail.1  4 Jan 2015 05:42:08 -
@@ -41,6 +41,7 @@
 .Nm mail
 .Bk -words
 .Op Fl dEIinv
+.Op Fl a Ar from
 .Op Fl b Ar list
 .Op Fl c Ar list
 .Op Fl s Ar subject
@@ -62,6 +63,11 @@ with lines replaced by messages.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl a Ar from
+Pass
+.Ar from
+to the mail delivery system as the from address.
+Overrides the from option below.
 .It Fl b Ar list
 Send blind carbon copies to
 .Ar list .
@@ -965,6 +971,14 @@ Causes
 .Nm mail
 to expand message recipient addresses, as explained in the section
 .Sx Recipient address specifications .
+.It Ar from
+Causes
+.Nm mail
+to pass a from address to the mail delivery system. If unset, no from
+address will be passed and the mail delivery system will use its default
+of user@host. This will be overriden if the
+.Fl a
+flag is set.
 .It Ar hold
 This option is used to hold messages in the system mailbox
 by default.
Index: main.c
===
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.26
diff -u -p -r1.26 main.c
--- main.c  16 Dec 2014 18:37:17 -  1.26
+++ main.c  4 Jan 2015 05:42:08 -
@@ -49,6 +49,7 @@ main(int argc, char **argv)
 {
int i;
struct name *to, *cc, *bcc, *smopts;
+   char *from = NULL;
char *subject;
char *ef;
char nosrc = 0;
@@ -78,7 +79,7 @@ main(int argc, char **argv)
bcc = NULL;
smopts = NULL;
subject = NULL;
-   while ((i = getopt(argc, argv, "EIN:b:c:dfins:u:v")) != -1) {
+   while ((i = getopt(argc, argv, "EIN:a:b:c:dfins:u:v")) != -1) {
switch (i) {
case 'u':
/*
@@ -158,6 +159,9 @@ main(int argc, char **argv)
 */
assign("skipempty", "");
break;
+   case 'a':
+   from = optarg;
+   break;
default:
usage();
/*NOTREACHED*/
@@ -202,6 +206,8 @@ main(int argc, char **argv)
if ((rc = getenv("MAILRC")) == 0)
rc = "~/.mailrc";
load(expand(rc));
+   if (from)
+   assign("from", from);
if (!rcvmode) {
mail(to, cc, bcc, smopts, subject);
/*
@@ -271,7 +277,7 @@ __dead void
 usage(void)
 {
 
-   fprintf(stderr, "usage: %s [-dEIinv] [-b list] [-c list] "
+   fprintf(stderr, "usage: %s [-dEIinv] [-a from] [-b list] [-c list] "
"[-s subject] to-addr ...\n", __progname);
fprintf(stderr, "   %s [-dEIiNnv] -f [file]\n", __progname);
fprintf(stderr, "   %s [-dEIiNnv] [-u user]\n", __progname);
Index: send.c
===
RCS file: /cvs/src/usr.bin/mail/send.c,v
retrieving revision 1.23
diff -u -p -r1.23 send.c
--- send.c  17 Jan 2014 18:42:30 -  1.23
+++ send.c  4 Jan 2015 05:42:08 -
@@ -287,7 +287,11 @@ mail(struct name *to, struct name *cc, s
head.h_subject = subject;
head.h_cc = cc;
head.h_bcc = bcc;
-   head.h_smopts = smopts;
+   if (value("from")) {
+   head.h_smopts = cat(smopts, nalloc("-f", 0));
+   head.h_smopts = cat(head.h_smopts, nalloc(value("from"), 0));
+   } else
+   head.h_smopts = smopts;
mail1(&head, 0);
return(0);
 }
@@ -307,7 +311,11 @@ sendmail(void *v)
head.h_subject = NULL;
head.h_cc = NULL;
head.h_bcc = NULL;
-   head.h_smopts = NULL;
+   if (value("from")) {
+   head.h_smopts = nalloc("-f", 0);
+   head.h_smopts = cat(head.h_smopts, nalloc(value("from"), 0));
+   } else
+   head.h_smopts = NULL;
mail1(&head, 0);
return(0);
 }



ntpd: be more verbose when logging privsep errors

2015-01-03 Thread Brent Cook
From: Brent Cook 

The idea here is to make it easier for a sysadmin to diagnose a privilege
separation path problem without looking at the source code. Otherwise, privsep
failers are pretty cryptic.

Maybe its better to make fatal() variadic instead?
---
 src/usr.sbin/ntpd/ntp.c | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c
index f7478b0..c2d1fd2 100644
--- a/src/usr.sbin/ntpd/ntp.c
+++ b/src/usr.sbin/ntpd/ntp.c
@@ -121,10 +121,15 @@ ntp_main(int pipe_prnt[2], int fd_ctl, struct ntpd_conf 
*nconf,
ntp_dns(pipe_dns, nconf, pw);
close(pipe_dns[1]);
 
-   if (stat(pw->pw_dir, &stb) == -1)
-   fatal("stat");
-   if (stb.st_uid != 0 || (stb.st_mode & (S_IWGRP|S_IWOTH)) != 0)
-   fatalx("bad privsep dir permissions");
+   if (stat(pw->pw_dir, &stb) == -1) {
+   log_warn("privsep dir %s could not be opened", pw->pw_dir);
+   exit(1);
+   }
+   if (stb.st_uid != 0 || (stb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
+   log_warnx("bad privsep dir %s permissions: %o",
+   pw->pw_dir, stb.st_mode);
+   exit(1);
+   }
if (chroot(pw->pw_dir) == -1)
fatal("chroot");
if (chdir("/") == -1)
-- 
1.9.1



ntpd: do not allow privsep user to be a privileged user

2015-01-03 Thread Brent Cook
From: Brent Cook 

Maybe these two checks are redundant. OpenNTPD-portable lets one configure
the built-in privilege separation username. Thus, you can potentially
configure that user to be root as well.
---
 src/usr.sbin/ntpd/ntp.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c
index c2d1fd2..86f58b8 100644
--- a/src/usr.sbin/ntpd/ntp.c
+++ b/src/usr.sbin/ntpd/ntp.c
@@ -147,6 +147,12 @@ ntp_main(int pipe_prnt[2], int fd_ctl, struct ntpd_conf 
*nconf,
conf = nconf;
setup_listeners(se, conf, &listener_cnt);
 
+   if (pw->pw_uid == 0 || pw->pw_gid == 0)
+   fatal("privsep user cannot be root");
+
+   if (pw->pw_uid == geteuid() || pw->pw_gid == getegid())
+   fatal("privsep user cannot be the privileged user");
+
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
-- 
1.9.1



Re: disk quotas bug fix [was: quotas grace period "none" right away]

2015-01-03 Thread Boris Goldberg
Hello Otto,

Friday, January 2, 2015, 4:16:50 PM, you wrote:

OM> On Fri, Jan 02, 2015 at 03:28:46PM -0600, Boris Goldberg wrote:

>>   What about our second patch?

OM> I'd rather stay in line with FreeBSD and document quoaoff/quotaon is
OM> needed for the new grace period to take effect. 

OM> 
https://svnweb.freebsd.org/base/head/usr.sbin/edquota/edquota.8?r1=140442&r2=166496&pathrev=166496


  In my tests just quotaon was sufficient. However, is it safe to run
quotaon on active system? Also - it's a workaround, not a solution.

-- 
Best regards,
 Borismailto:bo...@twopoint.com



mail(1) and chdir command

2015-01-03 Thread Kaspars Bankovskis
Due to the order in commands table, "c" maps to "copy", not "chdir" as
man page says. "cd" and "ch" work instead. Two alternative fixes: either
man page or the order of commands - leaving for you to decide. IMHO
better to update man page than muscle memory of old time users.

Index: mail.1
===
RCS file: /cvs/src/usr.bin/mail/mail.1,v
retrieving revision 1.70
diff -u -p -r1.70 mail.1
--- mail.1  16 Dec 2014 18:37:17 -  1.70
+++ mail.1  3 Jan 2015 20:49:55 -
@@ -422,12 +422,14 @@ If the
 command is given with no argument, the current set of alternate
 names is displayed.
 .It Ic chdir
-.Pq Ic c
+.Pf ( Ic ch
+or
+.Ic cd )
 Changes the user's working directory to that specified, if given.
 If
 no directory is given, then changes to the user's login directory.
 .It Ic copy
-.Pq Ic co
+.Pq Ic c
 The
 .Ic copy
 command does the same thing that


Alternatively, keeping man page, but moving copy command down:


Index: cmdtab.c
===
RCS file: /cvs/src/usr.bin/mail/cmdtab.c,v
retrieving revision 1.13
diff -u -p -r1.13 cmdtab.c
--- cmdtab.c27 Oct 2009 23:59:40 -  1.13
+++ cmdtab.c3 Jan 2015 20:41:36 -
@@ -69,9 +69,9 @@ const struct cmd cmdtab[] = {
{ "unread", { unread }, MSGLIST,0,  MMNDEL },
{ "Unread", { unread }, MSGLIST,0,  MMNDEL },
{ "!",  { shell },  I|STRLIST,  0,  0 },
-   { "copy",   { copycmd },M|STRLIST,  0,  0 },
{ "chdir",  { schdir }, M|RAWLIST,  0,  1 },
{ "cd", { schdir }, M|RAWLIST,  0,  1 },
+   { "copy",   { copycmd },M|STRLIST,  0,  0 },
{ "save",   { save },   STRLIST,0,  0 },
{ "source", { source }, M|RAWLIST,  1,  1 },
{ "set",{ set },M|RAWLIST,  0,  1000 },



Re: httpd: multiple addresses for one server

2015-01-03 Thread Reyk Floeter
On Sat, Jan 03, 2015 at 05:19:16PM +0100, Reyk Floeter wrote:
> My tests show that memory usage is not the problem but that there's
> indeed a problem with the pre-opened file descriptors for servers;
> something that is not necessary with aliases. A simple fix will follow.
> 

Here is a fix for the previous: in the parent, only open a socket once
per unique listen statement.  This allows to specify many aliases and
listen statements.

Reyk

Index: config.c
===
RCS file: /cvs/src/usr.sbin/httpd/config.c,v
retrieving revision 1.27
diff -u -p -u -p -r1.27 config.c
--- config.c3 Jan 2015 15:49:18 -   1.27
+++ config.c3 Jan 2015 19:32:00 -
@@ -200,7 +200,9 @@ config_setserver(struct httpd *env, stru
n = -1;
proc_range(ps, id, &n, &m);
for (n = 0; n < m; n++) {
-   if ((fd = dup(srv->srv_s)) == -1)
+   if (srv->srv_s == -1)
+   fd = -1;
+   else if ((fd = dup(srv->srv_s)) == -1)
return (-1);
proc_composev_imsg(ps, id, n,
IMSG_CFG_SERVER, fd, iov, c);
@@ -211,9 +213,6 @@ config_setserver(struct httpd *env, stru
}
}
 
-   close(srv->srv_s);
-   srv->srv_s = -1;
-
return (0);
 }
 
@@ -356,8 +355,12 @@ config_getserver(struct httpd *env, stru
if ((srv = server_byaddr((struct sockaddr *)
&srv_conf.ss, srv_conf.port)) != NULL) {
/* Add "host" to existing listening server */
-   if (imsg->fd != -1)
-   close(imsg->fd);
+   if (imsg->fd != -1) {
+   if (srv->srv_s == -1)
+   srv->srv_s = imsg->fd;
+   else
+   close(imsg->fd);
+   }
return (config_getserver_config(env, srv, imsg));
}
 
Index: parse.y
===
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.48
diff -u -p -u -p -r1.48 parse.y
--- parse.y 3 Jan 2015 16:20:31 -   1.48
+++ parse.y 3 Jan 2015 19:32:01 -
@@ -226,6 +226,7 @@ server  : SERVER STRING {
strlcpy(s->srv_conf.errorlog, HTTPD_ERROR_LOG,
sizeof(s->srv_conf.errorlog));
s->srv_conf.id = ++last_server_id;
+   s->srv_s = -1;
s->srv_conf.timeout.tv_sec = SERVER_TIMEOUT;
s->srv_conf.maxrequests = SERVER_MAXREQUESTS;
s->srv_conf.maxrequestbody = SERVER_MAXREQUESTBODY;
@@ -493,6 +494,7 @@ serveroptsl : LISTEN ON STRING opttls po
/* A location entry uses the parent id */
s->srv_conf.id = srv->srv_conf.id;
s->srv_conf.flags = SRVFLAG_LOCATION;
+   s->srv_s = -1;
memcpy(&s->srv_conf.ss, &srv->srv_conf.ss,
sizeof(s->srv_conf.ss));
s->srv_conf.port = srv->srv_conf.port;
@@ -1742,6 +1744,8 @@ server_inherit(struct server *src, const
fatal("out of memory");
 
dst->srv_conf.id = ++last_server_id;
+   dst->srv_s = -1;
+
if (last_server_id == INT_MAX) {
yyerror("too many servers defined");
serverconfig_free(&dst->srv_conf);
@@ -1806,6 +1810,7 @@ server_inherit(struct server *src, const
sizeof(dstl->srv_conf.ss));
dstl->srv_conf.port = addr->port;
dstl->srv_conf.prefixlen = addr->prefixlen;
+   dstl->srv_s = -1;
 
DPRINTF("adding location \"%s\" for \"%s[%u]\"",
dstl->srv_conf.location,
Index: server.c
===
RCS file: /cvs/src/usr.sbin/httpd/server.c,v
retrieving revision 1.49
diff -u -p -u -p -r1.49 server.c
--- server.c21 Dec 2014 00:54:49 -  1.49
+++ server.c3 Jan 2015 19:32:01 -
@@ -101,11 +101,27 @@ server_shutdown(void)
 int
 server_privinit(struct server *srv)
 {
+   struct server   *s;
+
if (srv->srv_conf.flags & SRVFLAG_LOCATION)
return (0);
 
log_debug("%s: adding server %s", __func__, srv->srv_conf.name);
 
+   /*
+* There's no need to open a new socket if a server with the
+* same address already exists.
+*/
+   TAILQ_FOREACH(s, env->sc_servers, srv_entry) {
+   if (s != srv && s->srv_s != -1 &&
+   s->srv_conf.port == srv->srv_conf.port &&
+   sockaddr_cmp((struct sockaddr *)&s->srv_c

Patch for mail(1) man page

2015-01-03 Thread trondd
Just a small patch to document the '=' command.

Tim.

Index: mail.1
===
RCS file: /cvs/src/usr.bin/mail/mail.1,v
retrieving revision 1.70
diff -u -p -r1.70 mail.1
--- mail.1  16 Dec 2014 18:37:17 -  1.70
+++ mail.1  3 Jan 2015 18:42:15 -
@@ -385,6 +385,8 @@ argument
 goes to the
 .Ar n Ns th
 previous message and prints it.
+.It Ic \&=
+Prints the currently selected message number.
 .It Ic \&?
 Prints a brief summary of commands.
 .It Ic \&!



httpd directory listing not properly encoded.

2015-01-03 Thread Remco
I think that the directory listing generated by httpd doesn't properly encode 
strings that are taken from C-variables. (function "server_file_index" in 
server_file.c)

e.g., filenames with spaces, or odd characters, produce non-functioning links.

I used the following directory structure to test:
mkdir test
echo "TEST" > test/test.txt
echo "Test" > test/.hidden.txt
echo "test ONCE more" > test/"test once more".txt
mkdir test/" \\test\"&\"&"
echo "& test" > test/" \\test\"&\"&"/"".txt

What I see:
- the file test/"test once more".txt cannot be displayed because is has spaces 
in its name. (doesn't appear to be a problem on CURRENT though)
- the directory test/" \\test\"&\"&" cannot be displayed either and 
will also cause subsequent characters to be printed in bold because of the 
 character sequence.
- the filename part of test/" \\test\"& \"&"/"".txt is possibly 
rendered as .txt.

AFAICT tell the C-variables need to be "HTML encoded" or both "URI percent 
encoded" and "HTML encoded" in case of URIs in hrefs.

I spotted the url_decode function but i don't immediately see any encoding 
functions so I'm wondering do encoding functions exist ?

Just in case it's of interrest, I ripped an "URI percent encode" and a "HTML 
encode" function from some hobby project of mine and used it to encode the C-
variables. This appears to solve the issues described. Though I don't know for 
sure my code is anywhere near perfect I can produce a diff if that's 
appreciated.



sendsyslog failure logging

Hi,

My goal is to make logging via syslog reliable.  At least I want
to see when a message gets lost.

So my idea is to write a kernel log message if sendsyslog(2) cannot
deliver a message.  Then you see the problem on the console and in
the dmesg buffer.  If syslogd comes back later, you will also get
the error into the log files via /dev/klog.

comments? ok?

bluhm

Index: kern/subr_log.c
===
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/subr_log.c,v
retrieving revision 1.25
diff -u -p -u -p -r1.25 subr_log.c
--- kern/subr_log.c 13 Dec 2014 21:05:33 -  1.25
+++ kern/subr_log.c 3 Jan 2015 13:48:32 -
@@ -347,14 +347,21 @@ sys_sendsyslog(struct proc *p, void *v, 
struct iovec *ktriov = NULL;
int iovlen;
 #endif
+#ifndef SMALL_KERNEL
+   const struct timeval mininterval = { 30, 0 };
+   static struct timeval lasttime;
+   static unsigned int failed;
+#endif
struct iovec aiov;
struct uio auio;
struct file *f;
size_t len;
int error;
 
-   if (syslogf == NULL)
-   return (ENOTCONN);
+   if (syslogf == NULL) {
+   error = ENOTCONN;
+   goto out;
+   }
f = syslogf;
FREF(f);
 
@@ -390,5 +397,19 @@ sys_sendsyslog(struct proc *p, void *v, 
}
 #endif
FRELE(f, p);
-   return error;
+
+ out:
+#ifndef SMALL_KERNEL
+   if (error)
+   failed++;
+   if (failed && ratecheck(&lasttime, &mininterval)) {
+   if (failed == 1)
+   log(LOG_ERR, "send message to syslog failed\n");
+   else
+   log(LOG_ERR, "send message to syslog failed %u times\n",
+   failed);
+   failed = 0;
+   }
+#endif
+   return (error);
 }



Re: httpd: multiple addresses for one server

On Sat, Jan 03, 2015 at 04:40:19PM +0100, Christopher Zimmermann wrote:
> Hi,
> 
> 
> On Sat, 3 Jan 2015 14:42:18 +0100 Reyk Floeter  wrote:
> 
> > On Thu, Jan 01, 2015 at 11:54:46PM -0500, Geoff Steckel wrote:
> > > Is there any way todo the equivalent of:
> > > 
> > > server "an.example.com"
> > > listen on 192.168.2.99
> > > listen on 2001.fefe.1.1::99
> > 
> > I used "include" directives to avoid duplications (see previous reply)
> > but the following diff allows to add aliases and multiple listen
> > statements.
> > 
> > Reyk
> 
> As I understand your diff you will duplicate the entire struct
> server_config for each combination of hostname (alias), listen address
> and location section.

Correct.

> Isn't this overkill?

No, it is just a few K per server block that is allocated once on
startup.  How many aliases do you have?

My tests show that memory usage is not the problem but that there's
indeed a problem with the pre-opened file descriptors for servers;
something that is not necessary with aliases. A simple fix will follow.

> To me it seems like server_config is serving too much purposes here. A
> clean design should split up the struct server_config into one struct
> for connection settings, which will contain a TAILQ of hostnames, a
> TAILQ of listen addresses and a TAILQ of structs with location settings:
> 

"A clean design should ..."

One could argue that a clean design wouldn't try to add too many
layers of indirection that add code complexity and kill some of the
flexibility that we have with the current implementation.  I might
split up struct server_config at some point, when it is really needed,
but it is not the right time.

> TAILQ_HEAD(hostnames, char*);
> 
> struct server_config {
>   charlocation[NAME_MAX];
>   charroot[MAXPATHLEN];
>   [...]
> }
> TAILQ_HEAD(server_configs, server_config);
> 
> struct serverhost {
>   struct sockaddr_storages*srv_ss;
>   char*tls_cert;
>   int  tcpbufsize;
>   [... other connection settings ...]
>   struct hostnames*srv_names;
>   struct server_configs   *srv_confs;
> }
> 
> 
> For now you could simply loop over a TAILQ of hostnames in
> server_privinit() and add an inner LOOP in server_response() searching
> for the hostname/aliases.
> 
> 

Which makes the implementation more complicated, especially the reload
and privsep code, adds additional loops to save a few bytes of memory.

Don't get me wrong - I do care about memory usage - but this is not
per connection - it is persistent during runtime.

Reyk



Re: httpd: multiple addresses for one server

Hi,


On Sat, 3 Jan 2015 14:42:18 +0100 Reyk Floeter  wrote:

> On Thu, Jan 01, 2015 at 11:54:46PM -0500, Geoff Steckel wrote:
> > Is there any way todo the equivalent of:
> > 
> > server "an.example.com"
> > listen on 192.168.2.99
> > listen on 2001.fefe.1.1::99
> 
> I used "include" directives to avoid duplications (see previous reply)
> but the following diff allows to add aliases and multiple listen
> statements.
> 
> Reyk

As I understand your diff you will duplicate the entire struct
server_config for each combination of hostname (alias), listen address
and location section. Isn't this overkill?
To me it seems like server_config is serving too much purposes here. A
clean design should split up the struct server_config into one struct
for connection settings, which will contain a TAILQ of hostnames, a
TAILQ of listen addresses and a TAILQ of structs with location settings:

TAILQ_HEAD(hostnames, char*);

struct server_config {
charlocation[NAME_MAX];
charroot[MAXPATHLEN];
[...]
}
TAILQ_HEAD(server_configs, server_config);

struct serverhost {
struct sockaddr_storages*srv_ss;
char*tls_cert;
int  tcpbufsize;
[... other connection settings ...]
struct hostnames*srv_names;
struct server_configs   *srv_confs;
}


For now you could simply loop over a TAILQ of hostnames in
server_privinit() and add an inner LOOP in server_response() searching
for the hostname/aliases.


Christopher



-- 
http://gmerlin.de
OpenPGP: http://gmerlin.de/christopher.pub
F190 D013 8F01 AA53 E080  3F3C F17F B0A1 D44E 4FEE



Re: httpd: multiple addresses for one server

On Thu, Jan 01, 2015 at 11:54:46PM -0500, Geoff Steckel wrote:
> Is there any way todo the equivalent of:
> 
> server "an.example.com"
> listen on 192.168.2.99
> listen on 2001.fefe.1.1::99
> 
> ??
> It appears that the code in parse.y explicitly forbids this
> and the data structures for a server don't *seem*
> to have more than one slot for an address.
> 
> Is there another way to achieve this effect?
> From one comment in the checkins, it looks like
> 
> server "an.example.com"
> listen on 192.168.2.99
> .
> server "an.example.com"
> listen on 2001.fefe.1.1::99
> 
> would work.
> 
> Duplicating the entire server description is
> difficult to maintain.
> 
> Is someone planning to work in this area soon?
> 
> thanks
> Geoff Steckel
> 

I used "include" directives to avoid duplications (see previous reply)
but the following diff allows to add aliases and multiple listen
statements.

Reyk

Index: config.c
===
RCS file: /cvs/src/usr.sbin/httpd/config.c,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 config.c
--- config.c21 Dec 2014 00:54:49 -  1.26
+++ config.c3 Jan 2015 13:33:25 -
@@ -174,7 +174,9 @@ config_setserver(struct httpd *env, stru
if ((what & CONFIG_SERVERS) == 0 || id == privsep_process)
continue;
 
-   DPRINTF("%s: sending server \"%s[%u]\" to %s fd %d", __func__,
+   DPRINTF("%s: sending %s \"%s[%u]\" to %s fd %d", __func__,
+   (srv->srv_conf.flags & SRVFLAG_LOCATION) ?
+   "location" : "server",
srv->srv_conf.name, srv->srv_conf.id,
ps->ps_title[id], srv->srv_s);
 
Index: httpd.conf.5
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.40
diff -u -p -u -p -r1.40 httpd.conf.5
--- httpd.conf.528 Dec 2014 13:53:23 -  1.40
+++ httpd.conf.53 Jan 2015 13:33:25 -
@@ -135,6 +135,10 @@ must have a
 .Ar name
 and include one or more lines of the following syntax:
 .Bl -tag -width Ds
+.It Ic alias Ar name
+Specify an additional alias
+.Ar name
+for this server.
 .It Ic connection Ar option
 Set the specified options and limits for HTTP connections.
 Valid options are:
@@ -180,6 +184,7 @@ and defaults to
 .Pa /run/slowcgi.sock .
 .It Ic listen on Ar address Oo Ic tls Oc Ic port Ar number
 Set the listen address and port.
+This statement can be specified multiple times.
 .It Ic location Ar path Brq ...
 Specify server configuration rules for a specific location.
 The
@@ -391,6 +396,13 @@ If the same address is repeated multiple
 statement,
 the server will be matched based on the requested host name.
 .Bd -literal -offset indent
+server "www.example.com" {
+   alias "example.com"
+   listen on * port 80
+   listen on * tls port 443
+   root "/htdocs/www.example.com"
+}
+
 server "www.a.example.com" {
listen on 203.0.113.1 port 80
root "/htdocs/www.a.example.com"
Index: parse.y
===
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.46
diff -u -p -u -p -r1.46 parse.y
--- parse.y 21 Dec 2014 00:54:49 -  1.46
+++ parse.y 3 Jan 2015 13:33:26 -
@@ -106,6 +106,8 @@ int  host_if(const char *, struct addre
 int host(const char *, struct addresslist *,
int, struct portrange *, const char *, int);
 voidhost_free(struct addresslist *);
+struct server  *server_inherit(struct server *, const char *,
+   struct server_config *);
 int getservice(char *);
 int is_if_in_group(const char *, const char *);
 
@@ -125,10 +127,10 @@ typedef struct {
 
 %}
 
-%token ACCESS AUTO BACKLOG BODY BUFFER CERTIFICATE CHROOT CIPHERS COMMON
+%token ACCESS ALIAS AUTO BACKLOG BODY BUFFER CERTIFICATE CHROOT CIPHERS COMMON
 %token COMBINED CONNECTION DIRECTORY ERR FCGI INDEX IP KEY LISTEN LOCATION
 %token LOG LOGDIR MAXIMUM NO NODELAY ON PORT PREFORK REQUEST REQUESTS ROOT
-%token SACK SERVER SOCKET STYLE SYSLOG TCP TIMEOUT TLS TYPES 
+%token SACK SERVER SOCKET STYLE SYSLOG TCP TIMEOUT TLS TYPES
 %token ERROR INCLUDE
 %token   STRING
 %token   NUMBER
@@ -247,8 +249,14 @@ server : SERVER STRING {
srv_conf = &srv->srv_conf;
 
SPLAY_INIT(&srv->srv_clients);
+   TAILQ_INIT(&srv->srv_hosts);
+
+   TAILQ_INSERT_TAIL(&srv->srv_hosts, srv_conf, entry);
} '{' optnl serveropts_l '}'{
-   struct server   *s = NULL;
+   struct server   *s = NULL, *sn;
+   struct server_config*a, *b;
+
+   srv_conf = &srv->srv_conf;
 
TAILQ_FOREACH(s, conf

Re: Sort APs by signal strength

On 03/01/15(Sat) 12:26, Stefan Sperling wrote:
> On Fri, Jan 02, 2015 at 09:02:53PM +0100, Simon Nicolussi wrote:
> > Hello,
> > 
> > 31C3 had lots of access points sharing a network ID. Coming up with an
> > AWK script to determine the network with the best coverage is easy, but
> > still harder than simply choosing the first one that ifconfig iwn0 scan
> > would spit out if only its output was sorted by signal strength (and in
> > decreasing order, as by convention).
> 
> Thanks! I like this. Works as expected for me on STAs and APs.
> 
> Note that 'ifconfig scan' is also used to list associated STAs when
> running as AP. So this will also sort associated STAs by received
> signal strength indication.

I like it too.  I guess it should fit on the RAMDISK media as well now
that list_cloners() uses qsort(3).

> > Index: ifconfig.c
> > ===
> > RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> > retrieving revision 1.290
> > diff -u -p -u -r1.290 ifconfig.c
> > --- ifconfig.c  1 Jan 2015 22:53:39 -   1.290
> > +++ ifconfig.c  2 Jan 2015 18:29:06 -
> > @@ -2221,6 +2221,17 @@ ieee80211_listchans(void)
> > }
> >  }
> >  
> > +/*
> > + * Returns an integer less than, equal to, or greater than zero if nr1's
> > + * RSSI is respectively greater than, equal to, or less than nr2's RSSI.
> > + */
> > +static int
> > +rssicmp(const void *nr1, const void *nr2)
> > +{
> > +   const struct ieee80211_nodereq *x = nr1, *y = nr2;
> > +   return y->nr_rssi < x->nr_rssi ? -1 : y->nr_rssi > x->nr_rssi;
> > +}
> > +
> >  void
> >  ieee80211_listnodes(void)
> >  {
> > @@ -2256,6 +2267,8 @@ ieee80211_listnodes(void)
> >  
> > if (!na.na_nodes)
> > printf("\t\tnone\n");
> > +   else
> > +   qsort(nr, na.na_nodes, sizeof(*nr), rssicmp);
> >  
> > for (i = 0; i < na.na_nodes; i++) {
> > printf("\t\t");
> > 
> > -- 
> > Simon Nicolussi 
> > http{s,}://{www.,}sinic.name/
> 



Re: Sort APs by signal strength

On Fri, Jan 02, 2015 at 09:02:53PM +0100, Simon Nicolussi wrote:
> Hello,
> 
> 31C3 had lots of access points sharing a network ID. Coming up with an
> AWK script to determine the network with the best coverage is easy, but
> still harder than simply choosing the first one that ifconfig iwn0 scan
> would spit out if only its output was sorted by signal strength (and in
> decreasing order, as by convention).

Thanks! I like this. Works as expected for me on STAs and APs.

Note that 'ifconfig scan' is also used to list associated STAs when
running as AP. So this will also sort associated STAs by received
signal strength indication.

> Index: ifconfig.c
> ===
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.290
> diff -u -p -u -r1.290 ifconfig.c
> --- ifconfig.c1 Jan 2015 22:53:39 -   1.290
> +++ ifconfig.c2 Jan 2015 18:29:06 -
> @@ -2221,6 +2221,17 @@ ieee80211_listchans(void)
>   }
>  }
>  
> +/*
> + * Returns an integer less than, equal to, or greater than zero if nr1's
> + * RSSI is respectively greater than, equal to, or less than nr2's RSSI.
> + */
> +static int
> +rssicmp(const void *nr1, const void *nr2)
> +{
> + const struct ieee80211_nodereq *x = nr1, *y = nr2;
> + return y->nr_rssi < x->nr_rssi ? -1 : y->nr_rssi > x->nr_rssi;
> +}
> +
>  void
>  ieee80211_listnodes(void)
>  {
> @@ -2256,6 +2267,8 @@ ieee80211_listnodes(void)
>  
>   if (!na.na_nodes)
>   printf("\t\tnone\n");
> + else
> + qsort(nr, na.na_nodes, sizeof(*nr), rssicmp);
>  
>   for (i = 0; i < na.na_nodes; i++) {
>   printf("\t\t");
> 
> -- 
> Simon Nicolussi 
> http{s,}://{www.,}sinic.name/