convert tab to space in README - libgcgi - REST library for Gopher
HTML git clone git://bitreich.org/libgcgi git://hg6vgqziawt5s4dj.onion/libgcgi
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
DIR LICENSE
---
DIR commit 7a737dac78b68760118454337c2caeb6906fd90c
DIR parent b3f118ffbf6488c5e8897be2fa8e225d5149c394
HTML Author: Josuah Demangeon <me@josuah.net>
Date: Wed, 3 Aug 2022 23:59:08 +0200
convert tab to space in README
Diffstat:
M Makefile | 2 +-
M README | 146 ++++++++++++++++----------------
M index.c | 15 +++++++++++++++
3 files changed, 89 insertions(+), 74 deletions(-)
---
DIR diff --git a/Makefile b/Makefile
@@ -8,7 +8,7 @@ clean:
rm -f *.o index.cgi
README: libgcgi.3
- mandoc -Tutf8 libgcgi.3 | col -b | sed '1h; $$g' >$@
+ mandoc -Tutf8 libgcgi.3 | col -b | expand | sed '1h; $$g' >$@
index.cgi: index.c libgcgi.c libgcgi.h
${CC} ${LDFLAGS} ${CFLAGS} -o $@ index.c libgcgi.c ${LIBS}
DIR diff --git a/README b/README
@@ -1,4 +1,4 @@
-LIBGCGI(3) Library Functions Manual LIBGCGI(3)
+LIBGCGI(3) Library Functions Manual LIBGCGI(3)
NAME
gcgi_handle_request, gcgi_fatal, gcgi_template, gcgi_set_var,
@@ -42,7 +42,7 @@ SYNOPSIS
DESCRIPTION
This library is a C wrapper around the geomyidae(8) new CGI interface,
- which permits REST applications to be written for Gopher. In this mode,
+ which permits REST applications to be written for Gopher. In this mode,
geomyidae(8) directs all requests to a single binary in charge of
handling all paths, rather than trying to serve a file.
@@ -51,8 +51,8 @@ DESCRIPTION
appropriate handler depending on the query path.
struct gcgi_handler {
- char const *glob;
- void (*fn)(char **matches);
+ char const *glob;
+ void (*fn)(char **matches);
};
The glob is a string against which the path (everything in the query
@@ -63,103 +63,103 @@ DESCRIPTION
glob.
void gcgi_handle_request(struct gcgi_handler h[], int argc, char **argv)
- Given an array of handlers h, call the first function pointer
- that matches. argc and argv should be set to the program ones to
- extract the arguments given by geomyidae(8). The h struct is an
- array of struct gcgi_handler:
+ Given an array of handlers h, call the first function pointer
+ that matches. argc and argv should be set to the program ones to
+ extract the arguments given by geomyidae(8). The h struct is an
+ array of struct gcgi_handler:
Content Generation
According to geomyidae(8) behavior, the output format will be:
- • a raw gophermap if the binary is “index.cgi”,
- • a geomyidae(8) ‘gph’ format if the binary is “index.dcgi”.
+ • a raw gophermap if the binary is “index.cgi”,
+ • a geomyidae(8) ‘gph’ format if the binary is “index.dcgi”.
void gcgi_fatal(char *fmt, ...)
- Prints an error message formatted by fmt and exit(3) the program
- with status 1.
+ Prints an error message formatted by fmt and exit(3) the program
+ with status 1.
void gcgi_template(char const *path, struct gcgi_var_list *vars)
- Format the template at path replacing every occurence of
- “{{key}}” by the matching value by searching in vars.
+ Format the template at path replacing every occurence of
+ “{{key}}” by the matching value by searching in vars.
void gcgi_print_gophermap(char type, char *desc, char *path, char *host,
- char *port)
- Print a gophermap entry line with type, desc, path, host, port to
- be set to the chosen value as described in RFC 1436. Both host
- and port are NULL, default values will be used.
+ char *port)
+ Print a gophermap entry line with type, desc, path, host, port to
+ be set to the chosen value as described in RFC 1436. Both host
+ and port are NULL, default values will be used.
void gcgi_print_gph(char type, char *desc, char *path, char *host, char
- *port)
- Print a gph entry line with type, desc, path, host, port to be
- set to the chosen value as described in geomyidae(8) manual page.
- If host or port are NULL, default values will be used.
+ *port)
+ Print a gph entry line with type, desc, path, host, port to be
+ set to the chosen value as described in geomyidae(8) manual page.
+ If host or port are NULL, default values will be used.
Variable List Handling
A common data format is used for handling lists of variables:
- • For parsing a simple text-based database format and writing it back.
- • For storing the parsed query string in gcgi_gopher_query.
- • For passing variables to expand in the templates.
+ • For parsing a simple text-based database format and writing it back.
+ • For storing the parsed query string in gcgi_gopher_query.
+ • For passing variables to expand in the templates.
void gcgi_set_var(struct gcgi_var_list *vars, char *key, char *val)
- Overwrite with val the value of a variable matching key of vars.
- The key and val buffers are not duplicated, and must remain valid
- at all time they need to be accessible, such as through
- gcgi_get_var().
+ Overwrite with val the value of a variable matching key of vars.
+ The key and val buffers are not duplicated, and must remain valid
+ at all time they need to be accessible, such as through
+ gcgi_get_var().
char * gcgi_get_var(struct gcgi_var_list *vars, char *key)
- Get the value of the variable of vars matching key or NULL if
- none match.
+ Get the value of the variable of vars matching key or NULL if
+ none match.
void gcgi_free_var_list(struct gcgi_var_list *vars)
- Free memory used by a list of variable. This only frees the
- memory allocated by this library.
+ Free memory used by a list of variable. This only frees the
+ memory allocated by this library.
void gcgi_read_var_list(struct gcgi_var_list *vars, char *path)
- Store all variables from path onto variables in vars. The file
- format is similar to RFC822 messages or HTTP headers:
- • One line per variable, with a key=value format.
- • The key is everything at the beginning of the line until the
- occurence of “:”.
- • The value is everything after “: ”.
- • After the list of variables, an empty line declares the body
- of the message, which continues until the end and is stored in
- a “text” key.
+ Store all variables from path onto variables in vars. The file
+ format is similar to RFC822 messages or HTTP headers:
+ • One line per variable, with a key=value format.
+ • The key is everything at the beginning of the line until the
+ occurence of “:”.
+ • The value is everything after “: ”.
+ • After the list of variables, an empty line declares the body
+ of the message, which continues until the end and is stored in
+ a “text” key.
int gcgi_write_var_list(struct gcgi_var_list *vars, char *path)
- Encode the variable list vars into a new file at path. A
- temporary file will be created in the meantime, and the
- replacement will be atomic so that no partial write can occur.
- The “text” special key will be turned into the body of the
- message after an empty line instead of a variable on its own
- line.
+ Encode the variable list vars into a new file at path. A
+ temporary file will be created in the meantime, and the
+ replacement will be atomic so that no partial write can occur.
+ The “text” special key will be turned into the body of the
+ message after an empty line instead of a variable on its own
+ line.
Global Variables
These variables are filled with the components of the query. They will
only be valid after handle_request() is called.
char *gcgi_gopher_search
- From argv[1], this is the search string, passed after a tab in
- the gopher protocol for item type “7”.
+ From argv[1], this is the search string, passed after a tab in
+ the gopher protocol for item type “7”.
char *gcgi_gopher_path
- From argv[2], this is the query path. It is the full query
- without the search string and with the query string removed.
+ From argv[2], this is the query path. It is the full query
+ without the search string and with the query string removed.
struct gcgi_var_list gcgi_gopher_query
- From argv[2], this is the query string stored as a key-value
- gcgi_var_list. It is extracted from the part of the query after
- the “”?, usually formated as
- “?key1=value1&key2=value2&key3=value3”
+ From argv[2], this is the query string stored as a key-value
+ gcgi_var_list. It is extracted from the part of the query after
+ the “”?, usually formated as
+ “?key1=value1&key2=value2&key3=value3”
char *gcgi_gopher_host
- From argv[3], this is the current host name configured in
- geomyidae(8). It is what to use as a ‘host’ in links printed
- out.
+ From argv[3], this is the current host name configured in
+ geomyidae(8). It is what to use as a ‘host’ in links printed
+ out.
char *gcgi_gopher_port
- From argv[4], this is the current port number configured in
- geomyidae(8). It is what to use as a ‘port’ in links printed
- out.
+ From argv[4], this is the current port number configured in
+ geomyidae(8). It is what to use as a ‘port’ in links printed
+ out.
EXAMPLES
#include "libgcgi.h"
@@ -167,25 +167,25 @@ EXAMPLES
/* implementation of each handler here */
static struct gcgi_handler handlers[] = {
- { "/", page_home },
- { "/song", page_song_list },
- { "/song/*", page_song_item },
- { "*", page_not_found },
- { NULL, NULL },
+ { "/", page_home },
+ { "/song", page_song_list },
+ { "/song/*", page_song_item },
+ { "*", page_not_found },
+ { NULL, NULL },
};
int
main(int argc, char **argv)
{
- /* privilege dropping, chroot and/or syscall restriction here */
+ /* privilege dropping, chroot and/or syscall restriction here */
- gcgi_handle_request(handlers, argv, argc);
- return 0;
+ gcgi_handle_request(handlers, argv, argc);
+ return 0;
}
ENVIRONMENT VARIABLES
libgcgi does not use environment variable, but the application code can
- make use of them. The environment variables applied to geomyidae(8) will
+ make use of them. The environment variables applied to geomyidae(8) will
be inherited and accessible.
BUGS
@@ -198,7 +198,7 @@ CAVEATS
The Gopher protocol is not designed for file upload. A dedicated file
upload protocol such as SFTP or FTP may be used instead.
- The Gopher protocol is not designed for dynamic scripting. A dedicated
+ The Gopher protocol is not designed for dynamic scripting. A dedicated
remote interface protocol such as SSH or telnet may be used instead.
SEE ALSO
@@ -208,4 +208,4 @@ AUTHORS
Josuah Demangeon <me@josuah.net>
gopher://bitreich.org: The Bitreich Project
-LIBGCGI(3) Library Functions Manual LIBGCGI(3)
+LIBGCGI(3) Library Functions Manual LIBGCGI(3)
DIR diff --git a/index.c b/index.c
@@ -34,6 +34,21 @@ main(int argc, char **argv)
gcgi_fatal("unveil failed: %s", strerror(errno));
if (pledge("stdio rpath wpath cpath", NULL) == -1)
gcgi_fatal("pledge failed: %s", strerror(errno));
+#elif defined(__linux__)
+ scmp_filter_ctx ctx;
+ if (chroot(".") == -1)
+ gcgi_fatal("chroot failed");
+ if ((ctx = seccomp_init(SCMP_ACT_KILL)) == NULL)
+ gcgi_fatal("seccomp_init failed: %s", strerror(errno));
+ if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(open), 0) < 0
+ || seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit), 0) < 0
+ || seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0) < 0
+ || seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(read), 0) < 0
+ || seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(write), 1,
+ SCMP_A0(SCMP_CMP_EQ, 0)) < 0)
+ gcgi_fatal("seccomp_rule_add failed");
+ if (seccomp_load(ctx) < 0)
+ gcgi_fatal("seccomp_load failed: %s", strerror(errno));
#else
#warning "no syscall restriction enabled"
#endif