Commit f16f148f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use VENC instead of local b64 decoder.

parent d4406492
......@@ -8,9 +8,7 @@ bin_PROGRAMS = varnishncsa
varnishncsa_SOURCES = \
varnishncsa.c \
varnishncsa_options.h \
b64.h \
b64.c
varnishncsa_options.h
varnishncsa_LDADD = \
$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
......
/*
* Written by Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* This file is in the public domain.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "b64.h"
static const char b64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static char i64[256];
void
VB64_init(void)
{
int i;
const char *p;
for (i = 0; i < 256; i++)
i64[i] = -1;
for (p = b64, i = 0; *p; p++, i++)
i64[(int)*p] = (char)i;
i64['='] = 0;
}
int
VB64_decode(char *d, unsigned dlen, const char *s, const char *e)
{
unsigned u, v, l;
int i;
if (e == NULL)
e = s + strlen(s);
u = 0;
l = 0;
while (s < e) {
for (v = 0; s < e && v < 4; v++) {
i = i64[(int)*s++];
if (i < 0)
return (-1);
u <<= 6;
u |= i;
}
for (v = 0; v < 3; v++) {
if (l >= dlen - 1)
return (-1);
*d = (u >> 16) & 0xff;
u <<= 8;
l++;
d++;
}
}
*d = '\0';
return (0);
}
#ifdef TEST_DRIVER
#include <stdio.h> // for test-prog
const char *test1 =
"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"
"IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg"
"dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu"
"dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo"
"ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=";
int
main(int argc, char **argv)
{
int i;
char buf[BUFSIZ];
unsigned l;
(void)argc;
(void)argv;
VB64_init();
l = sizeof buf;
VB64_decode(buf, l, test1, NULL);
printf("%s\n", buf);
return (0);
}
#endif
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
void VB64_init(void);
int VB64_decode(char *d, unsigned dlen, const char *s, const char *e);
......@@ -58,10 +58,10 @@
#include "vdef.h"
#include "b64.h"
#include "vapi/vsl.h"
#include "vapi/voptget.h"
#include "vas.h"
#include "venc.h"
#include "vsb.h"
#include "vut.h"
#include "vqueue.h"
......@@ -361,21 +361,24 @@ format_requestline(const struct format *format)
static int v_matchproto_(format_f)
format_auth(const struct format *format)
{
char buf[128];
struct vsb *vsb = VSB_new_auto();
AN(vsb);
char *q;
if (CTX.frag[F_auth].gen != CTX.gen ||
VB64_decode(buf, sizeof buf, CTX.frag[F_auth].b,
CTX.frag[F_auth].e)) {
VENC_Decode_Base64(vsb, CTX.frag[F_auth].b, CTX.frag[F_auth].e)) {
VSB_destroy(&vsb);
if (format->string == NULL)
return (-1);
VSB_quote(CTX.vsb, format->string, -1, CTX.quote_how);
return (0);
}
q = strchr(buf, ':');
AZ(VSB_finish(vsb));
q = strchr(VSB_data(vsb), ':');
if (q != NULL)
*q = '\0';
VSB_quote(CTX.vsb, buf, -1, CTX.quote_how);
VSB_quote(CTX.vsb, VSB_data(vsb), -1, CTX.quote_how);
VSB_destroy(&vsb);
return (1);
}
......@@ -1160,7 +1163,6 @@ main(int argc, char * const *argv)
VTAILQ_INIT(&CTX.watch_vsl);
CTX.vsb = VSB_new_auto();
AN(CTX.vsb);
VB64_init();
CTX.quote_how = VSB_QUOTE_ESCHEX;
REPLACE(CTX.missing_string, "-");
REPLACE(CTX.missing_int, "-");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment