[Patch] httpd(8) - Add CORS header

2022-07-01 Thread David Rinehart
This diff adds the ability to specify a CORS header for httpd(8) static
content.

All feedback appreciated - Thanks, in advance!

--

Index: usr.sbin/httpd/httpd.conf.5
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.conf.5,v
retrieving revision 1.121
diff -u -p -u -p -r1.121 httpd.conf.5
--- usr.sbin/httpd/httpd.conf.5    9 Mar 2022 13:50:41 -    1.121
+++ usr.sbin/httpd/httpd.conf.5    1 Jul 2022 06:25:18 -
@@ -297,6 +297,12 @@ for example the maximum time to wait for
 The default timeout is 600 seconds (10 minutes).
 The maximum is 2147483647 seconds (68 years).
 .El
+.It Ic cors-static Ar option
+Set a Cross-Origin Resource Sharing (CORS)
+.Pa Access-Control-Allow-Origin
+header value.
+.Pp
+The CORS header, if specified, is added for static content only.
 .It Ic default type Ar type/subtype
 Set the default media type for the specified location,
 overwriting the global setting.
Index: usr.sbin/httpd/httpd.h
===
RCS file: /cvs/src/usr.sbin/httpd/httpd.h,v
retrieving revision 1.160
diff -u -p -u -p -r1.160 httpd.h
--- usr.sbin/httpd/httpd.h    2 Mar 2022 11:10:43 -    1.160
+++ usr.sbin/httpd/httpd.h    1 Jul 2022 06:25:18 -
@@ -393,6 +393,7 @@ SPLAY_HEAD(client_tree, client);
 #define SRVFLAG_PATH_REWRITE    0x0100
 #define SRVFLAG_NO_PATH_REWRITE    0x0200
 #define SRVFLAG_GZIP_STATIC    0x0400
+#define SRVFLAG_CORS_STATIC    0x0800
 #define SRVFLAG_LOCATION_FOUND    0x4000
 #define SRVFLAG_LOCATION_NOT_FOUND 0x8000
 
@@ -480,6 +481,7 @@ struct server_config {
 char             root[PATH_MAX];
 char             path[PATH_MAX];
 char             index[PATH_MAX];
+    char             cors_static[PATH_MAX];
 char             accesslog[PATH_MAX];
 char             errorlog[PATH_MAX];
 struct media_type     default_type;
Index: usr.sbin/httpd/parse.y
===
RCS file: /cvs/src/usr.sbin/httpd/parse.y,v
retrieving revision 1.128
diff -u -p -u -p -r1.128 parse.y
--- usr.sbin/httpd/parse.y    27 Feb 2022 20:30:30 -    1.128
+++ usr.sbin/httpd/parse.y    1 Jul 2022 06:25:18 -
@@ -141,7 +141,7 @@ typedef struct {
 %token    TIMEOUT TLS TYPE TYPES HSTS MAXAGE SUBDOMAINS DEFAULT PRELOAD
REQUEST
 %token    ERROR INCLUDE AUTHENTICATE WITH BLOCK DROP RETURN PASS REWRITE
 %token    CA CLIENT CRL OPTIONAL PARAM FORWARDED FOUND NOT
-%token    ERRDOCS GZIPSTATIC
+%token    ERRDOCS GZIPSTATIC CORSSTATIC
 %token        STRING
 %token      NUMBER
 %type        port
@@ -554,6 +554,7 @@ serveroptsl    : LISTEN ON STRING opttls po
     | fastcgi
     | authenticate
     | gzip_static
+        | cors_static
     | filter
     | LOCATION optfound optmatch STRING    {
         struct server        *s;
@@ -1226,6 +1227,27 @@ gzip_static    : NO GZIPSTATIC        {
     }
     ;
 
+cors_static    : CORSSTATIC corsflags
+        | CORSSTATIC '{' optnl corsflags_l '}'
+        ;
+
+corsflags_l    : corsflags optcommanl corsflags_l
+        | corsflags optnl
+        ;
+
+corsflags    : STRING        {
+            if (strlcpy(srv->srv_conf.cors_static, $1,
+                sizeof(srv->srv_conf.cors_static)) >=
+                sizeof(srv->srv_conf.cors_static)) {
+                yyerror("cors value too long");
+                free($1);
+                YYERROR;
+            }
+            free($1);
+            srv->srv_conf.flags |= SRVFLAG_CORS_STATIC;
+        }
+        ;
+
 tcpip        : TCP '{' optnl tcpflags_l '}'
     | TCP tcpflags
     ;
@@ -1439,6 +1461,7 @@ lookup(char *s)
     { "combined",        COMBINED },
     { "common",        COMMON },
     { "connection",        CONNECTION },
+        { "cors-static",    CORSSTATIC },
     { "crl",        CRL },
     { "default",        DEFAULT },
     { "dhe",        DHE },
Index: usr.sbin/httpd/server_file.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_file.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 server_file.c
--- usr.sbin/httpd/server_file.c    4 Mar 2022 01:46:07 -    1.74
+++ usr.sbin/httpd/server_file.c    1 Jul 2022 06:25:18 -
@@ -269,6 +269,12 @@ server_file_request(struct httpd *env, s
     }
 }
 
+    if (srv_conf->flags & SRVFLAG_CORS_STATIC) {
+        struct http_descriptor    *resp = clt->clt_descresp;
+        kv_add(>http_headers,
+            "Access-Control-Allow-Origin", srv_conf->cors_static);
+    }
+
 /* Now open the file, should be readable or we have another problem */
 if (fd == -1) {
     if ((fd = open(path, O_RDONLY)) == -1)

--
David Rinehart



Re: [PATCH] man - apmd(8) reference

2022-06-19 Thread David Rinehart
apm(4): apm - Alliance ProMotion video driver


On 6/18/22 23:34, Theo Buehler wrote:
> On Sat, Jun 18, 2022 at 10:14:18PM -0700, David Rinehart wrote:
>> apm(4) seems unrelated to apmd(8)
> What makes you think so?
>
> DESCRIPTION
>  apmd monitors the advanced power management device, apm(4), acting on
>  signaled events and upon user requests as sent by the apm(8) program.



[PATCH] man - apmd(8) reference

2022-06-19 Thread David Rinehart
apm(4) seems unrelated to apmd(8)


Index: usr.sbin/apmd/apmd.8
===
RCS file: /cvs/src/usr.sbin/apmd/apmd.8,v
retrieving revision 1.55
diff -u -p -u -p -r1.55 apmd.8
--- usr.sbin/apmd/apmd.8    28 May 2022 16:07:54 -  1.55
+++ usr.sbin/apmd/apmd.8    19 Jun 2022 05:01:30 -
@@ -191,7 +191,6 @@ socket used for communication with
 .El
 .Sh SEE ALSO
 .Xr syslog 3 ,
-.Xr apm 4 ,
 .Xr apm 8 ,
 .Xr sysctl 8
 .Pp


--

David Rinehart



Re: ucc(4): consumer control keyboard device driver

2021-08-21 Thread David Rinehart
I use usbhidaction, a little differently:

- OBSD media server in office, connected to speakers

- Custom microservice on media server, to control volume

- When I am docked at startup (detected in .xsession), configure:

- Set AUDIODEVICE to office media server for sndio

- Use usbhidaction to send volume and mute commands to media
  center microservice

This setup works incredibly well - and I would never have considered it
with other OSs.  I would have tried to rig a headphone jack and
splitter or something.  Current config just uses the network.

Since I have other OBSD media servers around the house, I can easily
change the address and send audio & control to other rooms.

Wondering if my custom config will still be possible with ucc...


On 8/18/21 10:24 AM, Florian Obser wrote:
> My microsoft sculpt has a bunch of media keys. I tried mute and
> increment / decrement. They don't seem to have an effect.
>
> --- dmesg.bootWed Aug 18 19:19:07 2021
> +++ dmesg.boot.uccWed Aug 18 19:19:16 2021
> @@ -1,7 +1,7 @@
> -OpenBSD 7.0-beta (GENERIC.MP) #131: Wed Aug 18 10:18:06 CEST 2021
> +OpenBSD 7.0-beta (GENERIC.MP) #132: Wed Aug 18 13:41:45 CEST 2021
>  florian@x1:/usr/src/sys/arch/amd64/compile/GENERIC.MP
>  real mem = 8266944512 (7883MB)
> -avail mem = 8000442368 (7629MB)
> +avail mem = 8000446464 (7629MB)
>  random: good seed from bootblocks
>  mpath0 at root
>  scsibus0 at mpath0: 256 targets
> @@ -122,21 +122,21 @@
>  uhidev1 at uhub0 port 2 configuration 1 interface 1 "Microsoft Microsoft\M-. 
> 2.4GHz Transceiver v9.0" rev 2.00/7.97 addr 2
>  uhidev1: iclass 3/1, 26 report ids
>  uhid0 at uhidev1 reportid 18: input=0, output=0, feature=1
> -uhid1 at uhidev1 reportid 23: input=0, output=0, feature=1
> +ucc0 at uhidev1 reportid 23 hid error 6
>  ums0 at uhidev1 reportid 26: 5 buttons, Z and W dir
>  wsmouse2 at ums0 mux 0
>  uhidev2 at uhub0 port 2 configuration 1 interface 2 "Microsoft Microsoft\M-. 
> 2.4GHz Transceiver v9.0" rev 2.00/7.97 addr 2
>  uhidev2: iclass 3/0, 39 report ids
> -uhid2 at uhidev2 reportid 3: input=1, output=0, feature=0
> -uhid3 at uhidev2 reportid 7: input=7, output=0, feature=0
> -uhid4 at uhidev2 reportid 32: input=0, output=0, feature=18
> -uhid5 at uhidev2 reportid 33: input=2, output=0, feature=0
> -uhid6 at uhidev2 reportid 34: input=0, output=0, feature=26
> -uhid7 at uhidev2 reportid 35: input=0, output=0, feature=26
> -uhid8 at uhidev2 reportid 36: input=0, output=0, feature=31
> -uhid9 at uhidev2 reportid 37: input=0, output=0, feature=31
> -uhid10 at uhidev2 reportid 38: input=0, output=0, feature=31
> -uhid11 at uhidev2 reportid 39: input=31, output=0, feature=0
> +uhid1 at uhidev2 reportid 3: input=1, output=0, feature=0
> +ucc1 at uhidev2 reportid 7 keys 1, mappings 0
> +uhid2 at uhidev2 reportid 32: input=0, output=0, feature=18
> +uhid3 at uhidev2 reportid 33: input=2, output=0, feature=0
> +uhid4 at uhidev2 reportid 34: input=0, output=0, feature=26
> +uhid5 at uhidev2 reportid 35: input=0, output=0, feature=26
> +uhid6 at uhidev2 reportid 36: input=0, output=0, feature=31
> +uhid7 at uhidev2 reportid 37: input=0, output=0, feature=31
> +uhid8 at uhidev2 reportid 38: input=0, output=0, feature=31
> +ucc2 at uhidev2 reportid 39 keys 1, mappings 0
>  umb0 at uhub0 port 4 configuration 1 interface 0 "Sierra Wireless Inc. 
> Sierra Wireless EM7345 4G LTE" rev 2.00/17.29 addr 3
>  umodem0 at uhub0 port 4 configuration 1 interface 2 "Sierra Wireless Inc. 
> Sierra Wireless EM7345 4G LTE" rev 2.00/17.29 addr 3
>  umodem0: data interface 3, has no CM over data, has break
> @@ -145,12 +145,12 @@
>  uhub2 at uhub1 port 1 configuration 1 interface 0 "Intel Rate Matching Hub" 
> rev 2.00/0.04 addr 2
>  uhidev3 at uhub2 port 5 configuration 1 interface 0 "ELAN Touchscreen" rev 
> 2.00/0.12 addr 3
>  uhidev3: iclass 3/0, 68 report ids
> -uhid12 at uhidev3 reportid 1: input=115, output=0, feature=0
> -uhid13 at uhidev3 reportid 2: input=64, output=0, feature=0
> -uhid14 at uhidev3 reportid 3: input=0, output=31, feature=0
> -uhid15 at uhidev3 reportid 4: input=19, output=0, feature=0
> -uhid16 at uhidev3 reportid 10: input=0, output=0, feature=1
> -uhid17 at uhidev3 reportid 68: input=0, output=0, feature=255
> +uhid9 at uhidev3 reportid 1: input=115, output=0, feature=0
> +uhid10 at uhidev3 reportid 2: input=64, output=0, feature=0
> +uhid11 at uhidev3 reportid 3: input=0, output=31, feature=0
> +uhid12 at uhidev3 reportid 4: input=19, output=0, feature=0
> +uhid13 at uhidev3 reportid 10: input=0, output=0, feature=1
> +uhid14 at uhidev3 reportid 68: input=0, output=0, feature=255
>  uvideo0 at uhub2 port 8 configuration 1 interface 0 "Chicony Electronics 
> Co.,Ltd. Integrated Camera" rev 2.00/25.09 addr 4
>  video0 at uvideo0
>  vscsi0 at root
>
>
> dmesg.boot.ucc:
> OpenBSD 7.0-beta (GENERIC.MP) #132: Wed Aug 18 13:41:45 CEST 2021
> florian@x1:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> real mem = 8266944512 (7883MB)
> avail