Project

General

Profile

Feature #426 » mod-auth-ticket-for-lighttpd-1.4.52.patch

Buffer patches for mod-auth-ticket. - flynn, 2018-12-26 16:05

View differences:

Makefile
1 1
## EDIT BELOW AS NEEDED ##
2 2

  
3 3
# Where lighttpd source tarball is extracted
4
LIGHTTPD_DIR = /d/src/lighttpd/1.4.x
4
LIGHTTPD_DIR = /usr/src/lighttpd-1.4.52
5 5
#LIGHTTPD_DIR = /d/src/lighttpd-1.4.29
6 6
#LIGHTTPD_DIR = /d/src/lighttpd-1.4.28
7 7

  
base64.c
34 34

  
35 35
	size_t in_len = strlen(in);
36 36

  
37
	buffer_prepare_copy(out, in_len);
37
	buffer_string_prepare_copy(out, in_len);
38 38

  
39 39
	result = (unsigned char *)out->ptr;
40 40

  
mod_auth_ticket.c
15 15
//
16 16

  
17 17
#include <ctype.h>
18
#include <stdlib.h>
18 19
#include <string.h>
19 20
#include <stdio.h>
20 21

  
22
#include "base.h"
21 23
#include "plugin.h"
22 24
#include "log.h"
23 25
#include "response.h"
......
138 140
    buffer_append_string_encoded(url, CONST_BUF_LEN(con->uri.scheme), enc);
139 141
    buffer_append_string_encoded(url, CONST_STR_LEN("://"), enc);
140 142
    buffer_append_string_encoded(url, CONST_BUF_LEN(con->uri.authority), enc);
141
    buffer_append_string_encoded(url, CONST_BUF_LEN(con->request.uri), enc);
143
    buffer_append_string_encoded(url, CONST_BUF_LEN(con->request.orig_uri), enc);
142 144
    return url;
143 145
}
144 146

  
......
158 160
    buffer *url = buffer_init_buffer(pc->authurl);
159 161
    buffer_append_string(url, strchr(url->ptr, '?') ? "&url=" : "?url=");
160 162
    self_url(con, url, ENCODING_REL_URI);
161
    response_header_insert(srv, con, 
162
                           CONST_STR_LEN("Location"), CONST_BUF_LEN(url));
163
    response_header_insert(srv, con, CONST_STR_LEN("Location"), CONST_BUF_LEN(url));
163 164
    buffer_free(url);
164 165

  
165 166
    // prepare response
......
178 179
// generate hex-encoded random string
179 180
static int
180 181
gen_random(buffer *b, int len) {
181
    buffer_prepare_append(b, len);
182
    buffer_string_prepare_append(b, len);
182 183
    while (len--) {
183 184
        char c = int2hex(rand() >> 24);
184
        buffer_append_memory(b, &c, 1);
185
        buffer_append_string_len(b, &c, 1);
185 186
    }
186 187
    return 0;
187 188
}
188 189

  
189 190
// encode bytes into hexstring
190
static int
191
static void
191 192
hex_encode(buffer *b, const uint8_t *s, int len) {
192
    return buffer_copy_string_hex(b, (const char *)s, len);
193
    buffer_append_string_encoded_hex_lc(b, (const char *)s, len);
193 194
}
194 195

  
195 196
// decode hexstring into bytes
......
197 198
hex_decode(buffer *b, const char *s) {
198 199
    char c0, c1;
199 200

  
200
    buffer_prepare_append(b, strlen(s) >> 1);
201
    buffer_string_prepare_append(b, strlen(s) >> 1);
201 202
    while ((c0 = *s++) && (c1 = *s++)) {
202 203
        char v = (hex2int(c0) << 4) | hex2int(c1);
203
        buffer_append_memory(b, &v, 1);
204
        buffer_append_string_len(b, &v, 1);
204 205
    }
205 206
    return 0;
206 207
}
......
257 258
    // generate random token and relate it with authinfo
258 259
    gen_random(token = buffer_init(), MD5_LEN * 2); // length in hex string
259 260
    DEBUG("sb", "pairing authinfo with token:", token);
260
    buffer_copy_long(field, time(NULL));
261
    buffer_copy_int(field, time(NULL));
261 262
    buffer_append_string(field, ":");
262 263
    
263 264
    //rescbr: bugfix: authinfo does not end with \0
......
265 266
    array_set_key_value(pd->users, CONST_BUF_LEN(token), CONST_BUF_LEN(field));
266 267

  
267 268
    // insert opaque auth token
268
    buffer_copy_string_buffer(field, pc->name);
269
    buffer_copy_buffer(field, pc->name);
269 270
    buffer_append_string(field, "=token:");
270 271
    buffer_append_string_buffer(field, token);
271 272
    buffer_append_string(field, "; ");
......
593 594
        cv[6].destination = pc->options;
594 595

  
595 596
        array *ca = ((data_config *)srv->config_context->data[i])->value;
596
        if (config_insert_values_global(srv, ca, cv) != 0) {
597
        if (config_insert_values_global(srv, ca, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION) != 0) {
597 598
            return HANDLER_ERROR;
598 599
        }
599 600
    }
(3-3/3)