aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 13:51:58 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-11-01 14:01:54 +0200
commit43ad26ba4149be4700ea60ad0750454bc9420c4b (patch)
tree6e5777f849f5fd557fa2e5885d38cfc927510eea /src
parent94e89bc0207394e49295bdeade92d8a6322a8aa7 (diff)
downloadvmod-basicauth-43ad26ba4149be4700ea60ad0750454bc9420c4b.tar.gz
vmod-basicauth-43ad26ba4149be4700ea60ad0750454bc9420c4b.tar.bz2
Support for VCL 4.0
* NEWS: Update. * configure.ac: Version 1.2.90 Detect varnish version. * src/.gitignore: Update. * src/Makefile.am: Always build vcc_if.c and vcc_if.h, don't include them in the distribution. (.vcc.vcc3): New implicit rule for VCL 3.0 * src/vmod_basicauth.c: Include config.h. Define varnish datatypes depending on the value of VARNISHVERSION. (vmod_match): Change declaration. * src/vmod_basicauth.vcc: Rewrite.
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am31
-rw-r--r--src/vmod_basicauth.c15
-rw-r--r--src/vmod_basicauth.vcc57
4 files changed, 91 insertions, 13 deletions
diff --git a/src/.gitignore b/src/.gitignore
index 7f6e438..ce7aef0 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,2 +1,3 @@
vcc_if.c
vcc_if.h
+*.rst
diff --git a/src/Makefile.am b/src/Makefile.am
index 983bee9..6ddcf41 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
# This file is part of vmod-basicauth
-# Copyright (C) 2013 Sergey Poznyakoff
+# Copyright (C) 2013-2014 Sergey Poznyakoff
#
# Vmod-basicauth is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -29,17 +29,34 @@ libvmod_basicauth_la_SOURCES = \
md5.c\
sha1.c\
sha1.h\
- vcc_if.c \
- vcc_if.h \
vmod_basicauth.c
-BUILT_SOURCES = vcc_if.c vcc_if.h
+nodist_libvmod_basicauth_la_SOURCES = vcc_if.c vcc_if.h
-vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_basicauth.vcc
- @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_basicauth.vcc
+vmod_basicauth.lo: vcc_if.h
+
+CLEANFILES = vcc_if.c vcc_if.h *.rst
+
+if VARNISH4
+ vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py
+ vmodtoolargs = --strict
+ vccfile = $(top_srcdir)/src/vmod_basicauth.vcc
+else
+ vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py
+ vmodtoolargs =
+ vccfile = vmod_basicauth.vcc3
+
+vmod_basicauth.vcc3: $(top_srcdir)/src/vmod_basicauth.vcc
+ CLEANFILES += vmod_basicauth.vcc3
+endif
+
+.vcc.vcc3:
+ sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@
+
+vcc_if.c vcc_if.h: $(vmodtool) $(vccfile)
+ @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile)
EXTRA_DIST = \
vmod_basicauth.vcc
-CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
diff --git a/src/vmod_basicauth.c b/src/vmod_basicauth.c
index c63f7fa..3563c20 100644
--- a/src/vmod_basicauth.c
+++ b/src/vmod_basicauth.c
@@ -15,6 +15,7 @@
along with vmod-basicauth. If not, see <http://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -26,6 +27,15 @@
#include "vrt.h"
#include "vcc_if.h"
+#include "pthread.h"
+#if VARNISHVERSION == 3
+# define VCL_VOID void
+# define VCL_BOOL unsigned
+# define VCL_STRING const char *
+# define MOD_CTX struct sess *
+#else
+# define MOD_CTX const struct vrt_ctx *
+#endif
#include "basicauth.h"
#include "sha1.h"
@@ -169,9 +179,8 @@ match(const char *pass, const char *hash, struct priv_data *pd)
#define BASICPREF "Basic "
#define BASICLEN (sizeof(BASICPREF)-1)
-unsigned
-vmod_match(struct sess *sp, struct vmod_priv *priv,
- const char *file, const char *s)
+VCL_BOOL
+vmod_match(MOD_CTX sp, struct vmod_priv *priv, VCL_STRING file, VCL_STRING s)
{
char buf[1024];
char lbuf[1024];
diff --git a/src/vmod_basicauth.vcc b/src/vmod_basicauth.vcc
index 35ac3c7..cda0d66 100644
--- a/src/vmod_basicauth.vcc
+++ b/src/vmod_basicauth.vcc
@@ -1,4 +1,55 @@
-Module basicauth
-Init init_function
-Function BOOL match(PRIV_VCL, STRING, STRING)
+# This file is part of vmod-basicauth
+# Copyright (C) 2013-2014 Sergey Poznyakoff
+#
+# Vmod-basicauth is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Vmod-basicauth is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with vmod-basicauth. If not, see <http://www.gnu.org/licenses/>.
+$Module basicauth 3 Basic HTTP authentication
+
+COLOPHON
+========
+This document provides a short description of the **vmod-basicauth** module.
+For a detailed documentation, please see the vmod-basicauth(3) manual page.
+
+DESCRIPTION
+===========
+The **vmod-basicauth** module implements basic HTTP authentication against
+the password file created using the **htpasswd** command.
+
+Four kinds of password hashes are supported: Apache MD5, crypt, SHA1,
+and plaintext.
+
+$Init init_function
+$Function BOOL match(PRIV_VCL, STRING, STRING)
+
+Description
+ The **match** function returns **TRUE** or **FALSE** depending on whether
+ the authentication succeeds or not. The *passfile* argument supplies the
+ name of the password file to use. The *authstr* argument is the
+ authentication string (normally, the value of the Authorization HTTP
+ header).
+
+Example
+ ::
+
+ if (!basicauth.match("/var/www/.htpasswd", req.http.Authorization)) {
+ return(synth(401, "Restricted"));
+ }
+
+SEE ALSO
+========
+
+* vcl(7)
+* varnishd(1)
+
+ \ No newline at end of file

Return to:

Send suggestions and report system problems to the System administrator.