summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/basicauth.c23
-rw-r--r--src/basicauth.h6
-rw-r--r--src/conf.c12
-rw-r--r--src/conf.h2
4 files changed, 24 insertions, 19 deletions
diff --git a/src/basicauth.c b/src/basicauth.c
index d6c2420..ed0553b 100644
--- a/src/basicauth.c
+++ b/src/basicauth.c
@@ -48,10 +48,10 @@ ssize_t basicauth_string(const char *user, const char *pass,
/*
* Add entry to the basicauth list
*/
-void basicauth_add (vector_t authlist,
+void basicauth_add (sblist *authlist,
const char *user, const char *pass)
{
- char b[BASE64ENC_BYTES((256+2)-1) + 1];
+ char b[BASE64ENC_BYTES((256+2)-1) + 1], *s;
ssize_t ret;
ret = basicauth_string(user, pass, b, sizeof b);
@@ -65,7 +65,8 @@ void basicauth_add (vector_t authlist,
return;
}
- if (vector_append(authlist, b, ret + 1) == -ENOMEM) {
+ if (!(s = safestrdup(b)) || !sblist_add(authlist, &s)) {
+ safefree(s);
log_message (LOG_ERR,
"Unable to allocate memory in basicauth_add()");
return;
@@ -80,18 +81,16 @@ void basicauth_add (vector_t authlist,
* is in the basicauth list.
* return 1 on success, 0 on failure.
*/
-int basicauth_check (vector_t authlist, const char *authstring)
+int basicauth_check (sblist *authlist, const char *authstring)
{
- ssize_t vl, i;
- size_t el;
- const char* entry;
+ size_t i;
+ char** entry;
- vl = vector_length (authlist);
- if (vl == -EINVAL) return 0;
+ if (!authlist) return 0;
- for (i = 0; i < vl; i++) {
- entry = vector_getentry (authlist, i, &el);
- if (strcmp (authstring, entry) == 0)
+ for (i = 0; i < sblist_getsize(authlist); i++) {
+ entry = sblist_get (authlist, i);
+ if (entry && strcmp (authstring, *entry) == 0)
return 1;
}
return 0;
diff --git a/src/basicauth.h b/src/basicauth.h
index 61dc5c3..ef25b66 100644
--- a/src/basicauth.h
+++ b/src/basicauth.h
@@ -22,14 +22,14 @@
#define TINYPROXY_BASICAUTH_H
#include <stddef.h>
-#include "vector.h"
+#include "sblist.h"
extern ssize_t basicauth_string(const char *user, const char *pass,
char *buf, size_t bufsize);
-extern void basicauth_add (vector_t authlist,
+extern void basicauth_add (sblist *authlist,
const char *user, const char *pass);
-extern int basicauth_check (vector_t authlist, const char *authstring);
+extern int basicauth_check (sblist *authlist, const char *authstring);
#endif
diff --git a/src/conf.c b/src/conf.c
index b29c1fb..206ff3a 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -289,7 +289,7 @@ free_added_headers (sblist* add_headers)
void free_config (struct config_s *conf)
{
- char *k;
+ char *k, **s;
htab_value *v;
size_t it;
safefree (conf->logf_name);
@@ -297,7 +297,13 @@ void free_config (struct config_s *conf)
safefree (conf->user);
safefree (conf->group);
vector_delete(conf->listen_addrs);
- vector_delete(conf->basicauth_list);
+ if(conf->basicauth_list) {
+ for(it = 0; it < sblist_getsize(conf->basicauth_list); it++) {
+ s = sblist_get(conf->basicauth_list, it);
+ if(s) safefree(*s);
+ }
+ sblist_free(conf->basicauth_list);
+ }
#ifdef FILTER_ENABLE
safefree (conf->filter);
#endif /* FILTER_ENABLE */
@@ -915,7 +921,7 @@ static HANDLE_FUNC (handle_basicauth)
return -1;
}
if (!conf->basicauth_list) {
- conf->basicauth_list = vector_create ();
+ conf->basicauth_list = sblist_new (sizeof(char*), 16);
}
basicauth_add (conf->basicauth_list, user, pass);
diff --git a/src/conf.h b/src/conf.h
index c075215..1ba32f2 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -38,7 +38,7 @@ typedef struct {
* Hold all the configuration time information.
*/
struct config_s {
- vector_t basicauth_list;
+ sblist *basicauth_list;
char *logf_name;
unsigned int syslog; /* boolean */
unsigned int port;