Commit Diff


commit - 70c1d88e1cfe187e76bb33de7910355397892044
commit + 4b6fc920bb67081914ce11a8733ffb7d22eceb5c
blob - 16dfe1f6b6d576c1a272bb35ecf4914c0d3dde51
blob + 6ef924e5644a1c406890a94cd559e6ebb2134c01
--- Makefile
+++ Makefile
@@ -2,9 +2,9 @@ LOCALBASE?=	/usr/local
 BINDIR=		${LOCALBASE}/bin
 MANDIR=		${LOCALBASE}/man/man
 
-PROG=		snmpd_extends
+PROG=		snmpd_extend
 SRCS=		parse.y main.c log.c
-MAN=		snmpd_extends.8 snmpd_extends.conf.5
+MAN=		snmpd_extend.8 snmpd_extend.conf.5
 
 CFLAGS+=	-Wall -I${.CURDIR}
 CFLAGS+=	-Wstrict-prototypes -Wmissing-prototypes
blob - 26213696096518f3ae91a95961476081e4989233 (mode 644)
blob + /dev/null
--- extends.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*	$OpenBSD$	*/
-
-/*
- * Copyright (c) 2026 Martijn van Duren <martijn@openbsd.org>
- *
- * 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 <sys/tree.h>
-
-#include <event.h>
-#include <time.h>
-
-#ifndef CONFFILE
-#define CONFFILE "/etc/snmpd_extends.conf"
-#endif
-
-#define MIB_NETSNMP			AGENTX_ENTERPRISES, 8072
-#define MIB_NETSNMPOBJECTS		MIB_NETSNMP, 1
-#define MIB_NSEXTENSIONS		MIB_NETSNMPOBJECTS, 3
-#define MIB_NSEXTENDOBJECTS		MIB_NSEXTENSIONS, 2
-#define MIB_NSEXTENDNUMENTRIES		MIB_NSEXTENDOBJECTS, 1
-#define MIB_NSEXTENDCONFIGTABLE		MIB_NSEXTENDOBJECTS, 2
-#define MIB_NSEXTENDCONFIGENTRY		MIB_NSEXTENDCONFIGTABLE, 1
-#define MIB_NSEXTENDTOKEN		MIB_NSEXTENDCONFIGENTRY, 1
-#define MIB_NSEXTENDCOMMAND		MIB_NSEXTENDCONFIGENTRY, 2
-#define MIB_NSEXTENDARGS		MIB_NSEXTENDCONFIGENTRY, 3
-#define MIB_NSEXTENDINPUT		MIB_NSEXTENDCONFIGENTRY, 4
-#define MIB_NSEXTENDCACHETIME		MIB_NSEXTENDCONFIGENTRY, 5
-#define MIB_NSEXTENDEXECTYPE		MIB_NSEXTENDCONFIGENTRY, 6
-#define MIB_NSEXTENDRUNTYPE		MIB_NSEXTENDCONFIGENTRY, 7
-#define MIB_NSEXTENDSTORAGE		MIB_NSEXTENDCONFIGENTRY, 20
-#define MIB_NSEXTENDSTATUS		MIB_NSEXTENDCONFIGENTRY, 21
-#define MIB_NSEXTENDOUTPUT1TABLE	MIB_NSEXTENDOBJECTS, 3
-#define MIB_NSEXTENDOUTPUT1ENTRY	MIB_NSEXTENDOUTPUT1TABLE, 1
-#define MIB_NSEXTENDOUTPUT1LINE		MIB_NSEXTENDOUTPUT1ENTRY, 1
-#define MIB_NSEXTENDOUTPUTFULL		MIB_NSEXTENDOUTPUT1ENTRY, 2
-#define MIB_NSEXTENDOUTPUTNUMLINES	MIB_NSEXTENDOUTPUT1ENTRY, 3
-#define MIB_NSEXTENDRESULT		MIB_NSEXTENDOUTPUT1ENTRY, 4
-#define MIB_NSEXTENDOUTPUT2TABLE	MIB_NSEXTENDOBJECTS, 4
-#define MIB_NSEXTENDOUTPUT2ENTRY	MIB_NSEXTENDOUTPUT2TABLE, 1
-#define MIB_NSEXTENDLINEINDEX		MIB_NSEXTENDOUTPUT2ENTRY, 1
-#define MIB_NSEXTENDOUTLINE		MIB_NSEXTENDOUTPUT2ENTRY, 2
-
-enum exectype {
-	exectype_exec = 1,
-	exectype_shell = 2
-};
-
-struct command {
-	int			 id;
-	uid_t			 user;
-	gid_t			 group;
-	char			*home;
-	char			**env;
-	
-	/* nsExtendConfigTable */
-	const char		*token;
-	size_t			 tokenlen;
-	char			*command;
-	char			**args;
-	char			*input;
-	int			 cachetime;
-	enum exectype		 exectype;
-
-	/* nsExtendOutput1Table */
-	struct timespec		 lastrun;
-	int			 running;
-	char			*output;
-	int			 result;
-
-	/* runtime */
-	pid_t			 pid;
-	int			 infd;
-	int			 outfd;
-	int			 errfd;
-	struct event		 inev;
-	struct event		 outev;
-	struct event		 errev;
-	char			*inputcont;
-	char			 errstr[1024];
-
-	RB_ENTRY(command)	 entry;
-};
-
-struct extends {
-	RB_HEAD(commands, command) commands;
-};
-
-int command_cmp(struct command *, struct command *);
-
-struct extends *parse_config(const char *);
-int cmdline_symset(char *);
-
-RB_PROTOTYPE(commands, command, entry, command_cmp);
blob - /dev/null
blob + a390bceb558f33f0c96db79f4ca805a5f8c15561 (mode 644)
--- /dev/null
+++ extend.h
@@ -0,0 +1,104 @@
+/*	$OpenBSD$	*/
+
+/*
+ * Copyright (c) 2026 Martijn van Duren <martijn@openbsd.org>
+ *
+ * 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 <sys/tree.h>
+
+#include <event.h>
+#include <time.h>
+
+#ifndef CONFFILE
+#define CONFFILE "/etc/snmpd_extend.conf"
+#endif
+
+#define MIB_NETSNMP			AGENTX_ENTERPRISES, 8072
+#define MIB_NETSNMPOBJECTS		MIB_NETSNMP, 1
+#define MIB_NSEXTENSIONS		MIB_NETSNMPOBJECTS, 3
+#define MIB_NSEXTENDOBJECTS		MIB_NSEXTENSIONS, 2
+#define MIB_NSEXTENDNUMENTRIES		MIB_NSEXTENDOBJECTS, 1
+#define MIB_NSEXTENDCONFIGTABLE		MIB_NSEXTENDOBJECTS, 2
+#define MIB_NSEXTENDCONFIGENTRY		MIB_NSEXTENDCONFIGTABLE, 1
+#define MIB_NSEXTENDTOKEN		MIB_NSEXTENDCONFIGENTRY, 1
+#define MIB_NSEXTENDCOMMAND		MIB_NSEXTENDCONFIGENTRY, 2
+#define MIB_NSEXTENDARGS		MIB_NSEXTENDCONFIGENTRY, 3
+#define MIB_NSEXTENDINPUT		MIB_NSEXTENDCONFIGENTRY, 4
+#define MIB_NSEXTENDCACHETIME		MIB_NSEXTENDCONFIGENTRY, 5
+#define MIB_NSEXTENDEXECTYPE		MIB_NSEXTENDCONFIGENTRY, 6
+#define MIB_NSEXTENDRUNTYPE		MIB_NSEXTENDCONFIGENTRY, 7
+#define MIB_NSEXTENDSTORAGE		MIB_NSEXTENDCONFIGENTRY, 20
+#define MIB_NSEXTENDSTATUS		MIB_NSEXTENDCONFIGENTRY, 21
+#define MIB_NSEXTENDOUTPUT1TABLE	MIB_NSEXTENDOBJECTS, 3
+#define MIB_NSEXTENDOUTPUT1ENTRY	MIB_NSEXTENDOUTPUT1TABLE, 1
+#define MIB_NSEXTENDOUTPUT1LINE		MIB_NSEXTENDOUTPUT1ENTRY, 1
+#define MIB_NSEXTENDOUTPUTFULL		MIB_NSEXTENDOUTPUT1ENTRY, 2
+#define MIB_NSEXTENDOUTPUTNUMLINES	MIB_NSEXTENDOUTPUT1ENTRY, 3
+#define MIB_NSEXTENDRESULT		MIB_NSEXTENDOUTPUT1ENTRY, 4
+#define MIB_NSEXTENDOUTPUT2TABLE	MIB_NSEXTENDOBJECTS, 4
+#define MIB_NSEXTENDOUTPUT2ENTRY	MIB_NSEXTENDOUTPUT2TABLE, 1
+#define MIB_NSEXTENDLINEINDEX		MIB_NSEXTENDOUTPUT2ENTRY, 1
+#define MIB_NSEXTENDOUTLINE		MIB_NSEXTENDOUTPUT2ENTRY, 2
+
+enum exectype {
+	exectype_exec = 1,
+	exectype_shell = 2
+};
+
+struct command {
+	int			 id;
+	uid_t			 user;
+	gid_t			 group;
+	char			*home;
+	char			**env;
+	
+	/* nsExtendConfigTable */
+	const char		*token;
+	size_t			 tokenlen;
+	char			*command;
+	char			**args;
+	char			*input;
+	int			 cachetime;
+	enum exectype		 exectype;
+
+	/* nsExtendOutput1Table */
+	struct timespec		 lastrun;
+	int			 running;
+	char			*output;
+	int			 result;
+
+	/* runtime */
+	pid_t			 pid;
+	int			 infd;
+	int			 outfd;
+	int			 errfd;
+	struct event		 inev;
+	struct event		 outev;
+	struct event		 errev;
+	char			*inputcont;
+	char			 errstr[1024];
+
+	RB_ENTRY(command)	 entry;
+};
+
+struct extends {
+	RB_HEAD(commands, command) commands;
+};
+
+int command_cmp(struct command *, struct command *);
+
+struct extends *parse_config(const char *);
+int cmdline_symset(char *);
+
+RB_PROTOTYPE(commands, command, entry, command_cmp);
blob - 17a1d7f37dcf4a1da2244d92497006ee405e485a
blob + 13bf5968a29746a6ec48a0174f1b787dc4074fad
--- main.c
+++ main.c
@@ -37,7 +37,7 @@
 #include <syslog.h>
 #include <unistd.h>
 
-#include <extends.h>
+#include "extend.h"
 #include "log.h"
 
 enum imsg_type {
blob - 320c412c84846537ddcc069653be9c678513ca40
blob + 2047f88403419209a8c38fd5d918e2cfb185c676
--- parse.y
+++ parse.y
@@ -39,7 +39,7 @@
 #include <syslog.h>
 #include <unistd.h>
 
-#include "extends.h"
+#include "extend.h"
 #include "log.h"
 
 TAILQ_HEAD(files, file)		 files = TAILQ_HEAD_INITIALIZER(files);
blob - 2e6f84343449c64a2aa59dc0f774b601bccc9698 (mode 644)
blob + /dev/null
--- snmpd_extends.8
+++ /dev/null
@@ -1,55 +0,0 @@
-.\"	$OpenBSD$
-.\"
-.\" Copyright (c) 2026 Martijn van Duren <martijn@openbsd.org>
-.\"
-.\" 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.
-.\"
-.Dd $Mdocdate$
-.Dt SNMPD_EXTENDS 8
-.Os
-.Sh NAME
-.Nm snmpd_extends
-.Nd export net-snmp compatible extends
-.Sh SYNOPSIS
-.Nm
-.Op Fl dv
-.Op Fl C Ar context
-.Op Fl c Ar file
-.Op Fl s Ar path
-.Sh DESCRIPTION
-.Nm
-Execute arbitrary executables, and export results via NET-SNMP-EXTEND-MIB.
-.Pp
-The options are as follows:
-.Bl -tag -width Ds
-.It Fl C Ar context
-The SNMPv3 context and can usually be omitted.
-.It Fl c Ar file
-The config file. Defaults to
-.Pa /etc/snmpd_extends.conf .
-.It Fl d
-Do not daemonize and log to
-.Em stderr .
-.It Fl s Ar path
-Connect to the AgentX master via
-.Ar path .
-It defaults to
-.Pa /var/agentx/master .
-.It Fl v
-Produce more verbose output.
-.El
-.Sh SEE ALSO
-.Xr snmp 1 ,
-.Xr snmpd 8
-.Sh AUTHORS
-.An Martijn van Duren Aq Mt martijn@openbsd.org
blob - /dev/null
blob + 0bad91b977354de9ccfbf0c1a50249a71bee61aa (mode 644)
--- /dev/null
+++ snmpd_extend.8
@@ -0,0 +1,55 @@
+.\"	$OpenBSD$
+.\"
+.\" Copyright (c) 2026 Martijn van Duren <martijn@openbsd.org>
+.\"
+.\" 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.
+.\"
+.Dd $Mdocdate$
+.Dt SNMPD_EXTEND 8
+.Os
+.Sh NAME
+.Nm snmpd_extend
+.Nd export net-snmp compatible extends
+.Sh SYNOPSIS
+.Nm
+.Op Fl dv
+.Op Fl C Ar context
+.Op Fl c Ar file
+.Op Fl s Ar path
+.Sh DESCRIPTION
+.Nm
+Execute arbitrary executables, and export results via NET-SNMP-EXTEND-MIB.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl C Ar context
+The SNMPv3 context and can usually be omitted.
+.It Fl c Ar file
+The config file. Defaults to
+.Pa /etc/snmpd_extend.conf .
+.It Fl d
+Do not daemonize and log to
+.Em stderr .
+.It Fl s Ar path
+Connect to the AgentX master via
+.Ar path .
+It defaults to
+.Pa /var/agentx/master .
+.It Fl v
+Produce more verbose output.
+.El
+.Sh SEE ALSO
+.Xr snmp 1 ,
+.Xr snmpd 8
+.Sh AUTHORS
+.An Martijn van Duren Aq Mt martijn@openbsd.org
blob - a851aaf6510e4089175ff369a70df3fc3d8e9867 (mode 644)
blob + /dev/null
--- snmpd_extends.conf.5
+++ /dev/null
@@ -1,186 +0,0 @@
-.\" $OpenBSD$
-.\"
-.\" Copyright (c) 2026 Martijn van Duren <martijn@openbsd.org>
-.\"
-.\" 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.
-.\"
-.Dd $Mdocdate$
-.Dt SNMPD_EXTENDS.CONF 5
-.Os
-.Sh NAME
-.Nm snmpd_extends.conf
-.Nd SNMP extends configuration file
-.Sh DESCRIPTION
-.Nm
-is the configuration file for the
-.Xr snmpd_extends 8
-daemon.
-.Pp
-The
-.Nm
-file is divided into the following main sections:
-.Bl -tag -width xxxx
-.It Sx Macros
-Definitions of variables that can be used later, simplifying the
-configuration file.
-.It Sx Extends configuration
-Definitions of commands to be exported via
-.Xr snmpd_extends 8 .
-.El
-.Pp
-The current line can be extended over multiple lines using a backslash
-.Pq Sq \e .
-Comments can be put anywhere in the file using a hash mark
-.Pq Sq # ,
-and extend to the end of the current line.
-Care should be taken when commenting out multi-line text:
-the comment is effective until the end of the entire block.
-.Pp
-Arguments not beginning with a letter, digit, or underscore
-must be quoted.
-.Pp
-Additional configuration files can be included with the
-.Ic include
-keyword, for example:
-.Bd -literal -offset indent
-include "/etc/snmpd_extends.conf.local"
-.Ed
-.Ss Macros
-A macro is defined with a command of the form
-.Ar name Ns = Ns Ar value .
-The macro
-.Ar name
-can contain letters, digits, and underscores and cannot be a reserved word
-(for example,
-.Ic command ,
-.Ic args ,
-or
-.Ic user ) .
-Within unquoted arguments, the string
-.Pf $ Ar name
-is later expanded to
-.Ar value .
-.Pp
-For example:
-.Bd -literal -offset indent
-username="localuser"
-echo {
-	args "$USER"
-	user $username
-	exectype shell
-}
-.Ed
-.Ss Extends configuration
-Each
-.Ic extend
-section starts with the declaration of an extend
-.Ar token :
-.Bl -tag -width Ds
-.It Ar token Brq ...
-The
-.Ar token
-must contain ASCII characters and can't be more than 113 characters long.
-This is used as the index into the 3 NET-SNMP-EXTEND-MIB tables.
-.El
-.Pp
-The block enclosed in curly braces can contain the following parameters:
-.Bl -tag -width Ds
-.It Ic args Ar argumentlist
-A list of strings separated by spaces used as the arguments for the command.
-Double quotes surrounding a string aren't copied to the final command.
-In
-.Ic exectype Ic shell
-mode, if an argument needs to be quoted it must be added explicitly.
-See
-.Sx EXAMPLES .
-.It Ic cachetime Ar seconds
-The amount of
-.Ar seconds
-the result of a command is cached, rounded up, before executing again.
-It defaults to 5 seconds.
-.It Ic command Ar command
-The
-.Ar command
-to be executed.
-It defaults to
-.Ar token .
-.It Ic env Ar environment
-A list of strings in the standard
-.Xr environ 7
-form of
-.Ar name Ns = Ns Ar value .
-This overwrites any default values set.
-.It Ic exectype Pq Ic exec | Ic shell
-Determines if the extend should be exected as stated via
-.Ic exec ,
-or first interpreted by
-.Pa /bin/sh
-via
-.Ic shell .
-It defaults to
-.Ic exec .
-.It Ic group Ar group
-Execute the extend as group
-.Ar group .
-It defaults to the
-.Ar user Ns 's
-primary group, and falls back to the _snmpd group.
-.It Ic home Ar home
-Changes to this directory before executing, and set as
-.Ev HOME
-in the default
-.Ic env .
-It defaults to the
-.Ar user
-home directory, or
-.Pa /var/empty
-if none can be found.
-.It Ic input Ar input
-Input to the stdin of the executed extend.
-.It Ic user Ar user
-Execute the extend as user
-.Ar user .
-It defaults to the _snmpd user.
-.Sh FILES
-.Bl -tag -width /etc/snmpd_extends.conf -compact
-.It Pa /etc/snmpd_extends.conf
-Default location of the configuration file.
-.El
-.Sh EXAMPLES
-The following example will tell
-.Xr snmpd_extends 8
-to list the content of your music collection:
-.Bd -literal -offset indent
-music {
-	command ls
-	args "-d" "*/*"
-	home "/home/user/Music"
-	exectype shell
-}
-.Ed
-The following example adds required quotes to a shell command:
-.Bd -literal -offset indent
-quote {
-	command "printf"
-	args "%s\en" "\e"$HOME\e""
-	exectype shell
-}
-.Sh SEE ALSO
-.Xr snmpd_extends 8
-.Xr snmp 1 ,
-.Xr snmpd 8
-.Sh AUTHORS
-The
-.Xr snmpd_extends 8
-program was written by
-.An Martijn van Duren Aq Mt martijn@openbsd.org .
blob - /dev/null
blob + a014228348348c83b5fef64c86631a56890f894d (mode 644)
--- /dev/null
+++ snmpd_extend.conf.5
@@ -0,0 +1,186 @@
+.\" $OpenBSD$
+.\"
+.\" Copyright (c) 2026 Martijn van Duren <martijn@openbsd.org>
+.\"
+.\" 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.
+.\"
+.Dd $Mdocdate$
+.Dt SNMPD_EXTEND.CONF 5
+.Os
+.Sh NAME
+.Nm snmpd_extend.conf
+.Nd SNMP extend configuration file
+.Sh DESCRIPTION
+.Nm
+is the configuration file for the
+.Xr snmpd_extend 8
+daemon.
+.Pp
+The
+.Nm
+file is divided into the following main sections:
+.Bl -tag -width xxxx
+.It Sx Macros
+Definitions of variables that can be used later, simplifying the
+configuration file.
+.It Sx Extends configuration
+Definitions of commands to be exported via
+.Xr snmpd_extend 8 .
+.El
+.Pp
+The current line can be extended over multiple lines using a backslash
+.Pq Sq \e .
+Comments can be put anywhere in the file using a hash mark
+.Pq Sq # ,
+and extend to the end of the current line.
+Care should be taken when commenting out multi-line text:
+the comment is effective until the end of the entire block.
+.Pp
+Arguments not beginning with a letter, digit, or underscore
+must be quoted.
+.Pp
+Additional configuration files can be included with the
+.Ic include
+keyword, for example:
+.Bd -literal -offset indent
+include "/etc/snmpd_extend.conf.local"
+.Ed
+.Ss Macros
+A macro is defined with a command of the form
+.Ar name Ns = Ns Ar value .
+The macro
+.Ar name
+can contain letters, digits, and underscores and cannot be a reserved word
+(for example,
+.Ic command ,
+.Ic args ,
+or
+.Ic user ) .
+Within unquoted arguments, the string
+.Pf $ Ar name
+is later expanded to
+.Ar value .
+.Pp
+For example:
+.Bd -literal -offset indent
+username="localuser"
+echo {
+	args "$USER"
+	user $username
+	exectype shell
+}
+.Ed
+.Ss Extends configuration
+Each
+.Ic extend
+section starts with the declaration of an extend
+.Ar token :
+.Bl -tag -width Ds
+.It Ar token Brq ...
+The
+.Ar token
+must contain ASCII characters and can't be more than 113 characters long.
+This is used as the index into the 3 NET-SNMP-EXTEND-MIB tables.
+.El
+.Pp
+The block enclosed in curly braces can contain the following parameters:
+.Bl -tag -width Ds
+.It Ic args Ar argumentlist
+A list of strings separated by spaces used as the arguments for the command.
+Double quotes surrounding a string aren't copied to the final command.
+In
+.Ic exectype Ic shell
+mode, if an argument needs to be quoted it must be added explicitly.
+See
+.Sx EXAMPLES .
+.It Ic cachetime Ar seconds
+The amount of
+.Ar seconds
+the result of a command is cached, rounded up, before executing again.
+It defaults to 5 seconds.
+.It Ic command Ar command
+The
+.Ar command
+to be executed.
+It defaults to
+.Ar token .
+.It Ic env Ar environment
+A list of strings in the standard
+.Xr environ 7
+form of
+.Ar name Ns = Ns Ar value .
+This overwrites any default values set.
+.It Ic exectype Pq Ic exec | Ic shell
+Determines if the extend should be exected as stated via
+.Ic exec ,
+or first interpreted by
+.Pa /bin/sh
+via
+.Ic shell .
+It defaults to
+.Ic exec .
+.It Ic group Ar group
+Execute the extend as group
+.Ar group .
+It defaults to the
+.Ar user Ns 's
+primary group, and falls back to the _snmpd group.
+.It Ic home Ar home
+Changes to this directory before executing, and set as
+.Ev HOME
+in the default
+.Ic env .
+It defaults to the
+.Ar user
+home directory, or
+.Pa /var/empty
+if none can be found.
+.It Ic input Ar input
+Input to the stdin of the executed extend.
+.It Ic user Ar user
+Execute the extend as user
+.Ar user .
+It defaults to the _snmpd user.
+.Sh FILES
+.Bl -tag -width /etc/snmpd_extend.conf -compact
+.It Pa /etc/snmpd_extend.conf
+Default location of the configuration file.
+.El
+.Sh EXAMPLES
+The following example will tell
+.Xr snmpd_extend 8
+to list the content of your music collection:
+.Bd -literal -offset indent
+music {
+	command ls
+	args "-d" "*/*"
+	home "/home/user/Music"
+	exectype shell
+}
+.Ed
+The following example adds required quotes to a shell command:
+.Bd -literal -offset indent
+quote {
+	command "printf"
+	args "%s\en" "\e"$HOME\e""
+	exectype shell
+}
+.Sh SEE ALSO
+.Xr snmpd_extend 8
+.Xr snmp 1 ,
+.Xr snmpd 8
+.Sh AUTHORS
+The
+.Xr snmpd_extend 8
+program was written by
+.An Martijn van Duren Aq Mt martijn@openbsd.org .